}
// @Ignore @Test
public void testBulkDeleteWithNumberOfVersions() throws Throwable {
byte[] tableName = Bytes.toBytes("testBulkDeleteWithNumberOfVersions");
Table ht = createTable(tableName);
List<Put> puts = new ArrayList<Put>(100);
for (int j = 0; j < 100; j++) {
Put put = new Put(Bytes.toBytes(j));
// TS = 1000L
byte[] value = "v1".getBytes();
put.add(FAMILY1, QUALIFIER1, 1000L, value);
put.add(FAMILY1, QUALIFIER2, 1000L, value);
put.add(FAMILY1, QUALIFIER3, 1000L, value);
// TS = 1234L
value = "v2".getBytes();
put.add(FAMILY1, QUALIFIER1, 1234L, value);
put.add(FAMILY1, QUALIFIER2, 1234L, value);
put.add(FAMILY1, QUALIFIER3, 1234L, value);
// TS = 2000L
value = "v3".getBytes();
put.add(FAMILY1, QUALIFIER1, 2000L, value);
put.add(FAMILY1, QUALIFIER2, 2000L, value);
put.add(FAMILY1, QUALIFIER3, 2000L, value);
// Latest version values
value = "v4".getBytes();
put.add(FAMILY1, QUALIFIER1, value);
put.add(FAMILY1, QUALIFIER2, value);
put.add(FAMILY1, QUALIFIER3, value);
puts.add(put);
}
ht.put(puts);
// Delete all the versions of columns cf1:c1 and cf1:c2 falling with the time range
// [1000,2000)
final Scan scan = new Scan();
scan.addColumn(FAMILY1, QUALIFIER1);
scan.addColumn(FAMILY1, QUALIFIER2);
scan.setTimeRange(1000L, 2000L);
scan.setMaxVersions();
long noOfDeletedRows = 0L;
long noOfVersionsDeleted = 0L;
Batch.Call<BulkDeleteService, BulkDeleteResponse> callable =
new Batch.Call<BulkDeleteService, BulkDeleteResponse>() {
ServerRpcController controller = new ServerRpcController();
BlockingRpcCallback<BulkDeleteResponse> rpcCallback =
new BlockingRpcCallback<BulkDeleteResponse>();
public BulkDeleteResponse call(BulkDeleteService service) throws IOException {
Builder builder = BulkDeleteRequest.newBuilder();
builder.setScan(ProtobufUtil.toScan(scan));
builder.setDeleteType(DeleteType.VERSION);
builder.setRowBatchSize(500);
service.delete(controller, builder.build(), rpcCallback);
return rpcCallback.get();
}
};
Map<byte[], BulkDeleteResponse> result = ht.coprocessorService(BulkDeleteService.class, scan
.getStartRow(), scan.getStopRow(), callable);
for (BulkDeleteResponse response : result.values()) {
noOfDeletedRows += response.getRowsDeleted();
noOfVersionsDeleted += response.getVersionsDeleted();
}
assertEquals(100, noOfDeletedRows);
assertEquals(400, noOfVersionsDeleted);
int rows = 0;
Scan scan1 = new Scan();
scan1.setMaxVersions();
for (Result res : ht.getScanner(scan1)) {
assertEquals(3, res.getFamilyMap(FAMILY1).size());
List<Cell> column = res.getColumnCells(FAMILY1, QUALIFIER1);
assertEquals(2, column.size());
assertTrue(CellUtil.matchingValue(column.get(0), "v4".getBytes()));
assertTrue(CellUtil.matchingValue(column.get(1), "v3".getBytes()));
column = res.getColumnCells(FAMILY1, QUALIFIER2);
assertEquals(2, column.size());
assertTrue(CellUtil.matchingValue(column.get(0), "v4".getBytes()));
assertTrue(CellUtil.matchingValue(column.get(1), "v3".getBytes()));
assertEquals(4, res.getColumnCells(FAMILY1, QUALIFIER3).size());
rows++;
}
assertEquals(100, rows);
ht.close();
}