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));
}
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());
}
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 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));
}
Aggregations