public void increaseTo(long newTimestamp) { timestamp.increaseTo(newTimestamp); upperLimit.increaseToAtLeast(newTimestamp); }
public TimestampRange incrementBy(long delta) { TimestampRange range = timestamp.incrementBy(delta); upperLimit.increaseToAtLeast(range.getUpperBound()); return range; }
public PersistentTimestamp(PersistentUpperLimit upperLimit, long lastKnownValue) { this.upperLimit = upperLimit; this.timestamp = new AtomicTimestamp(lastKnownValue); DebugLogger.createdPersistentTimestamp(); }
@Test public void cannotOverflow() { timestamp.increaseTo(Long.MAX_VALUE); assertThatExceptionOfType(ArithmeticException.class).isThrownBy(() -> timestamp.incrementBy(1)); }
@Test public void handleConcurrentlyIncreasingTheValue() throws InterruptedException { for (int i = 0; i < 100; i++) { executor.submit(() -> timestamp.incrementBy(1)); } waitForExecutorToFinish(); assertThat(timestamp.incrementBy(1).getUpperBound(), is(INITIAL_TIMESTAMP + 101)); }
public void increaseTo(long newTimestamp) { timestamp.increaseTo(newTimestamp); upperLimit.increaseToAtLeast(newTimestamp); }
public PersistentTimestamp(PersistentUpperLimit upperLimit, long lastKnownValue) { this.upperLimit = upperLimit; this.timestamp = new AtomicTimestamp(lastKnownValue); DebugLogger.createdPersistentTimestamp(); }
@Test public void shouldIncreaseTheValueToAHigherNumber() { TimestampRange range = timestamp.incrementBy(10); assertThat(range.getUpperBound(), is(INITIAL_TIMESTAMP + 10)); }
public TimestampRange incrementBy(long delta) { TimestampRange range = timestamp.incrementBy(delta); upperLimit.increaseToAtLeast(range.getUpperBound()); return range; }