use of io.aeron.test.driver.TestMediaDriver in project Aeron by real-logic.
the class SpecifiedPositionPublicationTest method shouldStartAtSpecifiedPositionForPublications.
@InterruptAfter(5)
@ParameterizedTest
@CsvSource({ CommonContext.IPC_CHANNEL + ",true", "aeron:udp?endpoint=localhost:24325,true", CommonContext.IPC_CHANNEL + ",false", "aeron:udp?endpoint=localhost:24325,false" })
void shouldStartAtSpecifiedPositionForPublications(final String initialUri, final boolean exclusive) {
final MediaDriver.Context context = new MediaDriver.Context().dirDeleteOnStart(true).ipcPublicationTermWindowLength(LogBufferDescriptor.TERM_MIN_LENGTH).threadingMode(ThreadingMode.SHARED);
final DirectBuffer msg = new UnsafeBuffer(new byte[64]);
final int termLength = 1 << 16;
final int initialTermId = randomWatcher.random().nextInt();
final int activeTermId = initialTermId + randomWatcher.random().nextInt(Integer.MAX_VALUE);
final int positionBitsToShift = LogBufferDescriptor.positionBitsToShift(termLength);
final int termOffset = randomWatcher.random().nextInt(termLength) & -FrameDescriptor.FRAME_ALIGNMENT;
final long startPosition = LogBufferDescriptor.computePosition(activeTermId, termOffset, positionBitsToShift, initialTermId);
final PositionCalculator positionCalculator = new PositionCalculator(startPosition, termLength, termOffset);
final long nextPosition = positionCalculator.addMessage(DataHeaderFlyweight.HEADER_LENGTH + msg.capacity());
final String channel = new ChannelUriStringBuilder(initialUri).initialPosition(startPosition, initialTermId, termLength).build();
final int streamId = 1001;
final Function<Aeron, Publication> publicationSupplier = exclusive ? (a) -> a.addExclusivePublication(channel, streamId) : (a) -> a.addPublication(channel, streamId);
try (TestMediaDriver mediaDriver = TestMediaDriver.launch(context, testWatcher);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(initialUri, streamId);
Publication publication = publicationSupplier.apply(aeron)) {
Tests.awaitConnected(subscription);
Tests.awaitConnected(publication);
assertEquals(startPosition, publication.position());
Tests.await(() -> publication.offer(msg) > 0);
assertEquals(nextPosition, publication.position());
final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> assertEquals(nextPosition, header.position());
Tests.await(() -> subscription.poll(fragmentHandler, 1) == 1);
} finally {
context.deleteDirectory();
}
}
use of io.aeron.test.driver.TestMediaDriver in project Aeron by real-logic.
the class TimestampingSystemTest method shouldSupportMediaReceiveTimestampsInCDriver.
@Test
@InterruptAfter(10)
@EnabledOnOs(OS.LINUX)
void shouldSupportMediaReceiveTimestampsInCDriver() {
assumeTrue(TestMediaDriver.shouldRunCMediaDriver());
final DirectBuffer buffer = new UnsafeBuffer(new byte[64]);
try (TestMediaDriver driver = driver();
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
final Subscription sub = aeron.addSubscription(CHANNEL_WITH_MEDIA_TIMESTAMP, 1000);
while (null == sub.resolvedEndpoint()) {
Tests.yieldingIdle("Failed to resolve endpoint");
}
final String uri = "aeron:udp?endpoint=" + sub.resolvedEndpoint();
final Publication pub = aeron.addPublication(uri, 1000);
Tests.awaitConnected(pub);
while (0 > pub.offer(buffer, 0, buffer.capacity(), (termBuffer, termOffset, frameLength) -> SENTINEL_VALUE)) {
Tests.yieldingIdle("Failed to offer message");
}
final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> assertNotEquals(SENTINEL_VALUE, header.reservedValue());
while (1 > sub.poll(fragmentHandler, 1)) {
Tests.yieldingIdle("Failed to receive message");
}
}
}
use of io.aeron.test.driver.TestMediaDriver in project Aeron by real-logic.
the class TimestampingSystemTest method shouldErrorIfSubscriptionConfigurationForTimestampsDoesNotMatch.
@Test
void shouldErrorIfSubscriptionConfigurationForTimestampsDoesNotMatch() {
systemTestWatcher.ignoreErrorsMatching((s) -> s.contains("option conflicts"));
try (TestMediaDriver driver = driver();
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
aeron.addSubscription("aeron:udp?endpoint=localhost:23436|channel-rcv-ts-offset=reserved", 1000);
assertThrows(RegistrationException.class, () -> aeron.addSubscription("aeron:udp?endpoint=localhost:23436", 1000));
assertThrows(RegistrationException.class, () -> aeron.addSubscription("aeron:udp?endpoint=localhost:23436|channel-rcv-ts-offset=8", 1000));
}
}
use of io.aeron.test.driver.TestMediaDriver in project Aeron by real-logic.
the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMds.
@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMds() {
final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
try (TestMediaDriver driver = driver();
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
final Subscription mdsSub = aeron.addSubscription("aeron:udp?control-mode=manual|channel-rcv-ts-offset=0", 1000);
final Publication pub1 = aeron.addPublication("aeron:udp?endpoint=localhost:23424", 1000);
final Publication pub2 = aeron.addPublication("aeron:udp?endpoint=localhost:23425", 1000);
mdsSub.addDestination("aeron:udp?endpoint=localhost:23424");
mdsSub.addDestination("aeron:udp?endpoint=localhost:23425");
while (!pub1.isConnected() || !pub2.isConnected()) {
Tests.yieldingIdle("Failed to connect");
}
buffer.putLong(0, SENTINEL_VALUE);
while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
Tests.yieldingIdle("Failed to offer message");
}
while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
Tests.yieldingIdle("Failed to offer message");
}
final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
while (1 > mdsSub.poll(fragmentHandler, 1)) {
Tests.yieldingIdle("Failed to receive message");
}
assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
while (1 > mdsSub.poll(fragmentHandler, 1)) {
Tests.yieldingIdle("Failed to receive message");
}
assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
}
}
use of io.aeron.test.driver.TestMediaDriver in project Aeron by real-logic.
the class MinFlowControlSystemTest method shouldPreventConnectionUntilGroupMinSizeIsMet.
@SlowTest
@Test
@InterruptAfter(20)
void shouldPreventConnectionUntilGroupMinSizeIsMet() {
final Integer groupSize = 3;
final ChannelUriStringBuilder builder = new ChannelUriStringBuilder().media("udp").endpoint("224.20.30.39:24326").networkInterface("localhost");
final String uriPlain = builder.flowControl((String) null).build();
final String uriWithMinFlowControl = builder.groupTag((Long) null).minFlowControl(groupSize, null).build();
driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
launch();
final CountersReader countersReader = clientA.countersReader();
TestMediaDriver driverC = null;
Aeron clientC = null;
Publication publication = null;
Subscription subscription0 = null;
Subscription subscription1 = null;
Subscription subscription2 = null;
try {
driverC = TestMediaDriver.launch(new MediaDriver.Context().publicationTermBufferLength(TERM_BUFFER_LENGTH).aeronDirectoryName(ROOT_DIR + "C").timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(100)).errorHandler(Tests::onError).threadingMode(ThreadingMode.SHARED), testWatcher);
clientC = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverC.aeronDirectoryName()));
subscription0 = clientA.addSubscription(uriPlain, STREAM_ID);
subscription1 = clientB.addSubscription(uriPlain, STREAM_ID);
publication = clientA.addPublication(uriWithMinFlowControl, STREAM_ID);
awaitConnectionAndStatusMessages(countersReader, subscription0, subscription1);
assertFalse(publication.isConnected());
subscription2 = clientC.addSubscription(uriPlain, STREAM_ID);
// Should now have 3 receivers and publication should eventually be connected.
while (!publication.isConnected()) {
Tests.sleep(1);
}
subscription2.close();
subscription2 = null;
// Lost a receiver and publication should eventually be disconnected.
while (publication.isConnected()) {
Tests.sleep(1);
}
subscription2 = clientC.addSubscription(uriPlain, STREAM_ID);
while (!publication.isConnected()) {
Tests.sleep(1);
}
} finally {
CloseHelper.closeAll(publication, subscription0, subscription1, subscription2, clientC, driverC);
}
}
Aggregations