Search in sources :

Example 51 with Response

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

the class TestGetAndPutResource method testLatestCellGetJSON.

@Test
public void testLatestCellGetJSON() throws IOException, JAXBException {
    final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
    CellSetModel cellSetModel = new CellSetModel();
    RowModel rowModel = new RowModel(ROW_4);
    CellModel cellOne = new CellModel(Bytes.toBytes(COLUMN_1), 1L, Bytes.toBytes(VALUE_1));
    CellModel cellTwo = new CellModel(Bytes.toBytes(COLUMN_1), 2L, Bytes.toBytes(VALUE_2));
    rowModel.addCell(cellOne);
    rowModel.addCell(cellTwo);
    cellSetModel.addRow(rowModel);
    String jsonString = jsonMapper.writeValueAsString(cellSetModel);
    Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
    assertEquals(response.getCode(), 200);
    Thread.yield();
    response = client.get(path, Constants.MIMETYPE_JSON);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    CellSetModel cellSet = jsonMapper.readValue(response.getBody(), CellSetModel.class);
    assertTrue(cellSet.getRows().size() == 1);
    assertTrue(cellSet.getRows().get(0).getCells().size() == 1);
    CellModel cell = cellSet.getRows().get(0).getCells().get(0);
    assertEquals(VALUE_2, Bytes.toString(cell.getValue()));
    assertEquals(2L, cell.getTimestamp());
    response = deleteRow(TABLE, ROW_4);
    assertEquals(response.getCode(), 200);
}
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)

Example 52 with Response

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

the class TestGetAndPutResource method testURLEncodedKey.

@Test
public void testURLEncodedKey() throws IOException, JAXBException {
    String urlKey = "http://example.com/foo";
    StringBuilder path = new StringBuilder();
    path.append('/');
    path.append(TABLE);
    path.append('/');
    path.append(URLEncoder.encode(urlKey, HConstants.UTF8_ENCODING));
    path.append('/');
    path.append(COLUMN_1);
    Response response;
    response = putValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
    assertEquals(response.getCode(), 200);
    checkValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 53 with Response

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

the class TestGetAndPutResource method testMultipleCellCheckDeletePB.

@Test
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
    Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
    assertEquals(response.getCode(), 404);
    // Add 3 Columns to setup the test
    response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
    assertEquals(response.getCode(), 200);
    checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
    response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
    assertEquals(response.getCode(), 200);
    checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
    response = putValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
    assertEquals(response.getCode(), 200);
    checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
    // Deletes the following columns based on Column1 check
    HashMap<String, String> cellsToDelete = new HashMap<>();
    // Value does not matter
    cellsToDelete.put(COLUMN_2, VALUE_2);
    // Value does not matter
    cellsToDelete.put(COLUMN_3, VALUE_3);
    // On Success update both the cells
    response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1, cellsToDelete);
    assertEquals(response.getCode(), 200);
    checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
    response = getValuePB(TABLE, ROW_1, COLUMN_2);
    assertEquals(response.getCode(), 404);
    response = getValuePB(TABLE, ROW_1, COLUMN_3);
    assertEquals(response.getCode(), 404);
    response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
    assertEquals(response.getCode(), 200);
    checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
    response = putValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
    assertEquals(response.getCode(), 200);
    checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
    // On Failure, we dont update any cells
    response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_3, cellsToDelete);
    assertEquals(response.getCode(), 304);
    checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
    checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
    checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
    response = deleteRow(TABLE, ROW_1);
    assertEquals(response.getCode(), 200);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 54 with Response

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

the class TestGetAndPutResource method testInvalidCheckParam.

@Test
public void testInvalidCheckParam() throws IOException, JAXBException {
    CellSetModel cellSetModel = new CellSetModel();
    RowModel rowModel = new RowModel(ROW_1);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
    cellSetModel.addRow(rowModel);
    StringWriter writer = new StringWriter();
    xmlMarshaller.marshal(cellSetModel, writer);
    final String path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "?check=blah";
    Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
    assertEquals(response.getCode(), 400);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) StringWriter(java.io.StringWriter) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Test(org.junit.Test)

Example 55 with Response

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

the class TestGetAndPutResource method testMetrics.

@Test
public void testMetrics() throws IOException, JAXBException {
    final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
    Response response = client.put(path, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_4));
    assertEquals(response.getCode(), 200);
    Thread.yield();
    response = client.get(path, Constants.MIMETYPE_JSON);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    response = deleteRow(TABLE, ROW_4);
    assertEquals(response.getCode(), 200);
    UserProvider userProvider = UserProvider.instantiate(conf);
    METRICS_ASSERT.assertCounterGt("requests", 2l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
    METRICS_ASSERT.assertCounterGt("successfulGet", 0l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
    METRICS_ASSERT.assertCounterGt("successfulPut", 0l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
    METRICS_ASSERT.assertCounterGt("successfulDelete", 0l, RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) UserProvider(org.apache.hadoop.hbase.security.UserProvider) Test(org.junit.Test)

Aggregations

Response (org.apache.hadoop.hbase.rest.client.Response)91 Test (org.junit.Test)73 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)39 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)30 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)24 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringWriter (java.io.StringWriter)16 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)10 Admin (org.apache.hadoop.hbase.client.Admin)9 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 JacksonJaxbJsonProvider (org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 HashMap (java.util.HashMap)4 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 Header (org.apache.http.Header)4 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)3 TableListModel (org.apache.hadoop.hbase.rest.model.TableListModel)3