use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testReadMyDeletesColumnRangePagingTransaction.
@Test
public void testReadMyDeletesColumnRangePagingTransaction() {
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) {
delete(t, "row1", "col" + 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 testEmptyColumnRangePagingTransaction.
@Test
public void testEmptyColumnRangePagingTransaction() {
byte[] row = PtBytes.toBytes("row1");
Transaction t = startTransaction();
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.of();
verifyMatchingResult(expected, row, columnRange);
put(t, "row1", "col1", "v1");
t.commit();
t = startTransaction();
delete(t, "row1", "col1");
columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
verifyMatchingResult(expected, row, columnRange);
t.commit();
t = startTransaction();
columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
verifyMatchingResult(expected, row, columnRange);
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testGetRanges.
@Test
public void testGetRanges() {
Transaction t = startTransaction();
byte[] row1Bytes = PtBytes.toBytes("row1");
Cell row1Key = Cell.create(row1Bytes, PtBytes.toBytes("col"));
byte[] row1Value = PtBytes.toBytes("value1");
byte[] row2Bytes = PtBytes.toBytes("row2");
Cell row2Key = Cell.create(row2Bytes, PtBytes.toBytes("col"));
byte[] row2Value = PtBytes.toBytes("value2");
t.put(TEST_TABLE, ImmutableMap.of(row1Key, row1Value, row2Key, row2Value));
t.commit();
t = startTransaction();
List<RangeRequest> ranges = ImmutableList.of(RangeRequest.builder().prefixRange(row1Bytes).build(), RangeRequest.builder().prefixRange(row2Bytes).build());
verifyAllGetRangesImplsNumRanges(t, ranges, ImmutableList.of("value1", "value2"));
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testWriteWriteConflict.
@Test
public void testWriteWriteConflict() {
Transaction t1 = startTransaction();
Transaction t2 = 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 testGetRangesPaging.
@Test
public void testGetRangesPaging() {
Transaction t = startTransaction();
byte[] row0Bytes = PtBytes.toBytes("row0");
byte[] row00Bytes = PtBytes.toBytes("row00");
byte[] colBytes = PtBytes.toBytes("col");
Cell k1 = Cell.create(row00Bytes, colBytes);
byte[] row1Bytes = PtBytes.toBytes("row1");
Cell k2 = Cell.create(row1Bytes, colBytes);
byte[] v = PtBytes.toBytes("v");
t.put(TEST_TABLE, ImmutableMap.of(Cell.create(row0Bytes, colBytes), v));
t.put(TEST_TABLE, ImmutableMap.of(k1, v));
t.put(TEST_TABLE, ImmutableMap.of(k2, v));
t.commit();
t = startTransaction();
t.delete(TEST_TABLE, ImmutableSet.of(k1));
t.commit();
t = startTransaction();
byte[] rangeEnd = RangeRequests.nextLexicographicName(row00Bytes);
List<RangeRequest> ranges = ImmutableList.of(RangeRequest.builder().prefixRange(row0Bytes).endRowExclusive(rangeEnd).batchHint(1).build());
verifyAllGetRangesImplsNumRanges(t, ranges, ImmutableList.of("v"));
}
Aggregations