use of com.palantir.atlasdb.api.TableRange 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();
}
use of com.palantir.atlasdb.api.TableRange 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());
}
use of com.palantir.atlasdb.api.TableRange 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());
}
use of com.palantir.atlasdb.api.TableRange 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);
}
});
}
use of com.palantir.atlasdb.api.TableRange in project atlasdb by palantir.
the class TableRangeDeserializer method deserialize.
@Override
public TableRange deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode node = jp.readValueAsTree();
String tableName = node.get("table").textValue();
TableMetadata metadata = metadataCache.getMetadata(tableName);
JsonNode optBatchSize = node.get("batch_size");
int batchSize = optBatchSize == null ? 2000 : optBatchSize.asInt();
Iterable<byte[]> columns = AtlasDeserializers.deserializeNamedCols(metadata.getColumns(), node.get("cols"));
byte[] startRow = new byte[0];
byte[] endRow = new byte[0];
if (node.has("prefix")) {
startRow = AtlasDeserializers.deserializeRowPrefix(metadata.getRowMetadata(), node.get("prefix"));
endRow = RangeRequests.createEndNameForPrefixScan(startRow);
} else {
if (node.has("raw_start")) {
startRow = node.get("raw_start").binaryValue();
} else if (node.has("start")) {
startRow = AtlasDeserializers.deserializeRow(metadata.getRowMetadata(), node.get("start"));
}
if (node.has("raw_end")) {
endRow = node.get("raw_end").binaryValue();
} else if (node.has("end")) {
endRow = AtlasDeserializers.deserializeRow(metadata.getRowMetadata(), node.get("end"));
}
}
return new TableRange(tableName, startRow, endRow, columns, batchSize);
}
Aggregations