use of com.palantir.common.base.BatchingVisitable in project atlasdb by palantir.
the class AbstractTransactionTest method testRangesTransactionColumnSelection.
@Test
public void testRangesTransactionColumnSelection() {
Transaction t = startTransaction();
put(t, "row1", "col1", "v1");
t.commit();
RangeRequest range1 = RangeRequest.builder().batchHint(3).build();
RangeRequest range2 = range1.getBuilder().retainColumns(ColumnSelection.create(ImmutableSet.of(PtBytes.toBytes("col1")))).build();
t = startTransaction();
Iterable<BatchingVisitable<RowResult<byte[]>>> ranges = t.getRanges(TEST_TABLE, Iterables.limit(Iterables.cycle(range1, range2), 1000));
for (BatchingVisitable<RowResult<byte[]>> batchingVisitable : ranges) {
final List<RowResult<byte[]>> list = BatchingVisitables.copyToList(batchingVisitable);
assertEquals(1, list.size());
assertEquals(1, list.get(0).getColumns().size());
}
RangeRequest range3 = range1.getBuilder().retainColumns(ColumnSelection.create(ImmutableSet.of(PtBytes.toBytes("col2")))).build();
verifyAllGetRangesImplsRangeSizes(t, range3, 0);
}
use of com.palantir.common.base.BatchingVisitable 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.common.base.BatchingVisitable 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.common.base.BatchingVisitable 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.common.base.BatchingVisitable in project atlasdb by palantir.
the class AbstractSerializableTransactionTest method testColumnRangeReadWriteNoConflict.
@Test
public void testColumnRangeReadWriteNoConflict() {
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();
put(t2, "row1", "col1", "v0_0");
t2.commit();
t1.commit();
}
Aggregations