use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testMultipleCellCheckPutPB.
@Test
public void testMultipleCellCheckPutPB() throws IOException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
// Add 2 Columns to setup the test
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
HashMap<String, String> otherCells = new HashMap<>();
otherCells.put(COLUMN_2, VALUE_3);
// On Success update both the cells
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_3, otherCells);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_3);
// On Failure, we dont update any cells
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_4, otherCells);
assertEquals(304, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_3);
response = deleteRow(TABLE, ROW_1);
assertEquals(200, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testIncrementJSON.
@Test
public void testIncrementJSON() throws IOException, JAXBException {
Response response = getValueJson(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
// append cell
response = incrementValueJson(TABLE, ROW_1, COLUMN_1, VALUE_5);
assertEquals(200, response.getCode());
checkIncrementValueJSON(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5));
response = incrementValueJson(TABLE, ROW_1, COLUMN_1, VALUE_6);
assertEquals(200, response.getCode());
checkIncrementValueJSON(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5) + Long.parseLong(VALUE_6));
response = deleteRow(TABLE, ROW_1);
assertEquals(200, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testIncrementXML.
@Test
public void testIncrementXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
// append single cell
response = incrementValueXML(TABLE, ROW_1, COLUMN_1, VALUE_5);
assertEquals(200, response.getCode());
checkIncrementValueXML(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5));
response = incrementValueXML(TABLE, ROW_1, COLUMN_1, VALUE_6);
assertEquals(200, response.getCode());
checkIncrementValueXML(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5) + Long.parseLong(VALUE_6));
response = deleteRow(TABLE, ROW_1);
assertEquals(200, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response 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(404, response.getCode());
// 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(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(200, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response 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(404, response.getCode());
// 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(200, response.getCode());
}
Aggregations