use of com.palantir.atlasdb.keyvalue.api.RangeRequest 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.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractTransactionTest method testRangeBatchSizeOne.
@Test
public void testRangeBatchSizeOne() {
RangeRequest range = RangeRequest.builder().batchHint(1).build();
ClosableIterator<RowResult<Value>> ranges = keyValueService.getRange(TEST_TABLE, range, 1);
assertEquals(false, ranges.hasNext());
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest 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"));
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractTransactionTest method testKeyValueRangeReverse.
@Test
public void testKeyValueRangeReverse() {
if (!supportsReverse()) {
return;
}
putDirect("row1", "col1", "", 0);
putDirect("row2", "col1", "", 0);
putDirect("row2", "col2", "", 0);
RangeRequest allRange = RangeRequest.reverseBuilder().batchHint(3).build();
ClosableIterator<RowResult<Value>> range = keyValueService.getRange(TEST_TABLE, allRange, 1);
ImmutableList<RowResult<Value>> list = ImmutableList.copyOf(range);
assertEquals(2, list.size());
assertEquals("row2", PtBytes.toString(list.iterator().next().getRowName()));
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class KeyValueServices method getFirstBatchForRangesUsingGetRangeConcurrent.
@SuppressWarnings("checkstyle:LineLength")
public static Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> getFirstBatchForRangesUsingGetRangeConcurrent(ExecutorService executor, final KeyValueService kv, final TableReference tableRef, Iterable<RangeRequest> rangeRequests, final long timestamp, int maxConcurrentRequests) {
final Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ret = Maps.newConcurrentMap();
BlockingWorkerPool pool = new BlockingWorkerPool(executor, maxConcurrentRequests);
try {
for (final RangeRequest request : rangeRequests) {
pool.submitTask(() -> getFirstBatchForRangeUsingGetRange(kv, tableRef, request, timestamp, ret));
}
pool.waitForSubmittedTasks();
return ret;
} catch (InterruptedException e) {
throw Throwables.rewrapAndThrowUncheckedException(e);
}
}
Aggregations