use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testLatestCellGetJSON.
@Test
public void testLatestCellGetJSON() throws IOException, JAXBException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_4);
CellModel cellOne = new CellModel(Bytes.toBytes(COLUMN_1), 1L, Bytes.toBytes(VALUE_1));
CellModel cellTwo = new CellModel(Bytes.toBytes(COLUMN_1), 2L, Bytes.toBytes(VALUE_2));
rowModel.addCell(cellOne);
rowModel.addCell(cellTwo);
cellSetModel.addRow(rowModel);
String jsonString = jsonMapper.writeValueAsString(cellSetModel);
Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(response.getCode(), 200);
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
CellSetModel cellSet = jsonMapper.readValue(response.getBody(), CellSetModel.class);
assertTrue(cellSet.getRows().size() == 1);
assertTrue(cellSet.getRows().get(0).getCells().size() == 1);
CellModel cell = cellSet.getRows().get(0).getCells().get(0);
assertEquals(VALUE_2, Bytes.toString(cell.getValue()));
assertEquals(2L, cell.getTimestamp());
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testURLEncodedKey.
@Test
public void testURLEncodedKey() throws IOException, JAXBException {
String urlKey = "http://example.com/foo";
StringBuilder path = new StringBuilder();
path.append('/');
path.append(TABLE);
path.append('/');
path.append(URLEncoder.encode(urlKey, HConstants.UTF8_ENCODING));
path.append('/');
path.append(COLUMN_1);
Response response;
response = putValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
checkValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testMultipleCellCheckDeletePB.
@Test
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
// Add 3 Columns to setup the test
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = putValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
assertEquals(response.getCode(), 200);
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
// Deletes the following columns based on Column1 check
HashMap<String, String> cellsToDelete = new HashMap<>();
// Value does not matter
cellsToDelete.put(COLUMN_2, VALUE_2);
// Value does not matter
cellsToDelete.put(COLUMN_3, VALUE_3);
// On Success update both the cells
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1, cellsToDelete);
assertEquals(response.getCode(), 200);
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = getValuePB(TABLE, ROW_1, COLUMN_2);
assertEquals(response.getCode(), 404);
response = getValuePB(TABLE, ROW_1, COLUMN_3);
assertEquals(response.getCode(), 404);
response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = putValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
assertEquals(response.getCode(), 200);
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
// On Failure, we dont update any cells
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_3, cellsToDelete);
assertEquals(response.getCode(), 304);
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testInvalidCheckParam.
@Test
public void testInvalidCheckParam() throws IOException, JAXBException {
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
xmlMarshaller.marshal(cellSetModel, writer);
final String path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "?check=blah";
Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
assertEquals(response.getCode(), 400);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testMetrics.
@Test
public void testMetrics() throws IOException, JAXBException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_4));
assertEquals(response.getCode(), 200);
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);
UserProvider userProvider = UserProvider.instantiate(conf);
METRICS_ASSERT.assertCounterGt("requests", 2l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
METRICS_ASSERT.assertCounterGt("successfulGet", 0l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
METRICS_ASSERT.assertCounterGt("successfulPut", 0l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
METRICS_ASSERT.assertCounterGt("successfulDelete", 0l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
}
Aggregations