use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testReadMyWritesRange.
@Test
public void testReadMyWritesRange() {
Transaction t = startTransaction();
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"));
BatchingVisitable<RowResult<byte[]>> visitable = t.getRange(TEST_TABLE, RangeRequest.builder().build());
put(t, "row0", "col1", "v5");
put(t, "row1", "col1", "v5");
put(t, "row1", "col3", "v6");
put(t, "row3", "col1", "v7");
delete(t, "row2", "col1");
put(t, "row2", "col2", "v8");
final Map<Cell, byte[]> vals = Maps.newHashMap();
visitable.batchAccept(100, AbortingVisitors.batching((RowVisitor) item -> {
MapEntries.putAll(vals, item.getCells());
if (Arrays.equals(item.getRowName(), "row1".getBytes())) {
assertEquals(3, IterableView.of(item.getCells()).size());
assertEquals("v5", new String(item.getColumns().get("col1".getBytes())));
}
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())));
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testColumnRangeReadWriteConflictOnNewCell.
@Test
public void testColumnRangeReadWriteConflictOnNewCell() {
byte[] row = PtBytes.toBytes("row1");
writeColumns();
Transaction t1 = startTransaction();
Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t1.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
// Serializable transaction records only the first column as read.
Map.Entry<Cell, byte[]> read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()));
assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey());
// Write to avoid the read only path.
put(t1, "row1_1", "col0", "v0");
Transaction t2 = startTransaction();
// Write on the start of the range.
put(t2, "row1", "col", "v");
t2.commit();
try {
t1.commit();
fail();
} catch (TransactionSerializableConflictException e) {
// expected
}
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testNonPhantomRead.
@Test
public void testNonPhantomRead() {
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, "row11", "col1", initialValue);
t2.commit();
t1.commit();
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testColumnSelection2.
@Test
public void testColumnSelection2() {
String initialValue = "100";
Transaction t0 = startTransaction();
put(t0, "row1", "col1", initialValue);
put(t0, "row1", "col2", initialValue);
put(t0, "row2", "col1", initialValue);
t0.commit();
Transaction t1 = startTransaction();
BatchingVisitables.copyToList(getRangeRetainingCol(t1, "col1"));
BatchingVisitables.copyToList(getRangeRetainingCol(t1, "col2"));
// We need to do at least one put so we don't get caught by the read only code path
put(t1, "row22", "col2", initialValue);
t1.commit();
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testCellReadWriteFailure2.
@Test
public void testCellReadWriteFailure2() {
String initialValue = "100";
Transaction t0 = startTransaction();
put(t0, "row1", "col1", initialValue);
put(t0, "row2", "col1", initialValue);
t0.commit();
Transaction t1 = startTransaction();
BatchingVisitables.copyToList(t1.getRange(TEST_TABLE, RangeRequest.builder().build()));
put(t1, "row22", "col1", initialValue);
Transaction t2 = startTransaction();
put(t2, "row2", "col1", "101");
t2.commit();
try {
t1.commit();
fail();
} catch (TransactionSerializableConflictException e) {
// this is expectecd to throw because it is a write skew
}
}
Aggregations