@Test public void examinedCellLimit() { List<BatchOfCellsToSweep> batches = partition( ImmutableList.of( batchWithThreeTssPerCell(0, 20, 30), batchWithThreeTssPerCell(20, 20, 30), batchWithThreeTssPerCell(40, 20, 30)), // A large timestamp batch size. Without the examined cell limit, we would // combine all three input batches in one. 100000, RangeRequests.getFirstRowName(), 50); // The first input batch examines 30 cells and is not sufficient to satisfy the limit (50). // However, the first two batches combined together examine 60 cells, which covers the limit. // Hence we expect one output batch which is the concatenation of the first two input batches. assertThat(batches).containsExactly(batchWithThreeTssPerCell(0, 40, 60)); }
@Test public void inexactPartition() { List<BatchOfCellsToSweep> batches = partition( // Three input batches with 6 (cell, timestamp) pairs in each ImmutableList.of( batchWithThreeTssPerCell(0, 2, 6), batchWithThreeTssPerCell(2, 2, 6), batchWithThreeTssPerCell(4, 2, 6)), // Request 8 (cell, ts) pairs per output batch. The first input batch is not sufficient // to fill that, but the first two batches are. 8, RangeRequests.getFirstRowName(), 1000); assertThat(batches).containsExactly(batchWithThreeTssPerCell(0, 4, 12), batchWithThreeTssPerCell(4, 2, 6)); }
@Test public void exactPartition() { List<BatchOfCellsToSweep> batches = partition( // Three input batches with 6 (cell, timestamp) pairs in each ImmutableList.of( batchWithThreeTssPerCell(0, 2, 6), batchWithThreeTssPerCell(2, 2, 6), batchWithThreeTssPerCell(4, 2, 6)), // Request 12 (cell, ts) pairs per output batch: this should amount to // exactly two input batches per one output batch 12, RangeRequests.getFirstRowName(), // An arbitrarily large examined cell limit to make sure we go through the entire input 1000); // Expect two output batches: the first one should be the first two input batches combined assertThat(batches).containsExactly(batchWithThreeTssPerCell(0, 4, 12), batchWithThreeTssPerCell(4, 2, 6)); }
private void doTestGetRangePagingLastRowEdgeCase(int numColumnsInMetadata, int batchSizeHint, boolean reverse) { TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata); byte[] last = reverse ? RangeRequests.getFirstRowName() : RangeRequests.getLastRowName(); Map<Cell, byte[]> values = ImmutableMap.of( Cell.create(last, PtBytes.toBytes("c1")), PtBytes.toBytes("a"), Cell.create(last, last), PtBytes.toBytes("b")); keyValueService.put(tableRef, values, TEST_TIMESTAMP); RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build(); try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) { List<RowResult<Value>> results = ImmutableList.copyOf(iter); List<RowResult<Value>> expected = ImmutableList.of( RowResult.create(last, ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)) .put(last, Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)) .build())); assertEquals(expected, results); } }
@Test public void testEmpty() { RangeRequest request = RangeRequest.builder().endRowExclusive(RangeRequests.getFirstRowName()).build(); Assert.assertTrue(request.isEmptyRange()); request = RangeRequest.reverseBuilder().endRowExclusive(RangeRequests.getLastRowName()).build(); Assert.assertTrue(request.isEmptyRange()); }
PtBytes.toBytes("b")); values.put(Cell.create(PtBytes.toBytes("01"), RangeRequests.getFirstRowName()), PtBytes.toBytes("c")); RowResult.create(PtBytes.toBytes("01"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(RangeRequests.getFirstRowName(), Value.create(PtBytes.toBytes("c"), TEST_TIMESTAMP)) .build()),
private void doTestGetRangePagingLastRowEdgeCase(int numColumnsInMetadata, int batchSizeHint, boolean reverse) { TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata); byte[] last = reverse ? RangeRequests.getFirstRowName() : RangeRequests.getLastRowName(); Map<Cell, byte[]> values = ImmutableMap.of( Cell.create(last, PtBytes.toBytes("c1")), PtBytes.toBytes("a"), Cell.create(last, last), PtBytes.toBytes("b")); keyValueService.put(tableRef, values, TEST_TIMESTAMP); RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build(); try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) { List<RowResult<Value>> results = ImmutableList.copyOf(iter); List<RowResult<Value>> expected = ImmutableList.of( RowResult.create(last, ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)) .put(last, Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)) .build())); assertEquals(expected, results); } }
PtBytes.toBytes("b")); values.put(Cell.create(PtBytes.toBytes("01"), RangeRequests.getFirstRowName()), PtBytes.toBytes("c")); RowResult.create(PtBytes.toBytes("01"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(RangeRequests.getFirstRowName(), Value.create(PtBytes.toBytes("c"), TEST_TIMESTAMP)) .build()),