Search in sources :

Example 6 with RangeToken

use of com.palantir.atlasdb.api.RangeToken in project atlasdb by palantir.

the class AtlasConsoleServiceTest method testGetRange.

@Test
public void testGetRange() throws IOException {
    final TableRange input = context.mock(TableRange.class);
    final RangeToken output = context.mock(RangeToken.class);
    context.checking(fromJson(input, TableRange.class));
    context.checking(new Expectations() {

        {
            oneOf(delegate).getRange(token, input);
            will(returnValue(output));
        }
    });
    context.checking(toJson(output, RangeToken.class));
    assertEquals(service.getRange(token, QUERY), RESULT);
    context.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) Test(org.junit.Test)

Example 7 with RangeToken

use of com.palantir.atlasdb.api.RangeToken in project atlasdb by palantir.

the class TransactionRemotingTest method testGetRangeNone.

@Test
public void testGetRangeNone() {
    setupFooStatus1("sweep.priority");
    TransactionToken token = TransactionToken.autoCommit();
    RangeToken range = service.getRange(token, new TableRange("sweep.priority", new byte[1], new byte[2], ImmutableList.<byte[]>of(), 10));
    Assert.assertTrue(Iterables.isEmpty(range.getResults().getResults()));
    Assert.assertNull(range.getNextRange());
}
Also used : TransactionToken(com.palantir.atlasdb.api.TransactionToken) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) Test(org.junit.Test)

Example 8 with RangeToken

use of com.palantir.atlasdb.api.RangeToken in project atlasdb by palantir.

the class TransactionRemotingTest method testDelete.

@Test
public void testDelete() {
    setupFooStatus1("sweep.priority");
    Map<Cell, byte[]> contents = getSweepPriorityTableContents("foo");
    TransactionToken token = TransactionToken.autoCommit();
    service.delete(token, new TableCell("sweep.priority", contents.keySet()));
    RangeToken range = service.getRange(token, new TableRange("sweep.priority", new byte[0], new byte[0], ImmutableList.<byte[]>of(), 10));
    Assert.assertTrue(Iterables.isEmpty(range.getResults().getResults()));
    Assert.assertNull(range.getNextRange());
}
Also used : TableCell(com.palantir.atlasdb.api.TableCell) TransactionToken(com.palantir.atlasdb.api.TransactionToken) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TableCell(com.palantir.atlasdb.api.TableCell) Test(org.junit.Test)

Example 9 with RangeToken

use of com.palantir.atlasdb.api.RangeToken in project atlasdb by palantir.

the class AtlasDbServiceImpl method getRange.

@Override
public RangeToken getRange(TransactionToken token, final TableRange range) {
    return runReadOnly(token, transaction -> {
        int limit = range.getBatchSize() + 1;
        RangeRequest request = RangeRequest.builder().startRowInclusive(range.getStartRow()).endRowExclusive(range.getEndRow()).batchHint(limit).retainColumns(range.getColumns()).build();
        BatchingVisitable<RowResult<byte[]>> visitable = transaction.getRange(getTableRef(range.getTableName()), request);
        List<RowResult<byte[]>> results = BatchingVisitables.limit(visitable, limit).immutableCopy();
        if (results.size() == limit) {
            TableRowResult data = new TableRowResult(range.getTableName(), results.subList(0, limit - 1));
            RowResult<byte[]> lastResultInBatch = results.get(limit - 1);
            TableRange nextRange = range.withStartRow(lastResultInBatch.getRowName());
            return new RangeToken(data, nextRange);
        } else {
            TableRowResult data = new TableRowResult(range.getTableName(), results);
            return new RangeToken(data, null);
        }
    });
}
Also used : TableRowResult(com.palantir.atlasdb.api.TableRowResult) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableRowResult(com.palantir.atlasdb.api.TableRowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange)

Aggregations

RangeToken (com.palantir.atlasdb.api.RangeToken)9 TableRange (com.palantir.atlasdb.api.TableRange)9 Test (org.junit.Test)6 TransactionToken (com.palantir.atlasdb.api.TransactionToken)5 TableRowResult (com.palantir.atlasdb.api.TableRowResult)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 TableCell (com.palantir.atlasdb.api.TableCell)1 TableCellVal (com.palantir.atlasdb.api.TableCellVal)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 SweepPriorityRowResult (com.palantir.atlasdb.schema.generated.SweepPriorityTable.SweepPriorityRowResult)1 Expectations (org.jmock.Expectations)1