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:
Andrew Kyle Purtell 2010-06-01 22:10:25 +00:00
parent 8e870fa13e
commit 9abbe3075a
8 changed files with 339 additions and 214 deletions

View File

@ -656,6 +656,7 @@ Release 0.21.0 - Unreleased
HBASE-2632 Shell should autodetect terminal width
HBASE-2636 Upgrade Jetty to 6.1.24
HBASE-2437 Refactor HLog splitLog (Cosmin Lehene via Stack)
HBASE-2638 Speed up REST tests
NEW FEATURES
HBASE-1961 HBase EC2 scripts

View File

@ -34,7 +34,6 @@ import org.apache.commons.httpclient.Header;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.rest.client.Client;
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;
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";
private static final String COLUMN_1 = "a:";
private static final String COLUMN_2 = "b:";
private static final String ROW_1 = "testrow1";
private static final String VALUE_1 = "testvalue1";
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";
Client client;
JAXBContext context;
Marshaller marshaller;
Unmarshaller unmarshaller;
HBaseAdmin admin;
private Client client;
private JAXBContext context;
private Marshaller marshaller;
private Unmarshaller unmarshaller;
private HBaseAdmin admin;
public TestRowResource() throws JAXBException {
super();
@Override
protected void setUp() throws Exception {
super.setUp();
context = JAXBContext.newInstance(
CellModel.class,
CellSetModel.class,
RowModel.class);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
}
@Override
protected void setUp() throws Exception {
super.setUp();
client = new Client(new Cluster().add("localhost", testServletPort));
admin = new HBaseAdmin(conf);
if (admin.tableExists(TABLE)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
Bytes.toBytes(COLUMN_1))[0]));
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
Bytes.toBytes(COLUMN_2))[0]));
htd.addFamily(new HColumnDescriptor(COLUMN_1));
htd.addFamily(new HColumnDescriptor(COLUMN_2));
admin.createTable(htd);
}
@ -96,7 +88,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
super.tearDown();
}
private Response deleteRow(String table, String row) throws IOException {
Response deleteRow(String table, String row) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -107,7 +99,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
return response;
}
private Response deleteValue(String table, String row, String column)
Response deleteValue(String table, String row, String column)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@ -121,7 +113,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
return response;
}
private Response getValueXML(String table, String row, String column)
Response getValueXML(String table, String row, String column)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@ -134,7 +126,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
return response;
}
private Response getValuePB(String table, String row, String column)
Response getValuePB(String table, String row, String column)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@ -147,8 +139,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
return response;
}
private Response putValueXML(String table, String row, String column,
String value) throws IOException, JAXBException {
Response putValueXML(String table, String row, String column, String value)
throws IOException, JAXBException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -157,7 +149,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
path.append('/');
path.append(column);
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.addRow(rowModel);
StringWriter writer = new StringWriter();
@ -168,8 +161,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
return response;
}
private void checkValueXML(String table, String row, String column,
String value) throws IOException, JAXBException {
void checkValueXML(String table, String row, String column, String value)
throws IOException, JAXBException {
Response response = getValueXML(table, row, column);
assertEquals(response.getCode(), 200);
CellSetModel cellSet = (CellSetModel)
@ -180,8 +173,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(Bytes.toString(cell.getValue()), value);
}
private Response putValuePB(String table, String row, String column,
String value) throws IOException {
Response putValuePB(String table, String row, String column, String value)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -190,7 +183,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
path.append('/');
path.append(column);
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.addRow(rowModel);
Response response = client.put(path.toString(), MIMETYPE_PROTOBUF,
@ -199,8 +193,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
return response;
}
private void checkValuePB(String table, String row, String column,
String value) throws IOException {
void checkValuePB(String table, String row, String column, String value)
throws IOException {
Response response = getValuePB(table, row, column);
assertEquals(response.getCode(), 200);
CellSetModel cellSet = new CellSetModel();
@ -211,7 +205,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(Bytes.toString(cell.getValue()), value);
}
public void testDelete() throws IOException, JAXBException {
void doTestDelete() throws IOException, JAXBException {
Response response;
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
@ -235,7 +229,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 404);
}
public void testSingleCellGetPutXML() throws IOException, JAXBException {
void doTestSingleCellGetPutXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
@ -250,7 +244,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testSingleCellGetPutPB() throws IOException, JAXBException {
void doTestSingleCellGetPutPB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
@ -269,7 +263,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testSingleCellGetPutBinary() throws IOException {
void doTestSingleCellGetPutBinary() throws IOException {
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
final byte[] body = Bytes.toBytes(VALUE_3);
Response response = client.put(path, MIMETYPE_BINARY, body);
@ -292,7 +286,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testSingleCellGetJSON() throws IOException, JAXBException {
void doTestSingleCellGetJSON() throws IOException, JAXBException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, MIMETYPE_BINARY,
Bytes.toBytes(VALUE_4));
@ -304,7 +298,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testURLEncodedKey() throws IOException, JAXBException {
void doTestURLEncodedKey() throws IOException, JAXBException {
String encodedKey = URLEncoder.encode("http://www.google.com/",
HConstants.UTF8_ENCODING);
Response response;
@ -316,17 +310,21 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
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
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)));
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)));
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();
marshaller.marshal(cellSetModel, writer);
@ -350,17 +348,21 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testMultiCellGetPutPB() throws IOException {
void doTestMultiCellGetPutPB() throws IOException {
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
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)));
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)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
Bytes.toBytes(VALUE_3)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
Bytes.toBytes(VALUE_4)));
cellSetModel.addRow(rowModel);
Response response = client.put(path, MIMETYPE_PROTOBUF,
cellSetModel.createProtobufOutput());
@ -381,4 +383,15 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
}
public void testRowResource() throws Exception {
doTestDelete();
doTestSingleCellGetPutXML();
doTestSingleCellGetPutPB();
doTestSingleCellGetPutBinary();
doTestSingleCellGetJSON();
doTestURLEncodedKey();
doTestMultiCellGetPutXML();
doTestMultiCellGetPutPB();
}
}

