Search in sources :

Example 1 with MutableLong

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

the class ListRecordingsForUriSessionTest method shouldLimitSendingToSingleMtu.

@Test
public void shouldLimitSendingToSingleMtu() {
    when(controlSession.maxPayloadLength()).thenReturn(BLOCK_LENGTH);
    final ListRecordingsForUriSession session = new ListRecordingsForUriSession(correlationId, 0, 3, "localhost", 1, catalog, controlResponseProxy, controlSession, descriptorBuffer, recordingDescriptorDecoder);
    final MutableLong counter = new MutableLong(0);
    when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
    session.doWork();
    verify(controlSession).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
    session.doWork();
    verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
    session.doWork();
    verify(controlSession, times(3)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.Test)

Example 2 with MutableLong

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

the class SequencerAgentTest method shouldSuspendThenResume.

@Test
public void shouldSuspendThenResume() {
    final CachedEpochClock clock = new CachedEpochClock();
    final MutableLong stateValue = new MutableLong();
    final Counter mockState = mock(Counter.class);
    when(mockState.get()).thenAnswer((invocation) -> stateValue.value);
    doAnswer((invocation) -> {
        stateValue.value = invocation.getArgument(0);
        return null;
    }).when(mockState).set(anyLong());
    final MutableLong controlValue = new MutableLong(NEUTRAL.code());
    final Counter mockControlToggle = mock(Counter.class);
    when(mockControlToggle.get()).thenAnswer((invocation) -> controlValue.value);
    doAnswer((invocation) -> {
        controlValue.value = invocation.getArgument(0);
        return null;
    }).when(mockControlToggle).set(anyLong());
    ctx.moduleStateCounter(mockState);
    ctx.controlToggleCounter(mockControlToggle);
    ctx.epochClock(clock);
    final SequencerAgent agent = newSequencerAgent();
    agent.commitPositionCounter(mock(Counter.class));
    agent.logRecordingPositionCounter(mock(ReadableCounter.class));
    assertThat((int) stateValue.get(), is(ConsensusModule.State.INIT.code()));
    agent.state(ConsensusModule.State.ACTIVE);
    agent.role(Cluster.Role.LEADER);
    assertThat((int) stateValue.get(), is(ConsensusModule.State.ACTIVE.code()));
    controlValue.value = SUSPEND.code();
    clock.update(1);
    agent.doWork();
    assertThat((int) stateValue.get(), is(ConsensusModule.State.SUSPENDED.code()));
    assertThat((int) controlValue.get(), is(NEUTRAL.code()));
    controlValue.value = RESUME.code();
    clock.update(2);
    agent.doWork();
    assertThat((int) stateValue.get(), is(ConsensusModule.State.ACTIVE.code()));
    assertThat((int) controlValue.get(), is(NEUTRAL.code()));
    final InOrder inOrder = Mockito.inOrder(mockLogPublisher);
    inOrder.verify(mockLogPublisher).appendClusterAction(eq(ClusterAction.SUSPEND), anyLong(), anyLong(), anyLong());
    inOrder.verify(mockLogPublisher).appendClusterAction(eq(ClusterAction.RESUME), anyLong(), anyLong(), anyLong());
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) MutableLong(org.agrona.collections.MutableLong) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) Counter(io.aeron.Counter) ReadableCounter(io.aeron.status.ReadableCounter) InOrder(org.mockito.InOrder) CachedEpochClock(org.agrona.concurrent.CachedEpochClock) Test(org.junit.Test)

Example 3 with MutableLong

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));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Example 4 with MutableLong

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));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Example 5 with MutableLong

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

the class ListRecordingsForUriSessionTest method shouldSend2DescriptorsAndRecordingUnknown.

@Test
public void shouldSend2DescriptorsAndRecordingUnknown() {
    final ListRecordingsForUriSession session = new ListRecordingsForUriSession(correlationId, 1, 5, LOCALHOST_BYTES, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer, recordingDescriptorDecoder);
    final MutableLong counter = new MutableLong(1);
    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));
    verify(controlSession).sendRecordingUnknown(eq(correlationId), eq(5L), eq(controlResponseProxy));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

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