Search in sources :

Example 1 with ScannerModel

use of org.apache.hadoop.hbase.rest.model.ScannerModel in project hbase by apache.

the class TestScannersWithLabels method testSimpleScannerXMLWithLabelsThatReceivesData.

@Test
public void testSimpleScannerXMLWithLabelsThatReceivesData() throws IOException, JAXBException {
    // new scanner
    ScannerModel model = new ScannerModel();
    model.setBatch(5);
    model.addColumn(Bytes.toBytes(COLUMN_1));
    model.addLabel(SECRET);
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    byte[] body = Bytes.toBytes(writer.toString());
    // recall previous put operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(201, response.getCode());
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    // Respond with 204 as there are no cells to be retrieved
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    assertEquals(5, countCellSet(cellSet));
}
Also used : VisibilityLabelsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse) Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 2 with ScannerModel

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

Example 3 with ScannerModel

use of org.apache.hadoop.hbase.rest.model.ScannerModel in project hbase by apache.

the class TestScannerResource method testFullTableScan.

@Test
public void testFullTableScan() throws IOException {
    ScannerModel model = new ScannerModel();
    model.addColumn(Bytes.toBytes(COLUMN_1));
    assertEquals(expectedRows1, fullTableScan(model));
    model = new ScannerModel();
    model.addColumn(Bytes.toBytes(COLUMN_2));
    assertEquals(expectedRows2, fullTableScan(model));
}
Also used : ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 4 with ScannerModel

use of org.apache.hadoop.hbase.rest.model.ScannerModel in project hbase by apache.

the class TestScannerResource method testTableScanWithTableDisable.

@Test
public void testTableScanWithTableDisable() throws IOException {
    TEST_UTIL.getAdmin().disableTable(TABLE_TO_BE_DISABLED);
    ScannerModel model = new ScannerModel();
    model.addColumn(Bytes.toBytes(COLUMN_1));
    model.setCaching(1);
    Response response = client.put("/" + TABLE_TO_BE_DISABLED + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
    // we will see the exception when we actually want to get the result.
    assertEquals(201, response.getCode());
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
    assertEquals(410, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 5 with ScannerModel

use of org.apache.hadoop.hbase.rest.model.ScannerModel 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(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_XML, body);
    assertEquals(201, response.getCode());
    scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(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());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Aggregations

ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)11 Response (org.apache.hadoop.hbase.rest.client.Response)10 Test (org.junit.Test)8 StringWriter (java.io.StringWriter)7 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)3 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)2 VisibilityLabelsResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse)2 Header (org.apache.http.Header)1