use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestScannerResource method fullTableScan.
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;
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class RowResourceBase method putValueJson.
protected static Response putValueJson(String url, String table, String row, String column, String value) throws IOException, JAXBException {
RowModel rowModel = new RowModel(row);
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
String jsonString = jsonMapper.writeValueAsString(cellSetModel);
Response response = client.put(url, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
Thread.yield();
return response;
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestGetAndPutResource method testMultiCellGetJson.
@Test
public void testMultiCellGetJson() throws IOException, JAXBException {
// deliberate nonexistent row
String path = "/" + TABLE + "/fakerow";
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
cellSetModel.addRow(rowModel);
rowModel = new RowModel(ROW_2);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
cellSetModel.addRow(rowModel);
String jsonString = jsonMapper.writeValueAsString(cellSetModel);
Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
Thread.yield();
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 404);
// check that all of the values were created
checkValueJSON(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValueJSON(TABLE, ROW_1, COLUMN_2, VALUE_2);
checkValueJSON(TABLE, ROW_2, COLUMN_1, VALUE_3);
checkValueJSON(TABLE, ROW_2, COLUMN_2, VALUE_4);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestGetAndPutResource method testMultiColumnGetXML.
@Test
public void testMultiColumnGetXML() throws Exception {
String path = "/" + TABLE + "/fakerow";
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_3), Bytes.toBytes(VALUE_2)));
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
xmlMarshaller.marshal(cellSetModel, writer);
Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
Thread.yield();
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
// Try getting all the column values at once.
path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "," + COLUMN_2 + "," + COLUMN_3;
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertTrue(cellSet.getRows().size() == 1);
assertTrue(cellSet.getRows().get(0).getCells().size() == 3);
List<CellModel> cells = cellSet.getRows().get(0).getCells();
assertTrue(containsCellModel(cells, COLUMN_1, VALUE_1));
assertTrue(containsCellModel(cells, COLUMN_2, VALUE_2));
assertTrue(containsCellModel(cells, COLUMN_3, VALUE_2));
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestGetAndPutResource method testMultiCellGetPutPB.
@Test
public void testMultiCellGetPutPB() throws IOException {
// deliberate nonexistent row
String path = "/" + TABLE + "/fakerow";
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
cellSetModel.addRow(rowModel);
rowModel = new RowModel(ROW_2);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
cellSetModel.addRow(rowModel);
Response response = client.put(path, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput());
Thread.yield();
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 404);
// check that all of the values were created
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
checkValuePB(TABLE, ROW_2, COLUMN_1, VALUE_3);
checkValuePB(TABLE, ROW_2, COLUMN_2, VALUE_4);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
}
Aggregations