PreStartHandlingTransactionService implements TransactionService { @CheckForNull @Override public Long get(long startTimestamp) { return AtlasFutures.getUnchecked(getInternal(startTimestamp, synchronousAsyncTransactionService)); } PreStartHandlingTransactionService(TransactionService delegate); @CheckForNull @Override Long get(long startTimestamp); @Override Map<Long, Long> get(Iterable<Long> startTimestamps); @Override ListenableFuture<Long> getAsync(long startTimestamp); @Override ListenableFuture<Map<Long, Long>> getAsync(Iterable<Long> startTimestamps); @Override void putUnlessExists(long startTimestamp, long commitTimestamp); @Override void close();  }
@Test public void passesThroughGetsOnValidCommittedTimestamp() { Long timestamp = preStartHandlingService.get(START_TIMESTAMP); assertThat(timestamp).isEqualTo(COMMIT_TIMESTAMP); verify(delegate).get(START_TIMESTAMP); }
@Test public void passesThroughGetsOnValidUncommittedTimestamp() { Long timestamp = preStartHandlingService.get(UNCOMMITTED_START_TIMESTAMP); assertThat(timestamp).isNull(); verify(delegate).get(UNCOMMITTED_START_TIMESTAMP); }
@Test public void returnsTimestampBeforeStartingTimestampWhenGettingInvalidTimestamps() { assertThat(preStartHandlingService.get(ZERO_TIMESTAMP)).isEqualTo(BEFORE_TIME_TIMESTAMP); assertThat(preStartHandlingService.get(NEGATIVE_TIMESTAMP)).isEqualTo(BEFORE_TIME_TIMESTAMP); }
@Test public void passesThroughGetsOnMultipleValidTimestamps() { Map<Long, Long> result = preStartHandlingService.get(TWO_VALID_TIMESTAMPS); assertThat(result).containsExactly(Maps.immutableEntry(START_TIMESTAMP, COMMIT_TIMESTAMP)); verify(delegate).get(eq(TWO_VALID_TIMESTAMPS)); }
@Test public void passesThroughOnlyValidTimestampsToDelegateWhenGettingMultiple() { Map<Long, Long> result = preStartHandlingService.get(ONE_VALID_ONE_INVALID_TIMESTAMP); assertThat(result).containsOnly( Maps.immutableEntry(START_TIMESTAMP, COMMIT_TIMESTAMP), Maps.immutableEntry(ZERO_TIMESTAMP, BEFORE_TIME_TIMESTAMP)); verify(delegate).get(eq(ImmutableList.of(START_TIMESTAMP))); }
@Test public void doesNotInvokeDelegateIfNoValidTimestamps() { Map<Long, Long> result = preStartHandlingService.get(TWO_INVALID_TIMESTAMPS); assertThat(result).containsOnly( Maps.immutableEntry(ZERO_TIMESTAMP, BEFORE_TIME_TIMESTAMP), Maps.immutableEntry(NEGATIVE_TIMESTAMP, BEFORE_TIME_TIMESTAMP)); }