Java Code Examples for io.aeron.archive.Archive#Context

The following examples show how to use io.aeron.archive.Archive#Context . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuyerApplication.java    From artio with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws InterruptedException
{
    System.setProperty(CONTROL_CHANNEL_PROP_NAME, "aeron:udp?endpoint=localhost:9010");
    System.setProperty(CONTROL_RESPONSE_CHANNEL_PROP_NAME, "aeron:udp?endpoint=localhost:9020");

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true)
        .aeronDirectoryName(AERON_DIRECTORY_NAME);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true)
        .aeronDirectoryName(AERON_DIRECTORY_NAME)
        .recordingEventsChannel(RECORDING_EVENTS_CHANNEL);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext))
    {
        SampleUtil.runAgentUntilSignal(
            new BuyerAgent(),
            driver.mediaDriver());
    }
}
 
Example 2
Source File: TestFixtures.java    From artio with Apache License 2.0 5 votes vote down vote up
public static ArchivingMediaDriver launchMediaDriver(final MediaDriver.Context context)
{
    final Archive.Context archiveCtx = new Archive.Context()
        .deleteArchiveOnStart(context.dirDeleteOnStart())
        .segmentFileLength(context.ipcTermBufferLength());

    final ArchivingMediaDriver mediaDriver = ArchivingMediaDriver.launch(context, archiveCtx);
    archiveCtx.threadingMode(ArchiveThreadingMode.INVOKER);
    final String aeronDirectoryName = context.aeronDirectoryName();
    CloseChecker.onOpen(aeronDirectoryName, mediaDriver);

    return mediaDriver;
}
 
Example 3
Source File: SoleMediaDriver.java    From artio with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args)
{
    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(context, archiveContext))
    {
        StressUtil.awaitKeyPress();
    }
}
 
Example 4
Source File: Server.java    From artio with Apache License 2.0 5 votes vote down vote up
public Server()
{
    final AuthenticationStrategy authenticationStrategy = logon -> true;

    // Static configuration lasts the duration of a FIX-Gateway instance
    final String aeronChannel = "aeron:udp?endpoint=localhost:10000";
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", StressConfiguration.PORT)
        .logFileDir("stress-server-logs")
        .libraryAeronChannel(aeronChannel)
        .sessionPersistenceStrategy(alwaysPersistent());

    configuration
        .authenticationStrategy(authenticationStrategy)
        .agentNamePrefix("server-");

    System.out.println("Server Logs at " + configuration.logFileDir());

    StressUtil.cleanupOldLogFileDir(configuration);

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(ThreadingMode.SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    mediaDriver = ArchivingMediaDriver.launch(context, archiveContext);
    fixEngine = FixEngine.launch(configuration);

    final LibraryConfiguration libraryConfiguration = new LibraryConfiguration();
    libraryConfiguration
        .agentNamePrefix("server-");

    fixLibrary = blockingConnect(libraryConfiguration
        .sessionAcquireHandler((session, acquiredInfo) -> new StressSessionHandler(session))
        .sessionExistsHandler(new AcquiringSessionExistsHandler(true))
        .libraryAeronChannels(singletonList(aeronChannel)));
}
 
Example 5
Source File: ExchangeApplication.java    From artio with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    final MessageValidationStrategy validationStrategy = MessageValidationStrategy.targetCompId(ACCEPTOR_COMP_ID)
        .and(MessageValidationStrategy.senderCompId(Collections.singletonList(INITIATOR_COMP_ID)));

    final AuthenticationStrategy authenticationStrategy = AuthenticationStrategy.of(validationStrategy);

    // Static configuration lasts the duration of a FIX-Gateway instance
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", 9999)
        .libraryAeronChannel(IPC_CHANNEL);
    configuration.authenticationStrategy(authenticationStrategy);

    cleanupOldLogFileDir(configuration);

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .sharedIdleStrategy(backoffIdleStrategy())
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .idleStrategySupplier(CommonConfiguration::backoffIdleStrategy)
        .deleteArchiveOnStart(true);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext);
        FixEngine gateway = FixEngine.launch(configuration))
    {
        SampleUtil.runAgentUntilSignal(new ExchangeAgent(), driver.mediaDriver());
    }

    System.exit(0);
}
 
Example 6
Source File: ArchivingMediaDriver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
static ArchivingMediaDriver launchArchiveWithEmbeddedDriver()
{
    MediaDriver driver = null;
    Archive archive = null;
    try
    {
        final MediaDriver.Context driverCtx = new MediaDriver.Context()
            .dirDeleteOnStart(true)
            .spiesSimulateConnection(true);

        driver = MediaDriver.launch(driverCtx);

        final Archive.Context archiveCtx = new Archive.Context()
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .deleteArchiveOnStart(true);

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));
        return new ArchivingMediaDriver(driver, archive);
    }
    catch (final Exception ex)
    {
        CloseHelper.quietCloseAll(archive, driver);
        throw ex;
    }
}
 
