use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class UntetheredSubscriptionTest method shouldBecomeUnavailableWhenNotKeepingUp.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
public void shouldBecomeUnavailableWhenNotKeepingUp(final String channel) {
final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> {
};
final AtomicBoolean unavailableCalled = new AtomicBoolean();
final UnavailableImageHandler handler = (image) -> unavailableCalled.set(true);
final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
final String untetheredChannel = channel + "|tether=false";
final String publicationChannel = channel.startsWith("aeron-spy") ? channel.substring(10) : channel;
boolean pollingUntethered = true;
try (Subscription tetheredSub = aeron.addSubscription(channel, STREAM_ID);
Subscription untetheredSub = aeron.addSubscription(untetheredChannel, STREAM_ID, null, handler);
Publication publication = aeron.addPublication(publicationChannel, STREAM_ID)) {
while (!tetheredSub.isConnected() || !untetheredSub.isConnected()) {
Tests.yield();
aeron.conductorAgentInvoker().invoke();
}
while (true) {
if (publication.offer(srcBuffer) < 0) {
Tests.yield();
aeron.conductorAgentInvoker().invoke();
}
if (pollingUntethered && untetheredSub.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT) > 0) {
pollingUntethered = false;
}
tetheredSub.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT);
if (unavailableCalled.get()) {
assertTrue(tetheredSub.isConnected());
assertFalse(untetheredSub.isConnected());
while (publication.offer(srcBuffer) < 0) {
Tests.yield();
aeron.conductorAgentInvoker().invoke();
}
return;
}
}
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ArchiveDeleteAndRestartTest method recordAndReplayExclusivePublication.
@InterruptAfter(10)
@Test
public void recordAndReplayExclusivePublication() {
final UnsafeBuffer buffer = new UnsafeBuffer(new byte[1024]);
buffer.setMemory(0, buffer.capacity(), (byte) 'z');
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
final String uri = "aeron:ipc?term-length=16m|init-term-id=502090867|term-offset=0|term-id=502090867";
final ExclusivePublication recordedPublication1 = client.addExclusivePublication(uri, STREAM_ID);
final long subscriptionId = aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
for (int i = 0; i < 10; i++) {
while (recordedPublication1.offer(buffer, 0, 1024) < 0) {
Tests.yieldingIdle("Failed to offer data");
}
}
final long position1 = recordedPublication1.position();
final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
Tests.yieldingIdle("Didn't find recording");
}
while (position1 != aeronArchive.getRecordingPosition(collector.descriptors().get(0).recordingId())) {
Tests.yieldingIdle("Failed to record data");
}
recordedPublication1.close();
aeronArchive.stopRecording(subscriptionId);
while (position1 != aeronArchive.getStopPosition(collector.descriptors().get(0).recordingId())) {
Tests.yieldingIdle("Failed to stop recording");
}
aeronArchive.close();
archive.close();
archive.context().deleteDirectory();
archive = Archive.launch(archiveContext.clone());
aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
final ExclusivePublication recordedPublication2 = client.addExclusivePublication(uri, STREAM_ID);
aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
for (int i = 0; i < 10; i++) {
while (recordedPublication2.offer(buffer, 0, 1024) < 0) {
Tests.yieldingIdle("Failed to offer data");
}
}
while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
Tests.yieldingIdle("Didn't find recording");
}
assertEquals(1, aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()), collector.descriptors()::toString);
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ArchiveTest method recordAndReplayConcurrentPublication.
@ParameterizedTest
@MethodSource("threadingModes")
@InterruptAfter(10)
public void recordAndReplayConcurrentPublication(final ThreadingMode threadingMode, final ArchiveThreadingMode archiveThreadingMode) {
before(threadingMode, archiveThreadingMode);
final Publication controlPublication = client.addPublication(archive.context().localControlChannel(), archive.context().localControlStreamId());
final ArchiveProxy archiveProxy = new ArchiveProxy(controlPublication);
final Subscription recordingEvents = client.addSubscription(archive.context().recordingEventsChannel(), archive.context().recordingEventsStreamId());
prePublicationActionsAndVerifications(archiveProxy, controlPublication, recordingEvents);
final Publication recordedPublication = client.addExclusivePublication(publishUri, PUBLISH_STREAM_ID);
final int termBufferLength = recordedPublication.termBufferLength();
final long startPosition = recordedPublication.position();
preSendChecks(archiveProxy, recordingEvents, recordedPublication.sessionId(), termBufferLength, startPosition);
prepAndSendMessages(recordingEvents, recordedPublication);
postPublicationValidations(archiveProxy, recordingEvents, termBufferLength, recordedPublication.initialTermId(), recordedPublication.maxPayloadLength());
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ArchiveTest method recordAndReplayExclusivePublication.
@ParameterizedTest
@MethodSource("threadingModes")
@InterruptAfter(10)
public void recordAndReplayExclusivePublication(final ThreadingMode threadingMode, final ArchiveThreadingMode archiveThreadingMode) {
before(threadingMode, archiveThreadingMode);
final String controlChannel = archive.context().localControlChannel();
final int controlStreamId = archive.context().localControlStreamId();
final String recordingChannel = archive.context().recordingEventsChannel();
final int recordingStreamId = archive.context().recordingEventsStreamId();
final Publication controlPublication = client.addPublication(controlChannel, controlStreamId);
final Subscription recordingEvents = client.addSubscription(recordingChannel, recordingStreamId);
final ArchiveProxy archiveProxy = new ArchiveProxy(controlPublication);
prePublicationActionsAndVerifications(archiveProxy, controlPublication, recordingEvents);
final ExclusivePublication recordedPublication = client.addExclusivePublication(publishUri, PUBLISH_STREAM_ID);
final int sessionId = recordedPublication.sessionId();
final int termBufferLength = recordedPublication.termBufferLength();
final int initialTermId = recordedPublication.initialTermId();
final int maxPayloadLength = recordedPublication.maxPayloadLength();
final long startPosition = recordedPublication.position();
assertEquals(requestedStartPosition, startPosition);
assertEquals(requestedInitialTermId, recordedPublication.initialTermId());
preSendChecks(archiveProxy, recordingEvents, sessionId, termBufferLength, startPosition);
prepAndSendMessages(recordingEvents, recordedPublication);
postPublicationValidations(archiveProxy, recordingEvents, termBufferLength, initialTermId, maxPayloadLength);
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class SpecifiedPositionPublicationTest method shouldValidateSpecifiedPositionForConcurrentPublicationsInitiallyUnspecified.
@InterruptAfter(5)
@ParameterizedTest
@CsvSource({ CommonContext.IPC_CHANNEL, "aeron:udp?endpoint=localhost:24325" })
void shouldValidateSpecifiedPositionForConcurrentPublicationsInitiallyUnspecified(final String initialUri) {
final MediaDriver.Context context = new MediaDriver.Context().dirDeleteOnStart(true).ipcPublicationTermWindowLength(LogBufferDescriptor.TERM_MIN_LENGTH).threadingMode(ThreadingMode.SHARED);
final int streamId = 1001;
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 = aeron.addPublication(initialUri, streamId)) {
Tests.awaitConnected(subscription);
Tests.awaitConnected(publication);
final String channel = new ChannelUriStringBuilder(initialUri).initialPosition(publication.position(), publication.initialTermId(), publication.termBufferLength()).build();
try (Publication publication2 = aeron.addPublication(channel, streamId)) {
assertEquals(publication.position(), publication2.position());
assertEquals(publication.initialTermId(), publication2.initialTermId());
}
} finally {
context.deleteDirectory();
}
}
Aggregations