@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)); }
private static long findLatestRecording(final AeronArchive archive) final MutableLong lastRecordingId = new MutableLong(); strippedChannel, originalChannel, sourceIdentity) -> lastRecordingId.set(recordingId); return lastRecordingId.get();
public int compareTo(final MutableLong that) { return compare(this.value, that.value); }
final int toConsensusModuleStreamId = markFile.decoder().consensusModuleStreamId(); final MutableLong id = new MutableLong(NULL_VALUE); final MemberServiceAdapter.MemberServiceHandler handler = (correlationId, leaderMemberId, activeMembers, passiveMembers) -> if (correlationId == id.longValue()) id.set(NULL_VALUE); aeron.addSubscription(channel, toServiceStreamId), handler)) id.set(aeron.nextCorrelationId()); if (consensusModuleProxy.clusterMembersQuery(id.longValue())) while (NULL_VALUE != id.longValue()); return id.longValue() == NULL_VALUE;
private Answer<Object> verifySendDescriptor(final MutableLong counter) { return (invocation) -> { final UnsafeBuffer buffer = invocation.getArgument(1); recordingDescriptorDecoder.wrap( buffer, RecordingDescriptorHeaderDecoder.BLOCK_LENGTH, RecordingDescriptorDecoder.BLOCK_LENGTH, RecordingDescriptorDecoder.SCHEMA_VERSION); final int i = counter.intValue(); assertThat(recordingDescriptorDecoder.recordingId(), is(matchingRecordingIds[i])); counter.set(i + 1); return buffer.getInt(0); }; } }
final MutableLong stateValue = new MutableLong(); final Counter mockState = mock(Counter.class); when(mockState.get()).thenAnswer((invocation) -> stateValue.value); .when(mockState).set(anyLong()); final MutableLong controlValue = new MutableLong(NEUTRAL.code()); final Counter mockControlToggle = mock(Counter.class); when(mockControlToggle.get()).thenAnswer((invocation) -> controlValue.value); agent.appendedPositionCounter(mock(ReadableCounter.class)); assertThat((int)stateValue.get(), is(ConsensusModule.State.INIT.code())); assertThat((int)stateValue.get(), is(ConsensusModule.State.ACTIVE.code())); agent.doWork(); assertThat((int)stateValue.get(), is(ConsensusModule.State.SUSPENDED.code())); assertThat((int)controlValue.get(), is(NEUTRAL.code())); agent.doWork(); assertThat((int)stateValue.get(), is(ConsensusModule.State.ACTIVE.code())); assertThat((int)controlValue.get(), is(NEUTRAL.code()));
final int toConsensusModuleStreamId = markFile.decoder().consensusModuleStreamId(); final MutableLong id = new MutableLong(NULL_VALUE); final MemberServiceAdapter.MemberServiceHandler handler = (correlationId, leaderMemberId, activeMembers, passiveMembers) -> if (correlationId == id.longValue()) id.set(NULL_VALUE); aeron.addSubscription(channel, toServiceStreamId), handler)) id.set(aeron.nextCorrelationId()); if (consensusModuleProxy.clusterMembersQuery(id.longValue())) while (NULL_VALUE != id.longValue()); return id.longValue() == NULL_VALUE;
private Answer<Object> verifySendDescriptor(final MutableLong counter) { return (invocation) -> { final UnsafeBuffer buffer = invocation.getArgument(1); recordingDescriptorDecoder.wrap( buffer, RecordingDescriptorHeaderDecoder.BLOCK_LENGTH, RecordingDescriptorDecoder.BLOCK_LENGTH, RecordingDescriptorDecoder.SCHEMA_VERSION); final int i = counter.intValue(); assertThat(recordingDescriptorDecoder.recordingId(), is(recordingIds[i])); counter.set(i + 1); return buffer.getInt(0); }; } }
@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)); }
private long findRecordingId(final String expectedChannel) final MutableLong foundRecordingId = new MutableLong(); strippedChannel, originalChannel, sourceIdentity) -> foundRecordingId.set(recordingId); return foundRecordingId.get();
public int compareTo(final MutableLong that) { return compare(this.value, that.value); }
@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)); }
@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)); }
@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)); session.doWork(); verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy)); verify(controlSession).sendRecordingUnknown(eq(correlationId), eq(5L), eq(controlResponseProxy)); }
@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)); session.doWork(); verify(controlSession, times(3)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy)); }
@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); 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)); }
@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)); session.doWork(); verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy)); }
final MutableLong bytesRead = new MutableLong(); SystemTest.executeUntil( () -> bytesRead.value > 0,
final MutableLong serviceSessionId = new MutableLong(-1L); final MutableLong authenticatorSessionId = new MutableLong(-1L); final MutableReference<byte[]> encodedPrincipal = new MutableReference<>();
final MutableLong serviceSessionId = new MutableLong(-1L); final MutableLong authenticatorSessionId = new MutableLong(-1L); final MutableReference<byte[]> encodedPrincipal = new MutableReference<>();