use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestRESTServerSSL method testSslConnectionUsingKeystoreFormatJCEKS.
@Test
public void testSslConnectionUsingKeystoreFormatJCEKS() throws Exception {
startRESTServer("jceks");
Response response = sslClient.get("/version", Constants.MIMETYPE_TEXT);
assertEquals(200, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestScannerResource method testSimpleScannerPB.
@Test
public void testSimpleScannerPB() throws IOException {
final int BATCH_SIZE = 10;
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(BATCH_SIZE);
model.addColumn(Bytes.toBytes(COLUMN_1));
// test put operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(403, response.getCode());
String scannerURI = response.getLocation();
assertNull(scannerURI);
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(201, response.getCode());
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
// confirm batch size conformance
assertEquals(BATCH_SIZE, countCellSet(cellSet));
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(403, response.getCode());
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(200, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestScannerResource method fullTableScan.
private static int fullTableScan(ScannerModel model) throws IOException {
model.setBatch(100);
Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
int count = 0;
while (true) {
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertTrue(response.getCode() == 200 || response.getCode() == 204);
if (response.getCode() == 200) {
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
Iterator<RowModel> rows = cellSet.getRows().iterator();
while (rows.hasNext()) {
RowModel row = rows.next();
Iterator<CellModel> cells = row.getCells().iterator();
while (cells.hasNext()) {
cells.next();
count++;
}
}
} else {
break;
}
}
// delete the scanner
response = client.delete(scannerURI);
assertEquals(200, response.getCode());
return count;
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestDeleteRow method testDeleteXML.
@Test
public void testDeleteXML() throws IOException, JAXBException {
Response response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(200, response.getCode());
response = putValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = deleteValue(TABLE, ROW_1, COLUMN_1);
assertEquals(200, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(200, response.getCode());
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(200, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
response = deleteRow(TABLE, ROW_1);
assertEquals(200, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_2);
assertEquals(404, response.getCode());
// Delete a row in non existent table
response = deleteValue("dummy", ROW_1, COLUMN_1);
assertEquals(404, response.getCode());
// Delete non existent column
response = deleteValue(TABLE, ROW_1, "dummy");
assertEquals(404, response.getCode());
}
use of org.apache.hadoop.hbase.rest.client.Response 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(404, response.getCode());
// 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(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(200, response.getCode());
}
Aggregations