Search in sources :

Example 46 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class ListRecordingsSessionTest method shouldSendAllDescriptors.

@Test
public void shouldSendAllDescriptors() {
    final ListRecordingsSession session = new ListRecordingsSession(correlationId, 0, 3, catalog, controlResponseProxy, controlSession, descriptorBuffer);
    final MutableLong counter = new MutableLong(0);
    when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
    session.doWork();
    verify(controlSession, times(3)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Example 47 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class ListRecordingsSessionTest method shouldResendDescriptorWhenSendFails.

@Test
public void shouldResendDescriptorWhenSendFails() {
    final long fromRecordingId = 1;
    final ListRecordingsSession session = new ListRecordingsSession(correlationId, fromRecordingId, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer);
    when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).thenReturn(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));
    session.doWork();
    verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Example 48 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class ListRecordingsSessionTest method shouldSend2Descriptors.

@Test
public void shouldSend2Descriptors() {
    final int fromId = 1;
    final ListRecordingsSession session = new ListRecordingsSession(correlationId, fromId, 2, catalog, controlResponseProxy, controlSession, descriptorBuffer);
    final MutableLong counter = new MutableLong(fromId);
    when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
    session.doWork();
    verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Example 49 with MutableLong

use of org.agrona.collections.MutableLong 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();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) MutableLong(org.agrona.collections.MutableLong) MutableReference(org.agrona.collections.MutableReference) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 50 with MutableLong

use of org.agrona.collections.MutableLong 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");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) MutableLong(org.agrona.collections.MutableLong) MutableReference(org.agrona.collections.MutableReference) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

MutableLong (org.agrona.collections.MutableLong)82 Test (org.junit.jupiter.api.Test)68 InterruptAfter (io.aeron.test.InterruptAfter)44 MutableReference (org.agrona.collections.MutableReference)28 CountersReader (org.agrona.concurrent.status.CountersReader)19 RecordingSignal (io.aeron.archive.codecs.RecordingSignal)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MediaDriver (io.aeron.driver.MediaDriver)14 FragmentHandler (io.aeron.logbuffer.FragmentHandler)14 DirectBuffer (org.agrona.DirectBuffer)13 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)11 RegistrationException (io.aeron.exceptions.RegistrationException)10 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 AeronArchive (io.aeron.archive.client.AeronArchive)8 Authenticator (io.aeron.security.Authenticator)8 CredentialsSupplier (io.aeron.security.CredentialsSupplier)8