View File

@ -48,21 +48,20 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel;
import org.apache.hadoop.hbase.util.Bytes;
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";
private static final String COLUMN_1 = "a:";
private static final String COLUMN_2 = "b:";
static int expectedRows1;
static int expectedRows2;
private static int expectedRows1;
private static int expectedRows2;
Client client;
JAXBContext context;
Marshaller marshaller;
Unmarshaller unmarshaller;
HBaseAdmin admin;
private Client client;
private JAXBContext context;
private Marshaller marshaller;
private Unmarshaller unmarshaller;
private HBaseAdmin admin;
private int insertData(String tableName, String column, double prob)
int insertData(String tableName, String column, double prob)
throws IOException {
Random rng = new Random();
int count = 0;
@ -77,11 +76,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
k[1] = b2;
k[2] = b3;
Put put = new Put(k);
if(famAndQf.length == 1) {
put.add(famAndQf[0], new byte[0], k);
} else {
put.add(famAndQf[0], famAndQf[1], k);
}
put.add(famAndQf[0], famAndQf[1], k);
table.put(put);
count++;
}
@ -92,8 +87,9 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
return count;
}
public TestScannerResource() throws JAXBException {
super();
@Override
protected void setUp() throws Exception {
super.setUp();
context = JAXBContext.newInstance(
CellModel.class,
CellSetModel.class,
@ -101,21 +97,14 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
ScannerModel.class);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
}
@Override
protected void setUp() throws Exception {
super.setUp();
client = new Client(new Cluster().add("localhost", testServletPort));
admin = new HBaseAdmin(conf);
if (admin.tableExists(TABLE)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
Bytes.toBytes(COLUMN_1))[0]));
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
Bytes.toBytes(COLUMN_2))[0]));
htd.addFamily(new HColumnDescriptor(COLUMN_1));
htd.addFamily(new HColumnDescriptor(COLUMN_2));
admin.createTable(htd);
expectedRows1 = insertData(TABLE, COLUMN_1, 1.0);
expectedRows2 = insertData(TABLE, COLUMN_2, 0.5);
@ -127,7 +116,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
super.tearDown();
}
private int countCellSet(CellSetModel model) {
int countCellSet(CellSetModel model) {
int count = 0;
Iterator<RowModel> rows = model.getRows().iterator();
while (rows.hasNext()) {
@ -141,7 +130,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
return count;
}
public void testSimpleScannerXML() throws IOException, JAXBException {
void doTestSimpleScannerXML() throws IOException, JAXBException {
final int BATCH_SIZE = 5;
// new scanner
ScannerModel model = new ScannerModel();
@ -169,7 +158,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testSimpleScannerPB() throws IOException {
void doTestSimpleScannerPB() throws IOException {
final int BATCH_SIZE = 10;
// new scanner
ScannerModel model = new ScannerModel();
@ -194,7 +183,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
public void testSimpleScannerBinary() throws IOException {
void doTestSimpleScannerBinary() throws IOException {
// new scanner
ScannerModel model = new ScannerModel();
model.setBatch(1);
@ -231,7 +220,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
assertEquals(response.getCode(), 200);
}
private int fullTableScan(ScannerModel model) throws IOException {
int fullTableScan(ScannerModel model) throws IOException {
model.setBatch(100);
Response response = client.put("/" + TABLE + "/scanner",
MIMETYPE_PROTOBUF, model.createProtobufOutput());
@ -264,7 +253,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
return count;
}
public void testFullTableScan() throws IOException {
void doTestFullTableScan() throws IOException {
ScannerModel model = new ScannerModel();
model.addColumn(Bytes.toBytes(COLUMN_1));
assertEquals(fullTableScan(model), expectedRows1);
@ -273,4 +262,11 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
model.addColumn(Bytes.toBytes(COLUMN_2));
assertEquals(fullTableScan(model), expectedRows2);
}
public void testScannerResource() throws Exception {
doTestSimpleScannerXML();
doTestSimpleScannerPB();
doTestSimpleScannerBinary();
doTestFullTableScan();
}
}

View File

@ -28,7 +28,6 @@ import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
@ -69,47 +68,46 @@ import org.apache.hadoop.hbase.util.Bytes;
public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
private static final Log LOG =
LogFactory.getLog(TestScannersWithFilters.class);
static final Log LOG = LogFactory.getLog(TestScannersWithFilters.class);
private Client client;
private JAXBContext context;
private Marshaller marshaller;
private Unmarshaller unmarshaller;
private static final byte [][] ROWS_ONE = {
static final byte [][] ROWS_ONE = {
Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-1"),
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-2"), Bytes.toBytes("testRowTwo-3")
};
private static final byte [][] FAMILIES = {
static final byte [][] FAMILIES = {
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-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-2"), Bytes.toBytes("testQualifierTwo-3")
};
private static final byte [][] VALUES = {
static final byte [][] VALUES = {
Bytes.toBytes("testValueOne"), Bytes.toBytes("testValueTwo")
};
private long numRows = ROWS_ONE.length + ROWS_TWO.length;
private long colsPerRow = FAMILIES.length * QUALIFIERS_ONE.length;
Client client;
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 {
super();
@Override
protected void setUp() throws Exception {
super.setUp();
context = JAXBContext.newInstance(
CellModel.class,
CellSetModel.class,
@ -117,11 +115,6 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
ScannerModel.class);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
}
@Override
protected void setUp() throws Exception {
super.setUp();
client = new Client(new Cluster().add("localhost", testServletPort));
HBaseAdmin admin = new HBaseAdmin(conf);
if (!admin.tableExists(getName())) {
@ -200,7 +193,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
super.tearDown();
}
private void verifyScan(Scan s, long expectedRows, long expectedKeys)
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
@ -234,7 +227,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
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);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
@ -286,7 +279,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
kvs.length, idx);
}
private void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys)
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
@ -327,7 +320,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
" rows", expectedRows, j);
}
public void testNoFilter() throws Exception {
void doTestNoFilter() throws Exception {
// No filter
long expectedRows = this.numRows;
long expectedKeys = this.colsPerRow;
@ -342,7 +335,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
verifyScan(s, expectedRows, expectedKeys/2);
}
public void testPrefixFilter() throws Exception {
void doTestPrefixFilter() throws Exception {
// Grab rows from group one (half of total)
long expectedRows = this.numRows / 2;
long expectedKeys = this.colsPerRow;
@ -351,8 +344,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
verifyScan(s, expectedRows, expectedKeys);
}
public void testPageFilter() throws Exception {
void doTestPageFilter() throws Exception {
// KVs in first 6 rows
KeyValue [] expectedKVs = {
// testRowOne-0
@ -436,8 +428,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
verifyScanFull(s, Arrays.copyOf(expectedKVs, 6));
}
public void testInclusiveStopFilter() throws Exception {
void doTestInclusiveStopFilter() throws Exception {
// Grab rows from group one
// 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
long expectedRows = this.numRows / 2;
long expectedKeys = 2;
@ -536,7 +526,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
// Match keys not equal to
// 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,
new BinaryComparator(QUALIFIERS_ONE[2]));
s = new Scan();
@ -582,7 +573,6 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
};
verifyScanFull(s, kvs);
// Test across rows and groups with a regex
// Filter out "test*-2"
// 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]),
};
verifyScanFull(s, kvs);
}
public void testRowFilter() throws Exception {
void doTestRowFilter() throws Exception {
// Match a single row, all keys
long expectedRows = 1;
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]),
};
verifyScanFull(s, kvs);
// Test across rows and groups with a regex
// 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])
};
verifyScanFull(s, kvs);
}
public void testValueFilter() throws Exception {
void doTestValueFilter() throws Exception {
// Match group one rows
long expectedRows = this.numRows / 2;
long expectedKeys = this.colsPerRow;
@ -896,8 +881,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
verifyScanFull(s, kvs);
}
public void testSkipFilter() throws Exception {
void doTestSkipFilter() throws Exception {
// Test for qualifier regex: "testQualifierOne-2"
// Should only get rows from second group, and all keys
Filter f = new SkipFilter(new QualifierFilter(CompareOp.NOT_EQUAL,
@ -931,15 +915,17 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
verifyScanFull(s, kvs);
}
public void testFilterList() throws Exception {
void doTestFilterList() throws Exception {
// Test getting a single row, single key using Row, Qualifier, and Value
// regular expression and substring filters
// Use must pass all
List<Filter> filters = new ArrayList<Filter>();
filters.add(new RowFilter(CompareOp.EQUAL, new RegexStringComparator(".+-2")));
filters.add(new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator(".+-2")));
filters.add(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("One")));
filters.add(new RowFilter(CompareOp.EQUAL,
new RegexStringComparator(".+-2")));
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);
Scan s = new Scan();
s.addFamily(FAMILIES[0]);
@ -949,19 +935,22 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
};
verifyScanFull(s, kvs);
// Test getting everything with a MUST_PASS_ONE filter including row, qf, val
// regular expression and substring filters
// Test getting everything with a MUST_PASS_ONE filter including row, qf,
// val, regular expression and substring filters
filters.clear();
filters.add(new RowFilter(CompareOp.EQUAL, new RegexStringComparator(".+Two.+")));
filters.add(new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator(".+-2")));
filters.add(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("One")));
filters.add(new RowFilter(CompareOp.EQUAL,
new RegexStringComparator(".+Two.+")));
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);
s = new Scan();
s.setFilter(f);
verifyScanNoEarlyOut(s, this.numRows, this.colsPerRow);
}
public void testFirstKeyOnlyFilter() throws Exception {
void doTestFirstKeyOnlyFilter() throws Exception {
Scan s = new Scan();
s.setFilter(new FirstKeyOnlyFilter());
// Expected KVs, the first KV from each of the remaining 6 rows
@ -975,4 +964,17 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
};
verifyScanFull(s, kvs);
}
public void testScannersWithFilters() throws Exception {
doTestNoFilter();
doTestPrefixFilter();
doTestPageFilter();
doTestInclusiveStopFilter();
doTestQualifierFilter();
doTestRowFilter();
doTestValueFilter();
doTestSkipFilter();
doTestFilterList();
doTestFirstKeyOnlyFilter();
}
}

View File

@ -37,23 +37,19 @@ import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
import org.apache.hadoop.hbase.util.Bytes;
public class TestSchemaResource extends HBaseRESTClusterTestBase {
private Client client;
private JAXBContext context;
private HBaseAdmin admin;
static String TABLE1 = "TestSchemaResource1";
static String TABLE2 = "TestSchemaResource2";
private static String TABLE1 = "TestSchemaResource1";
private static String TABLE2 = "TestSchemaResource2";
public TestSchemaResource() throws JAXBException {
super();
context = JAXBContext.newInstance(
ColumnSchemaModel.class,
TableSchemaModel.class);
}
Client client;
JAXBContext context;
HBaseAdmin admin;
@Override
protected void setUp() throws Exception {
super.setUp();
context = JAXBContext.newInstance(
ColumnSchemaModel.class,
TableSchemaModel.class);
admin = new HBaseAdmin(conf);
client = new Client(new Cluster().add("localhost", testServletPort));
}
@ -64,19 +60,18 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
super.tearDown();
}
private byte[] toXML(TableSchemaModel model) throws JAXBException {
byte[] toXML(TableSchemaModel model) throws JAXBException {
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(model, writer);
return Bytes.toBytes(writer.toString());
}
private TableSchemaModel fromXML(byte[] content) throws JAXBException {
TableSchemaModel fromXML(byte[] content) throws JAXBException {
return (TableSchemaModel) context.createUnmarshaller()
.unmarshal(new ByteArrayInputStream(content));
}
public void testTableCreateAndDeleteXML()
throws IOException, JAXBException {
void doTestTableCreateAndDeleteXML() throws IOException, JAXBException {
String schemaPath = "/" + TABLE1 + "/schema";
TableSchemaModel model;
Response response;
@ -105,7 +100,7 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
assertFalse(admin.tableExists(TABLE1));
}
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
void doTestTableCreateAndDeletePB() throws IOException, JAXBException {
String schemaPath = "/" + TABLE2 + "/schema";
TableSchemaModel model;
Response response;
@ -135,4 +130,9 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
// make sure HBase concurs
assertFalse(admin.tableExists(TABLE2));
}
public void testSchemaResource() throws Exception {
doTestTableCreateAndDeleteXML();
doTestTableCreateAndDeletePB();
}
}

View File

@ -33,21 +33,17 @@ import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
import org.apache.hadoop.hbase.util.Bytes;
public class TestStatusResource extends HBaseRESTClusterTestBase {
private static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
private static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
private Client client;
private JAXBContext context;
Client client;
JAXBContext context;
public TestStatusResource() throws JAXBException {
super();
context = JAXBContext.newInstance(
StorageClusterStatusModel.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
context = JAXBContext.newInstance(
StorageClusterStatusModel.class);
client = new Client(new Cluster().add("localhost", testServletPort));
}
@ -57,7 +53,7 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
super.tearDown();
}
private void validate(StorageClusterStatusModel model) {
void validate(StorageClusterStatusModel model) {
assertNotNull(model);
assertTrue(model.getRegions() >= 2);
assertTrue(model.getRequests() >= 0);
@ -84,7 +80,7 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
assertTrue(foundMeta);
}
public void testGetClusterStatusXML() throws IOException, JAXBException {
void doTestGetClusterStatusXML() throws IOException, JAXBException {
Response response = client.get("/status/cluster", MIMETYPE_XML);
assertEquals(response.getCode(), 200);
StorageClusterStatusModel model = (StorageClusterStatusModel)
@ -93,11 +89,16 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
validate(model);
}
public void testGetClusterStatusPB() throws IOException {
void doTestGetClusterStatusPB() throws IOException {
Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());
validate(model);
}
public void testStatusResource() throws Exception {
doTestGetClusterStatusXML();
doTestGetClusterStatusPB();
}
}

View File

@ -22,16 +22,23 @@ package org.apache.hadoop.hbase.rest;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Iterator;
import java.util.Map;
import javax.xml.bind.JAXBContext;
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.HRegionInfo;
import org.apache.hadoop.hbase.HServerAddress;
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.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.rest.client.Client;
import org.apache.hadoop.hbase.rest.client.Cluster;
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.TableRegionModel;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.StringUtils;
public class TestTableResource extends HBaseRESTClusterTestBase {
private static String TABLE = "TestTableResource";
private static String COLUMN = "test:";
static final Log LOG = LogFactory.getLog(TestTableResource.class);
private Client client;
private JAXBContext context;
private HBaseAdmin admin;
static String TABLE = "TestTableResource";
static String COLUMN = "test:";
static Map<HRegionInfo,HServerAddress> regionMap;
public TestTableResource() throws JAXBException {
super();
Client client;
JAXBContext context;
HBaseAdmin admin;
@Override
protected void setUp() throws Exception {
super.setUp();
context = JAXBContext.newInstance(
TableModel.class,
TableInfoModel.class,
TableListModel.class,
TableRegionModel.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
client = new Client(new Cluster().add("localhost", testServletPort));
admin = new HBaseAdmin(conf);
if (admin.tableExists(TABLE)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
Bytes.toBytes(COLUMN))[0]));
htd.addFamily(new HColumnDescriptor(COLUMN));
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
@ -79,7 +117,7 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
super.tearDown();
}
private void checkTableList(TableListModel model) {
void checkTableList(TableListModel model) {
boolean found = false;
Iterator<TableModel> tables = model.getTables().iterator();
assertTrue(tables.hasNext());
@ -93,12 +131,12 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
assertTrue(found);
}
public void testTableListText() throws IOException {
void doTestTableListText() throws IOException {
Response response = client.get("/", MIMETYPE_TEXT);
assertEquals(response.getCode(), 200);
}
public void testTableListXML() throws IOException, JAXBException {
void doTestTableListXML() throws IOException, JAXBException {
Response response = client.get("/", MIMETYPE_XML);
assertEquals(response.getCode(), 200);
TableListModel model = (TableListModel)
@ -107,16 +145,82 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
checkTableList(model);
}
public void testTableListJSON() throws IOException {
void doTestTableListJSON() throws IOException {
Response response = client.get("/", MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
}
public void testTableListPB() throws IOException, JAXBException {
void doTestTableListPB() throws IOException, JAXBException {
Response response = client.get("/", MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
TableListModel model = new TableListModel();
model.getObjectFromMessage(response.getBody());
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();
}
}

View File

@ -28,7 +28,6 @@ import javax.xml.bind.JAXBException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.rest.client.Client;
import org.apache.hadoop.hbase.rest.client.Cluster;
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;
public class TestVersionResource extends HBaseRESTClusterTestBase {
private static final Log LOG =
LogFactory.getLog(TestVersionResource.class);
static final Log LOG = LogFactory.getLog(TestVersionResource.class);
private Client client;
private JAXBContext context;
Client client;
JAXBContext context;
public TestVersionResource() throws JAXBException {
super();
context = JAXBContext.newInstance(
VersionModel.class,
StorageClusterVersionModel.class);
VersionModel.class,
StorageClusterVersionModel.class);
}
@Override
@ -64,7 +62,7 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
super.tearDown();
}
private static void validate(VersionModel model) {
void validate(VersionModel model) {
assertNotNull(model);
assertNotNull(model.getRESTVersion());
assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
@ -85,7 +83,7 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
.getImplementationVersion());
}
public void testGetStargateVersionText() throws IOException {
void doTestGetStargateVersionText() throws IOException {
Response response = client.get("/version", MIMETYPE_TEXT);
assertTrue(response.getCode() == 200);
String body = Bytes.toString(response.getBody());
@ -101,7 +99,7 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
.getImplementationVersion()));
}
public void testGetStargateVersionXML() throws IOException, JAXBException {
void doTestGetStargateVersionXML() throws IOException, JAXBException {
Response response = client.get("/version", MIMETYPE_XML);
assertTrue(response.getCode() == 200);
VersionModel model = (VersionModel)
@ -111,12 +109,12 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
LOG.info("success retrieving Stargate version as XML");
}
public void testGetStargateVersionJSON() throws IOException {
void doTestGetStargateVersionJSON() throws IOException {
Response response = client.get("/version", MIMETYPE_JSON);
assertTrue(response.getCode() == 200);
}
public void testGetStargateVersionPB() throws IOException {
void doTestGetStargateVersionPB() throws IOException {
Response response = client.get("/version", MIMETYPE_PROTOBUF);
assertTrue(response.getCode() == 200);
VersionModel model = new VersionModel();
@ -125,12 +123,12 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
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);
assertTrue(response.getCode() == 200);
}
public void testGetStorageClusterVersionXML() throws IOException,
void doTestGetStorageClusterVersionXML() throws IOException,
JAXBException {
Response response = client.get("/version/cluster", MIMETYPE_XML);
assertTrue(response.getCode() == 200);
@ -143,8 +141,18 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
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);
assertTrue(response.getCode() == 200);
}
public void testVersionResource() throws Exception {
doTestGetStargateVersionText();
doTestGetStargateVersionXML();
doTestGetStargateVersionJSON();
doTestGetStargateVersionPB();
doTestGetStorageClusterVersionText();
doTestGetStorageClusterVersionXML();
doTestGetStorageClusterVersionJSON();
}
}