use of com.palantir.atlasdb.transaction.api.PreCommitCondition in project atlasdb by palantir.
the class SnapshotTransactionTest method cleanupPreCommitConditionsOnSuccess.
@Test
public void cleanupPreCommitConditionsOnSuccess() {
MutableLong counter = new MutableLong(0L);
PreCommitCondition succeedsCondition = new PreCommitCondition() {
@Override
public void throwIfConditionInvalid(long timestamp) {
}
@Override
public void cleanup() {
counter.increment();
}
};
serializableTxManager.runTaskWithConditionThrowOnConflict(succeedsCondition, (tx, condition) -> {
tx.put(TABLE, ImmutableMap.of(TEST_CELL, PtBytes.toBytes("value")));
return null;
});
assertThat(counter.intValue(), is(1));
serializableTxManager.runTaskReadOnlyWithCondition(succeedsCondition, (tx, condition) -> tx.get(TABLE, ImmutableSet.of(TEST_CELL)));
assertThat(counter.intValue(), is(2));
}
use of com.palantir.atlasdb.transaction.api.PreCommitCondition in project atlasdb by palantir.
the class SnapshotTransactionTest method runWithRetryFailsOnNonRetriableException.
@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"));
}
}
use of com.palantir.atlasdb.transaction.api.PreCommitCondition in project atlasdb by palantir.
the class SnapshotTransactionTest method cleanupPreCommitConditionsOnFailure.
@Test
public void cleanupPreCommitConditionsOnFailure() {
MutableLong counter = new MutableLong(0L);
PreCommitCondition failsCondition = new PreCommitCondition() {
@Override
public void throwIfConditionInvalid(long timestamp) {
throw new TransactionFailedRetriableException("Condition failed");
}
@Override
public void cleanup() {
counter.increment();
}
};
try {
serializableTxManager.runTaskWithConditionThrowOnConflict(failsCondition, (tx, condition) -> {
tx.put(TABLE, ImmutableMap.of(TEST_CELL, PtBytes.toBytes("value")));
return null;
});
fail();
} catch (TransactionFailedRetriableException e) {
// expected
}
assertThat(counter.intValue(), is(1));
try {
serializableTxManager.runTaskReadOnlyWithCondition(failsCondition, (tx, condition) -> tx.get(TABLE, ImmutableSet.of(TEST_CELL)));
fail();
} catch (TransactionFailedRetriableException e) {
// expected
}
assertThat(counter.intValue(), is(2));
}
Aggregations