Search in sources :

Example 56 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class RecordingDescriptorCollectorTest method shouldShouldNotReuseDescriptorIfPoolSizeIsZero.

@Test
void shouldShouldNotReuseDescriptorIfPoolSizeIsZero(@TempDir final Path tempDir) {
    try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
        Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
        createRecordings(aeronArchive, 3);
        final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(0);
        long fromRecordingId = 0;
        int count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc0 = collector.descriptors().get(0);
        fromRecordingId += count;
        count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc1 = collector.descriptors().get(0);
        assertNotEquals(desc0.recordingId(), desc1.recordingId());
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test)

Example 57 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class RecordingDescriptorCollectorTest method shouldCollectPagesOfRecordingDescriptors.

@Test
@InterruptAfter(10)
void shouldCollectPagesOfRecordingDescriptors(@TempDir final Path tempDir) {
    try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
        Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
        final int numRecordings = 10;
        createRecordings(aeronArchive, numRecordings);
        final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(3);
        long fromRecordingId = 0;
        int count;
        while (0 < (count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset()))) {
            final List<RecordingDescriptor> descriptors = collector.descriptors();
            assertThat(count, lessThanOrEqualTo(collector.poolSize()));
            assertThat(descriptors.size(), lessThanOrEqualTo(collector.poolSize()));
            // noinspection OptionalGetWithoutIsPresent
            final long maxRecordingId = descriptors.stream().mapToLong(RecordingDescriptor::recordingId).max().getAsLong();
            fromRecordingId = maxRecordingId + 1;
        }
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 58 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class LifecycleTest method shouldStartAndStopInstantly.

@Test
@InterruptAfter(10)
void shouldStartAndStopInstantly() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).errorHandler(Tests::onError);
    try (TestMediaDriver mediaDriver = TestMediaDriver.launch(driverCtx, testWatcher)) {
        final Aeron.Context clientCtx = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
        final Aeron aeron = Aeron.connect(clientCtx);
        aeron.close();
    } finally {
        driverCtx.deleteDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Tests(io.aeron.test.Tests) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 59 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class LifecycleTest method shouldNotifyOfClientTimestampCounter.

@Test
@InterruptAfter(10)
void shouldNotifyOfClientTimestampCounter() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).errorHandler(Tests::onError);
    try (TestMediaDriver mediaDriver = TestMediaDriver.launch(driverCtx, testWatcher)) {
        final Aeron.Context clientCtxOne = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
        final Aeron.Context clientCtxTwo = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
        try (Aeron aeron = Aeron.connect(clientCtxOne)) {
            final AvailableCounterHandler availableHandler = mock(AvailableCounterHandler.class);
            aeron.addAvailableCounterHandler(availableHandler);
            final UnavailableCounterHandler unavailableHandler = mock(UnavailableCounterHandler.class);
            aeron.addUnavailableCounterHandler(unavailableHandler);
            try (Aeron aeronTwo = Aeron.connect(clientCtxTwo)) {
                aeronTwo.addSubscription("aeron:ipc", 1001);
                verify(availableHandler, timeout(5000)).onAvailableCounter(any(), eq(clientCtxTwo.clientId()), anyInt());
            }
            verify(unavailableHandler, timeout(5000)).onUnavailableCounter(any(), eq(clientCtxTwo.clientId()), anyInt());
        }
    } finally {
        driverCtx.deleteDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Tests(io.aeron.test.Tests) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 60 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class BasicAuctionClusterClient method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
public static void main(final String[] args) {
    // <1>
    final int customerId = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.customerId"));
    // <2>
    final int numOfBids = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.numOfBids"));
    // <3>
    final int bidIntervalMs = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.bidIntervalMs"));
    final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(",");
    final String ingressEndpoints = ingressEndpoints(Arrays.asList(hostnames));
    final BasicAuctionClusterClient client = new BasicAuctionClusterClient(customerId, numOfBids, bidIntervalMs);
    // tag::connect[]
    try (MediaDriver mediaDriver = MediaDriver.launchEmbedded(// <1>
    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(true));
        AeronCluster aeronCluster = AeronCluster.connect(new AeronCluster.Context().egressListener(// <2>
        client).egressChannel(// <3>
        "aeron:udp?endpoint=localhost:0").aeronDirectoryName(mediaDriver.aeronDirectoryName()).ingressChannel(// <4>
        "aeron:udp").ingressEndpoints(// <5>
        ingressEndpoints))) {
        // end::connect[]
        client.bidInAuction(aeronCluster);
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) AeronCluster(io.aeron.cluster.client.AeronCluster)

Aggregations

MediaDriver (io.aeron.driver.MediaDriver)78 Aeron (io.aeron.Aeron)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 Test (org.junit.jupiter.api.Test)20 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)17 InterruptAfter (io.aeron.test.InterruptAfter)16 Subscription (io.aeron.Subscription)14 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)14 IdleStrategy (org.agrona.concurrent.IdleStrategy)14 ContinueBarrier (org.agrona.console.ContinueBarrier)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Publication (io.aeron.Publication)10 Archive (io.aeron.archive.Archive)10 FragmentHandler (io.aeron.logbuffer.FragmentHandler)10 Tests (io.aeron.test.Tests)10 CommonContext (io.aeron.CommonContext)8 ExecutorService (java.util.concurrent.ExecutorService)8 DirectBuffer (org.agrona.DirectBuffer)7 BusySpinIdleStrategy (org.agrona.concurrent.BusySpinIdleStrategy)7 AeronCluster (io.aeron.cluster.client.AeronCluster)6