use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class StreamTest method testStreamMetadataConflictDeleteFirst.
@Test
public void testStreamMetadataConflictDeleteFirst() throws Exception {
long streamId = timestampService.getFreshTimestamp();
runConflictingTasksConcurrently(streamId, new TwoConflictingTasks() {
@Override
public void startFirstAndFail(Transaction tx, long streamId) {
StreamTestStreamStore ss = StreamTestStreamStore.of(txManager, StreamTestTableFactory.of());
ss.storeStreams(tx, ImmutableMap.of(streamId, new ByteArrayInputStream(new byte[1])));
}
@Override
public void startSecondAndFinish(Transaction tx, long streamId) {
DeletingStreamStore deletingStreamStore = new DeletingStreamStore(StreamTestStreamStore.of(txManager, StreamTestTableFactory.of()));
deletingStreamStore.deleteStreams(tx, ImmutableSet.of(streamId));
}
});
assertStreamDoesNotExist(streamId);
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testClassicWriteSkew2Cell.
@Test
public void testClassicWriteSkew2Cell() {
Transaction t0 = startTransaction();
put(t0, "row1", "col1", "100");
put(t0, "row2", "col1", "100");
t0.commit();
Transaction t1 = startTransaction();
Transaction t2 = startTransaction();
withdrawMoney(t1, true, true);
withdrawMoney(t2, false, true);
t2.commit();
try {
t1.commit();
fail();
} catch (TransactionSerializableConflictException e) {
// this is expectecd to throw because it is a write skew
}
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testReadOnlySerializableTransactionsIgnoreReadWriteConflicts.
@Test
public void testReadOnlySerializableTransactionsIgnoreReadWriteConflicts() {
Transaction t0 = startTransaction();
put(t0, "row1", "col1", "100");
t0.commit();
Transaction t1 = startTransaction();
get(t1, "row1", "col1");
Transaction t2 = startTransaction();
put(t2, "row1", "col1", "101");
t2.commit();
// Succeeds, even though t1 is serializable, because it's read-only.
t1.commit();
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testPhantomReadFail.
@Test
public void testPhantomReadFail() {
String initialValue = "100";
Transaction t0 = startTransaction();
put(t0, "row1", "col1", initialValue);
put(t0, "row2", "col1", initialValue);
t0.commit();
Transaction t1 = startTransaction();
RowResult<byte[]> first = BatchingVisitables.getFirst(t1.getRange(TEST_TABLE, RangeRequest.builder().build()));
put(t1, "row22", "col1", initialValue);
Transaction t2 = startTransaction();
put(t2, "row0", "col1", initialValue);
t2.commit();
try {
t1.commit();
fail();
} catch (TransactionSerializableConflictException e) {
// this is expectecd to throw because it is a write skew
}
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testConcurrentWriteSkew.
@Test(expected = TransactionFailedRetriableException.class)
public void testConcurrentWriteSkew() throws InterruptedException, BrokenBarrierException {
Transaction t0 = startTransaction();
put(t0, "row1", "col1", "100");
put(t0, "row2", "col1", "100");
t0.commit();
final CyclicBarrier barrier = new CyclicBarrier(2);
final Transaction t1 = startTransaction();
ExecutorService exec = PTExecutors.newCachedThreadPool();
Future<?> future = exec.submit((Callable<Void>) () -> {
withdrawMoney(t1, true, false);
barrier.await();
t1.commit();
return null;
});
Transaction t2 = startTransaction();
withdrawMoney(t2, false, false);
barrier.await();
t2.commit();
try {
future.get();
fail();
} catch (ExecutionException e) {
throw Throwables.rewrapAndThrowUncheckedException(e.getCause());
}
}
Aggregations