use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testCustomFilter.
@Test
public void testCustomFilter() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder = new StringBuilder();
builder.append("/a*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("CustomFilter('abc')", "UTF-8"));
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testSimpleScannerXML.
@Test
public void testSimpleScannerXML() throws IOException, JAXBException, XMLStreamException {
// Test scanning particular columns
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 ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(10, count);
checkRowsNotNull(model);
//Test with no limit.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
model = (CellSetModel) ush.unmarshal(response.getStream());
count = TestScannerResource.countCellSet(model);
assertEquals(expectedRows1, count);
checkRowsNotNull(model);
//Test with start and end row.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
model = (CellSetModel) ush.unmarshal(response.getStream());
count = TestScannerResource.countCellSet(model);
RowModel startRow = model.getRows().get(0);
assertEquals("aaa", Bytes.toString(startRow.getKey()));
RowModel endRow = model.getRows().get(model.getRows().size() - 1);
assertEquals("aax", Bytes.toString(endRow.getKey()));
assertEquals(24, count);
checkRowsNotNull(model);
//Test with start row and limit.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_LIMIT + "=15");
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
model = (CellSetModel) ush.unmarshal(response.getStream());
startRow = model.getRows().get(0);
assertEquals("aaa", Bytes.toString(startRow.getKey()));
count = TestScannerResource.countCellSet(model);
assertEquals(15, count);
checkRowsNotNull(model);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testStreamingJSON.
@Test
public void testStreamingJSON() throws Exception {
// Test scanning particular columns with limit.
StringBuilder builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_LIMIT + "=20");
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
int count = TestScannerResource.countCellSet(model);
assertEquals(20, count);
checkRowsNotNull(model);
//Test scanning with no limit.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_2);
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
model = mapper.readValue(response.getStream(), CellSetModel.class);
count = TestScannerResource.countCellSet(model);
assertEquals(expectedRows2, count);
checkRowsNotNull(model);
//Test with start row and end row.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
count = 0;
JsonFactory jfactory = new JsonFactory(mapper);
JsonParser jParser = jfactory.createJsonParser(response.getStream());
boolean found = false;
while (jParser.nextToken() != JsonToken.END_OBJECT) {
if (jParser.getCurrentToken() == JsonToken.START_OBJECT && found) {
RowModel row = jParser.readValueAs(RowModel.class);
assertNotNull(row.getKey());
for (int i = 0; i < row.getCells().size(); i++) {
if (count == 0) {
assertEquals("aaa", Bytes.toString(row.getKey()));
}
if (count == 23) {
assertEquals("aax", Bytes.toString(row.getKey()));
}
count++;
}
jParser.skipChildren();
} else {
found = jParser.getCurrentToken() == JsonToken.START_ARRAY;
}
}
assertEquals(24, count);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testSimpleFilter.
@Test
public void testSimpleFilter() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
builder.append("&");
builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("PrefixFilter('aab')", "UTF-8"));
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
assertEquals("aab", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testSimpleScannerProtobuf.
@Test
public void testSimpleScannerProtobuf() throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_LIMIT + "=15");
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
int rowCount = readProtobufStream(response.getStream());
assertEquals(15, rowCount);
//Test with start row and end row.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_PROTOBUF);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
rowCount = readProtobufStream(response.getStream());
assertEquals(24, rowCount);
}
Aggregations