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());
}
}
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;
}
}
}
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();
}
}
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();
}
}
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);
}
}
Aggregations