Example 7
Source File: ClusterBackupMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a new {@link ClusterBackupMediaDriver} with provided contexts.
 *
 * @param driverCtx        for configuring the {@link MediaDriver}.
 * @param archiveCtx       for configuring the {@link Archive}.
 * @param clusterBackupCtx for the configuration of the {@link ClusterBackup}.
 * @return a new {@link ClusterBackupMediaDriver} with the provided contexts.
 */
public static ClusterBackupMediaDriver launch(
    final MediaDriver.Context driverCtx,
    final Archive.Context archiveCtx,
    final ClusterBackup.Context clusterBackupCtx)
{
    MediaDriver driver = null;
    Archive archive = null;
    ClusterBackup clusterBackup = null;

    try
    {
        driver = MediaDriver.launch(driverCtx
            .spiesSimulateConnection(true));

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));

        clusterBackup = ClusterBackup.launch(clusterBackupCtx
            .aeronDirectoryName(driverCtx.aeronDirectoryName()));

        return new ClusterBackupMediaDriver(driver, archive, clusterBackup);
    }
    catch (final Throwable throwable)
    {
        CloseHelper.quietCloseAll(driver, archive, clusterBackup);
        throw throwable;
    }
}
 
Example 8
Source File: ClusteredMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a new {@link ClusteredMediaDriver} with provided contexts.
 *
 * @param driverCtx          for configuring the {@link MediaDriver}.
 * @param archiveCtx         for configuring the {@link Archive}.
 * @param consensusModuleCtx for the configuration of the {@link ConsensusModule}.
 * @return a new {@link ClusteredMediaDriver} with the provided contexts.
 */
public static ClusteredMediaDriver launch(
    final MediaDriver.Context driverCtx,
    final Archive.Context archiveCtx,
    final ConsensusModule.Context consensusModuleCtx)
{
    MediaDriver driver = null;
    Archive archive = null;
    ConsensusModule consensusModule = null;

    try
    {
        driver = MediaDriver.launch(driverCtx
            .spiesSimulateConnection(true));

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .aeronDirectoryName(driver.aeronDirectoryName())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));

        consensusModule = ConsensusModule.launch(consensusModuleCtx
            .aeronDirectoryName(driverCtx.aeronDirectoryName()));

        return new ClusteredMediaDriver(driver, archive, consensusModule);
    }
    catch (final Exception ex)
    {
        CloseHelper.quietCloseAll(consensusModule, archive, driver);
        throw ex;
    }
}
 
Example 9
Source File: SingleNodeCluster.java    From aeron with Apache License 2.0 5 votes vote down vote up
public SingleNodeCluster(final ClusteredService externalService, final boolean cleanStart)
{
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context();
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context();
    final Archive.Context archiveContext = new Archive.Context();
    final ClusteredServiceContainer.Context serviceContainerContext = new ClusteredServiceContainer.Context();

    final ClusteredService service = null == externalService ? new SingleNodeCluster.Service() : externalService;

    mediaDriverContext
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Throwable::printStackTrace)
        .dirDeleteOnShutdown(true)
        .dirDeleteOnStart(true);

    archiveContext
        .recordingEventsEnabled(false)
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(cleanStart);

    consensusModuleContext
        .errorHandler(Throwable::printStackTrace)
        .deleteDirOnStart(cleanStart);

    serviceContainerContext
        .clusteredService(service)
        .errorHandler(Throwable::printStackTrace);

    clusteredMediaDriver = ClusteredMediaDriver.launch(
        mediaDriverContext,
        archiveContext,
        consensusModuleContext);

    container = ClusteredServiceContainer.launch(serviceContainerContext);
}
 
