use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateStoppedRecordingsConcurrently.
@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecordingsConcurrently() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long[] srcRecordingIds = new long[2];
long position = 0;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
for (int i = 0; i < 2; i++) {
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader counters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
srcRecordingIds[i] = RecordingPos.getRecordingId(counters, counterId);
offer(publication, messageCount, messagePrefix);
position = publication.position();
awaitPosition(counters, counterId, position);
}
}
srcAeronArchive.stopRecording(subscriptionId);
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
for (int i = 0; i < 2; i++) {
dstAeronArchive.archiveProxy().replicate(srcRecordingIds[i], NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null, dstAeronArchive.context().aeron().nextCorrelationId(), dstAeronArchive.controlSessionId());
}
int stopCount = 0;
while (stopCount < 2) {
if (RecordingSignal.STOP == awaitSignal(signalRef, adapter)) {
stopCount++;
}
}
assertEquals(dstAeronArchive.getStopPosition(0), position);
assertEquals(dstAeronArchive.getStopPosition(1), position);
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class ClusterNetworkTopologyTest method connectAndSendMessages.
private void connectAndSendMessages(final String ingressChannel, final String ingressEndpoints, final Selector selector, final double messageCount) {
final String message = "Hello World!";
final MutableDirectBuffer messageBuffer = new UnsafeBuffer(ByteBuffer.allocate(128));
final int length = messageBuffer.putStringAscii(0, message);
final MutableReference<String> egressResponse = new MutableReference<>();
final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length1, header) -> {
final String stringAscii = buffer.getStringAscii(offset);
egressResponse.set(stringAscii);
};
try (MediaDriver mediaDriver = MediaDriver.launchEmbedded(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(true));
AeronCluster.AsyncConnect asyncConnect = AeronCluster.asyncConnect(new AeronCluster.Context().messageTimeoutNs(TimeUnit.SECONDS.toNanos(CLUSTER_START_ELECTION_TIMEOUT_S * 2)).egressListener(egressListener).egressChannel("aeron:udp?endpoint=10.42.0.1:0").aeronDirectoryName(mediaDriver.aeronDirectoryName()).ingressChannel(ingressChannel).ingressEndpoints(ingressEndpoints));
AeronCluster aeronCluster = pollUntilConnected(asyncConnect, selector)) {
for (int i = 0; i < messageCount; i++) {
Tests.await(() -> {
final long position = aeronCluster.offer(messageBuffer, 0, length);
pollSelector(selector);
return 0 < position;
}, SECONDS.toNanos(5));
Tests.await(() -> {
aeronCluster.pollEgress();
pollSelector(selector);
return message.equals(egressResponse.get());
}, SECONDS.toNanos(5));
}
}
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class TwoBufferOfferMessageTest method shouldTransferFragmentedTwoPartMessage.
@Test
@InterruptAfter(10)
void shouldTransferFragmentedTwoPartMessage() {
final UnsafeBuffer expectedBuffer = new UnsafeBuffer(new byte[32 + driver.context().mtuLength()]);
final UnsafeBuffer bufferOne = new UnsafeBuffer(expectedBuffer, 0, 32);
final UnsafeBuffer bufferTwo = new UnsafeBuffer(expectedBuffer, 32, expectedBuffer.capacity() - 32);
bufferOne.setMemory(0, bufferOne.capacity(), (byte) 'a');
bufferTwo.setMemory(0, bufferTwo.capacity(), (byte) 'b');
final String expectedMessage = expectedBuffer.getStringWithoutLengthAscii(0, expectedBuffer.capacity());
final MutableReference<String> receivedMessage = new MutableReference<>();
final FragmentHandler fragmentHandler = new FragmentAssembler((buffer, offset, length, header) -> receivedMessage.set(buffer.getStringWithoutLengthAscii(offset, length)));
try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
try (Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) {
publishMessage(bufferOne, bufferTwo, publication);
pollForMessage(subscription, receivedMessage, fragmentHandler);
assertEquals(expectedMessage, receivedMessage.get());
}
try (Publication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) {
publishMessage(bufferOne, bufferTwo, publication);
pollForMessage(subscription, receivedMessage, fragmentHandler);
assertEquals(expectedMessage, receivedMessage.get());
}
}
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class ManageRecordingHistoryTest method shouldPurgeRecording.
@Test
@InterruptAfter(10)
void shouldPurgeRecording() throws IOException {
final String messagePrefix = "Message-Prefix-";
final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;
try (Publication publication = aeronArchive.addRecordedPublication(uriBuilder.build(), STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
final long newRecordingId = RecordingPos.getRecordingId(counters, counterId);
offerToPosition(publication, messagePrefix, targetPosition);
awaitPosition(counters, counterId, publication.position());
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalConsumer consumer = (controlSessionId, correlationId, recordingId, subscriptionId, position, transitionType) -> {
if (newRecordingId == recordingId) {
signalRef.set(transitionType);
}
};
final RecordingSignalAdapter adapter = new RecordingSignalAdapter(aeronArchive.controlSessionId(), ERROR_CONTROL_LISTENER, consumer, aeronArchive.controlResponsePoller().subscription(), FRAGMENT_LIMIT);
aeronArchive.stopRecording(publication);
assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
final String prefix = newRecordingId + "-";
final File archiveDir = archive.context().archiveDir();
assertTrue(new File(archiveDir, prefix + (SEGMENT_LENGTH * 4L) + ".rec").createNewFile());
assertTrue(new File(archiveDir, prefix + (SEGMENT_LENGTH * 5L) + ".rec.del").createNewFile());
aeronArchive.purgeRecording(newRecordingId);
assertEquals(RecordingSignal.DELETE, awaitSignal(signalRef, adapter));
assertThat(archiveDir.list(((dir, name) -> name.startsWith(prefix))), arrayWithSize(0));
}
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateLiveWithoutMergingRecording.
@Test
@InterruptAfter(10)
public void shouldReplicateLiveWithoutMergingRecording() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader srcCounters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(srcCounters, publication.sessionId());
srcRecordingId = RecordingPos.getRecordingId(srcCounters, counterId);
offer(publication, messageCount, messagePrefix);
awaitPosition(srcCounters, counterId, publication.position());
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
final long replicationId = dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
final CountersReader dstCounters = dstAeron.countersReader();
final int dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId.get());
awaitPosition(dstCounters, dstCounterId, publication.position());
offer(publication, messageCount, messagePrefix);
awaitPosition(dstCounters, dstCounterId, publication.position());
dstAeronArchive.stopReplication(replicationId);
assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
}
srcAeronArchive.stopRecording(subscriptionId);
}
Aggregations