private long findRecordingId(final String expectedChannel) final MutableLong foundRecordingId = new MutableLong();
private static long findLatestRecording(final AeronArchive archive) final MutableLong lastRecordingId = new MutableLong();
@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)); }
@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 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)); }
@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<>();
@Test(timeout = 1000) public void shouldHandleMultipleRounds() { long controlTimestamp = 0; final MutableLong firedTimestamp = new MutableLong(-1); final DeadlineTimerWheel wheel = new DeadlineTimerWheel(TIME_UNIT, controlTimestamp, RESOLUTION, 16); final long id = wheel.scheduleTimer(controlTimestamp + (63 * wheel.tickResolution())); do { wheel.poll( controlTimestamp, (timeUnit, now, timerId) -> { assertThat(timerId, is(id)); firedTimestamp.value = now; return true; }, Integer.MAX_VALUE); controlTimestamp += wheel.tickResolution(); } while (-1 == firedTimestamp.value); // this is the first tick after the timer, so it should be on this edge assertThat(firedTimestamp.value, is(64 * wheel.tickResolution())); }
@Test(timeout = 1000) public void shouldHandleNonZeroStartTime() { long controlTimestamp = 100 * RESOLUTION; final MutableLong firedTimestamp = new MutableLong(-1); final DeadlineTimerWheel wheel = new DeadlineTimerWheel(TIME_UNIT, controlTimestamp, RESOLUTION, 1024); final long id = wheel.scheduleTimer(controlTimestamp + (5 * wheel.tickResolution())); do { wheel.poll( controlTimestamp, (timeUnit, now, timerId) -> { assertThat(timerId, is(id)); firedTimestamp.value = now; return true; }, Integer.MAX_VALUE); controlTimestamp += wheel.tickResolution(); } while (-1 == firedTimestamp.value); // this is the first tick after the timer, so it should be on this edge assertThat(firedTimestamp.value, is(106 * wheel.tickResolution())); }
@Test(timeout = 1000) public void shouldBeAbleToScheduleTimerOnEdgeOfTick() { long controlTimestamp = 0; final MutableLong firedTimestamp = new MutableLong(-1); final DeadlineTimerWheel wheel = new DeadlineTimerWheel(TIME_UNIT, controlTimestamp, RESOLUTION, 1024); final long id = wheel.scheduleTimer(5 * wheel.tickResolution()); do { wheel.poll( controlTimestamp, (timeUnit, now, timerId) -> { assertThat(timerId, is(id)); firedTimestamp.value = now; return true; }, Integer.MAX_VALUE); controlTimestamp += wheel.tickResolution(); } while (-1 == firedTimestamp.value); // this is the first tick after the timer, so it should be on this edge assertThat(firedTimestamp.value, is(6 * wheel.tickResolution())); }
@Test(timeout = 1000) public void shouldHandleNanoTimeUnitTimers() { long controlTimestamp = 0; final MutableLong firedTimestamp = new MutableLong(-1); final DeadlineTimerWheel wheel = new DeadlineTimerWheel(TIME_UNIT, controlTimestamp, RESOLUTION, 1024); final long id = wheel.scheduleTimer(controlTimestamp + (5 * wheel.tickResolution()) + 1); do { wheel.poll( controlTimestamp, (timeUnit, now, timerId) -> { assertThat(timerId, is(id)); firedTimestamp.value = now; return true; }, Integer.MAX_VALUE); controlTimestamp += wheel.tickResolution(); } while (-1 == firedTimestamp.value); // this is the first tick after the timer, so it should be on this edge assertThat(firedTimestamp.value, is(6 * wheel.tickResolution())); }
final MutableLong firedTimestamp1 = new MutableLong(-1); final MutableLong firedTimestamp2 = new MutableLong(-1); final DeadlineTimerWheel wheel = new DeadlineTimerWheel(TIME_UNIT, controlTimestamp, RESOLUTION, 256);
@Test(timeout = 1000) public void shouldHandleExpiringTimersInPreviousTicks() { long controlTimestamp = 0; final MutableLong firedTimestamp = new MutableLong(-1); final DeadlineTimerWheel wheel = new DeadlineTimerWheel(TIME_UNIT, controlTimestamp, RESOLUTION, 256); final long id = wheel.scheduleTimer(controlTimestamp + (15 * wheel.tickResolution())); final long pollStartTimeNs = 32 * wheel.tickResolution(); controlTimestamp += pollStartTimeNs; do { wheel.poll( controlTimestamp, (timeUnit, now, timerId) -> { assertThat(timerId, is(id)); firedTimestamp.value = now; return true; }, Integer.MAX_VALUE); if (wheel.currentTickTime() > pollStartTimeNs) { controlTimestamp += wheel.tickResolution(); } } while (-1 == firedTimestamp.value && controlTimestamp < (128 * wheel.tickResolution())); assertThat(firedTimestamp.value, is(pollStartTimeNs)); }
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);
final int toConsensusModuleStreamId = markFile.decoder().consensusModuleStreamId(); final MutableLong id = new MutableLong(NULL_VALUE); final MemberServiceAdapter.MemberServiceHandler handler = (correlationId, leaderMemberId, activeMembers, passiveMembers) ->