use of org.apache.hadoop.hbase.rest.model.RowModel 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);
}
use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.
the class TestGetAndPutResource method testMultiCellGetPutXML.
@Test
public void testMultiCellGetPutXML() 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);
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);
// check that all of the values were created
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
checkValueXML(TABLE, ROW_2, COLUMN_1, VALUE_3);
checkValueXML(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 testStartEndRowGetPutXML.
@Test
public void testStartEndRowGetPutXML() throws IOException, JAXBException {
String[] rows = { ROW_1, ROW_2, ROW_3 };
String[] values = { VALUE_1, VALUE_2, VALUE_3 };
Response response = null;
for (int i = 0; i < rows.length; i++) {
response = putValueXML(TABLE, rows[i], COLUMN_1, values[i]);
assertEquals(200, response.getCode());
checkValueXML(TABLE, rows[i], COLUMN_1, values[i]);
}
response = getValueXML(TABLE, rows[0], rows[2], COLUMN_1);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertEquals(2, cellSet.getRows().size());
for (int i = 0; i < cellSet.getRows().size() - 1; i++) {
RowModel rowModel = cellSet.getRows().get(i);
for (CellModel cell : rowModel.getCells()) {
assertEquals(COLUMN_1, Bytes.toString(cell.getColumn()));
assertEquals(values[i], Bytes.toString(cell.getValue()));
}
}
for (String row : rows) {
response = deleteRow(TABLE, row);
assertEquals(200, response.getCode());
}
}
use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.
the class RowResourceBase method checkAndDeleteXML.
protected static Response checkAndDeleteXML(String url, String table, String row, String column, String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException, JAXBException {
RowModel rowModel = new RowModel(row);
if (cellsToDelete != null) {
for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
}
}
// Add this at the end
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
xmlMarshaller.marshal(cellSetModel, writer);
Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
Thread.yield();
return response;
}
use of org.apache.hadoop.hbase.rest.model.RowModel in project hbase by apache.
the class RowResourceBase method putValueXML.
protected static Response putValueXML(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);
StringWriter writer = new StringWriter();
xmlMarshaller.marshal(cellSetModel, writer);
Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
Thread.yield();
return response;
}
Aggregations