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);
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testNegativeCustomFilter.
@Test
public void testNegativeCustomFilter() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder.append("/b*");
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);
// Should return no rows as the filters conflict
assertEquals(0, count);
}
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.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(), StandardCharsets.UTF_8));
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testQualifierAndPrefixFilters.
@Test
public void testQualifierAndPrefixFilters() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder.append("/abc*");
builder.append("?");
builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("QualifierFilter(=,'binary:1')", "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(), StandardCharsets.UTF_8));
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestTableScan method testSimpleScannerJson.
@Test
public void testSimpleScannerJson() throws IOException {
// 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 + "=2");
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(2, 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());
model = mapper.readValue(response.getStream(), CellSetModel.class);
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()));
count = TestScannerResource.countCellSet(model);
assertEquals(24, count);
checkRowsNotNull(model);
}
Aggregations