Java 类org.apache.hadoop.hbase.rest.client.Response 实例源码

项目:ditb    文件:TestDeleteRow.java   
@Test
public void testDeleteNonExistentColumn() throws Exception {
  Response response = putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
  assertEquals(response.getCode(), 200);

  response = checkAndDeleteJson(TABLE, ROW_1, COLUMN_1, VALUE_2);
  assertEquals(304, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_2, COLUMN_1, VALUE_2);
  assertEquals(304, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_1, "dummy", VALUE_1);
  assertEquals(400, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_1, "dummy:test", VALUE_1);
  assertEquals(404, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_1, "a:test", VALUE_1);
  assertEquals(304, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
}
项目:ditb    文件:TestNamespacesInstanceResource.java   
@Test
public void testCannotDeleteDefaultAndHbaseNamespaces() throws IOException {
  String defaultPath = "/namespaces/default";
  String hbasePath = "/namespaces/hbase";
  Response response;

  // Check that doesn't exist via non-REST call.
  Admin admin = TEST_UTIL.getHBaseAdmin();
  assertNotNull(findNamespace(admin, "default"));
  assertNotNull(findNamespace(admin, "hbase"));

  // Try (but fail) to delete namespaces via REST.
  response = client.delete(defaultPath);
  assertEquals(503, response.getCode());
  response = client.delete(hbasePath);
  assertEquals(503, response.getCode());

  assertNotNull(findNamespace(admin, "default"));
  assertNotNull(findNamespace(admin, "hbase"));
}
项目:ditb    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetJSON() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
  String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;


  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));


  Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));

  client.delete(row_5_url);
  client.delete(row_6_url);

}
项目:ditb    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetXML() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
  String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;


  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));


  Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));

  client.delete(row_5_url);
  client.delete(row_6_url);

}
项目:ditb    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetJSONNotFound() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;

  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
  assertEquals(response.getCode(), 200);
  ObjectMapper mapper = new JacksonProvider().locateMapper(CellSetModel.class,
    MediaType.APPLICATION_JSON_TYPE);
  CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class);
  assertEquals(1, cellSet.getRows().size());
  assertEquals(ROW_1, Bytes.toString(cellSet.getRows().get(0).getKey()));
  assertEquals(VALUE_1, Bytes.toString(cellSet.getRows().get(0).getCells().get(0).getValue()));
  client.delete(row_5_url);
}
项目:ditb    文件:TestScannersWithLabels.java   
@Test
public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException {
  final int BATCH_SIZE = 5;
  // new scanner
  ScannerModel model = new ScannerModel();
  model.setBatch(BATCH_SIZE);
  model.addColumn(Bytes.toBytes(COLUMN_1));
  model.addLabel(PUBLIC);
  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(response.getCode(), 201);
  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(response.getCode(), 204);
  assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
}
项目:ditb    文件:TestGetAndPutResource.java   
@Test
public void testSingleCellGetPutXML() throws IOException, JAXBException {
  Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
  assertEquals(response.getCode(), 404);

  response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
  assertEquals(response.getCode(), 200);
  checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
  response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
  assertEquals(response.getCode(), 200);
  checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
  response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
  assertEquals(response.getCode(), 200);
  checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
  response = checkAndDeleteXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
  assertEquals(response.getCode(), 200);

  response = deleteRow(TABLE, ROW_1);
  assertEquals(response.getCode(), 200);
}
项目:ditb    文件:TestGetAndPutResource.java   
@Test
public void testSingleCellGetPutPB() throws IOException, JAXBException {
  Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
  assertEquals(response.getCode(), 404);

  response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
  response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2);

  response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
  response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3, VALUE_4);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_4);

  response = deleteRow(TABLE, ROW_1);
  assertEquals(response.getCode(), 200);
}
项目:ditb    文件:TestGetAndPutResource.java   
@Test
public void testSingleCellGetPutBinary() throws IOException {
  final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
  final byte[] body = Bytes.toBytes(VALUE_3);
  Response response = client.put(path, Constants.MIMETYPE_BINARY, body);
  assertEquals(response.getCode(), 200);
  Thread.yield();

  response = client.get(path, Constants.MIMETYPE_BINARY);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
  assertTrue(Bytes.equals(response.getBody(), body));
  boolean foundTimestampHeader = false;
  for (Header header: response.getHeaders()) {
    if (header.getName().equals("X-Timestamp")) {
      foundTimestampHeader = true;
      break;
    }
  }
  assertTrue(foundTimestampHeader);

  response = deleteRow(TABLE, ROW_3);
  assertEquals(response.getCode(), 200);
}
项目:ditb    文件:TestGetAndPutResource.java   
@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);
}
项目:ditb    文件:TestGetAndPutResource.java   
@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);
}
项目:ditb    文件:TestGetAndPutResource.java   
@Test
public void testInvalidColumnPut() throws IOException, JAXBException {
  String dummyColumn = "doesnot:exist";
  CellSetModel cellSetModel = new CellSetModel();
  RowModel rowModel = new RowModel(ROW_1);
  rowModel.addCell(new CellModel(Bytes.toBytes(dummyColumn),
    Bytes.toBytes(VALUE_1)));
  cellSetModel.addRow(rowModel);
  StringWriter writer = new StringWriter();
  xmlMarshaller.marshal(cellSetModel, writer);

  final String path = "/" + TABLE + "/" + ROW_1 + "/" + dummyColumn;

  Response response = client.put(path, Constants.MIMETYPE_XML,
    Bytes.toBytes(writer.toString()));
  assertEquals(response.getCode(), 404);
}
项目:ditb    文件:TestGetAndPutResource.java   
@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());
}
项目:ditb    文件:TestVersionResource.java   
@Test
public void testGetStargateVersionText() throws IOException {
  Response response = client.get("/version", Constants.MIMETYPE_TEXT);
  assertTrue(response.getCode() == 200);
  assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
  String body = Bytes.toString(response.getBody());
  assertTrue(body.length() > 0);
  assertTrue(body.contains(RESTServlet.VERSION_STRING));
  assertTrue(body.contains(System.getProperty("java.vm.vendor")));
  assertTrue(body.contains(System.getProperty("java.version")));
  assertTrue(body.contains(System.getProperty("java.vm.version")));
  assertTrue(body.contains(System.getProperty("os.name")));
  assertTrue(body.contains(System.getProperty("os.version")));
  assertTrue(body.contains(System.getProperty("os.arch")));
  assertTrue(body.contains(ServletContainer.class.getPackage()
    .getImplementationVersion()));
}
项目:ditb    文件:TestTableScan.java   
@Test
public void testScanningUnknownColumnJson() throws IOException, JAXBException {
  // Test scanning particular columns with limit.
  StringBuilder builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=a:test");
  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 JacksonProvider().locateMapper(CellSetModel.class,
    MediaType.APPLICATION_JSON_TYPE);
  CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
  int count = TestScannerResource.countCellSet(model);
  assertEquals(0, count);
}
项目:ditb    文件:TestTableScan.java   
@Test
public void testSimpleFilter() throws IOException, JAXBException {
  StringBuilder builder = new StringBuilder();
  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");
  builder.append("&");
  builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("PrefixFilter('aab')", "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("aab", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
项目:ditb    文件:TestTableScan.java   
@Test
public void testCompoundFilter() throws IOException, JAXBException {
  StringBuilder builder = new StringBuilder();
  builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_FILTER + "="
      + URLEncoder.encode("PrefixFilter('abc') AND 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()));
}
项目:ditb    文件:TestTableScan.java   
@Test
public void testCustomFilter() throws IOException, JAXBException {
  StringBuilder builder = new 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()));
}
项目:ditb    文件:TestTableScan.java   
@Test
public void testNegativeCustomFilter() throws IOException, JAXBException {
  StringBuilder builder = new 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);
}
项目:ditb    文件:RowResourceBase.java   
protected static Response checkAndPutValuePB(String url, String table,
    String row, String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
      throws IOException {
  RowModel rowModel = new RowModel(row);
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToPut)));

  if(otherCells != null) {
    for (Map.Entry<String,String> entry :otherCells.entrySet()) {
      rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
    }
  }

  // This Cell need to be added as last cell.
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToCheck)));

  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  Response response = client.put(url, Constants.MIMETYPE_PROTOBUF,
    cellSetModel.createProtobufOutput());
  Thread.yield();
  return response;
}
项目:ditb    文件:RowResourceBase.java   
protected static Response checkAndPutValueXML(String url, String table,
    String row, String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
      throws IOException, JAXBException {
  RowModel rowModel = new RowModel(row);
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToPut)));

  if(otherCells != null) {
    for (Map.Entry<String,String> entry :otherCells.entrySet()) {
      rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
    }
  }

  // This Cell need to be added as last cell.
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToCheck)));
  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  StringWriter writer = new StringWriter();
  xmlMarshaller.marshal(cellSetModel, writer);
  Response response = client.put(url, Constants.MIMETYPE_XML,
    Bytes.toBytes(writer.toString()));
  Thread.yield();
  return response;
}
项目:ditb    文件:RowResourceBase.java   
protected static Response checkAndDeleteXML(String url, String table,
    String row, String column, String valueToCheck, HashMap<String,String> cellsToDelete)
      throws IOException, JAXBException {
  RowModel rowModel = new RowModel(row);

  if(cellsToDelete != null) {
    for (Map.Entry<String,String> entry :cellsToDelete.entrySet()) {
      rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
    }
  }
  // Add this at the end
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToCheck)));
  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  StringWriter writer = new StringWriter();
  xmlMarshaller.marshal(cellSetModel, writer);
  Response response = client.put(url, Constants.MIMETYPE_XML,
    Bytes.toBytes(writer.toString()));
  Thread.yield();
  return response;
}
项目:ditb    文件:RowResourceBase.java   
protected static Response checkAndDeleteJson(String url, String table,
    String row, String column, String valueToCheck, HashMap<String,String> cellsToDelete)
      throws IOException, JAXBException {
  RowModel rowModel = new RowModel(row);

  if(cellsToDelete != null) {
    for (Map.Entry<String,String> entry :cellsToDelete.entrySet()) {
      rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
    }
  }
  // Add this at the end
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToCheck)));
  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  String jsonString = jsonMapper.writeValueAsString(cellSetModel);
  Response response = client.put(url, Constants.MIMETYPE_JSON,
    Bytes.toBytes(jsonString));
  Thread.yield();
  return response;
}
项目:ditb    文件:RowResourceBase.java   
protected static Response checkAndDeleteValuePB(String url, String table,
    String row, String column, String valueToCheck, HashMap<String,String> cellsToDelete)
    throws IOException {
  RowModel rowModel = new RowModel(row);

  if(cellsToDelete != null) {
    for (Map.Entry<String,String> entry :cellsToDelete.entrySet()) {
      rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
    }
  }
  // Add this at the end
  rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes
      .toBytes(valueToCheck)));
  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  Response response = client.put(url, Constants.MIMETYPE_PROTOBUF,
      cellSetModel.createProtobufOutput());
  Thread.yield();
  return response;
}
项目:LCIndex-HBase-0.94.16    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetJSON() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
  String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;


  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));


  Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));

  client.delete(row_5_url);
  client.delete(row_6_url);

}
项目:LCIndex-HBase-0.94.16    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetXML() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
  String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;


  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));


  Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));

  client.delete(row_5_url);
  client.delete(row_6_url);

}
项目:LCIndex-HBase-0.94.16    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetJSONNotFound() throws IOException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;

  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));

  Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);

  assertEquals(response.getCode(), 404);

}
项目:HIndex    文件:RowResourceBase.java   
protected static Response checkAndPutValueXML(String url, String table,
    String row, String column, String valueToCheck, String valueToPut)
      throws IOException, JAXBException {
  RowModel rowModel = new RowModel(row);
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToPut)));
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToCheck)));
  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  StringWriter writer = new StringWriter();
  xmlMarshaller.marshal(cellSetModel, writer);
  Response response = client.put(url, Constants.MIMETYPE_XML,
    Bytes.toBytes(writer.toString()));
  Thread.yield();
  return response;
}
项目:LCIndex-HBase-0.94.16    文件:TestRowResource.java   
private static Response checkAndPutValueXML(String url, String table,
    String row, String column, String valueToCheck, String valueToPut)
      throws IOException, JAXBException {
  RowModel rowModel = new RowModel(row);
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToPut)));
  rowModel.addCell(new CellModel(Bytes.toBytes(column),
    Bytes.toBytes(valueToCheck)));
  CellSetModel cellSetModel = new CellSetModel();
  cellSetModel.addRow(rowModel);
  StringWriter writer = new StringWriter();
  marshaller.marshal(cellSetModel, writer);
  Response response = client.put(url, Constants.MIMETYPE_XML,
    Bytes.toBytes(writer.toString()));
  Thread.yield();
  return response;
}
项目:LCIndex-HBase-0.94.16    文件:TestRowResource.java   
@Test
public void testSingleCellGetPutXML() throws IOException, JAXBException {
  Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
  assertEquals(response.getCode(), 404);

  response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
  assertEquals(response.getCode(), 200);
  checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
  response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
  assertEquals(response.getCode(), 200);
  checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
  response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
  assertEquals(response.getCode(), 200);
  checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
  response = checkAndDeleteXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
  assertEquals(response.getCode(), 200);

  response = deleteRow(TABLE, ROW_1);
  assertEquals(response.getCode(), 200);
}
项目:LCIndex-HBase-0.94.16    文件:TestRowResource.java   
@Test
public void testSingleCellGetPutPB() throws IOException, JAXBException {
  Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
  assertEquals(response.getCode(), 404);

  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_1, VALUE_1);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
  response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2);

  response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
  response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3, VALUE_4);
  assertEquals(response.getCode(), 200);
  checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_4);

  response = deleteRow(TABLE, ROW_1);
  assertEquals(response.getCode(), 200);
}
项目:LCIndex-HBase-0.94.16    文件:TestRowResource.java   
@Test
public void testSingleCellGetPutBinary() throws IOException {
  final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
  final byte[] body = Bytes.toBytes(VALUE_3);
  Response response = client.put(path, Constants.MIMETYPE_BINARY, body);
  assertEquals(response.getCode(), 200);
  Thread.yield();

  response = client.get(path, Constants.MIMETYPE_BINARY);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
  assertTrue(Bytes.equals(response.getBody(), body));
  boolean foundTimestampHeader = false;
  for (Header header: response.getHeaders()) {
    if (header.getName().equals("X-Timestamp")) {
      foundTimestampHeader = true;
      break;
    }
  }
  assertTrue(foundTimestampHeader);

  response = deleteRow(TABLE, ROW_3);
  assertEquals(response.getCode(), 200);
}
项目:LCIndex-HBase-0.94.16    文件:TestRowResource.java   
@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);
}
项目:LCIndex-HBase-0.94.16    文件:TestRowResource.java   
@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();
  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);
}
项目:LCIndex-HBase-0.94.16    文件:TestVersionResource.java   
@Test
public void testGetStargateVersionText() throws IOException {
  Response response = client.get("/version", Constants.MIMETYPE_TEXT);
  assertTrue(response.getCode() == 200);
  assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
  String body = Bytes.toString(response.getBody());
  assertTrue(body.length() > 0);
  assertTrue(body.contains(RESTServlet.VERSION_STRING));
  assertTrue(body.contains(System.getProperty("java.vm.vendor")));
  assertTrue(body.contains(System.getProperty("java.version")));
  assertTrue(body.contains(System.getProperty("java.vm.version")));
  assertTrue(body.contains(System.getProperty("os.name")));
  assertTrue(body.contains(System.getProperty("os.version")));
  assertTrue(body.contains(System.getProperty("os.arch")));
  assertTrue(body.contains(ServletContainer.class.getPackage()
    .getImplementationVersion()));
}
项目:HIndex    文件:TestTableScan.java   
@Test
public void testScanningUnknownColumnJson() throws IOException, JAXBException {
  // Test scanning particular columns with limit.
  StringBuilder builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=a:test");
  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 JacksonProvider().locateMapper(CellSetModel.class,
    MediaType.APPLICATION_JSON_TYPE);
  CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
  int count = TestScannerResource.countCellSet(model);
  assertEquals(0, count);
}
项目:HIndex    文件:TestDeleteRow.java   
@Test
public void testDeleteNonExistentColumn() throws Exception {
  Response response = putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
  assertEquals(response.getCode(), 200);

  response = checkAndDeleteJson(TABLE, ROW_1, COLUMN_1, VALUE_2);
  assertEquals(304, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_2, COLUMN_1, VALUE_2);
  assertEquals(304, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_1, "dummy", VALUE_1);
  assertEquals(400, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_1, "dummy:test", VALUE_1);
  assertEquals(404, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());

  response = checkAndDeleteJson(TABLE, ROW_1, "a:test", VALUE_1);
  assertEquals(304, response.getCode());
  assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
}
项目:HIndex    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetJSON() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
  String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;


  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));


  Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));

  client.delete(row_5_url);
  client.delete(row_6_url);

}
项目:HIndex    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetXML() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
  String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;


  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2));


  Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));

  client.delete(row_5_url);
  client.delete(row_6_url);

}
项目:HIndex    文件:TestMultiRowResource.java   
@Test
public void testMultiCellGetJSONNotFound() throws IOException, JAXBException {
  String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;

  StringBuilder path = new StringBuilder();
  path.append("/");
  path.append(TABLE);
  path.append("/multiget/?row=");
  path.append(ROW_1);
  path.append("&row=");
  path.append(ROW_2);

  client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1));
  Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
  assertEquals(response.getCode(), 200);
  ObjectMapper mapper = new JacksonProvider().locateMapper(CellSetModel.class,
    MediaType.APPLICATION_JSON_TYPE);
  CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class);
  assertEquals(1, cellSet.getRows().size());
  assertEquals(ROW_1, Bytes.toString(cellSet.getRows().get(0).getKey()));
  assertEquals(VALUE_1, Bytes.toString(cellSet.getRows().get(0).getCells().get(0).getValue()));
  client.delete(row_5_url);
}