Search in sources :

Example 61 with RangeRequest

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"));
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 62 with RangeRequest

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());
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 63 with RangeRequest

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"));
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 64 with RangeRequest

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()));
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 65 with RangeRequest

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);
    }
}
Also used : TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) BlockingWorkerPool(com.palantir.common.concurrent.BlockingWorkerPool)

Aggregations

RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)68 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)36 Test (org.junit.Test)35 Value (com.palantir.atlasdb.keyvalue.api.Value)17 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)14 Cell (com.palantir.atlasdb.keyvalue.api.Cell)12 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 List (java.util.List)5 Set (java.util.Set)5 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 StringValue (com.palantir.atlasdb.table.description.test.StringValue)4 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)4 Map (java.util.Map)4 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)3 AbstractIterator (com.google.common.collect.AbstractIterator)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Hashing (com.google.common.hash.Hashing)2 NameComponentDescription (com.palantir.atlasdb.table.description.NameComponentDescription)2 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)2 ClosableIterator (com.palantir.common.base.ClosableIterator)2