use of org.apache.hadoop.hbase.rest.model.RowModel 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.RowModel 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.RowModel in project hbase by apache.
the class TestTableScan method testReversed.
@Test
public void testReversed() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(24, count);
List<RowModel> rowModels = model.getRows().subList(1, count);
//reversed
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aay");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_REVERSED + "=true");
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
model = (CellSetModel) ush.unmarshal(response.getStream());
count = TestScannerResource.countCellSet(model);
assertEquals(24, count);
List<RowModel> reversedRowModels = model.getRows().subList(1, count);
Collections.reverse(reversedRowModels);
assertEquals(rowModels.size(), reversedRowModels.size());
for (int i = 0; i < rowModels.size(); i++) {
RowModel rowModel = rowModels.get(i);
RowModel reversedRowModel = reversedRowModels.get(i);
assertEquals(new String(rowModel.getKey(), "UTF-8"), new String(reversedRowModel.getKey(), "UTF-8"));
assertEquals(new String(rowModel.getCells().get(0).getValue(), "UTF-8"), new String(reversedRowModel.getCells().get(0).getValue(), "UTF-8"));
}
}
use of org.apache.hadoop.hbase.rest.model.RowModel 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.RowModel 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);
}
Aggregations