private long putWriteAndFailOnPreCommitConditionReturningStartTimestamp(WriteReference writeRef) { AtomicLong startTs = new AtomicLong(0); assertThatThrownBy(() -> serializableTxManager .runTaskWithConditionWithRetry( FailingPreCommitCondition::new, (txn, ignore) -> { put(txn, writeRef); startTs.set(txn.getTimestamp()); return null; })).isInstanceOf(RuntimeException.class); return startTs.get(); }
@Test public void commitWithPreCommitConditionOnRetry() { Supplier<PreCommitCondition> conditionSupplier = mock(Supplier.class); when(conditionSupplier.get()).thenReturn(ALWAYS_FAILS_CONDITION) .thenReturn(PreCommitConditions.NO_OP); serializableTxManager.runTaskWithConditionWithRetry(conditionSupplier, (tx, condition) -> { tx.put(TABLE, ImmutableMap.of(TEST_CELL, PtBytes.toBytes("value"))); return null; }); }
@Test public void runWithRetryFailsOnNonRetriableException() { PreCommitCondition nonRetriableFailure = new PreCommitCondition() { @Override public void throwIfConditionInvalid(long timestamp) { throw new TransactionFailedNonRetriableException("Condition failed"); } @Override public void cleanup() {} }; Supplier<PreCommitCondition> conditionSupplier = Suppliers.ofInstance(nonRetriableFailure); try { serializableTxManager.runTaskWithConditionWithRetry(conditionSupplier, (tx, condition) -> { tx.put(TABLE, ImmutableMap.of(TEST_CELL, PtBytes.toBytes("value"))); return null; }); fail(); } catch (TransactionFailedNonRetriableException e) { assertThat(e.getMessage(), containsString("Condition failed")); } }
assertThatThrownBy(() -> serializableTxManager.runTaskWithConditionWithRetry(() -> new PreCommitCondition() { @Override public void throwIfConditionInvalid(long timestamp) {