use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testSingleCellGetPutBinary.
@Test
public void testSingleCellGetPutBinary() throws IOException {
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
final byte[] body = Bytes.toBytes(VALUE_3);
Response response = client.put(path, Constants.MIMETYPE_BINARY, body);
assertEquals(response.getCode(), 200);
Thread.yield();
response = client.get(path, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
assertTrue(Bytes.equals(response.getBody(), body));
boolean foundTimestampHeader = false;
for (Header header : response.getHeaders()) {
if (header.getName().equals("X-Timestamp")) {
foundTimestampHeader = true;
break;
}
}
assertTrue(foundTimestampHeader);
response = deleteRow(TABLE, ROW_3);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testSuffixGlobbingXML.
@Test
public void testSuffixGlobbingXML() 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
StringBuilder query = new StringBuilder();
query.append('/');
query.append(TABLE);
query.append('/');
query.append("testrow*");
query.append('/');
query.append(COLUMN_1);
response = client.get(query.toString(), Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
List<RowModel> rows = cellSet.getRows();
assertTrue(rows.size() == 2);
for (RowModel row : rows) {
assertTrue(row.getCells().size() == 1);
assertEquals(COLUMN_1, Bytes.toString(row.getCells().get(0).getColumn()));
}
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.client.Response in project hbase by apache.
the class TestGetAndPutResource method testMultipleCellCheckPutXML.
@Test
public void testMultipleCellCheckPutXML() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
// Add 2 Columns to setup the test
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
checkValueXML(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 = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_3, otherCells);
assertEquals(response.getCode(), 200);
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_3);
// On Failure, we dont update any cells
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_4, otherCells);
assertEquals(response.getCode(), 304);
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValueXML(TABLE, ROW_1, COLUMN_2, 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 testForbidden.
@Test
public void testForbidden() throws IOException, JAXBException {
conf.set("hbase.rest.readonly", "true");
Response response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 403);
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 403);
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_2);
assertEquals(response.getCode(), 403);
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_2);
assertEquals(response.getCode(), 403);
response = deleteValue(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 403);
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 403);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 403);
conf.set("hbase.rest.readonly", "false");
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_2);
assertEquals(response.getCode(), 200);
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
assertEquals(response.getCode(), 200);
response = deleteValue(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 200);
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 testSingleCellGetPutXML.
@Test
public void testSingleCellGetPutXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(response.getCode(), 200);
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
assertEquals(response.getCode(), 200);
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
response = checkAndDeleteXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
assertEquals(response.getCode(), 200);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
}
Aggregations