use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestGetAndPutResource method testInvalidColumnPut.
@Test
public void testInvalidColumnPut() throws IOException, JAXBException {
String dummyColumn = "doesnot:exist";
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
rowModel.addCell(new CellModel(Bytes.toBytes(dummyColumn), Bytes.toBytes(VALUE_1)));
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
xmlMarshaller.marshal(cellSetModel, writer);
final String path = "/" + TABLE + "/" + ROW_1 + "/" + dummyColumn;
Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
assertEquals(response.getCode(), 404);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestNamespacesResource method testNamespaceListPBandDefault.
@Test
public void testNamespaceListPBandDefault() throws IOException, JAXBException {
String schemaPath = "/namespaces/";
NamespacesModel model;
Response response;
// Check that namespace does not yet exist via non-REST call.
Admin admin = TEST_UTIL.getAdmin();
assertFalse(doesNamespaceExist(admin, NAMESPACE1));
model = testNamespacesModel.buildTestModel();
testNamespacesModel.checkModel(model);
// Check that REST GET finds only default namespaces via PB and default Accept header.
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
model.getObjectFromMessage(response.getBody());
testNamespacesModel.checkModel(model, "hbase", "default");
response = client.get(schemaPath);
assertEquals(200, response.getCode());
// Create namespace and check that REST GET finds one additional namespace.
createNamespaceViaAdmin(admin, NAMESPACE1);
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
model.getObjectFromMessage(response.getBody());
testNamespacesModel.checkModel(model, NAMESPACE1, "hbase", "default");
response = client.get(schemaPath);
assertEquals(200, response.getCode());
// Create another namespace and check that REST GET finds one additional namespace.
createNamespaceViaAdmin(admin, NAMESPACE2);
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
model.getObjectFromMessage(response.getBody());
testNamespacesModel.checkModel(model, NAMESPACE1, NAMESPACE2, "hbase", "default");
response = client.get(schemaPath);
assertEquals(200, response.getCode());
// Delete namespace and check that REST GET still finds correct namespaces.
admin.deleteNamespace(NAMESPACE1);
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
model.getObjectFromMessage(response.getBody());
testNamespacesModel.checkModel(model, NAMESPACE2, "hbase", "default");
response = client.get(schemaPath);
assertEquals(200, response.getCode());
admin.deleteNamespace(NAMESPACE2);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestScannerResource method testSimpleScannerXML.
@Test
public void testSimpleScannerXML() throws IOException, JAXBException {
final int BATCH_SIZE = 5;
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(BATCH_SIZE);
model.addColumn(Bytes.toBytes(COLUMN_1));
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
byte[] body = Bytes.toBytes(writer.toString());
// test put operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 403);
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_XML, body);
assertEquals(response.getCode(), 201);
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// confirm batch size conformance
assertEquals(countCellSet(cellSet), BATCH_SIZE);
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestScannerResource method testTableDoesNotExist.
@Test
public void testTableDoesNotExist() throws IOException, JAXBException {
ScannerModel model = new ScannerModel();
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + NONEXISTENT_TABLE + "/scanner", Constants.MIMETYPE_XML, body);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestScannerResource method testSimpleScannerBinary.
@Test
public void testSimpleScannerBinary() throws IOException {
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(1);
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(response.getCode(), 403);
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(response.getCode(), 201);
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell
response = client.get(scannerURI, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
// verify that data was returned
assertTrue(response.getBody().length > 0);
// verify that the expected X-headers are present
boolean foundRowHeader = false, foundColumnHeader = false, foundTimestampHeader = false;
for (Header header : response.getHeaders()) {
if (header.getName().equals("X-Row")) {
foundRowHeader = true;
} else if (header.getName().equals("X-Column")) {
foundColumnHeader = true;
} else if (header.getName().equals("X-Timestamp")) {
foundTimestampHeader = true;
}
}
assertTrue(foundRowHeader);
assertTrue(foundColumnHeader);
assertTrue(foundTimestampHeader);
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
Aggregations