use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestScannerResource method testTableScanWithTableDisable.
// performs table scan during which the underlying table is disabled
// assert that we get 410 (Gone)
@Test
public void testTableScanWithTableDisable() throws IOException {
ScannerModel model = new ScannerModel();
model.addColumn(Bytes.toBytes(COLUMN_1));
model.setCaching(1);
Response response = client.put("/" + TABLE_TO_BE_DISABLED + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
TEST_UTIL.getAdmin().disableTable(TABLE_TO_BE_DISABLED);
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertTrue("got " + response.getCode(), response.getCode() == 410);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class RowResourceBase method checkAndDeleteJson.
protected static Response checkAndDeleteJson(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);
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.client.Response in project hbase by apache.
the class RowResourceBase method checkAndPutValuePB.
protected static Response checkAndPutValuePB(String url, String table, String row, String column, String valueToCheck, String valueToPut, HashMap<String, String> otherCells) throws IOException {
RowModel rowModel = new RowModel(row);
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut)));
if (otherCells != null) {
for (Map.Entry<String, String> entry : otherCells.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
}
}
// This Cell need to be added as last cell.
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput());
Thread.yield();
return response;
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestDeleteRow method testDeleteNonExistentColumn.
@Test
public void testDeleteNonExistentColumn() throws Exception {
Response response = putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
response = checkAndDeleteJson(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(304, response.getCode());
assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
response = checkAndDeleteJson(TABLE, ROW_2, COLUMN_1, VALUE_2);
assertEquals(304, response.getCode());
assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
response = checkAndDeleteJson(TABLE, ROW_1, "dummy", VALUE_1);
assertEquals(400, response.getCode());
assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
response = checkAndDeleteJson(TABLE, ROW_1, "dummy:test", VALUE_1);
assertEquals(404, response.getCode());
assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
response = checkAndDeleteJson(TABLE, ROW_1, "a:test", VALUE_1);
assertEquals(304, response.getCode());
assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testScanUsingListenerUnmarshallerXML.
/**
* An example to scan using listener in unmarshaller for XML.
* @throws Exception the exception
*/
@Test
public void testScanUsingListenerUnmarshallerXML() throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_LIMIT + "=10");
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
JAXBContext context = JAXBContext.newInstance(ClientSideCellSetModel.class, RowModel.class, CellModel.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
final ClientSideCellSetModel.Listener listener = new ClientSideCellSetModel.Listener() {
@Override
public void handleRowModel(ClientSideCellSetModel helper, RowModel row) {
assertTrue(row.getKey() != null);
assertTrue(row.getCells().size() > 0);
}
};
// install the callback on all ClientSideCellSetModel instances
unmarshaller.setListener(new Unmarshaller.Listener() {
public void beforeUnmarshal(Object target, Object parent) {
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(listener);
}
}
public void afterUnmarshal(Object target, Object parent) {
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(null);
}
}
});
// create a new XML parser
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
XMLReader reader = factory.newSAXParser().getXMLReader();
reader.setContentHandler(unmarshaller.getUnmarshallerHandler());
assertFalse(ClientSideCellSetModel.listenerInvoked);
reader.parse(new InputSource(response.getStream()));
assertTrue(ClientSideCellSetModel.listenerInvoked);
}
Aggregations