Example 10
Source File: ArchiveLoggingAgentTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void testArchiveLogging(final String enabledEvents, final EnumSet<ArchiveEventCode> expectedEvents)
    throws InterruptedException
{
    before(enabledEvents, expectedEvents);

    final String aeronDirectoryName = testDir.toPath().resolve("media").toString();

    final MediaDriver.Context mediaDriverCtx = new MediaDriver.Context()
        .errorHandler(Tests::onError)
        .aeronDirectoryName(aeronDirectoryName)
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010")
        .controlRequestStreamId(100)
        .controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:8020")
        .controlResponseStreamId(101)
        .recordingEventsChannel("aeron:udp?control-mode=dynamic|control=localhost:8030");

    final Archive.Context archiveCtx = new Archive.Context()
        .errorHandler(Tests::onError)
        .archiveDir(new File(testDir, "archive"))
        .deleteArchiveOnStart(true)
        .controlChannel(aeronArchiveContext.controlRequestChannel())
        .controlStreamId(aeronArchiveContext.controlRequestStreamId())
        .localControlStreamId(aeronArchiveContext.controlRequestStreamId())
        .recordingEventsChannel(aeronArchiveContext.recordingEventsChannel())
        .threadingMode(ArchiveThreadingMode.SHARED);

    try (ArchivingMediaDriver ignore1 = ArchivingMediaDriver.launch(mediaDriverCtx, archiveCtx))
    {
        try (AeronArchive ignore2 = AeronArchive.connect(aeronArchiveContext))
        {
            latch.await();
        }
    }
}
 
Example 11
Source File: SampleServer.java    From artio with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final MessageValidationStrategy validationStrategy = MessageValidationStrategy.targetCompId(ACCEPTOR_COMP_ID)
        .and(MessageValidationStrategy.senderCompId(Collections.singletonList(INITIATOR_COMP_ID)));

    final AuthenticationStrategy authenticationStrategy = AuthenticationStrategy.of(validationStrategy);

    // Static configuration lasts the duration of a FIX-Gateway instance
    final String aeronChannel = "aeron:udp?endpoint=localhost:10000";
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", 9999)
        .libraryAeronChannel(aeronChannel);
    configuration.authenticationStrategy(authenticationStrategy);

    cleanupOldLogFileDir(configuration);

    final Context context = new Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext);
        FixEngine gateway = FixEngine.launch(configuration))
    {
        final LibraryConfiguration libraryConfiguration = new LibraryConfiguration();

        // You register the new session handler - which is your application hook
        // that receives messages for new sessions
        libraryConfiguration
            .sessionAcquireHandler((session, acquiredInfo) -> onConnect(session))
            .sessionExistsHandler(new AcquiringSessionExistsHandler())
            .libraryAeronChannels(singletonList(aeronChannel));

        final IdleStrategy idleStrategy = CommonConfiguration.backoffIdleStrategy();

        try (FixLibrary library = SampleUtil.blockingConnect(libraryConfiguration))
        {
            final AtomicBoolean running = new AtomicBoolean(true);
            SigInt.register(() -> running.set(false));

            while (running.get())
            {
                idleStrategy.idle(library.poll(1));

                if (session != null && session.state() == DISCONNECTED)
                {
                    break;
                }
            }
        }
    }

    System.exit(0);
}
 
Example 12
Source File: ArchiveCreator.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        new File("archive") : new File(archiveDirName);

    final MediaDriver.Context driverContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_LENGTH)
        .termBufferSparseFile(true)
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Throwable::printStackTrace)
        .spiesSimulateConnection(true)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .maxCatalogEntries(MAX_CATALOG_ENTRIES)
        .segmentFileLength(SEGMENT_LENGTH)
        .deleteArchiveOnStart(true)
        .archiveDir(archiveDir)
        .fileSyncLevel(0)
        .threadingMode(ArchiveThreadingMode.SHARED);

    System.out.println("Creating basic archive at " + archiveContext.archiveDir());

    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverContext, archiveContext);
        Aeron aeron = Aeron.connect();
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron)))
    {
        createRecording(
            aeron,
            aeronArchive,
            0,
            (SEGMENT_LENGTH * 5L) + 1);

        createRecording(
            aeron,
            aeronArchive,
            (long)TERM_LENGTH + (FrameDescriptor.FRAME_ALIGNMENT * 2),
            (SEGMENT_LENGTH * 3L) + 1);

    }
    catch (final Exception ex)
    {
        ex.printStackTrace();
    }
}
 
