use of org.agrona.collections.MutableReference in project Aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateLiveRecordingAndMergeWhileFollowingWithTaggedSubscription.
@Test
@InterruptAfter(10)
public void shouldReplicateLiveRecordingAndMergeWhileFollowingWithTaggedSubscription() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long channelTagId = dstAeron.nextCorrelationId();
final long subscriptionTagId = dstAeron.nextCorrelationId();
final String taggedChannel = "aeron:udp?control-mode=manual|rejoin=false|tags=" + channelTagId + "," + subscriptionTagId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter;
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID);
Subscription taggedSubscription = dstAeron.addSubscription(taggedChannel, 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();
adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
dstAeronArchive.taggedReplicate(srcRecordingId, NULL_VALUE, channelTagId, subscriptionTagId, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, LIVE_CHANNEL);
consume(taggedSubscription, messageCount, messagePrefix);
offer(publication, messageCount, messagePrefix);
consume(taggedSubscription, messageCount, messagePrefix);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.MERGE, awaitSignal(signalRef, adapter));
final CountersReader dstCounters = dstAeron.countersReader();
final int dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId.get());
offer(publication, messageCount, messagePrefix);
consume(taggedSubscription, messageCount, messagePrefix);
awaitPosition(dstCounters, dstCounterId, publication.position());
final Image image = taggedSubscription.imageBySessionId(publication.sessionId());
assertEquals(publication.position(), image.position());
}
srcAeronArchive.stopRecording(subscriptionId);
assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
}
use of org.agrona.collections.MutableReference in project Aeron by real-logic.
the class MultiModuleSharedDriverTest method shouldSupportTwoMultiNodeClusters.
@Test
@InterruptAfter(30)
public void shouldSupportTwoMultiNodeClusters() {
try (MultiClusterNode node0 = new MultiClusterNode(0, systemTestWatcher.dataCollector());
MultiClusterNode node1 = new MultiClusterNode(1, systemTestWatcher.dataCollector())) {
final MutableReference<String> egress = new MutableReference<>();
final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
try (AeronCluster client0 = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(node0.archivingMediaDriver.mediaDriver().aeronDirectoryName()).egressListener(egressListener).ingressChannel("aeron:udp?term-length=64k").ingressEndpoints(TestCluster.ingressEndpoints(0, 2)).egressChannel("aeron:udp?endpoint=localhost:9020"));
AeronCluster client1 = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(node1.archivingMediaDriver.mediaDriver().aeronDirectoryName()).egressListener(egressListener).ingressChannel("aeron:udp?term-length=64k").ingressEndpoints(TestCluster.ingressEndpoints(1, 2)).egressChannel("aeron:udp?endpoint=localhost:9120"))) {
echoMessage(client0, "Message 0", egress);
echoMessage(client1, "Message 1", egress);
}
}
}
use of org.agrona.collections.MutableReference in project Aeron by real-logic.
the class TwoBufferOfferMessageTest method shouldTransferUnfragmentedTwoPartMessage.
@Test
@InterruptAfter(10)
void shouldTransferUnfragmentedTwoPartMessage() {
final UnsafeBuffer expectedBuffer = new UnsafeBuffer(new byte[256]);
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 = (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 AuthenticationTest method shouldAuthenticateOnConnectRequestWithCredentials.
@Test
@InterruptAfter(10)
public void shouldAuthenticateOnConnectRequestWithCredentials() {
final AtomicLong serviceMsgCounter = new AtomicLong(0L);
final MutableLong serviceSessionId = new MutableLong(-1L);
final MutableLong authenticatorSessionId = new MutableLong(-1L);
final MutableReference<byte[]> encodedPrincipal = new MutableReference<>();
final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {
public byte[] encodedCredentials() {
return encodedCredentials;
}
public byte[] onChallenge(final byte[] encodedChallenge) {
fail();
return null;
}
});
final Authenticator authenticator = spy(new Authenticator() {
public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
authenticatorSessionId.value = sessionId;
assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
}
public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
fail();
}
public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
fail();
}
});
launchClusteredMediaDriver(() -> authenticator);
launchService(serviceSessionId, encodedPrincipal, serviceMsgCounter);
connectClient(credentialsSupplier);
sendCountedMessageIntoCluster(0);
Tests.awaitValue(serviceMsgCounter, 1);
assertEquals(aeronCluster.clusterSessionId(), authenticatorSessionId.value);
assertEquals(aeronCluster.clusterSessionId(), serviceSessionId.value);
assertEquals(PRINCIPAL_STRING, new String(encodedPrincipal.get()));
ClusterTests.failOnClusterError();
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class AuthenticationTest method shouldAuthenticateOnChallengeResponse.
@Test
@InterruptAfter(10)
public void shouldAuthenticateOnChallengeResponse() {
final AtomicLong serviceMsgCounter = new AtomicLong(0L);
final MutableLong serviceSessionId = new MutableLong(-1L);
final MutableLong authenticatorSessionId = new MutableLong(-1L);
final MutableReference<byte[]> encodedPrincipal = new MutableReference<>();
final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {
public byte[] encodedCredentials() {
return NULL_CREDENTIAL;
}
public byte[] onChallenge(final byte[] encodedChallenge) {
assertEquals(CHALLENGE_STRING, new String(encodedChallenge));
return encodedCredentials;
}
});
final Authenticator authenticator = spy(new Authenticator() {
boolean challengeSuccessful = false;
public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
authenticatorSessionId.value = sessionId;
assertEquals(0, encodedCredentials.length);
}
public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
assertEquals(sessionId, authenticatorSessionId.value);
assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
challengeSuccessful = true;
}
public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.challenge(encodedChallenge);
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
if (challengeSuccessful) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
}
}
});
launchClusteredMediaDriver(() -> authenticator);
launchService(serviceSessionId, encodedPrincipal, serviceMsgCounter);
connectClient(credentialsSupplier);
sendCountedMessageIntoCluster(0);
Tests.awaitValue(serviceMsgCounter, 1);
assertEquals(aeronCluster.clusterSessionId(), authenticatorSessionId.value);
assertEquals(aeronCluster.clusterSessionId(), serviceSessionId.value);
assertEquals(PRINCIPAL_STRING, new String(encodedPrincipal.get()));
ClusterTests.failOnClusterError();
}
Aggregations