@Test public void valuePreservingTransformationsDoNotWriteTheSameValueAgain() { coordinationStore.transformAgreedValue(unused -> VALUE_1); SequenceAndBound firstSequenceAndBound = coordinationStore.getCoordinationValue().get(); coordinationStore.transformAgreedValue(VALUE_PRESERVING_FUNCTION); SequenceAndBound secondSequenceAndBound = coordinationStore.getCoordinationValue().get(); assertThat(firstSequenceAndBound.sequence()).isEqualTo(secondSequenceAndBound.sequence()); assertThat(firstSequenceAndBound.bound()).isLessThan(secondSequenceAndBound.bound()); }
@Test public void valuePreservingTransformationsAdvanceTheBound() { coordinationStore.transformAgreedValue(unused -> VALUE_1); ValueAndBound<String> firstValueAndBound = coordinationStore.getAgreedValue().get(); coordinationStore.transformAgreedValue(VALUE_PRESERVING_FUNCTION); ValueAndBound<String> secondValueAndBound = coordinationStore.getAgreedValue().get(); assertThat(firstValueAndBound.value()).contains(VALUE_1); assertThat(secondValueAndBound.value()).contains(VALUE_1); assertThat(firstValueAndBound.bound()).isLessThan(secondValueAndBound.bound()); }
@Test public void canApplyMultipleTransformations() { coordinationStore.transformAgreedValue(unused -> VALUE_1); ValueAndBound<String> firstValueAndBound = coordinationStore.getAgreedValue().get(); coordinationStore.transformAgreedValue(unused -> VALUE_2); ValueAndBound<String> secondValueAndBound = coordinationStore.getAgreedValue().get(); assertThat(firstValueAndBound.value()).contains(VALUE_1); assertThat(secondValueAndBound.value()).contains(VALUE_2); assertThat(firstValueAndBound.bound()).isLessThan(secondValueAndBound.bound()); }
@Test public void canStoreAndRetrieveValues() { CheckAndSetResult<ValueAndBound<String>> casResult = coordinationStore.transformAgreedValue(unused -> VALUE_1); assertThat(casResult.successful()).isTrue(); assertThat(Iterables.getOnlyElement(casResult.existingValues()).value()).contains(VALUE_1); assertThat(coordinationStore.getAgreedValue()).hasValueSatisfying( valueAndBound -> { assertThat(valueAndBound.value()).contains(VALUE_1); assertThat(valueAndBound.bound()).isGreaterThanOrEqualTo(0); }); }
@Test public void multipleStoresCanCoexist() { byte[] otherCoordinationKey = PtBytes.toBytes("bbbbb"); CoordinationStore<String> otherCoordinationStore = KeyValueServiceCoordinationStore.create( ObjectMappers.newServerObjectMapper(), keyValueService, otherCoordinationKey, timestampSequence::incrementAndGet, String.class, false); coordinationStore.transformAgreedValue(unused -> VALUE_1); otherCoordinationStore.transformAgreedValue(unused -> VALUE_2); assertThat(coordinationStore.getAgreedValue().get().value()).contains(VALUE_1); assertThat(otherCoordinationStore.getAgreedValue().get().value()).contains(VALUE_2); } }