use of org.agrona.collections.MutableReference in project Aeron by real-logic.
the class ReentrantClientTest method shouldThrowWhenReentering.
@Test
void shouldThrowWhenReentering() {
final MutableReference<Throwable> expectedException = new MutableReference<>();
final ErrorHandler errorHandler = expectedException::set;
try (Aeron aeron = Aeron.connect(new Aeron.Context().errorHandler(errorHandler))) {
final String channel = CommonContext.IPC_CHANNEL;
final AvailableImageHandler mockHandler = mock(AvailableImageHandler.class);
doAnswer((invocation) -> aeron.addSubscription(channel, 3)).when(mockHandler).onAvailableImage(any(Image.class));
final Subscription sub = aeron.addSubscription(channel, 1001, mockHandler, null);
final Publication pub = aeron.addPublication(channel, 1001);
verify(mockHandler, timeout(5000L)).onAvailableImage(any(Image.class));
pub.close();
sub.close();
assertThat(expectedException.get(), instanceOf(AeronException.class));
}
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class AuthenticationTest method shouldRejectOnChallengeResponse.
@Test
@InterruptAfter(10)
public void shouldRejectOnChallengeResponse() {
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 challengeRespondedTo = 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));
challengeRespondedTo = 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 (challengeRespondedTo) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.reject();
}
}
});
launchClusteredMediaDriver(() -> authenticator);
launchService(serviceSessionId, encodedPrincipal, serviceMsgCounter);
try {
connectClient(credentialsSupplier);
} catch (final AuthenticationException ex) {
assertEquals(-1L, serviceSessionId.value);
ClusterTests.failOnClusterError();
return;
}
fail("should have seen exception");
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class AuthenticationTest method shouldAuthenticateOnConnectRequestWithEmptyCredentials.
@Test
@InterruptAfter(10)
public void shouldAuthenticateOnConnectRequestWithEmptyCredentials() {
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) {
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(0, encodedCredentials.length);
}
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(null);
}
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(0, encodedPrincipal.get().length);
ClusterTests.failOnClusterError();
}
use of org.agrona.collections.MutableReference in project aeron by real-logic.
the class AuthenticationTest method shouldRejectOnConnectRequest.
@Test
@InterruptAfter(10)
public void shouldRejectOnConnectRequest() {
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() {
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) {
fail();
}
public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.reject();
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
fail();
}
});
launchClusteredMediaDriver(() -> authenticator);
launchService(serviceSessionId, encodedPrincipal, serviceMsgCounter);
try {
connectClient(credentialsSupplier);
} catch (final AuthenticationException ex) {
assertEquals(-1L, serviceSessionId.value);
ClusterTests.failOnClusterError();
return;
}
fail("should have seen exception");
}
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);
}
}
}
Aggregations