private void tryInitialize() { long latestTimestamp = store.getUpperLimit(); PersistentUpperLimit upperLimit = new PersistentUpperLimit(store); timestamp = new PersistentTimestamp(upperLimit, latestTimestamp); }
@Override public void fastForwardTimestamp(long newTimestamp) { checkFastForwardRequest(newTimestamp); log.info("Fast-forwarding the timestamp service to timestamp {}.", SafeArg.of("timestamp", newTimestamp)); timestamp.increaseTo(newTimestamp); }
@Override public TimestampRange getFreshTimestamps(int numTimestampsRequested) { int numTimestampsToReturn = cleanUpTimestampRequest(numTimestampsRequested); TimestampRange range = timestamp.incrementBy(numTimestampsToReturn); DebugLogger.handedOutTimestamps(range); return range; }
@Test public void canFastForwardToANewMinimumTimestamp() { long newMinimum = 2 * UPPER_LIMIT; timestamp.increaseTo(newMinimum); assertThat(timestamp.incrementBy(1).getLowerBound(), is(newMinimum + 1L)); verify(upperLimit).increaseToAtLeast(longThat(is(greaterThan(newMinimum)))); }
@Override public long getUpperLimitTimestampToHandOutInclusive() { return timestamp.getUpperLimitTimestampToHandOutInclusive(); }
@Override public long getUpperLimitTimestampToHandOutInclusive() { return timestamp.getUpperLimitTimestampToHandOutInclusive(); }
@Test public void shouldRequestOnlyRequestASingleTimestampIfOnGetFreshTimestamp() { when(timestamp.incrementBy(1)).thenReturn(SINGLE_TIMESTAMP_RANGE); assertThat(timestampService.getFreshTimestamp(), is(TIMESTAMP)); }
@Test public void shouldDelegateFastForwardingToAvailableTimestamps() { timestampService.fastForwardTimestamp(INITIAL_TIMESTAMP + 1000); verify(timestamp).increaseTo(INITIAL_TIMESTAMP + 1000); }
@Before public void before() { when(upperLimit.get()).thenReturn(5L); timestamp = new PersistentTimestamp(upperLimit, INITIAL_TIMESTAMP); }
@Test public void shouldLimitRequestsTo10000Timestamps() { when(timestamp.incrementBy(anyLong())).thenReturn(RANGE); timestampService.getFreshTimestamps(20000); verify(timestamp).incrementBy(10000); }
@Override public void fastForwardTimestamp(long newTimestamp) { checkFastForwardRequest(newTimestamp); log.info("Fast-forwarding the timestamp service to timestamp {}.", SafeArg.of("timestamp", newTimestamp)); timestamp.increaseTo(newTimestamp); }
private void tryInitialize() { long latestTimestamp = store.getUpperLimit(); PersistentUpperLimit upperLimit = new PersistentUpperLimit(store); timestamp = new PersistentTimestamp(upperLimit, latestTimestamp); }
@Test public void shouldRequestTheRightTimestampFromTheAvailableTimestamps() { when(timestamp.incrementBy(10)).thenReturn(RANGE); assertThat(timestampService.getFreshTimestamps(10), is(RANGE)); }
@Test public void shouldHandOutNonOverLappingTimestampRanges() { TimestampRange first = timestamp.incrementBy(10); TimestampRange second = timestamp.incrementBy(10); assertThat(first.getUpperBound(), is(lessThan(second.getLowerBound()))); }
@Test public void shouldHandOutRangesOfTheCorrectSize() { assertThat(timestamp.incrementBy(10).size(), is(10L)); }
@Test public void shouldIncreaseUpperLimitWhenHandingOutNewTimestamps() { assertThat( timestamp.incrementBy(INITIAL_REMAINING_TIMESTAMPS + 10).getUpperBound(), is(UPPER_LIMIT + 10)); verify(upperLimit).increaseToAtLeast(UPPER_LIMIT + 10); }
@Override public TimestampRange getFreshTimestamps(int numTimestampsRequested) { int numTimestampsToReturn = cleanUpTimestampRequest(numTimestampsRequested); TimestampRange range = timestamp.incrementBy(numTimestampsToReturn); DebugLogger.handedOutTimestamps(range); return range; }