Package org.apache.hadoop.hbase.rest.client

Examples of org.apache.hadoop.hbase.rest.client.Response


  @Test
  public void testNoSuchCF() throws IOException, JAXBException {
    final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
    final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
    Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
      Bytes.toBytes(VALUE_1));
    assertEquals(response.getCode(), 200);
    assertEquals(client.get(goodPath, Constants.MIMETYPE_BINARY).getCode(),
      200);
    assertEquals(client.get(badPath, Constants.MIMETYPE_BINARY).getCode(),
      404);
    assertEquals(client.get(goodPath, Constants.MIMETYPE_BINARY).getCode(),
View Full Code Here


    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
      Bytes.toBytes(VALUE_4)));
    cellSetModel.addRow(rowModel);
    StringWriter writer = new StringWriter();
    marshaller.marshal(cellSetModel, writer);
    Response response = client.put(path, Constants.MIMETYPE_XML,
      Bytes.toBytes(writer.toString()));
    Thread.yield();

    // make sure the fake row was not actually created
    response = client.get(path, Constants.MIMETYPE_XML);
    assertEquals(response.getCode(), 404);

    // check that all of the values were created
    checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
    checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
    checkValueXML(TABLE, ROW_2, COLUMN_1, VALUE_3);
    checkValueXML(TABLE, ROW_2, COLUMN_2, VALUE_4);

    response = deleteRow(TABLE, ROW_1);
    assertEquals(response.getCode(), 200);
    response = deleteRow(TABLE, ROW_2);
    assertEquals(response.getCode(), 200);
  }
View Full Code Here

    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(response.getCode(), 404);

    // 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(response.getCode(), 200);
    response = deleteRow(TABLE, ROW_2);
    assertEquals(response.getCode(), 200);
  }
View Full Code Here

  @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)
      unmarshaller.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());
    }
  }
View Full Code Here

    StringWriter writer = new StringWriter();
    marshaller.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);
  }
View Full Code Here

    // input side filter

    Header[] headers = new Header[2];
    headers[0] = new Header("Content-Type", Constants.MIMETYPE_BINARY);
    headers[1] = new Header("Content-Encoding", "gzip");
    Response response = client.put(path, headers, value_1_gzip);
    assertEquals(response.getCode(), 200);

    HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE);
    Get get = new Get(Bytes.toBytes(ROW_1));
    get.addColumn(Bytes.toBytes(CFA), Bytes.toBytes("1"));
    Result result = table.get(get);
    byte[] value = result.getValue(Bytes.toBytes(CFA), Bytes.toBytes("1"));
    assertNotNull(value);
    assertTrue(Bytes.equals(value, VALUE_1));

    // output side filter

    headers[0] = new Header("Accept", Constants.MIMETYPE_BINARY);
    headers[1] = new Header("Accept-Encoding", "gzip");
    response = client.get(path, headers);
    assertEquals(response.getCode(), 200);
    ByteArrayInputStream bis = new ByteArrayInputStream(response.getBody());
    GZIPInputStream is = new GZIPInputStream(bis);
    value = new byte[VALUE_1.length];
    is.read(value, 0, VALUE_1.length);
    assertTrue(Bytes.equals(value, VALUE_1));
    is.close();
View Full Code Here

  @Test
  public void testErrorNotGzipped() throws Exception {
    Header[] headers = new Header[2];
    headers[0] = new Header("Accept", Constants.MIMETYPE_BINARY);
    headers[1] = new Header("Accept-Encoding", "gzip");
    Response response = client.get("/" + TABLE + "/" + ROW_1 + "/" + COLUMN_2, headers);
    assertEquals(response.getCode(), 404);
    String contentEncoding = response.getHeader("Content-Encoding");
    assertTrue(contentEncoding == null || !contentEncoding.contains("gzip"));
    response = client.get("/" + TABLE, headers);
    assertEquals(response.getCode(), 405);
    contentEncoding = response.getHeader("Content-Encoding");
    assertTrue(contentEncoding == null || !contentEncoding.contains("gzip"));
  }
View Full Code Here

  void testScannerResultCodes() throws Exception {
    Header[] headers = new Header[3];
    headers[0] = new Header("Content-Type", Constants.MIMETYPE_XML);
    headers[1] = new Header("Accept", Constants.MIMETYPE_JSON);
    headers[2] = new Header("Accept-Encoding", "gzip");
    Response response = client.post("/" + TABLE + "/scanner", headers,
        "<Scanner/>".getBytes());
    assertEquals(response.getCode(), 201);
    String scannerUrl = response.getLocation();
    assertNotNull(scannerUrl);
    response = client.get(scannerUrl);
    assertEquals(response.getCode(), 200);
    response = client.get(scannerUrl);
    assertEquals(response.getCode(), 204);
  }
View Full Code Here

  @Test
  public void testTableCreateAndDeleteXML() throws IOException, JAXBException {
    String schemaPath = "/" + TABLE1 + "/schema";
    TableSchemaModel model;
    Response response;

    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
    assertFalse(admin.tableExists(TABLE1));

    // create the table
    model = TestTableSchemaModel.buildTestModel(TABLE1);
    TestTableSchemaModel.checkModel(model, TABLE1);
    response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model));
    assertEquals(response.getCode(), 201);

    // recall the same put operation but in read-only mode
    conf.set("hbase.rest.readonly", "true");
    response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model));
    assertEquals(response.getCode(), 403);

    // retrieve the schema and validate it
    response = client.get(schemaPath, Constants.MIMETYPE_XML);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    model = fromXML(response.getBody());
    TestTableSchemaModel.checkModel(model, TABLE1);

    // test delete schema operation is forbidden in read-only mode
    response = client.delete(schemaPath);
    assertEquals(response.getCode(), 403);

    // return read-only setting back to default
    conf.set("hbase.rest.readonly", "false");

    // delete the table and make sure HBase concurs
    response = client.delete(schemaPath);
    assertEquals(response.getCode(), 200);
    assertFalse(admin.tableExists(TABLE1));
  }
View Full Code Here

  @Test
  public void testTableCreateAndDeletePB() throws IOException, JAXBException {
    String schemaPath = "/" + TABLE2 + "/schema";
    TableSchemaModel model;
    Response response;

    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
    assertFalse(admin.tableExists(TABLE2));

    // create the table
    model = TestTableSchemaModel.buildTestModel(TABLE2);
    TestTableSchemaModel.checkModel(model, TABLE2);
    response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
      model.createProtobufOutput());
    assertEquals(response.getCode(), 201);

    // recall the same put operation but in read-only mode
    conf.set("hbase.rest.readonly", "true");
    response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
      model.createProtobufOutput());
    assertEquals(response.getCode(), 403);

    // retrieve the schema and validate it
    response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
    model = new TableSchemaModel();
    model.getObjectFromMessage(response.getBody());
    TestTableSchemaModel.checkModel(model, TABLE2);

    // retrieve the schema and validate it with alternate pbuf type
    response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF_IETF);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
    model = new TableSchemaModel();
    model.getObjectFromMessage(response.getBody());
    TestTableSchemaModel.checkModel(model, TABLE2);

    // test delete schema operation is forbidden in read-only mode
    response = client.delete(schemaPath);
    assertEquals(response.getCode(), 403);

    // return read-only setting back to default
    conf.set("hbase.rest.readonly", "false");

    // delete the table and make sure HBase concurs
    response = client.delete(schemaPath);
    assertEquals(response.getCode(), 200);
    assertFalse(admin.tableExists(TABLE2));
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.rest.client.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.