本文整理汇总了Java中org.apache.hadoop.hbase.rest.client.Response.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getLocation方法的具体用法?Java Response.getLocation怎么用?Java Response.getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.rest.client.Response
的用法示例。
在下文中一共展示了Response.getLocation方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleScannerXMLWithLabelsThatReceivesNoData
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
@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"));
}
示例2: testScannerResultCodes
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
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);
}
示例3: fullTableScan
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
private static int fullTableScan(ScannerModel model) throws IOException {
model.setBatch(100);
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
int count = 0;
while (true) {
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertTrue(response.getCode() == 200 || response.getCode() == 204);
if (response.getCode() == 200) {
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
Iterator<RowModel> rows = cellSet.getRows().iterator();
while (rows.hasNext()) {
RowModel row = rows.next();
Iterator<CellModel> cells = row.getCells().iterator();
while (cells.hasNext()) {
cells.next();
count++;
}
}
} else {
break;
}
}
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
return count;
}
示例4: testSimpleScannerXMLWithLabelsThatReceivesData
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
@Test
public void testSimpleScannerXMLWithLabelsThatReceivesData() throws IOException, JAXBException {
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(5);
model.addColumn(Bytes.toBytes(COLUMN_1));
model.addLabel(SECRET);
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(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response
.getBody()));
assertEquals(countCellSet(cellSet), 5);
}
示例5: verifyScan
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
private static void verifyScan(Scan s, long expectedRows, long expectedKeys)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
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);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cells = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
int rows = cells.getRows().size();
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but scanned " + rows, expectedRows == rows);
for (RowModel row: cells.getRows()) {
int count = row.getCells().size();
assertEquals("Expected " + expectedKeys + " keys per row but " +
"returned " + count, expectedKeys, count);
}
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
示例6: verifyScan
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
private static void verifyScan(Scan s, long expectedRows, long expectedKeys)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
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);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cells = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
int rows = cells.getRows().size();
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but scanned " + rows, expectedRows == rows);
for (RowModel row: cells.getRows()) {
int count = row.getCells().size();
assertEquals("Expected " + expectedKeys + " keys per row but " +
"returned " + count, expectedKeys, count);
}
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
示例7: testSimpleScannerXML
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
@Test
public void testSimpleScannerXML() throws IOException, JAXBException {
final int BATCH_SIZE = 5;
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(BATCH_SIZE);
model.addColumn(Bytes.toBytes(COLUMN_1));
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
byte[] body = Bytes.toBytes(writer.toString());
// test put operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 403);
String scannerURI = response.getLocation();
assertNull(scannerURI);
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML,
body);
assertEquals(response.getCode(), 201);
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// confirm batch size conformance
assertEquals(countCellSet(cellSet), BATCH_SIZE);
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
示例8: testSimpleScannerPB
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
@Test
public void testSimpleScannerPB() throws IOException {
final int BATCH_SIZE = 10;
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(BATCH_SIZE);
model.addColumn(Bytes.toBytes(COLUMN_1));
// test put operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 403);
String scannerURI = response.getLocation();
assertNull(scannerURI);
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
// confirm batch size conformance
assertEquals(countCellSet(cellSet), BATCH_SIZE);
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
示例9: testSimpleScannerBinary
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
@Test
public void testSimpleScannerBinary() throws IOException {
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(1);
model.addColumn(Bytes.toBytes(COLUMN_1));
// test put operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 403);
String scannerURI = response.getLocation();
assertNull(scannerURI);
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell
response = client.get(scannerURI, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
// verify that data was returned
assertTrue(response.getBody().length > 0);
// verify that the expected X-headers are present
boolean foundRowHeader = false, foundColumnHeader = false,
foundTimestampHeader = false;
for (Header header: response.getHeaders()) {
if (header.getName().equals("X-Row")) {
foundRowHeader = true;
} else if (header.getName().equals("X-Column")) {
foundColumnHeader = true;
} else if (header.getName().equals("X-Timestamp")) {
foundTimestampHeader = true;
}
}
assertTrue(foundRowHeader);
assertTrue(foundColumnHeader);
assertTrue(foundTimestampHeader);
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}
示例10: verifyScanFull
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
private static void verifyScanFull(Scan s, KeyValue [] kvs)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
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);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
int row = 0;
int idx = 0;
Iterator<RowModel> i = cellSet.getRows().iterator();
for (boolean done = true; done; row++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many keys! Only expected " + kvs.length +
" total but already scanned " + (cells.size() + idx),
kvs.length >= idx + cells.size());
for (CellModel cell: cells) {
assertTrue("Row mismatch",
Bytes.equals(rowModel.getKey(), kvs[idx].getRow()));
byte[][] split = KeyValue.parseColumn(cell.getColumn());
assertTrue("Family mismatch",
Bytes.equals(split[0], kvs[idx].getFamily()));
assertTrue("Qualifier mismatch",
Bytes.equals(split[1], kvs[idx].getQualifier()));
assertTrue("Value mismatch",
Bytes.equals(cell.getValue(), kvs[idx].getValue()));
idx++;
}
}
assertEquals("Expected " + kvs.length + " total keys but scanned " + idx,
kvs.length, idx);
}
示例11: verifyScanNoEarlyOut
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
private static void verifyScanNoEarlyOut(Scan s, long expectedRows,
long expectedKeys) throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
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);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
Iterator<RowModel> i = cellSet.getRows().iterator();
int j = 0;
for (boolean done = true; done; j++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but already scanned " + (j+1), expectedRows > j);
assertEquals("Expected " + expectedKeys + " keys per row but " +
"returned " + cells.size(), expectedKeys, cells.size());
}
assertEquals("Expected " + expectedRows + " rows but scanned " + j +
" rows", expectedRows, j);
}
示例12: verifyScanFull
import org.apache.hadoop.hbase.rest.client.Response; //导入方法依赖的package包/类
private static void verifyScanFull(Scan s, KeyValue [] kvs)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
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);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
int row = 0;
int idx = 0;
Iterator<RowModel> i = cellSet.getRows().iterator();
for (boolean done = true; done; row++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many keys! Only expected " + kvs.length +
" total but already scanned " + (cells.size() + idx),
kvs.length >= idx + cells.size());
for (CellModel cell: cells) {
assertTrue("Row mismatch",
Bytes.equals(rowModel.getKey(), kvs[idx].getRow()));
byte[][] split = KeyValue.parseColumn(cell.getColumn());
assertTrue("Family mismatch",
Bytes.equals(split[0], kvs[idx].getFamily()));
assertTrue("Qualifier mismatch",
Bytes.equals(split[1], kvs[idx].getQualifier()));
assertTrue("Value mismatch",
Bytes.equals(cell.getValue(), kvs[idx].getValue()));
idx++;
}
}
assertEquals("Expected " + kvs.length + " total keys but scanned " + idx,
kvs.length, idx);
}