private static int fullTableScan(ScannerModel model) throws IOException { model.setBatch(100); Response response = client.put( "/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); assertEquals(response.getCode(), 201); String scannerURI = response.getLocation(); assertNotNull(scannerURI); int count = 0; while (true) { response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF); assertTrue(response.getCode() == 200 || response.getCode() == 204); if (response.getCode() == 200) { assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); Iterator<RowModel> rows = cellSet.getRows().iterator(); while (rows.hasNext()) { RowModel row = rows.next(); Iterator<CellModel> cells = row.getCells().iterator(); while (cells.hasNext()) { cells.next(); count++; } } } else { break; } } // delete the scanner response = client.delete(scannerURI); assertEquals(response.getCode(), 200); return count; }
@Test public void testSimpleScannerPB() throws IOException { final int BATCH_SIZE = 10; // new scanner ScannerModel model = new ScannerModel(); model.setBatch(BATCH_SIZE); model.addColumn(Bytes.toBytes(COLUMN_1)); // test put operation is forbidden in read-only mode conf.set("hbase.rest.readonly", "true"); Response response = client.put( "/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); assertEquals(response.getCode(), 403); String scannerURI = response.getLocation(); assertNull(scannerURI); // recall previous put operation with read-only off conf.set("hbase.rest.readonly", "false"); response = client.put( "/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); assertEquals(response.getCode(), 201); scannerURI = response.getLocation(); assertNotNull(scannerURI); // get a cell set response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF); assertEquals(response.getCode(), 200); assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); // confirm batch size conformance assertEquals(countCellSet(cellSet), BATCH_SIZE); // test delete scanner operation is forbidden in read-only mode conf.set("hbase.rest.readonly", "true"); response = client.delete(scannerURI); assertEquals(response.getCode(), 403); // recall previous delete scanner operation with read-only off conf.set("hbase.rest.readonly", "false"); response = client.delete(scannerURI); assertEquals(response.getCode(), 200); }