use of org.apache.hadoop.hbase.rest.model.CellModel 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);
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestGetAndPutResource method testSuffixGlobbingXML.
@Test
public void testSuffixGlobbingXML() throws IOException, JAXBException {
// 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);
StringWriter writer = new StringWriter();
xmlMarshaller.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
StringBuilder query = new StringBuilder();
query.append('/');
query.append(TABLE);
query.append('/');
query.append("testrow*");
query.append('/');
query.append(COLUMN_1);
response = client.get(query.toString(), Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
List<RowModel> rows = cellSet.getRows();
assertTrue(rows.size() == 2);
for (RowModel row : rows) {
assertTrue(row.getCells().size() == 1);
assertEquals(COLUMN_1, Bytes.toString(row.getCells().get(0).getColumn()));
}
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestGetAndPutResource method testInvalidColumnPut.
@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);
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class TestScannerResource method countCellSet.
static int countCellSet(CellSetModel model) {
int count = 0;
Iterator<RowModel> rows = model.getRows().iterator();
while (rows.hasNext()) {
RowModel row = rows.next();
Iterator<CellModel> cells = row.getCells().iterator();
while (cells.hasNext()) {
cells.next();
count++;
}
}
return count;
}
use of org.apache.hadoop.hbase.rest.model.CellModel in project hbase by apache.
the class RowResourceBase method checkAndDeleteJson.
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;
}
Aggregations