use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class TransactionGetBenchmarks method getRangeInner.
private List<RowResult<byte[]>> getRangeInner(ConsecutiveNarrowTable table) {
final int rangeRequestSize = 1000;
return table.getTransactionManager().runTaskThrowOnConflict(txn -> {
RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, rangeRequestSize, false));
List<RowResult<byte[]>> results = BatchingVisitables.copyToList(txn.getRange(table.getTableRef(), request));
Preconditions.checkState(results.size() == rangeRequestSize, "Expected %s rows, found %s rows", rangeRequestSize, results.size());
return results;
});
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class ConsecutiveNarrowTable method getRangeRequests.
public Iterable<RangeRequest> getRangeRequests(int numRequests, int sliceSize, boolean allColumns) {
List<RangeRequest> requests = Lists.newArrayList();
Set<Integer> used = Sets.newHashSet();
for (int i = 0; i < numRequests; i++) {
int startRow;
do {
startRow = getRandom().nextInt(getNumRows() - sliceSize);
} while (used.contains(startRow));
int endRow = startRow + sliceSize;
RangeRequest request = RangeRequest.builder().batchHint(1 + sliceSize).startRowInclusive(Ints.toByteArray(startRow)).endRowExclusive(Ints.toByteArray(endRow)).retainColumns(allColumns ? ColumnSelection.all() : ColumnSelection.create(ImmutableList.of(Tables.COLUMN_NAME_IN_BYTES.array()))).build();
requests.add(request);
used.add(startRow);
}
return requests;
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class OneNodeDownGetTest method canGetRange.
@Test
public void canGetRange() {
final RangeRequest range = RangeRequest.builder().endRowExclusive(OneNodeDownTestSuite.SECOND_ROW).build();
ClosableIterator<RowResult<Value>> it = OneNodeDownTestSuite.kvs.getRange(OneNodeDownTestSuite.TEST_TABLE, range, Long.MAX_VALUE);
ImmutableMap<byte[], Value> expectedColumns = ImmutableMap.of(OneNodeDownTestSuite.FIRST_COLUMN, OneNodeDownTestSuite.DEFAULT_VALUE, OneNodeDownTestSuite.SECOND_COLUMN, OneNodeDownTestSuite.DEFAULT_VALUE);
RowResult<Value> expectedRowResult = RowResult.create(OneNodeDownTestSuite.FIRST_ROW, ImmutableSortedMap.copyOf(expectedColumns, UnsignedBytes.lexicographicalComparator()));
assertThat(it).containsExactly(expectedRowResult);
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class OneNodeDownGetTest method getRangeOfTimestampsThrows.
@Test
public void getRangeOfTimestampsThrows() {
RangeRequest range = RangeRequest.builder().endRowExclusive(OneNodeDownTestSuite.SECOND_ROW).build();
ClosableIterator<RowResult<Set<Long>>> it = OneNodeDownTestSuite.kvs.getRangeOfTimestamps(OneNodeDownTestSuite.TEST_TABLE, range, Long.MAX_VALUE);
assertThatThrownBy(() -> it.next()).isExactlyInstanceOf(InsufficientConsistencyException.class).hasMessageContaining(REQUIRES_ALL_CASSANDRA_NODES);
}
use of com.palantir.atlasdb.keyvalue.api.RangeRequest in project atlasdb by palantir.
the class AbstractSchemaApiTest method testRowRangeSecondColumn.
@Test
public void testRowRangeSecondColumn() {
AbstractTransaction transaction = mock(AbstractTransaction.class);
Cell expectedCell = getCell(TEST_ROW_KEY, SECOND_COL_SHORT_NAME);
Cell anotherExpectedCell = getCell(TEST_ROW_KEY2, SECOND_COL_SHORT_NAME);
RangeRequest expectedRange = RangeRequest.builder().startRowInclusive(TEST_ROW_KEY.getBytes()).endRowExclusive(RANGE_END_ROW_KEY.getBytes()).retainColumns(SECOND_COLUMN_SELECTION).build();
when(transaction.getRange(tableRef, expectedRange)).thenReturn(BatchingVisitableFromIterable.create(Arrays.asList(RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)))));
Map<String, StringValue> result = getRangeSecondColumn(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY);
assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_STRING, TEST_ROW_KEY2, TEST_VALUE_STRING2));
verify(transaction, times(1)).getRange(tableRef, expectedRange);
}
Aggregations