use of org.agrona.collections.MutableLong 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.MutableLong in project aeron by real-logic.
the class ListRecordingsForUriSessionTest method shouldSend2Descriptors.
@Test
public void shouldSend2Descriptors() {
final long fromRecordingId = 1;
final ListRecordingsForUriSession session = new ListRecordingsForUriSession(correlationId, fromRecordingId, 2, LOCALHOST_BYTES, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer, recordingDescriptorDecoder);
final MutableLong counter = new MutableLong(fromRecordingId);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
assertEquals(2, session.doWork());
verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ListRecordingsForUriSessionTest method shouldResendDescriptorWhenSendFails.
@Test
public void shouldResendDescriptorWhenSendFails() {
final long fromRecordingId = 1;
final ListRecordingsForUriSession session = new ListRecordingsForUriSession(correlationId, fromRecordingId, 1, LOCALHOST_BYTES, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer, recordingDescriptorDecoder);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).thenReturn(0);
assertEquals(0, session.doWork());
verify(controlSession, times(1)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
final MutableLong counter = new MutableLong(fromRecordingId);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
assertEquals(1, session.doWork());
verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ListRecordingsForUriSessionTest method shouldSendAllDescriptors.
@Test
public void shouldSendAllDescriptors() {
final ListRecordingsForUriSession session = new ListRecordingsForUriSession(correlationId, 0, 3, LOCALHOST_BYTES, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer, recordingDescriptorDecoder);
final MutableLong counter = new MutableLong(0);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
assertEquals(3, session.doWork());
verify(controlSession, times(3)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ListRecordingsSessionTest method shouldSendTwoDescriptorsThenRecordingUnknown.
@Test
public void shouldSendTwoDescriptorsThenRecordingUnknown() {
final ListRecordingsSession session = new ListRecordingsSession(correlationId, 1, 3, catalog, controlResponseProxy, controlSession, descriptorBuffer);
final MutableLong counter = new MutableLong(1);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
session.doWork();
verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
verify(controlSession).sendRecordingUnknown(eq(correlationId), eq(3L), eq(controlResponseProxy));
}
Aggregations