KeyValueServiceCoordinationStore implements CoordinationStore<T> { @Override public CheckAndSetResult<ValueAndBound<T>> transformAgreedValue(Function<ValueAndBound<T>, T> transform) { Optional<CoordinationStoreState<T>> storeState = readLatestState(); T targetValue = transform.apply( storeState.map(CoordinationStoreState::valueAndBound) .orElseGet(() -> ValueAndBound.of(Optional.empty(), SequenceAndBound.INVALID_BOUND))); SequenceAndBound newSequenceAndBound = determineNewSequenceAndBound(storeState, targetValue); CheckAndSetResult<SequenceAndBound> casResult = checkAndSetCoordinationValue( storeState.map(CoordinationStoreState::sequenceAndBound), newSequenceAndBound); return extractRelevantValues(targetValue, newSequenceAndBound.bound(), casResult); } @VisibleForTesting  KeyValueServiceCoordinationStore(
            ObjectMapper objectMapper,
            KeyValueService kvs,
            byte[] coordinationRow,
            LongSupplier sequenceNumberSupplier,
            BiPredicate<T, T> shouldReuseExtantValue,
            Class<T> clazz); static CoordinationStore<T> create(
            ObjectMapper objectMapper,
            KeyValueService kvs,
            byte[] coordinationRow,
            LongSupplier sequenceNumberSupplier,
            BiPredicate<T, T> shouldReuseExistingValue,
            Class<T> clazz,
            boolean initializeAsync); @Override boolean isInitialized(); @Override Optional<ValueAndBound<T>> getAgreedValue(); @Override CheckAndSetResult<ValueAndBound<T>> transformAgreedValue(Function<ValueAndBound<T>, T> transform);  }
@Test public void retriesOnKeyValueServiceWhenValuesDeletedInTransforms() throws JsonProcessingException { KeyValueService mockKvs = mock(KeyValueService.class); KeyValueServiceCoordinationStore<String> store = coordinationStoreForKvs(mockKvs); setupOnceFailingMockKvs(mockKvs, store); CheckAndSetResult<ValueAndBound<String>> casResult = store.transformAgreedValue(value -> value.value().orElseThrow(() -> new RuntimeException("unexpected absent value")) + "."); assertThat(casResult.successful()).isTrue(); assertThat(Iterables.getOnlyElement(casResult.existingValues()).value()).contains(VALUE_2 + "."); verifyReadsOnOnceFailingMockKvs(mockKvs, store); }