Search in sources :

Example 26 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestGetAndPutResource method testStartEndRowGetPutXML.

@Test
public void testStartEndRowGetPutXML() throws IOException, JAXBException {
    String[] rows = { ROW_1, ROW_2, ROW_3 };
    String[] values = { VALUE_1, VALUE_2, VALUE_3 };
    Response response = null;
    for (int i = 0; i < rows.length; i++) {
        response = putValueXML(TABLE, rows[i], COLUMN_1, values[i]);
        assertEquals(200, response.getCode());
        checkValueXML(TABLE, rows[i], COLUMN_1, values[i]);
    }
    response = getValueXML(TABLE, rows[0], rows[2], COLUMN_1);
    assertEquals(200, response.getCode());
    CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    assertEquals(2, cellSet.getRows().size());
    for (int i = 0; i < cellSet.getRows().size() - 1; i++) {
        RowModel rowModel = cellSet.getRows().get(i);
        for (CellModel cell : rowModel.getCells()) {
            assertEquals(COLUMN_1, Bytes.toString(cell.getColumn()));
            assertEquals(values[i], Bytes.toString(cell.getValue()));
        }
    }
    for (String row : rows) {
        response = deleteRow(TABLE, row);
        assertEquals(200, response.getCode());
    }
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ByteArrayInputStream(java.io.ByteArrayInputStream) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Test(org.junit.Test)

Example 27 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestGetAndPutResource method testAppendXML.

@Test
public void testAppendXML() throws IOException, JAXBException {
    Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
    assertEquals(404, response.getCode());
    // append cell
    response = appendValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
    assertEquals(200, response.getCode());
    checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
    response = appendValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
    assertEquals(200, response.getCode());
    checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1 + VALUE_2);
    response = deleteRow(TABLE, ROW_1);
    assertEquals(200, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 28 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestGetAndPutResource method testSingleCellGetJSON.

@Test
public void testSingleCellGetJSON() throws IOException {
    final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
    Response response = client.put(path, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_4));
    assertEquals(200, response.getCode());
    Thread.yield();
    response = client.get(path, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    response = deleteRow(TABLE, ROW_4);
    assertEquals(200, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 29 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestGetAndPutResource method testIncrementPB.

@Test
public void testIncrementPB() throws IOException, JAXBException {
    Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
    assertEquals(404, response.getCode());
    // append cell
    response = incrementValuePB(TABLE, ROW_1, COLUMN_1, VALUE_5);
    assertEquals(200, response.getCode());
    checkIncrementValuePB(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5));
    response = incrementValuePB(TABLE, ROW_1, COLUMN_1, VALUE_6);
    assertEquals(200, response.getCode());
    checkIncrementValuePB(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5) + Long.parseLong(VALUE_6));
    response = deleteRow(TABLE, ROW_1);
    assertEquals(200, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 30 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestGetAndPutResource method testMultiCellGetPutPB.

@Test
public void testMultiCellGetPutPB() throws IOException {
    // deliberate nonexistent row
    String path = "/" + TABLE + "/fakerow";
    CellSetModel cellSetModel = new CellSetModel();
    RowModel rowModel = new RowModel(ROW_1);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
    cellSetModel.addRow(rowModel);
    rowModel = new RowModel(ROW_2);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
    cellSetModel.addRow(rowModel);
    Response response = client.put(path, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput());
    Thread.yield();
    // make sure the fake row was not actually created
    response = client.get(path, Constants.MIMETYPE_PROTOBUF);
    assertEquals(404, response.getCode());
    // check that all of the values were created
    checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
    checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
    checkValuePB(TABLE, ROW_2, COLUMN_1, VALUE_3);
    checkValuePB(TABLE, ROW_2, COLUMN_2, VALUE_4);
    response = deleteRow(TABLE, ROW_1);
    assertEquals(200, response.getCode());
    response = deleteRow(TABLE, ROW_2);
    assertEquals(200, response.getCode());
}
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) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) 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