use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testNoNonRepeatableReads.
@Test
public void testNoNonRepeatableReads() {
Transaction t0 = startTransaction();
put(t0, "row1", "col1", "v1");
t0.commit();
Transaction t1 = startTransaction();
assertEquals("v1", get(t1, "row1", "col1"));
Transaction t2 = startTransaction();
put(t2, "row1", "col1", "v2");
t2.commit();
// Repeated read: should see original value.
assertEquals("v1", get(t1, "row1", "col1"));
Transaction t3 = startTransaction();
assertEquals("v2", get(t3, "row1", "col1"));
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testReadMyWrites.
@Test
public void testReadMyWrites() {
Transaction t = startTransaction();
put(t, "row1", "col1", "v1");
put(t, "row1", "col2", "v2");
put(t, "row2", "col1", "v3");
assertEquals("v1", get(t, "row1", "col1"));
assertEquals("v2", get(t, "row1", "col2"));
assertEquals("v3", get(t, "row2", "col1"));
t.commit();
t = startTransaction();
assertEquals("v1", get(t, "row1", "col1"));
assertEquals("v2", get(t, "row1", "col2"));
assertEquals("v3", get(t, "row2", "col1"));
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testReadMyWritesColumnRangePagingTransaction.
@Test
public void testReadMyWritesColumnRangePagingTransaction() {
Transaction t = startTransaction();
int totalPuts = 101;
byte[] row = PtBytes.toBytes("row1");
// Record expected results using byte ordering
ImmutableSortedMap.Builder<Cell, byte[]> writes = ImmutableSortedMap.orderedBy(Ordering.from(UnsignedBytes.lexicographicalComparator()).onResultOf(key -> key.getColumnName()));
for (int i = 0; i < totalPuts; i++) {
put(t, "row1", "col" + i, "v" + i);
if (i % 2 == 0) {
writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("v" + i));
}
}
t.commit();
t = startTransaction();
for (int i = 0; i < totalPuts; i++) {
if (i % 2 == 1) {
put(t, "row1", "col" + i, "t_v" + i);
writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("t_v" + i));
}
}
Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
List<Map.Entry<Cell, byte[]>> expected = ImmutableList.copyOf(writes.build().entrySet());
verifyMatchingResult(expected, row, columnRange);
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testWriteWriteConflict2.
@Test
public void testWriteWriteConflict2() {
Transaction t2 = startTransaction();
Transaction t1 = startTransaction();
put(t1, "row1", "col1", "v1");
put(t2, "row1", "col1", "v2");
t1.commit();
try {
t2.commit();
fail("Expected write-write conflict.");
} catch (TransactionConflictException e) {
// expected
}
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testReadMyWritesAfterGetRange.
@Test
public void testReadMyWritesAfterGetRange() throws InterruptedException, ExecutionException {
Transaction t = startTransaction();
// this will come first in the range
put(t, "row0", "col1", "v0");
put(t, "row1", "col1", "v1");
put(t, "row1", "col2", "v2");
put(t, "row2", "col1", "v3");
put(t, "row4", "col1", "v4");
t.commit();
t = startTransaction();
assertEquals("v1", get(t, "row1", "col1"));
assertEquals("v2", get(t, "row1", "col2"));
assertEquals("v3", get(t, "row2", "col1"));
// we need a bunch of buffer writes so that we don't exhaust the local iterator right away
// because of peeking iterators looking ahead
put(t, "a0", "col2", "v0");
put(t, "b1", "col3", "v0");
put(t, "c2", "col3", "v0");
put(t, "d3", "col3", "v0");
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final BatchingVisitable<RowResult<byte[]>> visitable = t.getRange(TEST_TABLE, RangeRequest.builder().build());
FutureTask<Void> futureTask = new FutureTask<Void>(() -> {
final Map<Cell, byte[]> vals = Maps.newHashMap();
try {
visitable.batchAccept(1, AbortingVisitors.batching((RowVisitor) item -> {
try {
latch.countDown();
latch2.await();
} catch (InterruptedException e) {
throw Throwables.throwUncheckedException(e);
}
MapEntries.putAll(vals, item.getCells());
if (Arrays.equals(item.getRowName(), "row1".getBytes())) {
assertEquals("v5", new String(item.getColumns().get("col1".getBytes())));
assertEquals(3, IterableView.of(item.getCells()).size());
}
return true;
}));
assertTrue(vals.containsKey(Cell.create("row1".getBytes(), "col1".getBytes())));
assertTrue(Arrays.equals("v5".getBytes(), vals.get(Cell.create("row1".getBytes(), "col1".getBytes()))));
assertFalse(vals.containsKey(Cell.create("row2".getBytes(), "col1".getBytes())));
return null;
} catch (Throwable t1) {
latch.countDown();
Throwables.throwIfInstance(t1, Exception.class);
throw Throwables.throwUncheckedException(t1);
}
});
Thread thread = new Thread(futureTask);
thread.setName("testReadMyWritesAfterGetRange");
thread.start();
latch.await();
// These puts will be seen by the range scan happening on the other thread
// this put is checked to exist
put(t, "row1", "col1", "v5");
// it is checked there are 3 cells for this
put(t, "row1", "col3", "v6");
put(t, "row3", "col1", "v7");
// this delete is checked
delete(t, "row2", "col1");
put(t, "row2", "col2", "v8");
latch2.countDown();
futureTask.get();
}
Aggregations