Search in sources :

Example 96 with Response

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);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 97 with Response

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);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 98 with Response

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));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 99 with Response

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));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 100 with Response

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);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) JacksonJaxbJsonProvider(org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Response (org.apache.hadoop.hbase.rest.client.Response)111 Test (org.junit.Test)90 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)44 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)34 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)27 ByteArrayInputStream (java.io.ByteArrayInputStream)17 StringWriter (java.io.StringWriter)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)11 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)10 HashMap (java.util.HashMap)9 Admin (org.apache.hadoop.hbase.client.Admin)9 JAXBContext (javax.xml.bind.JAXBContext)8 Unmarshaller (javax.xml.bind.Unmarshaller)8 Header (org.apache.http.Header)6 Map (java.util.Map)5 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)5 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)4 NamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel)4 TestNamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel)4