Example 13
Source File: BasicAuctionClusteredServiceNode.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));                // <1>

    final List<String> hostnames = Arrays.asList("localhost", "localhost", "localhost");             // <2>
    final String hostname = hostnames.get(nodeId);

    final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);            // <3>
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";

    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();                               // <4>
    // end::main[]

    // tag::media_driver[]
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context()
        .aeronDirectoryName(aeronDirName)
        .threadingMode(ThreadingMode.SHARED)
        .termBufferSparseFile(true)
        .multicastFlowControlSupplier(new MinMulticastFlowControlSupplier())
        .terminationHook(barrier::signal)
        .errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
    // end::media_driver[]

    // tag::archive[]
    final Archive.Context archiveContext = new Archive.Context()
        .archiveDir(new File(baseDir, "archive"))
        .controlChannel(udpChannel(nodeId, "localhost", ARCHIVE_CONTROL_REQUEST_PORT_OFFSET))
        .localControlChannel("aeron:ipc?term-length=64k")
        .recordingEventsEnabled(false)
        .threadingMode(ArchiveThreadingMode.SHARED);
    // end::archive[]

    // tag::archive_client[]
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .controlRequestChannel(archiveContext.controlChannel())
        .controlRequestStreamId(archiveContext.controlStreamId())
        .controlResponseChannel(udpChannel(nodeId, "localhost", ARCHIVE_CONTROL_RESPONSE_PORT_OFFSET))
        .aeronDirectoryName(aeronDirName);
    // end::archive_client[]

    // tag::consensus_module[]
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context()
        .errorHandler(errorHandler("Consensus Module"))
        .clusterMemberId(nodeId)                                                                     // <1>
        .clusterMembers(clusterMembers(hostnames))                                                   // <2>
        .clusterDir(new File(baseDir, "consensus-module"))                                     // <3>
        .ingressChannel("aeron:udp?term-length=64k")                                                 // <4>
        .logChannel(logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET))                    // <5>
        .archiveContext(aeronArchiveContext.clone());                                                // <6>
    // end::consensus_module[]

    // tag::clustered_service[]
    final ClusteredServiceContainer.Context clusteredServiceContext =
        new ClusteredServiceContainer.Context()
        .aeronDirectoryName(aeronDirName)                                                            // <1>
        .archiveContext(aeronArchiveContext.clone())                                                 // <2>
        .clusterDir(new File(baseDir, "service"))
        .clusteredService(new BasicAuctionClusteredService())                                        // <3>
        .errorHandler(errorHandler("Clustered Service"));
    // end::clustered_service[]

    // tag::running[]
    try (
        ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(
            mediaDriverContext, archiveContext, consensusModuleContext);                             // <1>
        ClusteredServiceContainer container = ClusteredServiceContainer.launch(
            clusteredServiceContext))                                                                // <2>
    {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
        barrier.await();                                                                             // <3>
        System.out.println("[" + nodeId + "] Exiting");
    }
    // end::running[]
}
 
Example 14
Source File: ClusterLoggingAgentTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void testClusterEventsLogging(
    final String enabledEvents, final EnumSet<ClusterEventCode> expectedEvents) throws InterruptedException
{
    before(enabledEvents, expectedEvents.size());

    final String aeronDirectoryName = testDir.toPath().resolve("media").toString();

    final Context mediaDriverCtx = new Context()
        .errorHandler(Tests::onError)
        .aeronDirectoryName(aeronDirectoryName)
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010")
        .controlRequestStreamId(100)
        .controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:8020")
        .controlResponseStreamId(101)
        .recordingEventsChannel("aeron:udp?control-mode=dynamic|control=localhost:8030");

    final Archive.Context archiveCtx = new Archive.Context()
        .errorHandler(Tests::onError)
        .archiveDir(new File(testDir, "archive"))
        .deleteArchiveOnStart(true)
        .controlChannel(aeronArchiveContext.controlRequestChannel())
        .controlStreamId(aeronArchiveContext.controlRequestStreamId())
        .localControlStreamId(aeronArchiveContext.controlRequestStreamId())
        .recordingEventsChannel(aeronArchiveContext.recordingEventsChannel())
        .threadingMode(ArchiveThreadingMode.SHARED);

    final ConsensusModule.Context consensusModuleCtx = new ConsensusModule.Context()
        .errorHandler(Tests::onError)
        .clusterDir(new File(testDir, "consensus-module"))
        .archiveContext(aeronArchiveContext.clone())
        .clusterMemberId(0)
        .clusterMembers("0,localhost:20110,localhost:20220,localhost:20330,localhost:20440,localhost:8010")
        .logChannel("aeron:udp?term-length=256k|control-mode=manual|control=localhost:20550");

    final ClusteredService clusteredService = mock(ClusteredService.class);
    final ClusteredServiceContainer.Context clusteredServiceCtx = new ClusteredServiceContainer.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .errorHandler(Tests::onError)
        .archiveContext(aeronArchiveContext.clone())
        .clusterDir(new File(testDir, "service"))
        .clusteredService(clusteredService);

    clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverCtx, archiveCtx, consensusModuleCtx);
    container = ClusteredServiceContainer.launch(clusteredServiceCtx);

    latch.await();
    verify(clusteredService, timeout(5000)).onRoleChange(eq(Cluster.Role.LEADER));

    final Set<Integer> expected = expectedEvents
        .stream()
        .map(ClusterEventLogger::toEventCodeId)
        .collect(toSet());

    assertEquals(expected, LOGGED_EVENTS);
}