lowerBound = conservativeBound().applyAsLong(transactionManager); } catch (Exception e) { log.warn("Could not obtain a lower bound on timestamps, so we don't know if our transaction manager" + " is consistent"); return indeterminateResultForException(e); freshTimestamp = freshTimestampSource().applyAsLong(transactionManager); } catch (Exception e) { log.warn("Could not obtain a fresh timestamp, so we don't know if our transaction manager is" + " consistent."); return indeterminateResultForException(e); return ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.TERMINAL) .reasonForInconsistency(clocksWentBackwards(lowerBound, freshTimestamp)) .build();
@Test public void returnsTerminalIfBoundEqualsFreshTimestamp() { TimestampCorroborationConsistencyCheck check = createForTimestamps(42, 42); assertThat(check.apply(mock(TransactionManager.class))).satisfies( result -> { assertThat(result.consistencyState()).isEqualTo( TransactionManagerConsistencyResult.ConsistencyState.TERMINAL); assertThat(result.reasonForInconsistency()).isPresent(); }); }
lowerBound = conservativeBound().applyAsLong(transactionManager); } catch (Exception e) { log.warn("Could not obtain a lower bound on timestamps, so we don't know if our transaction manager" + " is consistent"); return indeterminateResultForException(e); freshTimestamp = freshTimestampSource().applyAsLong(transactionManager); } catch (Exception e) { log.warn("Could not obtain a fresh timestamp, so we don't know if our transaction manager is" + " consistent."); return indeterminateResultForException(e); return ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.TERMINAL) .reasonForInconsistency(clocksWentBackwards(lowerBound, freshTimestamp)) .build();
@Test public void returnsTerminalIfBoundIsAboveFreshTimestamp() { TimestampCorroborationConsistencyCheck check = createForTimestamps(111, 42); assertThat(check.apply(mock(TransactionManager.class))).satisfies( result -> { assertThat(result.consistencyState()).isEqualTo( TransactionManagerConsistencyResult.ConsistencyState.TERMINAL); assertThat(result.reasonForInconsistency()).isPresent(); }); }
@Test public void returnsConsistentIfBoundIsBelowFreshTimestamp() { TimestampCorroborationConsistencyCheck check = createForTimestamps(10, 20); assertThat(check.apply(mock(TransactionManager.class))) .isEqualTo(ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.CONSISTENT) .build()); }
@Test public void returnsIndeterminateIfCannotGetFreshTimestamp() { TimestampCorroborationConsistencyCheck checkFailingToGetFresh = ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(txMgr -> 10L) .freshTimestampSource(EXCEPTION_THROWER) .build(); assertThat(checkFailingToGetFresh.apply(mock(TransactionManager.class))) .isEqualTo(ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.INDETERMINATE) .reasonForInconsistency(EXCEPTION) .build()); }
@Test public void returnsIndeterminateIfCannotGetConservativeBound() { TimestampCorroborationConsistencyCheck checkFailingToGetBound = ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(EXCEPTION_THROWER) .freshTimestampSource(txMgr -> 7L) .build(); assertThat(checkFailingToGetBound.apply(mock(TransactionManager.class))) .isEqualTo(ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.INDETERMINATE) .reasonForInconsistency(EXCEPTION) .build()); }