HBASE-2638 Speed up REST tests
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@950284 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e870fa13e
commit
9abbe3075a
|
@ -656,6 +656,7 @@ Release 0.21.0 - Unreleased
|
||||||
HBASE-2632 Shell should autodetect terminal width
|
HBASE-2632 Shell should autodetect terminal width
|
||||||
HBASE-2636 Upgrade Jetty to 6.1.24
|
HBASE-2636 Upgrade Jetty to 6.1.24
|
||||||
HBASE-2437 Refactor HLog splitLog (Cosmin Lehene via Stack)
|
HBASE-2437 Refactor HLog splitLog (Cosmin Lehene via Stack)
|
||||||
|
HBASE-2638 Speed up REST tests
|
||||||
|
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
HBASE-1961 HBase EC2 scripts
|
HBASE-1961 HBase EC2 scripts
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.apache.commons.httpclient.Header;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
import org.apache.hadoop.hbase.HConstants;
|
import org.apache.hadoop.hbase.HConstants;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
|
||||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||||
import org.apache.hadoop.hbase.rest.client.Client;
|
import org.apache.hadoop.hbase.rest.client.Client;
|
||||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||||
|
@ -45,48 +44,41 @@ import org.apache.hadoop.hbase.rest.model.RowModel;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
public class TestRowResource extends HBaseRESTClusterTestBase {
|
public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
|
static final String TABLE = "TestRowResource";
|
||||||
|
static final String COLUMN_1 = "a:";
|
||||||
|
static final String COLUMN_2 = "b:";
|
||||||
|
static final String ROW_1 = "testrow1";
|
||||||
|
static final String VALUE_1 = "testvalue1";
|
||||||
|
static final String ROW_2 = "testrow2";
|
||||||
|
static final String VALUE_2 = "testvalue2";
|
||||||
|
static final String ROW_3 = "testrow3";
|
||||||
|
static final String VALUE_3 = "testvalue3";
|
||||||
|
static final String ROW_4 = "testrow4";
|
||||||
|
static final String VALUE_4 = "testvalue4";
|
||||||
|
|
||||||
private static final String TABLE = "TestRowResource";
|
Client client;
|
||||||
private static final String COLUMN_1 = "a:";
|
JAXBContext context;
|
||||||
private static final String COLUMN_2 = "b:";
|
Marshaller marshaller;
|
||||||
private static final String ROW_1 = "testrow1";
|
Unmarshaller unmarshaller;
|
||||||
private static final String VALUE_1 = "testvalue1";
|
HBaseAdmin admin;
|
||||||
private static final String ROW_2 = "testrow2";
|
|
||||||
private static final String VALUE_2 = "testvalue2";
|
|
||||||
private static final String ROW_3 = "testrow3";
|
|
||||||
private static final String VALUE_3 = "testvalue3";
|
|
||||||
private static final String ROW_4 = "testrow4";
|
|
||||||
private static final String VALUE_4 = "testvalue4";
|
|
||||||
|
|
||||||
private Client client;
|
@Override
|
||||||
private JAXBContext context;
|
protected void setUp() throws Exception {
|
||||||
private Marshaller marshaller;
|
super.setUp();
|
||||||
private Unmarshaller unmarshaller;
|
|
||||||
private HBaseAdmin admin;
|
|
||||||
|
|
||||||
public TestRowResource() throws JAXBException {
|
|
||||||
super();
|
|
||||||
context = JAXBContext.newInstance(
|
context = JAXBContext.newInstance(
|
||||||
CellModel.class,
|
CellModel.class,
|
||||||
CellSetModel.class,
|
CellSetModel.class,
|
||||||
RowModel.class);
|
RowModel.class);
|
||||||
marshaller = context.createMarshaller();
|
marshaller = context.createMarshaller();
|
||||||
unmarshaller = context.createUnmarshaller();
|
unmarshaller = context.createUnmarshaller();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||||
admin = new HBaseAdmin(conf);
|
admin = new HBaseAdmin(conf);
|
||||||
if (admin.tableExists(TABLE)) {
|
if (admin.tableExists(TABLE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||||
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
|
htd.addFamily(new HColumnDescriptor(COLUMN_1));
|
||||||
Bytes.toBytes(COLUMN_1))[0]));
|
htd.addFamily(new HColumnDescriptor(COLUMN_2));
|
||||||
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
|
|
||||||
Bytes.toBytes(COLUMN_2))[0]));
|
|
||||||
admin.createTable(htd);
|
admin.createTable(htd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +88,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response deleteRow(String table, String row) throws IOException {
|
Response deleteRow(String table, String row) throws IOException {
|
||||||
StringBuilder path = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
path.append('/');
|
path.append('/');
|
||||||
path.append(table);
|
path.append(table);
|
||||||
|
@ -107,7 +99,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response deleteValue(String table, String row, String column)
|
Response deleteValue(String table, String row, String column)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
StringBuilder path = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
path.append('/');
|
path.append('/');
|
||||||
|
@ -121,7 +113,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response getValueXML(String table, String row, String column)
|
Response getValueXML(String table, String row, String column)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
StringBuilder path = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
path.append('/');
|
path.append('/');
|
||||||
|
@ -134,7 +126,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response getValuePB(String table, String row, String column)
|
Response getValuePB(String table, String row, String column)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
StringBuilder path = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
path.append('/');
|
path.append('/');
|
||||||
|
@ -147,8 +139,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response putValueXML(String table, String row, String column,
|
Response putValueXML(String table, String row, String column, String value)
|
||||||
String value) throws IOException, JAXBException {
|
throws IOException, JAXBException {
|
||||||
StringBuilder path = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
path.append('/');
|
path.append('/');
|
||||||
path.append(table);
|
path.append(table);
|
||||||
|
@ -157,7 +149,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
path.append('/');
|
path.append('/');
|
||||||
path.append(column);
|
path.append(column);
|
||||||
RowModel rowModel = new RowModel(row);
|
RowModel rowModel = new RowModel(row);
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value)));
|
rowModel.addCell(new CellModel(Bytes.toBytes(column),
|
||||||
|
Bytes.toBytes(value)));
|
||||||
CellSetModel cellSetModel = new CellSetModel();
|
CellSetModel cellSetModel = new CellSetModel();
|
||||||
cellSetModel.addRow(rowModel);
|
cellSetModel.addRow(rowModel);
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
|
@ -168,8 +161,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkValueXML(String table, String row, String column,
|
void checkValueXML(String table, String row, String column, String value)
|
||||||
String value) throws IOException, JAXBException {
|
throws IOException, JAXBException {
|
||||||
Response response = getValueXML(table, row, column);
|
Response response = getValueXML(table, row, column);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
CellSetModel cellSet = (CellSetModel)
|
CellSetModel cellSet = (CellSetModel)
|
||||||
|
@ -180,8 +173,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(Bytes.toString(cell.getValue()), value);
|
assertEquals(Bytes.toString(cell.getValue()), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response putValuePB(String table, String row, String column,
|
Response putValuePB(String table, String row, String column, String value)
|
||||||
String value) throws IOException {
|
throws IOException {
|
||||||
StringBuilder path = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
path.append('/');
|
path.append('/');
|
||||||
path.append(table);
|
path.append(table);
|
||||||
|
@ -190,7 +183,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
path.append('/');
|
path.append('/');
|
||||||
path.append(column);
|
path.append(column);
|
||||||
RowModel rowModel = new RowModel(row);
|
RowModel rowModel = new RowModel(row);
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value)));
|
rowModel.addCell(new CellModel(Bytes.toBytes(column),
|
||||||
|
Bytes.toBytes(value)));
|
||||||
CellSetModel cellSetModel = new CellSetModel();
|
CellSetModel cellSetModel = new CellSetModel();
|
||||||
cellSetModel.addRow(rowModel);
|
cellSetModel.addRow(rowModel);
|
||||||
Response response = client.put(path.toString(), MIMETYPE_PROTOBUF,
|
Response response = client.put(path.toString(), MIMETYPE_PROTOBUF,
|
||||||
|
@ -199,8 +193,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkValuePB(String table, String row, String column,
|
void checkValuePB(String table, String row, String column, String value)
|
||||||
String value) throws IOException {
|
throws IOException {
|
||||||
Response response = getValuePB(table, row, column);
|
Response response = getValuePB(table, row, column);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
CellSetModel cellSet = new CellSetModel();
|
CellSetModel cellSet = new CellSetModel();
|
||||||
|
@ -211,7 +205,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(Bytes.toString(cell.getValue()), value);
|
assertEquals(Bytes.toString(cell.getValue()), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDelete() throws IOException, JAXBException {
|
void doTestDelete() throws IOException, JAXBException {
|
||||||
Response response;
|
Response response;
|
||||||
|
|
||||||
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
||||||
|
@ -235,7 +229,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 404);
|
assertEquals(response.getCode(), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingleCellGetPutXML() throws IOException, JAXBException {
|
void doTestSingleCellGetPutXML() throws IOException, JAXBException {
|
||||||
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
|
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
|
||||||
assertEquals(response.getCode(), 404);
|
assertEquals(response.getCode(), 404);
|
||||||
|
|
||||||
|
@ -250,7 +244,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingleCellGetPutPB() throws IOException, JAXBException {
|
void doTestSingleCellGetPutPB() throws IOException, JAXBException {
|
||||||
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
||||||
assertEquals(response.getCode(), 404);
|
assertEquals(response.getCode(), 404);
|
||||||
|
|
||||||
|
@ -269,7 +263,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingleCellGetPutBinary() throws IOException {
|
void doTestSingleCellGetPutBinary() throws IOException {
|
||||||
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
|
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
|
||||||
final byte[] body = Bytes.toBytes(VALUE_3);
|
final byte[] body = Bytes.toBytes(VALUE_3);
|
||||||
Response response = client.put(path, MIMETYPE_BINARY, body);
|
Response response = client.put(path, MIMETYPE_BINARY, body);
|
||||||
|
@ -292,7 +286,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingleCellGetJSON() throws IOException, JAXBException {
|
void doTestSingleCellGetJSON() throws IOException, JAXBException {
|
||||||
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
||||||
Response response = client.put(path, MIMETYPE_BINARY,
|
Response response = client.put(path, MIMETYPE_BINARY,
|
||||||
Bytes.toBytes(VALUE_4));
|
Bytes.toBytes(VALUE_4));
|
||||||
|
@ -304,7 +298,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testURLEncodedKey() throws IOException, JAXBException {
|
void doTestURLEncodedKey() throws IOException, JAXBException {
|
||||||
String encodedKey = URLEncoder.encode("http://www.google.com/",
|
String encodedKey = URLEncoder.encode("http://www.google.com/",
|
||||||
HConstants.UTF8_ENCODING);
|
HConstants.UTF8_ENCODING);
|
||||||
Response response;
|
Response response;
|
||||||
|
@ -316,17 +310,21 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
checkValueXML(TABLE, encodedKey, COLUMN_2, VALUE_2);
|
checkValueXML(TABLE, encodedKey, COLUMN_2, VALUE_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiCellGetPutXML() throws IOException, JAXBException {
|
void doTestMultiCellGetPutXML() throws IOException, JAXBException {
|
||||||
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
|
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
|
||||||
|
|
||||||
CellSetModel cellSetModel = new CellSetModel();
|
CellSetModel cellSetModel = new CellSetModel();
|
||||||
RowModel rowModel = new RowModel(ROW_1);
|
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_1),
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
|
Bytes.toBytes(VALUE_1)));
|
||||||
|
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
|
||||||
|
Bytes.toBytes(VALUE_2)));
|
||||||
cellSetModel.addRow(rowModel);
|
cellSetModel.addRow(rowModel);
|
||||||
rowModel = new RowModel(ROW_2);
|
rowModel = new RowModel(ROW_2);
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
|
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
|
Bytes.toBytes(VALUE_3)));
|
||||||
|
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
|
||||||
|
Bytes.toBytes(VALUE_4)));
|
||||||
cellSetModel.addRow(rowModel);
|
cellSetModel.addRow(rowModel);
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
marshaller.marshal(cellSetModel, writer);
|
marshaller.marshal(cellSetModel, writer);
|
||||||
|
@ -350,17 +348,21 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiCellGetPutPB() throws IOException {
|
void doTestMultiCellGetPutPB() throws IOException {
|
||||||
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
|
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
|
||||||
|
|
||||||
CellSetModel cellSetModel = new CellSetModel();
|
CellSetModel cellSetModel = new CellSetModel();
|
||||||
RowModel rowModel = new RowModel(ROW_1);
|
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_1),
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
|
Bytes.toBytes(VALUE_1)));
|
||||||
|
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
|
||||||
|
Bytes.toBytes(VALUE_2)));
|
||||||
cellSetModel.addRow(rowModel);
|
cellSetModel.addRow(rowModel);
|
||||||
rowModel = new RowModel(ROW_2);
|
rowModel = new RowModel(ROW_2);
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
|
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
|
||||||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
|
Bytes.toBytes(VALUE_3)));
|
||||||
|
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
|
||||||
|
Bytes.toBytes(VALUE_4)));
|
||||||
cellSetModel.addRow(rowModel);
|
cellSetModel.addRow(rowModel);
|
||||||
Response response = client.put(path, MIMETYPE_PROTOBUF,
|
Response response = client.put(path, MIMETYPE_PROTOBUF,
|
||||||
cellSetModel.createProtobufOutput());
|
cellSetModel.createProtobufOutput());
|
||||||
|
@ -381,4 +383,15 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
||||||
response = deleteRow(TABLE, ROW_2);
|
response = deleteRow(TABLE, ROW_2);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRowResource() throws Exception {
|
||||||
|
doTestDelete();
|
||||||
|
doTestSingleCellGetPutXML();
|
||||||
|
doTestSingleCellGetPutPB();
|
||||||
|
doTestSingleCellGetPutBinary();
|
||||||
|
doTestSingleCellGetJSON();
|
||||||
|
doTestURLEncodedKey();
|
||||||
|
doTestMultiCellGetPutXML();
|
||||||
|
doTestMultiCellGetPutPB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,21 +48,20 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
public class TestScannerResource extends HBaseRESTClusterTestBase {
|
public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
|
static final String TABLE = "TestScannerResource";
|
||||||
|
static final String COLUMN_1 = "a:";
|
||||||
|
static final String COLUMN_2 = "b:";
|
||||||
|
|
||||||
private static final String TABLE = "TestScannerResource";
|
static int expectedRows1;
|
||||||
private static final String COLUMN_1 = "a:";
|
static int expectedRows2;
|
||||||
private static final String COLUMN_2 = "b:";
|
|
||||||
|
|
||||||
private static int expectedRows1;
|
Client client;
|
||||||
private static int expectedRows2;
|
JAXBContext context;
|
||||||
|
Marshaller marshaller;
|
||||||
|
Unmarshaller unmarshaller;
|
||||||
|
HBaseAdmin admin;
|
||||||
|
|
||||||
private Client client;
|
int insertData(String tableName, String column, double prob)
|
||||||
private JAXBContext context;
|
|
||||||
private Marshaller marshaller;
|
|
||||||
private Unmarshaller unmarshaller;
|
|
||||||
private HBaseAdmin admin;
|
|
||||||
|
|
||||||
private int insertData(String tableName, String column, double prob)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Random rng = new Random();
|
Random rng = new Random();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -77,11 +76,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
k[1] = b2;
|
k[1] = b2;
|
||||||
k[2] = b3;
|
k[2] = b3;
|
||||||
Put put = new Put(k);
|
Put put = new Put(k);
|
||||||
if(famAndQf.length == 1) {
|
put.add(famAndQf[0], famAndQf[1], k);
|
||||||
put.add(famAndQf[0], new byte[0], k);
|
|
||||||
} else {
|
|
||||||
put.add(famAndQf[0], famAndQf[1], k);
|
|
||||||
}
|
|
||||||
table.put(put);
|
table.put(put);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -92,8 +87,9 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestScannerResource() throws JAXBException {
|
@Override
|
||||||
super();
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
context = JAXBContext.newInstance(
|
context = JAXBContext.newInstance(
|
||||||
CellModel.class,
|
CellModel.class,
|
||||||
CellSetModel.class,
|
CellSetModel.class,
|
||||||
|
@ -101,21 +97,14 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
ScannerModel.class);
|
ScannerModel.class);
|
||||||
marshaller = context.createMarshaller();
|
marshaller = context.createMarshaller();
|
||||||
unmarshaller = context.createUnmarshaller();
|
unmarshaller = context.createUnmarshaller();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||||
admin = new HBaseAdmin(conf);
|
admin = new HBaseAdmin(conf);
|
||||||
if (admin.tableExists(TABLE)) {
|
if (admin.tableExists(TABLE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||||
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
|
htd.addFamily(new HColumnDescriptor(COLUMN_1));
|
||||||
Bytes.toBytes(COLUMN_1))[0]));
|
htd.addFamily(new HColumnDescriptor(COLUMN_2));
|
||||||
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
|
|
||||||
Bytes.toBytes(COLUMN_2))[0]));
|
|
||||||
admin.createTable(htd);
|
admin.createTable(htd);
|
||||||
expectedRows1 = insertData(TABLE, COLUMN_1, 1.0);
|
expectedRows1 = insertData(TABLE, COLUMN_1, 1.0);
|
||||||
expectedRows2 = insertData(TABLE, COLUMN_2, 0.5);
|
expectedRows2 = insertData(TABLE, COLUMN_2, 0.5);
|
||||||
|
@ -127,7 +116,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countCellSet(CellSetModel model) {
|
int countCellSet(CellSetModel model) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Iterator<RowModel> rows = model.getRows().iterator();
|
Iterator<RowModel> rows = model.getRows().iterator();
|
||||||
while (rows.hasNext()) {
|
while (rows.hasNext()) {
|
||||||
|
@ -141,7 +130,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleScannerXML() throws IOException, JAXBException {
|
void doTestSimpleScannerXML() throws IOException, JAXBException {
|
||||||
final int BATCH_SIZE = 5;
|
final int BATCH_SIZE = 5;
|
||||||
// new scanner
|
// new scanner
|
||||||
ScannerModel model = new ScannerModel();
|
ScannerModel model = new ScannerModel();
|
||||||
|
@ -169,7 +158,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleScannerPB() throws IOException {
|
void doTestSimpleScannerPB() throws IOException {
|
||||||
final int BATCH_SIZE = 10;
|
final int BATCH_SIZE = 10;
|
||||||
// new scanner
|
// new scanner
|
||||||
ScannerModel model = new ScannerModel();
|
ScannerModel model = new ScannerModel();
|
||||||
|
@ -194,7 +183,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleScannerBinary() throws IOException {
|
void doTestSimpleScannerBinary() throws IOException {
|
||||||
// new scanner
|
// new scanner
|
||||||
ScannerModel model = new ScannerModel();
|
ScannerModel model = new ScannerModel();
|
||||||
model.setBatch(1);
|
model.setBatch(1);
|
||||||
|
@ -231,7 +220,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fullTableScan(ScannerModel model) throws IOException {
|
int fullTableScan(ScannerModel model) throws IOException {
|
||||||
model.setBatch(100);
|
model.setBatch(100);
|
||||||
Response response = client.put("/" + TABLE + "/scanner",
|
Response response = client.put("/" + TABLE + "/scanner",
|
||||||
MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||||
|
@ -264,7 +253,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFullTableScan() throws IOException {
|
void doTestFullTableScan() throws IOException {
|
||||||
ScannerModel model = new ScannerModel();
|
ScannerModel model = new ScannerModel();
|
||||||
model.addColumn(Bytes.toBytes(COLUMN_1));
|
model.addColumn(Bytes.toBytes(COLUMN_1));
|
||||||
assertEquals(fullTableScan(model), expectedRows1);
|
assertEquals(fullTableScan(model), expectedRows1);
|
||||||
|
@ -273,4 +262,11 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
||||||
model.addColumn(Bytes.toBytes(COLUMN_2));
|
model.addColumn(Bytes.toBytes(COLUMN_2));
|
||||||
assertEquals(fullTableScan(model), expectedRows2);
|
assertEquals(fullTableScan(model), expectedRows2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testScannerResource() throws Exception {
|
||||||
|
doTestSimpleScannerXML();
|
||||||
|
doTestSimpleScannerPB();
|
||||||
|
doTestSimpleScannerBinary();
|
||||||
|
doTestFullTableScan();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
|
||||||
|
@ -69,47 +68,46 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
|
|
||||||
private static final Log LOG =
|
static final Log LOG = LogFactory.getLog(TestScannersWithFilters.class);
|
||||||
LogFactory.getLog(TestScannersWithFilters.class);
|
|
||||||
|
|
||||||
private Client client;
|
static final byte [][] ROWS_ONE = {
|
||||||
private JAXBContext context;
|
|
||||||
private Marshaller marshaller;
|
|
||||||
private Unmarshaller unmarshaller;
|
|
||||||
|
|
||||||
private static final byte [][] ROWS_ONE = {
|
|
||||||
Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-1"),
|
Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-1"),
|
||||||
Bytes.toBytes("testRowOne-2"), Bytes.toBytes("testRowOne-3")
|
Bytes.toBytes("testRowOne-2"), Bytes.toBytes("testRowOne-3")
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final byte [][] ROWS_TWO = {
|
static final byte [][] ROWS_TWO = {
|
||||||
Bytes.toBytes("testRowTwo-0"), Bytes.toBytes("testRowTwo-1"),
|
Bytes.toBytes("testRowTwo-0"), Bytes.toBytes("testRowTwo-1"),
|
||||||
Bytes.toBytes("testRowTwo-2"), Bytes.toBytes("testRowTwo-3")
|
Bytes.toBytes("testRowTwo-2"), Bytes.toBytes("testRowTwo-3")
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final byte [][] FAMILIES = {
|
static final byte [][] FAMILIES = {
|
||||||
Bytes.toBytes("testFamilyOne"), Bytes.toBytes("testFamilyTwo")
|
Bytes.toBytes("testFamilyOne"), Bytes.toBytes("testFamilyTwo")
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final byte [][] QUALIFIERS_ONE = {
|
static final byte [][] QUALIFIERS_ONE = {
|
||||||
Bytes.toBytes("testQualifierOne-0"), Bytes.toBytes("testQualifierOne-1"),
|
Bytes.toBytes("testQualifierOne-0"), Bytes.toBytes("testQualifierOne-1"),
|
||||||
Bytes.toBytes("testQualifierOne-2"), Bytes.toBytes("testQualifierOne-3")
|
Bytes.toBytes("testQualifierOne-2"), Bytes.toBytes("testQualifierOne-3")
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final byte [][] QUALIFIERS_TWO = {
|
static final byte [][] QUALIFIERS_TWO = {
|
||||||
Bytes.toBytes("testQualifierTwo-0"), Bytes.toBytes("testQualifierTwo-1"),
|
Bytes.toBytes("testQualifierTwo-0"), Bytes.toBytes("testQualifierTwo-1"),
|
||||||
Bytes.toBytes("testQualifierTwo-2"), Bytes.toBytes("testQualifierTwo-3")
|
Bytes.toBytes("testQualifierTwo-2"), Bytes.toBytes("testQualifierTwo-3")
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final byte [][] VALUES = {
|
static final byte [][] VALUES = {
|
||||||
Bytes.toBytes("testValueOne"), Bytes.toBytes("testValueTwo")
|
Bytes.toBytes("testValueOne"), Bytes.toBytes("testValueTwo")
|
||||||
};
|
};
|
||||||
|
|
||||||
private long numRows = ROWS_ONE.length + ROWS_TWO.length;
|
Client client;
|
||||||
private long colsPerRow = FAMILIES.length * QUALIFIERS_ONE.length;
|
JAXBContext context;
|
||||||
|
Marshaller marshaller;
|
||||||
|
Unmarshaller unmarshaller;
|
||||||
|
long numRows = ROWS_ONE.length + ROWS_TWO.length;
|
||||||
|
long colsPerRow = FAMILIES.length * QUALIFIERS_ONE.length;
|
||||||
|
|
||||||
public TestScannersWithFilters() throws JAXBException {
|
@Override
|
||||||
super();
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
context = JAXBContext.newInstance(
|
context = JAXBContext.newInstance(
|
||||||
CellModel.class,
|
CellModel.class,
|
||||||
CellSetModel.class,
|
CellSetModel.class,
|
||||||
|
@ -117,11 +115,6 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
ScannerModel.class);
|
ScannerModel.class);
|
||||||
marshaller = context.createMarshaller();
|
marshaller = context.createMarshaller();
|
||||||
unmarshaller = context.createUnmarshaller();
|
unmarshaller = context.createUnmarshaller();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||||
if (!admin.tableExists(getName())) {
|
if (!admin.tableExists(getName())) {
|
||||||
|
@ -200,7 +193,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyScan(Scan s, long expectedRows, long expectedKeys)
|
void verifyScan(Scan s, long expectedRows, long expectedKeys)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ScannerModel model = ScannerModel.fromScan(s);
|
ScannerModel model = ScannerModel.fromScan(s);
|
||||||
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
||||||
|
@ -234,7 +227,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyScanFull(Scan s, KeyValue [] kvs) throws Exception {
|
void verifyScanFull(Scan s, KeyValue [] kvs) throws Exception {
|
||||||
ScannerModel model = ScannerModel.fromScan(s);
|
ScannerModel model = ScannerModel.fromScan(s);
|
||||||
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
|
@ -286,7 +279,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
kvs.length, idx);
|
kvs.length, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys)
|
void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ScannerModel model = ScannerModel.fromScan(s);
|
ScannerModel model = ScannerModel.fromScan(s);
|
||||||
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
||||||
|
@ -327,7 +320,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
" rows", expectedRows, j);
|
" rows", expectedRows, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoFilter() throws Exception {
|
void doTestNoFilter() throws Exception {
|
||||||
// No filter
|
// No filter
|
||||||
long expectedRows = this.numRows;
|
long expectedRows = this.numRows;
|
||||||
long expectedKeys = this.colsPerRow;
|
long expectedKeys = this.colsPerRow;
|
||||||
|
@ -342,7 +335,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
verifyScan(s, expectedRows, expectedKeys/2);
|
verifyScan(s, expectedRows, expectedKeys/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrefixFilter() throws Exception {
|
void doTestPrefixFilter() throws Exception {
|
||||||
// Grab rows from group one (half of total)
|
// Grab rows from group one (half of total)
|
||||||
long expectedRows = this.numRows / 2;
|
long expectedRows = this.numRows / 2;
|
||||||
long expectedKeys = this.colsPerRow;
|
long expectedKeys = this.colsPerRow;
|
||||||
|
@ -351,8 +344,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
verifyScan(s, expectedRows, expectedKeys);
|
verifyScan(s, expectedRows, expectedKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPageFilter() throws Exception {
|
void doTestPageFilter() throws Exception {
|
||||||
|
|
||||||
// KVs in first 6 rows
|
// KVs in first 6 rows
|
||||||
KeyValue [] expectedKVs = {
|
KeyValue [] expectedKVs = {
|
||||||
// testRowOne-0
|
// testRowOne-0
|
||||||
|
@ -436,8 +428,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
verifyScanFull(s, Arrays.copyOf(expectedKVs, 6));
|
verifyScanFull(s, Arrays.copyOf(expectedKVs, 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInclusiveStopFilter() throws Exception {
|
void doTestInclusiveStopFilter() throws Exception {
|
||||||
|
|
||||||
// Grab rows from group one
|
// Grab rows from group one
|
||||||
|
|
||||||
// If we just use start/stop row, we get total/2 - 1 rows
|
// If we just use start/stop row, we get total/2 - 1 rows
|
||||||
|
@ -470,8 +461,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testQualifierFilter() throws Exception {
|
void doTestQualifierFilter() throws Exception {
|
||||||
|
|
||||||
// Match two keys (one from each family) in half the rows
|
// Match two keys (one from each family) in half the rows
|
||||||
long expectedRows = this.numRows / 2;
|
long expectedRows = this.numRows / 2;
|
||||||
long expectedKeys = 2;
|
long expectedKeys = 2;
|
||||||
|
@ -536,7 +526,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
|
|
||||||
// Match keys not equal to
|
// Match keys not equal to
|
||||||
// Look across rows and fully validate the keys and ordering
|
// Look across rows and fully validate the keys and ordering
|
||||||
// Expect varied numbers of keys, 4 per row in group one, 6 per row in group two
|
// Expect varied numbers of keys, 4 per row in group one, 6 per row in
|
||||||
|
// group two
|
||||||
f = new QualifierFilter(CompareOp.NOT_EQUAL,
|
f = new QualifierFilter(CompareOp.NOT_EQUAL,
|
||||||
new BinaryComparator(QUALIFIERS_ONE[2]));
|
new BinaryComparator(QUALIFIERS_ONE[2]));
|
||||||
s = new Scan();
|
s = new Scan();
|
||||||
|
@ -582,7 +573,6 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
};
|
};
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
|
|
||||||
|
|
||||||
// Test across rows and groups with a regex
|
// Test across rows and groups with a regex
|
||||||
// Filter out "test*-2"
|
// Filter out "test*-2"
|
||||||
// Expect 4 keys per row across both groups
|
// Expect 4 keys per row across both groups
|
||||||
|
@ -624,11 +614,9 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
|
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
|
||||||
};
|
};
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRowFilter() throws Exception {
|
void doTestRowFilter() throws Exception {
|
||||||
|
|
||||||
// Match a single row, all keys
|
// Match a single row, all keys
|
||||||
long expectedRows = 1;
|
long expectedRows = 1;
|
||||||
long expectedKeys = this.colsPerRow;
|
long expectedKeys = this.colsPerRow;
|
||||||
|
@ -743,7 +731,6 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
|
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
|
||||||
};
|
};
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
|
|
||||||
|
|
||||||
// Test across rows and groups with a regex
|
// Test across rows and groups with a regex
|
||||||
// Filter out everything that doesn't match "*-2"
|
// Filter out everything that doesn't match "*-2"
|
||||||
|
@ -770,11 +757,9 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1])
|
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1])
|
||||||
};
|
};
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testValueFilter() throws Exception {
|
void doTestValueFilter() throws Exception {
|
||||||
|
|
||||||
// Match group one rows
|
// Match group one rows
|
||||||
long expectedRows = this.numRows / 2;
|
long expectedRows = this.numRows / 2;
|
||||||
long expectedKeys = this.colsPerRow;
|
long expectedKeys = this.colsPerRow;
|
||||||
|
@ -896,8 +881,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSkipFilter() throws Exception {
|
void doTestSkipFilter() throws Exception {
|
||||||
|
|
||||||
// Test for qualifier regex: "testQualifierOne-2"
|
// Test for qualifier regex: "testQualifierOne-2"
|
||||||
// Should only get rows from second group, and all keys
|
// Should only get rows from second group, and all keys
|
||||||
Filter f = new SkipFilter(new QualifierFilter(CompareOp.NOT_EQUAL,
|
Filter f = new SkipFilter(new QualifierFilter(CompareOp.NOT_EQUAL,
|
||||||
|
@ -931,15 +915,17 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFilterList() throws Exception {
|
void doTestFilterList() throws Exception {
|
||||||
|
|
||||||
// Test getting a single row, single key using Row, Qualifier, and Value
|
// Test getting a single row, single key using Row, Qualifier, and Value
|
||||||
// regular expression and substring filters
|
// regular expression and substring filters
|
||||||
// Use must pass all
|
// Use must pass all
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
List<Filter> filters = new ArrayList<Filter>();
|
||||||
filters.add(new RowFilter(CompareOp.EQUAL, new RegexStringComparator(".+-2")));
|
filters.add(new RowFilter(CompareOp.EQUAL,
|
||||||
filters.add(new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator(".+-2")));
|
new RegexStringComparator(".+-2")));
|
||||||
filters.add(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("One")));
|
filters.add(new QualifierFilter(CompareOp.EQUAL,
|
||||||
|
new RegexStringComparator(".+-2")));
|
||||||
|
filters.add(new ValueFilter(CompareOp.EQUAL,
|
||||||
|
new SubstringComparator("One")));
|
||||||
Filter f = new FilterList(Operator.MUST_PASS_ALL, filters);
|
Filter f = new FilterList(Operator.MUST_PASS_ALL, filters);
|
||||||
Scan s = new Scan();
|
Scan s = new Scan();
|
||||||
s.addFamily(FAMILIES[0]);
|
s.addFamily(FAMILIES[0]);
|
||||||
|
@ -949,19 +935,22 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
};
|
};
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
|
|
||||||
// Test getting everything with a MUST_PASS_ONE filter including row, qf, val
|
// Test getting everything with a MUST_PASS_ONE filter including row, qf,
|
||||||
// regular expression and substring filters
|
// val, regular expression and substring filters
|
||||||
filters.clear();
|
filters.clear();
|
||||||
filters.add(new RowFilter(CompareOp.EQUAL, new RegexStringComparator(".+Two.+")));
|
filters.add(new RowFilter(CompareOp.EQUAL,
|
||||||
filters.add(new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator(".+-2")));
|
new RegexStringComparator(".+Two.+")));
|
||||||
filters.add(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("One")));
|
filters.add(new QualifierFilter(CompareOp.EQUAL,
|
||||||
|
new RegexStringComparator(".+-2")));
|
||||||
|
filters.add(new ValueFilter(CompareOp.EQUAL,
|
||||||
|
new SubstringComparator("One")));
|
||||||
f = new FilterList(Operator.MUST_PASS_ONE, filters);
|
f = new FilterList(Operator.MUST_PASS_ONE, filters);
|
||||||
s = new Scan();
|
s = new Scan();
|
||||||
s.setFilter(f);
|
s.setFilter(f);
|
||||||
verifyScanNoEarlyOut(s, this.numRows, this.colsPerRow);
|
verifyScanNoEarlyOut(s, this.numRows, this.colsPerRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFirstKeyOnlyFilter() throws Exception {
|
void doTestFirstKeyOnlyFilter() throws Exception {
|
||||||
Scan s = new Scan();
|
Scan s = new Scan();
|
||||||
s.setFilter(new FirstKeyOnlyFilter());
|
s.setFilter(new FirstKeyOnlyFilter());
|
||||||
// Expected KVs, the first KV from each of the remaining 6 rows
|
// Expected KVs, the first KV from each of the remaining 6 rows
|
||||||
|
@ -975,4 +964,17 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||||
};
|
};
|
||||||
verifyScanFull(s, kvs);
|
verifyScanFull(s, kvs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testScannersWithFilters() throws Exception {
|
||||||
|
doTestNoFilter();
|
||||||
|
doTestPrefixFilter();
|
||||||
|
doTestPageFilter();
|
||||||
|
doTestInclusiveStopFilter();
|
||||||
|
doTestQualifierFilter();
|
||||||
|
doTestRowFilter();
|
||||||
|
doTestValueFilter();
|
||||||
|
doTestSkipFilter();
|
||||||
|
doTestFilterList();
|
||||||
|
doTestFirstKeyOnlyFilter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,23 +37,19 @@ import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
||||||
private Client client;
|
static String TABLE1 = "TestSchemaResource1";
|
||||||
private JAXBContext context;
|
static String TABLE2 = "TestSchemaResource2";
|
||||||
private HBaseAdmin admin;
|
|
||||||
|
|
||||||
private static String TABLE1 = "TestSchemaResource1";
|
Client client;
|
||||||
private static String TABLE2 = "TestSchemaResource2";
|
JAXBContext context;
|
||||||
|
HBaseAdmin admin;
|
||||||
public TestSchemaResource() throws JAXBException {
|
|
||||||
super();
|
|
||||||
context = JAXBContext.newInstance(
|
|
||||||
ColumnSchemaModel.class,
|
|
||||||
TableSchemaModel.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
context = JAXBContext.newInstance(
|
||||||
|
ColumnSchemaModel.class,
|
||||||
|
TableSchemaModel.class);
|
||||||
admin = new HBaseAdmin(conf);
|
admin = new HBaseAdmin(conf);
|
||||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||||
}
|
}
|
||||||
|
@ -64,19 +60,18 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] toXML(TableSchemaModel model) throws JAXBException {
|
byte[] toXML(TableSchemaModel model) throws JAXBException {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
context.createMarshaller().marshal(model, writer);
|
context.createMarshaller().marshal(model, writer);
|
||||||
return Bytes.toBytes(writer.toString());
|
return Bytes.toBytes(writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private TableSchemaModel fromXML(byte[] content) throws JAXBException {
|
TableSchemaModel fromXML(byte[] content) throws JAXBException {
|
||||||
return (TableSchemaModel) context.createUnmarshaller()
|
return (TableSchemaModel) context.createUnmarshaller()
|
||||||
.unmarshal(new ByteArrayInputStream(content));
|
.unmarshal(new ByteArrayInputStream(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTableCreateAndDeleteXML()
|
void doTestTableCreateAndDeleteXML() throws IOException, JAXBException {
|
||||||
throws IOException, JAXBException {
|
|
||||||
String schemaPath = "/" + TABLE1 + "/schema";
|
String schemaPath = "/" + TABLE1 + "/schema";
|
||||||
TableSchemaModel model;
|
TableSchemaModel model;
|
||||||
Response response;
|
Response response;
|
||||||
|
@ -105,7 +100,7 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
||||||
assertFalse(admin.tableExists(TABLE1));
|
assertFalse(admin.tableExists(TABLE1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
|
void doTestTableCreateAndDeletePB() throws IOException, JAXBException {
|
||||||
String schemaPath = "/" + TABLE2 + "/schema";
|
String schemaPath = "/" + TABLE2 + "/schema";
|
||||||
TableSchemaModel model;
|
TableSchemaModel model;
|
||||||
Response response;
|
Response response;
|
||||||
|
@ -135,4 +130,9 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
||||||
// make sure HBase concurs
|
// make sure HBase concurs
|
||||||
assertFalse(admin.tableExists(TABLE2));
|
assertFalse(admin.tableExists(TABLE2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSchemaResource() throws Exception {
|
||||||
|
doTestTableCreateAndDeleteXML();
|
||||||
|
doTestTableCreateAndDeletePB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,21 +33,17 @@ import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
public class TestStatusResource extends HBaseRESTClusterTestBase {
|
public class TestStatusResource extends HBaseRESTClusterTestBase {
|
||||||
private static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
|
static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
|
||||||
private static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
|
static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
|
||||||
|
|
||||||
private Client client;
|
Client client;
|
||||||
private JAXBContext context;
|
JAXBContext context;
|
||||||
|
|
||||||
public TestStatusResource() throws JAXBException {
|
|
||||||
super();
|
|
||||||
context = JAXBContext.newInstance(
|
|
||||||
StorageClusterStatusModel.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
context = JAXBContext.newInstance(
|
||||||
|
StorageClusterStatusModel.class);
|
||||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +53,7 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate(StorageClusterStatusModel model) {
|
void validate(StorageClusterStatusModel model) {
|
||||||
assertNotNull(model);
|
assertNotNull(model);
|
||||||
assertTrue(model.getRegions() >= 2);
|
assertTrue(model.getRegions() >= 2);
|
||||||
assertTrue(model.getRequests() >= 0);
|
assertTrue(model.getRequests() >= 0);
|
||||||
|
@ -84,7 +80,7 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
|
||||||
assertTrue(foundMeta);
|
assertTrue(foundMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetClusterStatusXML() throws IOException, JAXBException {
|
void doTestGetClusterStatusXML() throws IOException, JAXBException {
|
||||||
Response response = client.get("/status/cluster", MIMETYPE_XML);
|
Response response = client.get("/status/cluster", MIMETYPE_XML);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
StorageClusterStatusModel model = (StorageClusterStatusModel)
|
StorageClusterStatusModel model = (StorageClusterStatusModel)
|
||||||
|
@ -93,11 +89,16 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
|
||||||
validate(model);
|
validate(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetClusterStatusPB() throws IOException {
|
void doTestGetClusterStatusPB() throws IOException {
|
||||||
Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF);
|
Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
StorageClusterStatusModel model = new StorageClusterStatusModel();
|
StorageClusterStatusModel model = new StorageClusterStatusModel();
|
||||||
model.getObjectFromMessage(response.getBody());
|
model.getObjectFromMessage(response.getBody());
|
||||||
validate(model);
|
validate(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testStatusResource() throws Exception {
|
||||||
|
doTestGetClusterStatusXML();
|
||||||
|
doTestGetClusterStatusPB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,23 @@ package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
|
import org.apache.hadoop.hbase.HRegionInfo;
|
||||||
|
import org.apache.hadoop.hbase.HServerAddress;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
import org.apache.hadoop.hbase.KeyValue;
|
||||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||||
import org.apache.hadoop.hbase.client.HTable;
|
import org.apache.hadoop.hbase.client.HTable;
|
||||||
|
import org.apache.hadoop.hbase.client.Put;
|
||||||
import org.apache.hadoop.hbase.rest.client.Client;
|
import org.apache.hadoop.hbase.rest.client.Client;
|
||||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||||
import org.apache.hadoop.hbase.rest.client.Response;
|
import org.apache.hadoop.hbase.rest.client.Response;
|
||||||
|
@ -40,37 +47,68 @@ import org.apache.hadoop.hbase.rest.model.TableInfoModel;
|
||||||
import org.apache.hadoop.hbase.rest.model.TableListModel;
|
import org.apache.hadoop.hbase.rest.model.TableListModel;
|
||||||
import org.apache.hadoop.hbase.rest.model.TableRegionModel;
|
import org.apache.hadoop.hbase.rest.model.TableRegionModel;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
import org.apache.hadoop.util.StringUtils;
|
||||||
|
|
||||||
public class TestTableResource extends HBaseRESTClusterTestBase {
|
public class TestTableResource extends HBaseRESTClusterTestBase {
|
||||||
private static String TABLE = "TestTableResource";
|
static final Log LOG = LogFactory.getLog(TestTableResource.class);
|
||||||
private static String COLUMN = "test:";
|
|
||||||
|
|
||||||
private Client client;
|
static String TABLE = "TestTableResource";
|
||||||
private JAXBContext context;
|
static String COLUMN = "test:";
|
||||||
private HBaseAdmin admin;
|
static Map<HRegionInfo,HServerAddress> regionMap;
|
||||||
|
|
||||||
public TestTableResource() throws JAXBException {
|
Client client;
|
||||||
super();
|
JAXBContext context;
|
||||||
|
HBaseAdmin admin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
context = JAXBContext.newInstance(
|
context = JAXBContext.newInstance(
|
||||||
TableModel.class,
|
TableModel.class,
|
||||||
TableInfoModel.class,
|
TableInfoModel.class,
|
||||||
TableListModel.class,
|
TableListModel.class,
|
||||||
TableRegionModel.class);
|
TableRegionModel.class);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||||
admin = new HBaseAdmin(conf);
|
admin = new HBaseAdmin(conf);
|
||||||
if (admin.tableExists(TABLE)) {
|
if (admin.tableExists(TABLE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||||
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
|
htd.addFamily(new HColumnDescriptor(COLUMN));
|
||||||
Bytes.toBytes(COLUMN))[0]));
|
|
||||||
admin.createTable(htd);
|
admin.createTable(htd);
|
||||||
new HTable(conf, TABLE);
|
HTable table = new HTable(conf, TABLE);
|
||||||
|
byte[] k = new byte[3];
|
||||||
|
byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(COLUMN));
|
||||||
|
for (byte b1 = 'a'; b1 < 'z'; b1++) {
|
||||||
|
for (byte b2 = 'a'; b2 < 'z'; b2++) {
|
||||||
|
for (byte b3 = 'a'; b3 < 'z'; b3++) {
|
||||||
|
k[0] = b1;
|
||||||
|
k[1] = b2;
|
||||||
|
k[2] = b3;
|
||||||
|
Put put = new Put(k);
|
||||||
|
put.add(famAndQf[0], famAndQf[1], k);
|
||||||
|
table.put(put);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
table.flushCommits();
|
||||||
|
// get the initial layout (should just be one region)
|
||||||
|
Map<HRegionInfo,HServerAddress> m = table.getRegionsInfo();
|
||||||
|
assertEquals(m.size(), 1);
|
||||||
|
// tell the master to split the table
|
||||||
|
admin.split(TABLE);
|
||||||
|
// give some time for the split to happen
|
||||||
|
try {
|
||||||
|
Thread.sleep(15 * 1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOG.warn(StringUtils.stringifyException(e));
|
||||||
|
}
|
||||||
|
// check again
|
||||||
|
m = table.getRegionsInfo();
|
||||||
|
// should have two regions now
|
||||||
|
assertEquals(m.size(), 2);
|
||||||
|
regionMap = m;
|
||||||
|
LOG.info("regions: " + regionMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,7 +117,7 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkTableList(TableListModel model) {
|
void checkTableList(TableListModel model) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
Iterator<TableModel> tables = model.getTables().iterator();
|
Iterator<TableModel> tables = model.getTables().iterator();
|
||||||
assertTrue(tables.hasNext());
|
assertTrue(tables.hasNext());
|
||||||
|
@ -93,12 +131,12 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTableListText() throws IOException {
|
void doTestTableListText() throws IOException {
|
||||||
Response response = client.get("/", MIMETYPE_TEXT);
|
Response response = client.get("/", MIMETYPE_TEXT);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTableListXML() throws IOException, JAXBException {
|
void doTestTableListXML() throws IOException, JAXBException {
|
||||||
Response response = client.get("/", MIMETYPE_XML);
|
Response response = client.get("/", MIMETYPE_XML);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
TableListModel model = (TableListModel)
|
TableListModel model = (TableListModel)
|
||||||
|
@ -107,16 +145,82 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
||||||
checkTableList(model);
|
checkTableList(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTableListJSON() throws IOException {
|
void doTestTableListJSON() throws IOException {
|
||||||
Response response = client.get("/", MIMETYPE_JSON);
|
Response response = client.get("/", MIMETYPE_JSON);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTableListPB() throws IOException, JAXBException {
|
void doTestTableListPB() throws IOException, JAXBException {
|
||||||
Response response = client.get("/", MIMETYPE_PROTOBUF);
|
Response response = client.get("/", MIMETYPE_PROTOBUF);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(response.getCode(), 200);
|
||||||
TableListModel model = new TableListModel();
|
TableListModel model = new TableListModel();
|
||||||
model.getObjectFromMessage(response.getBody());
|
model.getObjectFromMessage(response.getBody());
|
||||||
checkTableList(model);
|
checkTableList(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkTableInfo(TableInfoModel model) {
|
||||||
|
assertEquals(model.getName(), TABLE);
|
||||||
|
Iterator<TableRegionModel> regions = model.getRegions().iterator();
|
||||||
|
assertTrue(regions.hasNext());
|
||||||
|
while (regions.hasNext()) {
|
||||||
|
TableRegionModel region = regions.next();
|
||||||
|
boolean found = false;
|
||||||
|
for (Map.Entry<HRegionInfo,HServerAddress> e: regionMap.entrySet()) {
|
||||||
|
HRegionInfo hri = e.getKey();
|
||||||
|
if (hri.getRegionNameAsString().equals(region.getName())) {
|
||||||
|
found = true;
|
||||||
|
byte[] startKey = hri.getStartKey();
|
||||||
|
byte[] endKey = hri.getEndKey();
|
||||||
|
InetSocketAddress sa = e.getValue().getInetSocketAddress();
|
||||||
|
String location = sa.getHostName() + ":" +
|
||||||
|
Integer.valueOf(sa.getPort());
|
||||||
|
assertEquals(hri.getRegionId(), region.getId());
|
||||||
|
assertTrue(Bytes.equals(startKey, region.getStartKey()));
|
||||||
|
assertTrue(Bytes.equals(endKey, region.getEndKey()));
|
||||||
|
assertEquals(location, region.getLocation());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(found);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void doTestTableInfoText() throws IOException {
|
||||||
|
Response response = client.get("/" + TABLE + "/regions", MIMETYPE_TEXT);
|
||||||
|
assertEquals(response.getCode(), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doTestTableInfoXML() throws IOException, JAXBException {
|
||||||
|
Response response = client.get("/" + TABLE + "/regions", MIMETYPE_XML);
|
||||||
|
assertEquals(response.getCode(), 200);
|
||||||
|
TableInfoModel model = (TableInfoModel)
|
||||||
|
context.createUnmarshaller()
|
||||||
|
.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||||
|
checkTableInfo(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doTestTableInfoJSON() throws IOException {
|
||||||
|
Response response = client.get("/" + TABLE + "/regions", MIMETYPE_JSON);
|
||||||
|
assertEquals(response.getCode(), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doTestTableInfoPB() throws IOException, JAXBException {
|
||||||
|
Response response =
|
||||||
|
client.get("/" + TABLE + "/regions", MIMETYPE_PROTOBUF);
|
||||||
|
assertEquals(response.getCode(), 200);
|
||||||
|
TableInfoModel model = new TableInfoModel();
|
||||||
|
model.getObjectFromMessage(response.getBody());
|
||||||
|
checkTableInfo(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTableResource() throws Exception {
|
||||||
|
doTestTableListText();
|
||||||
|
doTestTableListXML();
|
||||||
|
doTestTableListJSON();
|
||||||
|
doTestTableListPB();
|
||||||
|
doTestTableInfoText();
|
||||||
|
doTestTableInfoXML();
|
||||||
|
doTestTableInfoJSON();
|
||||||
|
doTestTableInfoPB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.rest.client.Client;
|
import org.apache.hadoop.hbase.rest.client.Client;
|
||||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||||
import org.apache.hadoop.hbase.rest.client.Response;
|
import org.apache.hadoop.hbase.rest.client.Response;
|
||||||
|
@ -39,17 +38,16 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||||
|
|
||||||
public class TestVersionResource extends HBaseRESTClusterTestBase {
|
public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
private static final Log LOG =
|
static final Log LOG = LogFactory.getLog(TestVersionResource.class);
|
||||||
LogFactory.getLog(TestVersionResource.class);
|
|
||||||
|
|
||||||
private Client client;
|
Client client;
|
||||||
private JAXBContext context;
|
JAXBContext context;
|
||||||
|
|
||||||
public TestVersionResource() throws JAXBException {
|
public TestVersionResource() throws JAXBException {
|
||||||
super();
|
super();
|
||||||
context = JAXBContext.newInstance(
|
context = JAXBContext.newInstance(
|
||||||
VersionModel.class,
|
VersionModel.class,
|
||||||
StorageClusterVersionModel.class);
|
StorageClusterVersionModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +62,7 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validate(VersionModel model) {
|
void validate(VersionModel model) {
|
||||||
assertNotNull(model);
|
assertNotNull(model);
|
||||||
assertNotNull(model.getRESTVersion());
|
assertNotNull(model.getRESTVersion());
|
||||||
assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
|
assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
|
||||||
|
@ -85,7 +83,7 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
.getImplementationVersion());
|
.getImplementationVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStargateVersionText() throws IOException {
|
void doTestGetStargateVersionText() throws IOException {
|
||||||
Response response = client.get("/version", MIMETYPE_TEXT);
|
Response response = client.get("/version", MIMETYPE_TEXT);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
String body = Bytes.toString(response.getBody());
|
String body = Bytes.toString(response.getBody());
|
||||||
|
@ -101,7 +99,7 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
.getImplementationVersion()));
|
.getImplementationVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStargateVersionXML() throws IOException, JAXBException {
|
void doTestGetStargateVersionXML() throws IOException, JAXBException {
|
||||||
Response response = client.get("/version", MIMETYPE_XML);
|
Response response = client.get("/version", MIMETYPE_XML);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
VersionModel model = (VersionModel)
|
VersionModel model = (VersionModel)
|
||||||
|
@ -111,12 +109,12 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
LOG.info("success retrieving Stargate version as XML");
|
LOG.info("success retrieving Stargate version as XML");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStargateVersionJSON() throws IOException {
|
void doTestGetStargateVersionJSON() throws IOException {
|
||||||
Response response = client.get("/version", MIMETYPE_JSON);
|
Response response = client.get("/version", MIMETYPE_JSON);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStargateVersionPB() throws IOException {
|
void doTestGetStargateVersionPB() throws IOException {
|
||||||
Response response = client.get("/version", MIMETYPE_PROTOBUF);
|
Response response = client.get("/version", MIMETYPE_PROTOBUF);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
VersionModel model = new VersionModel();
|
VersionModel model = new VersionModel();
|
||||||
|
@ -125,12 +123,12 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
LOG.info("success retrieving Stargate version as protobuf");
|
LOG.info("success retrieving Stargate version as protobuf");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStorageClusterVersionText() throws IOException {
|
void doTestGetStorageClusterVersionText() throws IOException {
|
||||||
Response response = client.get("/version/cluster", MIMETYPE_TEXT);
|
Response response = client.get("/version/cluster", MIMETYPE_TEXT);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStorageClusterVersionXML() throws IOException,
|
void doTestGetStorageClusterVersionXML() throws IOException,
|
||||||
JAXBException {
|
JAXBException {
|
||||||
Response response = client.get("/version/cluster", MIMETYPE_XML);
|
Response response = client.get("/version/cluster", MIMETYPE_XML);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
|
@ -143,8 +141,18 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||||
LOG.info("success retrieving storage cluster version as XML");
|
LOG.info("success retrieving storage cluster version as XML");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetStorageClusterVersionJSON() throws IOException {
|
void doTestGetStorageClusterVersionJSON() throws IOException {
|
||||||
Response response = client.get("/version/cluster", MIMETYPE_JSON);
|
Response response = client.get("/version/cluster", MIMETYPE_JSON);
|
||||||
assertTrue(response.getCode() == 200);
|
assertTrue(response.getCode() == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testVersionResource() throws Exception {
|
||||||
|
doTestGetStargateVersionText();
|
||||||
|
doTestGetStargateVersionXML();
|
||||||
|
doTestGetStargateVersionJSON();
|
||||||
|
doTestGetStargateVersionPB();
|
||||||
|
doTestGetStorageClusterVersionText();
|
||||||
|
doTestGetStorageClusterVersionXML();
|
||||||
|
doTestGetStorageClusterVersionJSON();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue