@Test public void cannotGetAgreedStateFromTheFuture() { assertThatThrownBy(() -> store.getAgreedState(Long.MAX_VALUE)) .isInstanceOf(NullPointerException.class); }
@VisibleForTesting SequenceAndBound getAgreedState(long seq) { final Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } Optional<SequenceAndBound> lastState = getLearnedState(seq - 1); if (!lastState.isPresent()) { SequenceAndBound forced = forceAgreedState(seq - 2, null); lastState = Optional.of(forceAgreedState(seq - 1, forced.getBound())); } return forceAgreedState(seq, lastState.get().getBound()); }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound getAgreedState(long seq) { final Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } Optional<SequenceAndBound> lastState = getLearnedState(seq - 1); if (!lastState.isPresent()) { SequenceAndBound forced = forceAgreedState(seq - 2, null); lastState = Optional.of(forceAgreedState(seq - 1, forced.getBound())); } return forceAgreedState(seq, lastState.get().getBound()); } }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound getAgreedState(long seq) { final Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } Optional<SequenceAndBound> lastState = getLearnedState(seq - 1); if (!lastState.isPresent()) { SequenceAndBound forced = forceAgreedState(seq - 2, null); lastState = Optional.of(forceAgreedState(seq - 1, forced.getBound())); } return forceAgreedState(seq, lastState.get().getBound()); } PaxosTimestampBoundStore(
            PaxosProposer proposer,
            PaxosLearner knowledge,
            PaxosAcceptorNetworkClient acceptorNetworkClient,
            PaxosLearnerNetworkClient learnerClient,
            long maximumWaitBeforeProposalMs); }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound getAgreedState(long seq) { final Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } Optional<SequenceAndBound> lastState = getLearnedState(seq - 1); if (!lastState.isPresent()) { SequenceAndBound forced = forceAgreedState(seq - 2, null); lastState = Optional.of(forceAgreedState(seq - 1, forced.getBound())); } return forceAgreedState(seq, lastState.get().getBound()); } PaxosTimestampBoundStore(
            PaxosProposer proposer,
            PaxosLearner knowledge,
            PaxosAcceptorNetworkClient acceptorNetworkClient,
            PaxosLearnerNetworkClient learnerClient,
            long maximumWaitBeforeProposalMs); @Override synchronized long getUpperLimit(); @Override synchronized void storeUpperLimit(long limit); }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound getAgreedState(long seq) { final Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } Optional<SequenceAndBound> lastState = getLearnedState(seq - 1); if (!lastState.isPresent()) { SequenceAndBound forced = forceAgreedState(seq - 2, null); lastState = Optional.of(forceAgreedState(seq - 1, forced.getBound())); } return forceAgreedState(seq, lastState.get().getBound()); } PaxosTimestampBoundStore(
            PaxosProposer proposer,
            PaxosLearner knowledge,
            PaxosAcceptorNetworkClient acceptorNetworkClient,
            PaxosLearnerNetworkClient learnerClient,
            long maximumWaitBeforeProposalMs); @Override synchronized long getUpperLimit(); @Override synchronized void storeUpperLimit(long limit);  }