@Test public void throwsIfAttemptingToPutTwice() { coordinationStore.putUnlessValueExists(SEQUENCE_NUMBER_1, VALUE_1); assertThatThrownBy(() -> coordinationStore.putUnlessValueExists(SEQUENCE_NUMBER_1, VALUE_2)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly."); }
@VisibleForTesting void putUnlessValueExists(long sequenceNumber, T value) { Preconditions.checkState( sequenceNumber > 0, "Only positive sequence numbers are supported, but found %s", sequenceNumber); try { kvs.putUnlessExists(AtlasDbConstants.COORDINATION_TABLE, ImmutableMap.of(getCellForSequence(sequenceNumber), serializeValue(value))); } catch (KeyAlreadyExistsException e) { throw new SafeIllegalStateException("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly." + " The offending sequence number was {}. " + " Please contact support - DO NOT ATTEMPT TO FIX THIS YOURSELF.", e, SafeArg.of("sequenceNumber", sequenceNumber)); } }
KeyValueServiceCoordinationStore implements CoordinationStore<T> { @VisibleForTesting void putUnlessValueExists(long sequenceNumber, T value) { Preconditions.checkState( sequenceNumber > 0, "Only positive sequence numbers are supported, but found %s", sequenceNumber); try { kvs.putUnlessExists(AtlasDbConstants.COORDINATION_TABLE, ImmutableMap.of(getCellForSequence(sequenceNumber), serializeValue(value))); } catch (KeyAlreadyExistsException e) { throw new SafeIllegalStateException("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly." + " The offending sequence number was {}. " + " Please contact support - DO NOT ATTEMPT TO FIX THIS YOURSELF.", e, SafeArg.of("sequenceNumber", sequenceNumber)); } } }
KeyValueServiceCoordinationStore implements CoordinationStore<T> { @VisibleForTesting void putUnlessValueExists(long sequenceNumber, T value) { Preconditions.checkState( sequenceNumber > 0, "Only positive sequence numbers are supported, but found %s", sequenceNumber); try { kvs.putUnlessExists(AtlasDbConstants.COORDINATION_TABLE, ImmutableMap.of(getCellForSequence(sequenceNumber), serializeValue(value))); } catch (KeyAlreadyExistsException e) { throw new SafeIllegalStateException("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly." + " The offending sequence number was {}. " + " Please contact support - DO NOT ATTEMPT TO FIX THIS YOURSELF.", e, SafeArg.of("sequenceNumber", sequenceNumber)); } } @VisibleForTesting  KeyValueServiceCoordinationStore(
            ObjectMapper objectMapper,
            KeyValueService kvs,
            byte[] coordinationRow,
            LongSupplier sequenceNumberSupplier,
            BiPredicate<T, T> shouldReuseExtantValue,
            Class<T> clazz); }
KeyValueServiceCoordinationStore implements CoordinationStore<T> { @VisibleForTesting void putUnlessValueExists(long sequenceNumber, T value) { Preconditions.checkState( sequenceNumber > 0, "Only positive sequence numbers are supported, but found %s", sequenceNumber); try { kvs.putUnlessExists(AtlasDbConstants.COORDINATION_TABLE, ImmutableMap.of(getCellForSequence(sequenceNumber), serializeValue(value))); } catch (KeyAlreadyExistsException e) { throw new SafeIllegalStateException("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly." + " The offending sequence number was {}. " + " Please contact support - DO NOT ATTEMPT TO FIX THIS YOURSELF.", e, SafeArg.of("sequenceNumber", sequenceNumber)); } } @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); }
KeyValueServiceCoordinationStore implements CoordinationStore<T> { @VisibleForTesting void putUnlessValueExists(long sequenceNumber, T value) { Preconditions.checkState( sequenceNumber > 0, "Only positive sequence numbers are supported, but found %s", sequenceNumber); try { kvs.putUnlessExists(AtlasDbConstants.COORDINATION_TABLE, ImmutableMap.of(getCellForSequence(sequenceNumber), serializeValue(value))); } catch (KeyAlreadyExistsException e) { throw new SafeIllegalStateException("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly." + " The offending sequence number was {}. " + " Please contact support - DO NOT ATTEMPT TO FIX THIS YOURSELF.", e, SafeArg.of("sequenceNumber", sequenceNumber)); } } @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);  }