HBASE-2564 [rest] Tests use deprecated foundation
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1031418 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0440bb0463
commit
9b91fe2113
|
@ -1101,6 +1101,7 @@ Release 0.21.0 - Unreleased
|
|||
HBASE-3180 Review periodic master logging, especially ServerManager once
|
||||
a minute
|
||||
HBASE-3189 Stagger Major Compactions (Nicolas Spiegelberg via Stack)
|
||||
HBASE-2564 [rest] Tests use deprecated foundation
|
||||
|
||||
|
||||
NEW FEATURES
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.apache.hadoop.hbase.rest;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HBaseClusterTestCase;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.servlet.Context;
|
||||
|
@ -30,33 +29,30 @@ import org.mortbay.jetty.servlet.ServletHolder;
|
|||
|
||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
public class HBaseRESTClusterTestBase extends HBaseClusterTestCase
|
||||
implements Constants {
|
||||
public class HBaseRESTTestingUtility {
|
||||
|
||||
static final Log LOG =
|
||||
LogFactory.getLog(HBaseRESTClusterTestBase.class);
|
||||
static final Log LOG = LogFactory.getLog(HBaseRESTTestingUtility.class);
|
||||
|
||||
protected int testServletPort;
|
||||
Server server;
|
||||
private Configuration conf;
|
||||
private int testServletPort;
|
||||
private Server server;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
startServletContainer();
|
||||
public HBaseRESTTestingUtility(Configuration conf) {
|
||||
this.conf = conf;
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
stopServletContainer();
|
||||
super.tearDown();
|
||||
public int getServletPort() {
|
||||
return testServletPort;
|
||||
}
|
||||
|
||||
private void startServletContainer() throws Exception {
|
||||
public void startServletContainer() throws Exception {
|
||||
if (server != null) {
|
||||
LOG.error("ServletContainer already running");
|
||||
return;
|
||||
}
|
||||
|
||||
// Inject the conf from the test cluster by being first to make singleton
|
||||
RESTServlet.getInstance(super.conf);
|
||||
// Inject the conf for the test by being first to make singleton
|
||||
RESTServlet.getInstance(conf);
|
||||
|
||||
// set up the Jersey servlet container for Jetty
|
||||
ServletHolder sh = new ServletHolder(ServletContainer.class);
|
||||
|
@ -84,7 +80,7 @@ public class HBaseRESTClusterTestBase extends HBaseClusterTestCase
|
|||
testServletPort);
|
||||
}
|
||||
|
||||
private void stopServletContainer() {
|
||||
public void shutdownServletContainer() {
|
||||
if (server != null) try {
|
||||
server.stop();
|
||||
server = null;
|
|
@ -31,6 +31,7 @@ import javax.xml.bind.Marshaller;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
|
@ -43,38 +44,47 @@ import org.apache.hadoop.hbase.rest.model.CellSetModel;
|
|||
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 CFA = "a";
|
||||
static final String CFB = "b";
|
||||
static final String COLUMN_1 = CFA + ":1";
|
||||
static final String COLUMN_2 = CFB + ":2";
|
||||
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";
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
Marshaller marshaller;
|
||||
Unmarshaller unmarshaller;
|
||||
HBaseAdmin admin;
|
||||
public class TestRowResource {
|
||||
private static final String TABLE = "TestRowResource";
|
||||
private static final String CFA = "a";
|
||||
private static final String CFB = "b";
|
||||
private static final String COLUMN_1 = CFA + ":1";
|
||||
private static final String COLUMN_2 = CFB + ":2";
|
||||
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";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
private static Marshaller marshaller;
|
||||
private static Unmarshaller unmarshaller;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
context = JAXBContext.newInstance(
|
||||
CellModel.class,
|
||||
CellSetModel.class,
|
||||
RowModel.class);
|
||||
marshaller = context.createMarshaller();
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
admin = new HBaseAdmin(conf);
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
if (admin.tableExists(TABLE)) {
|
||||
return;
|
||||
}
|
||||
|
@ -84,13 +94,14 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
admin.createTable(htd);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
Response deleteRow(String table, String row) throws IOException {
|
||||
private static Response deleteRow(String table, String row)
|
||||
throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
path.append(table);
|
||||
|
@ -101,7 +112,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
return response;
|
||||
}
|
||||
|
||||
Response deleteValue(String table, String row, String column)
|
||||
private static Response deleteValue(String table, String row, String column)
|
||||
throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
|
@ -115,7 +126,7 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
return response;
|
||||
}
|
||||
|
||||
Response getValueXML(String table, String row, String column)
|
||||
private static Response getValueXML(String table, String row, String column)
|
||||
throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
|
@ -127,12 +138,12 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
return getValueXML(path.toString());
|
||||
}
|
||||
|
||||
Response getValueXML(String url) throws IOException {
|
||||
Response response = client.get(url, MIMETYPE_XML);
|
||||
private static Response getValueXML(String url) throws IOException {
|
||||
Response response = client.get(url, Constants.MIMETYPE_XML);
|
||||
return response;
|
||||
}
|
||||
|
||||
Response getValuePB(String table, String row, String column)
|
||||
private static Response getValuePB(String table, String row, String column)
|
||||
throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
|
@ -144,13 +155,13 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
return getValuePB(path.toString());
|
||||
}
|
||||
|
||||
Response getValuePB(String url) throws IOException {
|
||||
Response response = client.get(url, MIMETYPE_PROTOBUF);
|
||||
private static Response getValuePB(String url) throws IOException {
|
||||
Response response = client.get(url, Constants.MIMETYPE_PROTOBUF);
|
||||
return response;
|
||||
}
|
||||
|
||||
Response putValueXML(String table, String row, String column, String value)
|
||||
throws IOException, JAXBException {
|
||||
private static Response putValueXML(String table, String row, String column,
|
||||
String value) throws IOException, JAXBException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
path.append(table);
|
||||
|
@ -161,8 +172,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
return putValueXML(path.toString(), table, row, column, value);
|
||||
}
|
||||
|
||||
Response putValueXML(String url, String table, String row, String column,
|
||||
String value) throws IOException, JAXBException {
|
||||
private static Response putValueXML(String url, String table, String row,
|
||||
String column, String value) throws IOException, JAXBException {
|
||||
RowModel rowModel = new RowModel(row);
|
||||
rowModel.addCell(new CellModel(Bytes.toBytes(column),
|
||||
Bytes.toBytes(value)));
|
||||
|
@ -170,14 +181,14 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
cellSetModel.addRow(rowModel);
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(cellSetModel, writer);
|
||||
Response response = client.put(url, MIMETYPE_XML,
|
||||
Response response = client.put(url, Constants.MIMETYPE_XML,
|
||||
Bytes.toBytes(writer.toString()));
|
||||
Thread.yield();
|
||||
return response;
|
||||
}
|
||||
|
||||
void checkValueXML(String table, String row, String column, String value)
|
||||
throws IOException, JAXBException {
|
||||
private static 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)
|
||||
|
@ -188,8 +199,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(Bytes.toString(cell.getValue()), value);
|
||||
}
|
||||
|
||||
void checkValueXML(String url, String table, String row, String column,
|
||||
String value) throws IOException, JAXBException {
|
||||
private static void checkValueXML(String url, String table, String row,
|
||||
String column, String value) throws IOException, JAXBException {
|
||||
Response response = getValueXML(url);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cellSet = (CellSetModel)
|
||||
|
@ -200,8 +211,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(Bytes.toString(cell.getValue()), value);
|
||||
}
|
||||
|
||||
Response putValuePB(String table, String row, String column, String value)
|
||||
throws IOException {
|
||||
private static Response putValuePB(String table, String row, String column,
|
||||
String value) throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
path.append(table);
|
||||
|
@ -212,21 +223,21 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
return putValuePB(path.toString(), table, row, column, value);
|
||||
}
|
||||
|
||||
Response putValuePB(String url, String table, String row, String column,
|
||||
String value) throws IOException {
|
||||
private static Response putValuePB(String url, String table, String row,
|
||||
String column, String value) throws IOException {
|
||||
RowModel rowModel = new RowModel(row);
|
||||
rowModel.addCell(new CellModel(Bytes.toBytes(column),
|
||||
Bytes.toBytes(value)));
|
||||
CellSetModel cellSetModel = new CellSetModel();
|
||||
cellSetModel.addRow(rowModel);
|
||||
Response response = client.put(url, MIMETYPE_PROTOBUF,
|
||||
Response response = client.put(url, Constants.MIMETYPE_PROTOBUF,
|
||||
cellSetModel.createProtobufOutput());
|
||||
Thread.yield();
|
||||
return response;
|
||||
}
|
||||
|
||||
void checkValuePB(String table, String row, String column, String value)
|
||||
throws IOException {
|
||||
private static 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();
|
||||
|
@ -237,19 +248,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(Bytes.toString(cell.getValue()), value);
|
||||
}
|
||||
|
||||
void checkValuePB(String url, String table, String row, String column,
|
||||
String value) throws IOException {
|
||||
Response response = getValuePB(url);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cellSet = new CellSetModel();
|
||||
cellSet.getObjectFromMessage(response.getBody());
|
||||
RowModel rowModel = cellSet.getRows().get(0);
|
||||
CellModel cell = rowModel.getCells().get(0);
|
||||
assertEquals(Bytes.toString(cell.getColumn()), column);
|
||||
assertEquals(Bytes.toString(cell.getValue()), value);
|
||||
}
|
||||
|
||||
void doTestDelete() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testDelete() throws IOException, JAXBException {
|
||||
Response response;
|
||||
|
||||
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
||||
|
@ -273,7 +273,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 404);
|
||||
}
|
||||
|
||||
void doTestSingleCellGetPutXML() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testSingleCellGetPutXML() throws IOException, JAXBException {
|
||||
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
|
||||
assertEquals(response.getCode(), 404);
|
||||
|
||||
|
@ -288,7 +289,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestSingleCellGetPutPB() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testSingleCellGetPutPB() throws IOException, JAXBException {
|
||||
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
||||
assertEquals(response.getCode(), 404);
|
||||
|
||||
|
@ -307,14 +309,15 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestSingleCellGetPutBinary() throws IOException {
|
||||
@Test
|
||||
public void testSingleCellGetPutBinary() throws IOException {
|
||||
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
|
||||
final byte[] body = Bytes.toBytes(VALUE_3);
|
||||
Response response = client.put(path, MIMETYPE_BINARY, body);
|
||||
Response response = client.put(path, Constants.MIMETYPE_BINARY, body);
|
||||
assertEquals(response.getCode(), 200);
|
||||
Thread.yield();
|
||||
|
||||
response = client.get(path, MIMETYPE_BINARY);
|
||||
response = client.get(path, Constants.MIMETYPE_BINARY);
|
||||
assertEquals(response.getCode(), 200);
|
||||
assertTrue(Bytes.equals(response.getBody(), body));
|
||||
boolean foundTimestampHeader = false;
|
||||
|
@ -330,19 +333,21 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestSingleCellGetJSON() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testSingleCellGetJSON() throws IOException, JAXBException {
|
||||
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
||||
Response response = client.put(path, MIMETYPE_BINARY,
|
||||
Response response = client.put(path, Constants.MIMETYPE_BINARY,
|
||||
Bytes.toBytes(VALUE_4));
|
||||
assertEquals(response.getCode(), 200);
|
||||
Thread.yield();
|
||||
response = client.get(path, MIMETYPE_JSON);
|
||||
response = client.get(path, Constants.MIMETYPE_JSON);
|
||||
assertEquals(response.getCode(), 200);
|
||||
response = deleteRow(TABLE, ROW_4);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
public void doTestURLEncodedKey() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testURLEncodedKey() throws IOException, JAXBException {
|
||||
String urlKey = "http://example.com/foo";
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append('/');
|
||||
|
@ -358,18 +363,23 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
checkValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
|
||||
}
|
||||
|
||||
public void doTestNoSuchCF() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testNoSuchCF() throws IOException, JAXBException {
|
||||
final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
|
||||
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
|
||||
Response response = client.post(goodPath, MIMETYPE_BINARY,
|
||||
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
|
||||
Bytes.toBytes(VALUE_1));
|
||||
assertEquals(response.getCode(), 200);
|
||||
assertEquals(client.get(goodPath, MIMETYPE_BINARY).getCode(), 200);
|
||||
assertEquals(client.get(badPath, MIMETYPE_BINARY).getCode(), 404);
|
||||
assertEquals(client.get(goodPath, MIMETYPE_BINARY).getCode(), 200);
|
||||
assertEquals(client.get(goodPath, Constants.MIMETYPE_BINARY).getCode(),
|
||||
200);
|
||||
assertEquals(client.get(badPath, Constants.MIMETYPE_BINARY).getCode(),
|
||||
404);
|
||||
assertEquals(client.get(goodPath, Constants.MIMETYPE_BINARY).getCode(),
|
||||
200);
|
||||
}
|
||||
|
||||
void doTestMultiCellGetPutXML() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testMultiCellGetPutXML() throws IOException, JAXBException {
|
||||
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
|
||||
|
||||
CellSetModel cellSetModel = new CellSetModel();
|
||||
|
@ -387,12 +397,12 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
cellSetModel.addRow(rowModel);
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(cellSetModel, writer);
|
||||
Response response = client.put(path, MIMETYPE_XML,
|
||||
Response response = client.put(path, Constants.MIMETYPE_XML,
|
||||
Bytes.toBytes(writer.toString()));
|
||||
Thread.yield();
|
||||
|
||||
// make sure the fake row was not actually created
|
||||
response = client.get(path, MIMETYPE_XML);
|
||||
response = client.get(path, Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 404);
|
||||
|
||||
// check that all of the values were created
|
||||
|
@ -407,7 +417,8 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestMultiCellGetPutPB() throws IOException {
|
||||
@Test
|
||||
public void testMultiCellGetPutPB() throws IOException {
|
||||
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
|
||||
|
||||
CellSetModel cellSetModel = new CellSetModel();
|
||||
|
@ -423,12 +434,12 @@ public class TestRowResource extends HBaseRESTClusterTestBase {
|
|||
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
|
||||
Bytes.toBytes(VALUE_4)));
|
||||
cellSetModel.addRow(rowModel);
|
||||
Response response = client.put(path, MIMETYPE_PROTOBUF,
|
||||
Response response = client.put(path, Constants.MIMETYPE_PROTOBUF,
|
||||
cellSetModel.createProtobufOutput());
|
||||
Thread.yield();
|
||||
|
||||
// make sure the fake row was not actually created
|
||||
response = client.get(path, MIMETYPE_PROTOBUF);
|
||||
response = client.get(path, Constants.MIMETYPE_PROTOBUF);
|
||||
assertEquals(response.getCode(), 404);
|
||||
|
||||
// check that all of the values were created
|
||||
|
@ -442,16 +453,4 @@ 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();
|
||||
doTestNoSuchCF();
|
||||
doTestMultiCellGetPutXML();
|
||||
doTestMultiCellGetPutPB();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import javax.xml.bind.Marshaller;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.KeyValue;
|
||||
|
@ -47,28 +48,34 @@ import org.apache.hadoop.hbase.rest.model.RowModel;
|
|||
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 NONEXISTENT_TABLE = "ThisTableDoesNotExist";
|
||||
static final String CFA = "a";
|
||||
static final String CFB = "b";
|
||||
static final String COLUMN_1 = CFA + ":1";
|
||||
static final String COLUMN_2 = CFB + ":2";
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
static int expectedRows1;
|
||||
static int expectedRows2;
|
||||
public class TestScannerResource {
|
||||
private static final String TABLE = "TestScannerResource";
|
||||
private static final String NONEXISTENT_TABLE = "ThisTableDoesNotExist";
|
||||
private static final String CFA = "a";
|
||||
private static final String CFB = "b";
|
||||
private static final String COLUMN_1 = CFA + ":1";
|
||||
private static final String COLUMN_2 = CFB + ":2";
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
Marshaller marshaller;
|
||||
Unmarshaller unmarshaller;
|
||||
HBaseAdmin admin;
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
private static Marshaller marshaller;
|
||||
private static Unmarshaller unmarshaller;
|
||||
private static int expectedRows1;
|
||||
private static int expectedRows2;
|
||||
|
||||
int insertData(String tableName, String column, double prob)
|
||||
private static int insertData(String tableName, String column, double prob)
|
||||
throws IOException {
|
||||
Random rng = new Random();
|
||||
int count = 0;
|
||||
HTable table = new HTable(conf, tableName);
|
||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||
byte[] k = new byte[3];
|
||||
byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column));
|
||||
for (byte b1 = 'a'; b1 < 'z'; b1++) {
|
||||
|
@ -90,36 +97,7 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
context = JAXBContext.newInstance(
|
||||
CellModel.class,
|
||||
CellSetModel.class,
|
||||
RowModel.class,
|
||||
ScannerModel.class);
|
||||
marshaller = context.createMarshaller();
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
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(CFA));
|
||||
htd.addFamily(new HColumnDescriptor(CFB));
|
||||
admin.createTable(htd);
|
||||
expectedRows1 = insertData(TABLE, COLUMN_1, 1.0);
|
||||
expectedRows2 = insertData(TABLE, COLUMN_2, 0.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
int countCellSet(CellSetModel model) {
|
||||
private static int countCellSet(CellSetModel model) {
|
||||
int count = 0;
|
||||
Iterator<RowModel> rows = model.getRows().iterator();
|
||||
while (rows.hasNext()) {
|
||||
|
@ -133,7 +111,72 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
return count;
|
||||
}
|
||||
|
||||
void doTestSimpleScannerXML() throws IOException, JAXBException {
|
||||
private static int fullTableScan(ScannerModel model) throws IOException {
|
||||
model.setBatch(100);
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
int count = 0;
|
||||
while (true) {
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
|
||||
assertTrue(response.getCode() == 200 || response.getCode() == 204);
|
||||
if (response.getCode() == 200) {
|
||||
CellSetModel cellSet = new CellSetModel();
|
||||
cellSet.getObjectFromMessage(response.getBody());
|
||||
Iterator<RowModel> rows = cellSet.getRows().iterator();
|
||||
while (rows.hasNext()) {
|
||||
RowModel row = rows.next();
|
||||
Iterator<CellModel> cells = row.getCells().iterator();
|
||||
while (cells.hasNext()) {
|
||||
cells.next();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// delete the scanner
|
||||
response = client.delete(scannerURI);
|
||||
assertEquals(response.getCode(), 200);
|
||||
return count;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
context = JAXBContext.newInstance(
|
||||
CellModel.class,
|
||||
CellSetModel.class,
|
||||
RowModel.class,
|
||||
ScannerModel.class);
|
||||
marshaller = context.createMarshaller();
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
if (admin.tableExists(TABLE)) {
|
||||
return;
|
||||
}
|
||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||
htd.addFamily(new HColumnDescriptor(CFA));
|
||||
htd.addFamily(new HColumnDescriptor(CFB));
|
||||
admin.createTable(htd);
|
||||
expectedRows1 = insertData(TABLE, COLUMN_1, 1.0);
|
||||
expectedRows2 = insertData(TABLE, COLUMN_2, 0.5);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScannerXML() throws IOException, JAXBException {
|
||||
final int BATCH_SIZE = 5;
|
||||
// new scanner
|
||||
ScannerModel model = new ScannerModel();
|
||||
|
@ -142,14 +185,14 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(model, writer);
|
||||
byte[] body = Bytes.toBytes(writer.toString());
|
||||
Response response = client.put("/" + TABLE + "/scanner", MIMETYPE_XML,
|
||||
body);
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
Constants.MIMETYPE_XML, body);
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
|
||||
// get a cell set
|
||||
response = client.get(scannerURI, MIMETYPE_XML);
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cellSet = (CellSetModel)
|
||||
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||
|
@ -161,20 +204,21 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestSimpleScannerPB() throws IOException {
|
||||
@Test
|
||||
public void testSimpleScannerPB() throws IOException {
|
||||
final int BATCH_SIZE = 10;
|
||||
// new scanner
|
||||
ScannerModel model = new ScannerModel();
|
||||
model.setBatch(BATCH_SIZE);
|
||||
model.addColumn(Bytes.toBytes(COLUMN_1));
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
|
||||
// get a cell set
|
||||
response = client.get(scannerURI, MIMETYPE_PROTOBUF);
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cellSet = new CellSetModel();
|
||||
cellSet.getObjectFromMessage(response.getBody());
|
||||
|
@ -186,19 +230,20 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestSimpleScannerBinary() throws IOException {
|
||||
@Test
|
||||
public void testSimpleScannerBinary() throws IOException {
|
||||
// new scanner
|
||||
ScannerModel model = new ScannerModel();
|
||||
model.setBatch(1);
|
||||
model.addColumn(Bytes.toBytes(COLUMN_1));
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
|
||||
// get a cell
|
||||
response = client.get(scannerURI, MIMETYPE_BINARY);
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_BINARY);
|
||||
assertEquals(response.getCode(), 200);
|
||||
// verify that data was returned
|
||||
assertTrue(response.getBody().length > 0);
|
||||
|
@ -223,40 +268,8 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
int fullTableScan(ScannerModel model) throws IOException {
|
||||
model.setBatch(100);
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
int count = 0;
|
||||
while (true) {
|
||||
response = client.get(scannerURI, MIMETYPE_PROTOBUF);
|
||||
assertTrue(response.getCode() == 200 || response.getCode() == 204);
|
||||
if (response.getCode() == 200) {
|
||||
CellSetModel cellSet = new CellSetModel();
|
||||
cellSet.getObjectFromMessage(response.getBody());
|
||||
Iterator<RowModel> rows = cellSet.getRows().iterator();
|
||||
while (rows.hasNext()) {
|
||||
RowModel row = rows.next();
|
||||
Iterator<CellModel> cells = row.getCells().iterator();
|
||||
while (cells.hasNext()) {
|
||||
cells.next();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// delete the scanner
|
||||
response = client.delete(scannerURI);
|
||||
assertEquals(response.getCode(), 200);
|
||||
return count;
|
||||
}
|
||||
|
||||
void doTestFullTableScan() throws IOException {
|
||||
@Test
|
||||
public void testFullTableScan() throws IOException {
|
||||
ScannerModel model = new ScannerModel();
|
||||
model.addColumn(Bytes.toBytes(COLUMN_1));
|
||||
assertEquals(fullTableScan(model), expectedRows1);
|
||||
|
@ -266,21 +279,14 @@ public class TestScannerResource extends HBaseRESTClusterTestBase {
|
|||
assertEquals(fullTableScan(model), expectedRows2);
|
||||
}
|
||||
|
||||
void doTestTableDoesNotExist() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testTableDoesNotExist() throws IOException, JAXBException {
|
||||
ScannerModel model = new ScannerModel();
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(model, writer);
|
||||
byte[] body = Bytes.toBytes(writer.toString());
|
||||
Response response = client.put("/" + NONEXISTENT_TABLE +
|
||||
"/scanner", MIMETYPE_XML, body);
|
||||
"/scanner", Constants.MIMETYPE_XML, body);
|
||||
assertEquals(response.getCode(), 404);
|
||||
}
|
||||
|
||||
public void testScannerResource() throws Exception {
|
||||
doTestSimpleScannerXML();
|
||||
doTestSimpleScannerPB();
|
||||
doTestSimpleScannerBinary();
|
||||
doTestFullTableScan();
|
||||
doTestTableDoesNotExist();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import javax.xml.bind.Unmarshaller;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
|
@ -66,48 +67,59 @@ import org.apache.hadoop.hbase.rest.model.RowModel;
|
|||
import org.apache.hadoop.hbase.rest.model.ScannerModel;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
static final Log LOG = LogFactory.getLog(TestScannersWithFilters.class);
|
||||
public class TestScannersWithFilters {
|
||||
|
||||
static final byte [][] ROWS_ONE = {
|
||||
private static final Log LOG = LogFactory.getLog(TestScannersWithFilters.class);
|
||||
|
||||
private static final String TABLE = "TestScannersWithFilters";
|
||||
|
||||
private static final byte [][] ROWS_ONE = {
|
||||
Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-1"),
|
||||
Bytes.toBytes("testRowOne-2"), Bytes.toBytes("testRowOne-3")
|
||||
};
|
||||
|
||||
static final byte [][] ROWS_TWO = {
|
||||
private static final byte [][] ROWS_TWO = {
|
||||
Bytes.toBytes("testRowTwo-0"), Bytes.toBytes("testRowTwo-1"),
|
||||
Bytes.toBytes("testRowTwo-2"), Bytes.toBytes("testRowTwo-3")
|
||||
};
|
||||
|
||||
static final byte [][] FAMILIES = {
|
||||
private static final byte [][] FAMILIES = {
|
||||
Bytes.toBytes("testFamilyOne"), Bytes.toBytes("testFamilyTwo")
|
||||
};
|
||||
|
||||
static final byte [][] QUALIFIERS_ONE = {
|
||||
private static final byte [][] QUALIFIERS_ONE = {
|
||||
Bytes.toBytes("testQualifierOne-0"), Bytes.toBytes("testQualifierOne-1"),
|
||||
Bytes.toBytes("testQualifierOne-2"), Bytes.toBytes("testQualifierOne-3")
|
||||
};
|
||||
|
||||
static final byte [][] QUALIFIERS_TWO = {
|
||||
private static final byte [][] QUALIFIERS_TWO = {
|
||||
Bytes.toBytes("testQualifierTwo-0"), Bytes.toBytes("testQualifierTwo-1"),
|
||||
Bytes.toBytes("testQualifierTwo-2"), Bytes.toBytes("testQualifierTwo-3")
|
||||
};
|
||||
|
||||
static final byte [][] VALUES = {
|
||||
private static final byte [][] VALUES = {
|
||||
Bytes.toBytes("testValueOne"), Bytes.toBytes("testValueTwo")
|
||||
};
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
Marshaller marshaller;
|
||||
Unmarshaller unmarshaller;
|
||||
long numRows = ROWS_ONE.length + ROWS_TWO.length;
|
||||
long colsPerRow = FAMILIES.length * QUALIFIERS_ONE.length;
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
private static Marshaller marshaller;
|
||||
private static Unmarshaller unmarshaller;
|
||||
private static long numRows = ROWS_ONE.length + ROWS_TWO.length;
|
||||
private static long colsPerRow = FAMILIES.length * QUALIFIERS_ONE.length;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
context = JAXBContext.newInstance(
|
||||
CellModel.class,
|
||||
CellSetModel.class,
|
||||
|
@ -115,14 +127,15 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
ScannerModel.class);
|
||||
marshaller = context.createMarshaller();
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
if (!admin.tableExists(getName())) {
|
||||
HTableDescriptor htd = new HTableDescriptor(getName());
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
if (!admin.tableExists(TABLE)) {
|
||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||
htd.addFamily(new HColumnDescriptor(FAMILIES[0]));
|
||||
htd.addFamily(new HColumnDescriptor(FAMILIES[1]));
|
||||
admin.createTable(htd);
|
||||
HTable table = new HTable(conf, getName());
|
||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE);
|
||||
// Insert first half
|
||||
for(byte [] ROW : ROWS_ONE) {
|
||||
Put p = new Put(ROW);
|
||||
|
@ -187,13 +200,13 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
void verifyScan(Scan s, long expectedRows, long expectedKeys)
|
||||
private static void verifyScan(Scan s, long expectedRows, long expectedKeys)
|
||||
throws Exception {
|
||||
ScannerModel model = ScannerModel.fromScan(s);
|
||||
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
||||
|
@ -201,14 +214,14 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
marshaller.marshal(model, writer);
|
||||
LOG.debug(writer.toString());
|
||||
byte[] body = Bytes.toBytes(writer.toString());
|
||||
Response response = client.put("/" + getName() + "/scanner", MIMETYPE_XML,
|
||||
body);
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
Constants.MIMETYPE_XML, body);
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
|
||||
// get a cell set
|
||||
response = client.get(scannerURI, MIMETYPE_XML);
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cells = (CellSetModel)
|
||||
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||
|
@ -227,21 +240,22 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void verifyScanFull(Scan s, KeyValue [] kvs) throws Exception {
|
||||
private static void verifyScanFull(Scan s, KeyValue [] kvs)
|
||||
throws Exception {
|
||||
ScannerModel model = ScannerModel.fromScan(s);
|
||||
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(model, writer);
|
||||
LOG.debug(writer.toString());
|
||||
byte[] body = Bytes.toBytes(writer.toString());
|
||||
Response response = client.put("/" + getName() + "/scanner", MIMETYPE_XML,
|
||||
body);
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
Constants.MIMETYPE_XML, body);
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
|
||||
// get a cell set
|
||||
response = client.get(scannerURI, MIMETYPE_XML);
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cellSet = (CellSetModel)
|
||||
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||
|
@ -279,22 +293,22 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
kvs.length, idx);
|
||||
}
|
||||
|
||||
void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys)
|
||||
throws Exception {
|
||||
private static void verifyScanNoEarlyOut(Scan s, long expectedRows,
|
||||
long expectedKeys) throws Exception {
|
||||
ScannerModel model = ScannerModel.fromScan(s);
|
||||
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(model, writer);
|
||||
LOG.debug(writer.toString());
|
||||
byte[] body = Bytes.toBytes(writer.toString());
|
||||
Response response = client.put("/" + getName() + "/scanner", MIMETYPE_XML,
|
||||
body);
|
||||
Response response = client.put("/" + TABLE + "/scanner",
|
||||
Constants.MIMETYPE_XML, body);
|
||||
assertEquals(response.getCode(), 201);
|
||||
String scannerURI = response.getLocation();
|
||||
assertNotNull(scannerURI);
|
||||
|
||||
// get a cell set
|
||||
response = client.get(scannerURI, MIMETYPE_XML);
|
||||
response = client.get(scannerURI, Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
CellSetModel cellSet = (CellSetModel)
|
||||
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||
|
@ -320,10 +334,11 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
" rows", expectedRows, j);
|
||||
}
|
||||
|
||||
void doTestNoFilter() throws Exception {
|
||||
@Test
|
||||
public void testNoFilter() throws Exception {
|
||||
// No filter
|
||||
long expectedRows = this.numRows;
|
||||
long expectedKeys = this.colsPerRow;
|
||||
long expectedRows = numRows;
|
||||
long expectedKeys = colsPerRow;
|
||||
|
||||
// Both families
|
||||
Scan s = new Scan();
|
||||
|
@ -335,16 +350,18 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScan(s, expectedRows, expectedKeys/2);
|
||||
}
|
||||
|
||||
void doTestPrefixFilter() throws Exception {
|
||||
@Test
|
||||
public void testPrefixFilter() throws Exception {
|
||||
// Grab rows from group one (half of total)
|
||||
long expectedRows = this.numRows / 2;
|
||||
long expectedKeys = this.colsPerRow;
|
||||
long expectedRows = numRows / 2;
|
||||
long expectedKeys = colsPerRow;
|
||||
Scan s = new Scan();
|
||||
s.setFilter(new PrefixFilter(Bytes.toBytes("testRowOne")));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
}
|
||||
|
||||
void doTestPageFilter() throws Exception {
|
||||
@Test
|
||||
public void testPageFilter() throws Exception {
|
||||
// KVs in first 6 rows
|
||||
KeyValue [] expectedKVs = {
|
||||
// testRowOne-0
|
||||
|
@ -393,7 +410,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Grab all 6 rows
|
||||
long expectedRows = 6;
|
||||
long expectedKeys = this.colsPerRow;
|
||||
long expectedKeys = colsPerRow;
|
||||
Scan s = new Scan();
|
||||
s.setFilter(new PageFilter(expectedRows));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
@ -402,7 +419,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Grab first 4 rows (6 cols per row)
|
||||
expectedRows = 4;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedKeys = colsPerRow;
|
||||
s = new Scan();
|
||||
s.setFilter(new PageFilter(expectedRows));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
@ -411,7 +428,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Grab first 2 rows
|
||||
expectedRows = 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedKeys = colsPerRow;
|
||||
s = new Scan();
|
||||
s.setFilter(new PageFilter(expectedRows));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
@ -420,7 +437,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Grab first row
|
||||
expectedRows = 1;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedKeys = colsPerRow;
|
||||
s = new Scan();
|
||||
s.setFilter(new PageFilter(expectedRows));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
@ -428,18 +445,19 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanFull(s, Arrays.copyOf(expectedKVs, 6));
|
||||
}
|
||||
|
||||
void doTestInclusiveStopFilter() throws Exception {
|
||||
@Test
|
||||
public void testInclusiveStopFilter() throws Exception {
|
||||
// Grab rows from group one
|
||||
|
||||
// If we just use start/stop row, we get total/2 - 1 rows
|
||||
long expectedRows = (this.numRows / 2) - 1;
|
||||
long expectedKeys = this.colsPerRow;
|
||||
long expectedRows = (numRows / 2) - 1;
|
||||
long expectedKeys = colsPerRow;
|
||||
Scan s = new Scan(Bytes.toBytes("testRowOne-0"),
|
||||
Bytes.toBytes("testRowOne-3"));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
||||
// Now use start row with inclusive stop filter
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
s = new Scan(Bytes.toBytes("testRowOne-0"));
|
||||
s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowOne-3")));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
@ -447,23 +465,23 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
// Grab rows from group two
|
||||
|
||||
// If we just use start/stop row, we get total/2 - 1 rows
|
||||
expectedRows = (this.numRows / 2) - 1;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = (numRows / 2) - 1;
|
||||
expectedKeys = colsPerRow;
|
||||
s = new Scan(Bytes.toBytes("testRowTwo-0"),
|
||||
Bytes.toBytes("testRowTwo-3"));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
||||
// Now use start row with inclusive stop filter
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
s = new Scan(Bytes.toBytes("testRowTwo-0"));
|
||||
s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowTwo-3")));
|
||||
verifyScan(s, expectedRows, expectedKeys);
|
||||
|
||||
}
|
||||
|
||||
void doTestQualifierFilter() throws Exception {
|
||||
@Test
|
||||
public void testQualifierFilter() throws Exception {
|
||||
// Match two keys (one from each family) in half the rows
|
||||
long expectedRows = this.numRows / 2;
|
||||
long expectedRows = numRows / 2;
|
||||
long expectedKeys = 2;
|
||||
Filter f = new QualifierFilter(CompareOp.EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testQualifierOne-2")));
|
||||
|
@ -473,7 +491,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match keys less than same qualifier
|
||||
// Expect only two keys (one from each family) in half the rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = 2;
|
||||
f = new QualifierFilter(CompareOp.LESS,
|
||||
new BinaryComparator(Bytes.toBytes("testQualifierOne-2")));
|
||||
|
@ -483,7 +501,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match keys less than or equal
|
||||
// Expect four keys (two from each family) in half the rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = 4;
|
||||
f = new QualifierFilter(CompareOp.LESS_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testQualifierOne-2")));
|
||||
|
@ -494,7 +512,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
// Match keys not equal
|
||||
// Expect four keys (two from each family)
|
||||
// Only look in first group of rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = 4;
|
||||
f = new QualifierFilter(CompareOp.NOT_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testQualifierOne-2")));
|
||||
|
@ -505,7 +523,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
// Match keys greater or equal
|
||||
// Expect four keys (two from each family)
|
||||
// Only look in first group of rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = 4;
|
||||
f = new QualifierFilter(CompareOp.GREATER_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testQualifierOne-2")));
|
||||
|
@ -516,7 +534,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
// Match keys greater
|
||||
// Expect two keys (one from each family)
|
||||
// Only look in first group of rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = 2;
|
||||
f = new QualifierFilter(CompareOp.GREATER,
|
||||
new BinaryComparator(Bytes.toBytes("testQualifierOne-2")));
|
||||
|
@ -616,10 +634,11 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanFull(s, kvs);
|
||||
}
|
||||
|
||||
void doTestRowFilter() throws Exception {
|
||||
@Test
|
||||
public void testRowFilter() throws Exception {
|
||||
// Match a single row, all keys
|
||||
long expectedRows = 1;
|
||||
long expectedKeys = this.colsPerRow;
|
||||
long expectedKeys = colsPerRow;
|
||||
Filter f = new RowFilter(CompareOp.EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
|
||||
Scan s = new Scan();
|
||||
|
@ -628,7 +647,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match a two rows, one from each group, using regex
|
||||
expectedRows = 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new RowFilter(CompareOp.EQUAL,
|
||||
new RegexStringComparator("testRow.+-2"));
|
||||
s = new Scan();
|
||||
|
@ -638,7 +657,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
// Match rows less than
|
||||
// Expect all keys in one row
|
||||
expectedRows = 1;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new RowFilter(CompareOp.LESS,
|
||||
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
|
||||
s = new Scan();
|
||||
|
@ -648,7 +667,7 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
// Match rows less than or equal
|
||||
// Expect all keys in two rows
|
||||
expectedRows = 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new RowFilter(CompareOp.LESS_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
|
||||
s = new Scan();
|
||||
|
@ -657,8 +676,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match rows not equal
|
||||
// Expect all keys in all but one row
|
||||
expectedRows = this.numRows - 1;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows - 1;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new RowFilter(CompareOp.NOT_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
|
||||
s = new Scan();
|
||||
|
@ -667,8 +686,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match keys greater or equal
|
||||
// Expect all keys in all but one row
|
||||
expectedRows = this.numRows - 1;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows - 1;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new RowFilter(CompareOp.GREATER_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
|
||||
s = new Scan();
|
||||
|
@ -677,8 +696,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match keys greater
|
||||
// Expect all keys in all but two rows
|
||||
expectedRows = this.numRows - 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows - 2;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new RowFilter(CompareOp.GREATER,
|
||||
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
|
||||
s = new Scan();
|
||||
|
@ -759,10 +778,11 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanFull(s, kvs);
|
||||
}
|
||||
|
||||
void doTestValueFilter() throws Exception {
|
||||
@Test
|
||||
public void testValueFilter() throws Exception {
|
||||
// Match group one rows
|
||||
long expectedRows = this.numRows / 2;
|
||||
long expectedKeys = this.colsPerRow;
|
||||
long expectedRows = numRows / 2;
|
||||
long expectedKeys = colsPerRow;
|
||||
Filter f = new ValueFilter(CompareOp.EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testValueOne")));
|
||||
Scan s = new Scan();
|
||||
|
@ -770,8 +790,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
|
||||
|
||||
// Match group two rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testValueTwo")));
|
||||
s = new Scan();
|
||||
|
@ -779,8 +799,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
|
||||
|
||||
// Match all values using regex
|
||||
expectedRows = this.numRows;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.EQUAL,
|
||||
new RegexStringComparator("testValue((One)|(Two))"));
|
||||
s = new Scan();
|
||||
|
@ -789,8 +809,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match values less than
|
||||
// Expect group one rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.LESS,
|
||||
new BinaryComparator(Bytes.toBytes("testValueTwo")));
|
||||
s = new Scan();
|
||||
|
@ -799,8 +819,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match values less than or equal
|
||||
// Expect all rows
|
||||
expectedRows = this.numRows;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.LESS_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testValueTwo")));
|
||||
s = new Scan();
|
||||
|
@ -809,8 +829,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match values less than or equal
|
||||
// Expect group one rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.LESS_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testValueOne")));
|
||||
s = new Scan();
|
||||
|
@ -819,8 +839,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match values not equal
|
||||
// Expect half the rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.NOT_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testValueOne")));
|
||||
s = new Scan();
|
||||
|
@ -829,8 +849,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match values greater or equal
|
||||
// Expect all rows
|
||||
expectedRows = this.numRows;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.GREATER_OR_EQUAL,
|
||||
new BinaryComparator(Bytes.toBytes("testValueOne")));
|
||||
s = new Scan();
|
||||
|
@ -839,8 +859,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
|
||||
// Match values greater
|
||||
// Expect half rows
|
||||
expectedRows = this.numRows / 2;
|
||||
expectedKeys = this.colsPerRow;
|
||||
expectedRows = numRows / 2;
|
||||
expectedKeys = colsPerRow;
|
||||
f = new ValueFilter(CompareOp.GREATER,
|
||||
new BinaryComparator(Bytes.toBytes("testValueOne")));
|
||||
s = new Scan();
|
||||
|
@ -881,7 +901,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanFull(s, kvs);
|
||||
}
|
||||
|
||||
void doTestSkipFilter() throws Exception {
|
||||
@Test
|
||||
public void testSkipFilter() 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,
|
||||
|
@ -915,7 +936,8 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
verifyScanFull(s, kvs);
|
||||
}
|
||||
|
||||
void doTestFilterList() throws Exception {
|
||||
@Test
|
||||
public void testFilterList() throws Exception {
|
||||
// Test getting a single row, single key using Row, Qualifier, and Value
|
||||
// regular expression and substring filters
|
||||
// Use must pass all
|
||||
|
@ -947,10 +969,11 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
f = new FilterList(Operator.MUST_PASS_ONE, filters);
|
||||
s = new Scan();
|
||||
s.setFilter(f);
|
||||
verifyScanNoEarlyOut(s, this.numRows, this.colsPerRow);
|
||||
verifyScanNoEarlyOut(s, numRows, colsPerRow);
|
||||
}
|
||||
|
||||
void doTestFirstKeyOnlyFilter() throws Exception {
|
||||
@Test
|
||||
public void testFirstKeyOnlyFilter() throws Exception {
|
||||
Scan s = new Scan();
|
||||
s.setFilter(new FirstKeyOnlyFilter());
|
||||
// Expected KVs, the first KV from each of the remaining 6 rows
|
||||
|
@ -964,17 +987,4 @@ public class TestScannersWithFilters extends HBaseRESTClusterTestBase {
|
|||
};
|
||||
verifyScanFull(s, kvs);
|
||||
}
|
||||
|
||||
public void testScannersWithFilters() throws Exception {
|
||||
doTestNoFilter();
|
||||
doTestPrefixFilter();
|
||||
doTestPageFilter();
|
||||
doTestInclusiveStopFilter();
|
||||
doTestQualifierFilter();
|
||||
doTestRowFilter();
|
||||
doTestValueFilter();
|
||||
doTestSkipFilter();
|
||||
doTestFilterList();
|
||||
doTestFirstKeyOnlyFilter();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.io.StringWriter;
|
|||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.rest.client.Client;
|
||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||
|
@ -36,59 +37,70 @@ import org.apache.hadoop.hbase.rest.model.TableSchemaModel;
|
|||
import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
||||
static String TABLE1 = "TestSchemaResource1";
|
||||
static String TABLE2 = "TestSchemaResource2";
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
HBaseAdmin admin;
|
||||
public class TestSchemaResource {
|
||||
private static String TABLE1 = "TestSchemaResource1";
|
||||
private static String TABLE2 = "TestSchemaResource2";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
context = JAXBContext.newInstance(
|
||||
ColumnSchemaModel.class,
|
||||
TableSchemaModel.class);
|
||||
admin = new HBaseAdmin(conf);
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
ColumnSchemaModel.class,
|
||||
TableSchemaModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
byte[] toXML(TableSchemaModel model) throws JAXBException {
|
||||
private static byte[] toXML(TableSchemaModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return Bytes.toBytes(writer.toString());
|
||||
}
|
||||
|
||||
TableSchemaModel fromXML(byte[] content) throws JAXBException {
|
||||
private static TableSchemaModel fromXML(byte[] content)
|
||||
throws JAXBException {
|
||||
return (TableSchemaModel) context.createUnmarshaller()
|
||||
.unmarshal(new ByteArrayInputStream(content));
|
||||
}
|
||||
|
||||
void doTestTableCreateAndDeleteXML() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testTableCreateAndDeleteXML() throws IOException, JAXBException {
|
||||
String schemaPath = "/" + TABLE1 + "/schema";
|
||||
TableSchemaModel model;
|
||||
Response response;
|
||||
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
assertFalse(admin.tableExists(TABLE1));
|
||||
|
||||
// create the table
|
||||
model = TestTableSchemaModel.buildTestModel(TABLE1);
|
||||
TestTableSchemaModel.checkModel(model, TABLE1);
|
||||
response = client.put(schemaPath, MIMETYPE_XML, toXML(model));
|
||||
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model));
|
||||
assertEquals(response.getCode(), 201);
|
||||
|
||||
// make sure HBase concurs, and wait for the table to come online
|
||||
admin.enableTable(TABLE1);
|
||||
|
||||
// retrieve the schema and validate it
|
||||
response = client.get(schemaPath, MIMETYPE_XML);
|
||||
response = client.get(schemaPath, Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
model = fromXML(response.getBody());
|
||||
TestTableSchemaModel.checkModel(model, TABLE1);
|
||||
|
@ -100,11 +112,13 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
|||
assertFalse(admin.tableExists(TABLE1));
|
||||
}
|
||||
|
||||
void doTestTableCreateAndDeletePB() throws IOException, JAXBException {
|
||||
@Test
|
||||
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
|
||||
String schemaPath = "/" + TABLE2 + "/schema";
|
||||
TableSchemaModel model;
|
||||
Response response;
|
||||
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
assertFalse(admin.tableExists(TABLE2));
|
||||
|
||||
// create the table
|
||||
|
@ -130,9 +144,4 @@ public class TestSchemaResource extends HBaseRESTClusterTestBase {
|
|||
// make sure HBase concurs
|
||||
assertFalse(admin.tableExists(TABLE2));
|
||||
}
|
||||
|
||||
public void testSchemaResource() throws Exception {
|
||||
doTestTableCreateAndDeleteXML();
|
||||
doTestTableCreateAndDeletePB();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,34 +26,29 @@ import java.io.IOException;
|
|||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.rest.client.Client;
|
||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||
import org.apache.hadoop.hbase.rest.client.Response;
|
||||
import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class TestStatusResource extends HBaseRESTClusterTestBase {
|
||||
static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
|
||||
static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
public class TestStatusResource {
|
||||
private static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
|
||||
private static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
context = JAXBContext.newInstance(
|
||||
StorageClusterStatusModel.class);
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
}
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
void validate(StorageClusterStatusModel model) {
|
||||
private static void validate(StorageClusterStatusModel model) {
|
||||
assertNotNull(model);
|
||||
assertTrue(model.getRegions() >= 2);
|
||||
assertTrue(model.getRequests() >= 0);
|
||||
|
@ -80,8 +75,24 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
|
|||
assertTrue(foundMeta);
|
||||
}
|
||||
|
||||
void doTestGetClusterStatusXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/status/cluster", MIMETYPE_XML);
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(2); // some tests depend on having only 2 RS
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
context = JAXBContext.newInstance(StorageClusterStatusModel.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClusterStatusXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/status/cluster", Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
StorageClusterStatusModel model = (StorageClusterStatusModel)
|
||||
context.createUnmarshaller().unmarshal(
|
||||
|
@ -89,16 +100,13 @@ public class TestStatusResource extends HBaseRESTClusterTestBase {
|
|||
validate(model);
|
||||
}
|
||||
|
||||
void doTestGetClusterStatusPB() throws IOException {
|
||||
Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF);
|
||||
@Test
|
||||
public void testGetClusterStatusPB() throws IOException {
|
||||
Response response = client.get("/status/cluster",
|
||||
Constants.MIMETYPE_PROTOBUF);
|
||||
assertEquals(response.getCode(), 200);
|
||||
StorageClusterStatusModel model = new StorageClusterStatusModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
validate(model);
|
||||
}
|
||||
|
||||
public void testStatusResource() throws Exception {
|
||||
doTestGetClusterStatusXML();
|
||||
doTestGetClusterStatusPB();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import javax.xml.bind.JAXBException;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HRegionInfo;
|
||||
import org.apache.hadoop.hbase.HServerAddress;
|
||||
|
@ -49,35 +50,44 @@ 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 {
|
||||
static final Log LOG = LogFactory.getLog(TestTableResource.class);
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
static String TABLE = "TestTableResource";
|
||||
static String COLUMN_FAMILY = "test";
|
||||
static String COLUMN = COLUMN_FAMILY + ":qualifier";
|
||||
static Map<HRegionInfo,HServerAddress> regionMap;
|
||||
public class TestTableResource {
|
||||
private static final Log LOG = LogFactory.getLog(TestTableResource.class);
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
HBaseAdmin admin;
|
||||
private static String TABLE = "TestTableResource";
|
||||
private static String COLUMN_FAMILY = "test";
|
||||
private static String COLUMN = COLUMN_FAMILY + ":qualifier";
|
||||
private static Map<HRegionInfo,HServerAddress> regionMap;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
context = JAXBContext.newInstance(
|
||||
TableModel.class,
|
||||
TableInfoModel.class,
|
||||
TableListModel.class,
|
||||
TableRegionModel.class);
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
admin = new HBaseAdmin(conf);
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
if (admin.tableExists(TABLE)) {
|
||||
return;
|
||||
}
|
||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||
htd.addFamily(new HColumnDescriptor(COLUMN_FAMILY));
|
||||
admin.createTable(htd);
|
||||
HTable table = new HTable(conf, TABLE);
|
||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE);
|
||||
byte[] k = new byte[3];
|
||||
byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(COLUMN));
|
||||
for (byte b1 = 'a'; b1 < 'z'; b1++) {
|
||||
|
@ -112,13 +122,13 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
|||
LOG.info("regions: " + regionMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
void checkTableList(TableListModel model) {
|
||||
private static void checkTableList(TableListModel model) {
|
||||
boolean found = false;
|
||||
Iterator<TableModel> tables = model.getTables().iterator();
|
||||
assertTrue(tables.hasNext());
|
||||
|
@ -132,34 +142,7 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
|||
assertTrue(found);
|
||||
}
|
||||
|
||||
void doTestTableListText() throws IOException {
|
||||
Response response = client.get("/", MIMETYPE_TEXT);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestTableListXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/", MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
TableListModel model = (TableListModel)
|
||||
context.createUnmarshaller()
|
||||
.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||
checkTableList(model);
|
||||
}
|
||||
|
||||
void doTestTableListJSON() throws IOException {
|
||||
Response response = client.get("/", MIMETYPE_JSON);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
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) {
|
||||
void checkTableInfo(TableInfoModel model) {
|
||||
assertEquals(model.getName(), TABLE);
|
||||
Iterator<TableRegionModel> regions = model.getRegions().iterator();
|
||||
assertTrue(regions.hasNext());
|
||||
|
@ -188,13 +171,48 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
void doTestTableInfoText() throws IOException {
|
||||
Response response = client.get("/" + TABLE + "/regions", MIMETYPE_TEXT);
|
||||
@Test
|
||||
public void testTableListText() throws IOException {
|
||||
Response response = client.get("/", Constants.MIMETYPE_TEXT);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestTableInfoXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/" + TABLE + "/regions", MIMETYPE_XML);
|
||||
@Test
|
||||
public void testTableListXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/", Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
TableListModel model = (TableListModel)
|
||||
context.createUnmarshaller()
|
||||
.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||
checkTableList(model);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableListJSON() throws IOException {
|
||||
Response response = client.get("/", Constants.MIMETYPE_JSON);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableListPB() throws IOException, JAXBException {
|
||||
Response response = client.get("/", Constants.MIMETYPE_PROTOBUF);
|
||||
assertEquals(response.getCode(), 200);
|
||||
TableListModel model = new TableListModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
checkTableList(model);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableInfoText() throws IOException {
|
||||
Response response = client.get("/" + TABLE + "/regions",
|
||||
Constants.MIMETYPE_TEXT);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableInfoXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/" + TABLE + "/regions",
|
||||
Constants.MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
TableInfoModel model = (TableInfoModel)
|
||||
context.createUnmarshaller()
|
||||
|
@ -202,28 +220,20 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
|
|||
checkTableInfo(model);
|
||||
}
|
||||
|
||||
void doTestTableInfoJSON() throws IOException {
|
||||
Response response = client.get("/" + TABLE + "/regions", MIMETYPE_JSON);
|
||||
@Test
|
||||
public void testTableInfoJSON() throws IOException {
|
||||
Response response = client.get("/" + TABLE + "/regions",
|
||||
Constants.MIMETYPE_JSON);
|
||||
assertEquals(response.getCode(), 200);
|
||||
}
|
||||
|
||||
void doTestTableInfoPB() throws IOException, JAXBException {
|
||||
Response response =
|
||||
client.get("/" + TABLE + "/regions", MIMETYPE_PROTOBUF);
|
||||
@Test
|
||||
public void testTableInfoPB() throws IOException, JAXBException {
|
||||
Response response = client.get("/" + TABLE + "/regions",
|
||||
Constants.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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
package org.apache.hadoop.hbase.rest;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
|
@ -31,25 +32,34 @@ import org.apache.hadoop.hbase.rest.client.Cluster;
|
|||
import org.apache.hadoop.hbase.rest.client.Response;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class BROKE_TestTransform extends HBaseRESTClusterTestBase {
|
||||
static final String TABLE = "TestTransform";
|
||||
static final String CFA = "a";
|
||||
static final String CFB = "b";
|
||||
static final String COLUMN_1 = CFA + ":1";
|
||||
static final String COLUMN_2 = CFB + ":2";
|
||||
static final String ROW_1 = "testrow1";
|
||||
static final byte[] VALUE_1 = Bytes.toBytes("testvalue1");
|
||||
static final byte[] VALUE_2 = Bytes.toBytes("testvalue2");
|
||||
static final byte[] VALUE_2_BASE64 = Bytes.toBytes("dGVzdHZhbHVlMg==");
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
Client client;
|
||||
HBaseAdmin admin;
|
||||
public class TestTransform {
|
||||
private static final String TABLE = "TestTransform";
|
||||
private static final String CFA = "a";
|
||||
private static final String CFB = "b";
|
||||
private static final String COLUMN_1 = CFA + ":1";
|
||||
private static final String COLUMN_2 = CFB + ":2";
|
||||
private static final String ROW_1 = "testrow1";
|
||||
private static final byte[] VALUE_1 = Bytes.toBytes("testvalue1");
|
||||
private static final byte[] VALUE_2 = Bytes.toBytes("testvalue2");
|
||||
private static final byte[] VALUE_2_BASE64 = Bytes.toBytes("dGVzdHZhbHVlMg==");
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
admin = new HBaseAdmin(conf);
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
if (admin.tableExists(TABLE)) {
|
||||
return;
|
||||
}
|
||||
|
@ -61,22 +71,23 @@ public class BROKE_TestTransform extends HBaseRESTClusterTestBase {
|
|||
admin.createTable(htd);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransform() throws Exception {
|
||||
String path1 = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
|
||||
String path2 = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_2;
|
||||
|
||||
// store value 1
|
||||
Response response = client.put(path1, MIMETYPE_BINARY, VALUE_1);
|
||||
Response response = client.put(path1, Constants.MIMETYPE_BINARY, VALUE_1);
|
||||
assertEquals(response.getCode(), 200);
|
||||
|
||||
// store value 2 (stargate should transform into base64)
|
||||
response = client.put(path2, MIMETYPE_BINARY, VALUE_2);
|
||||
response = client.put(path2, Constants.MIMETYPE_BINARY, VALUE_2);
|
||||
assertEquals(response.getCode(), 200);
|
||||
|
||||
// get the table contents directly
|
||||
|
@ -96,7 +107,7 @@ public class BROKE_TestTransform extends HBaseRESTClusterTestBase {
|
|||
table.close();
|
||||
|
||||
// stargate should decode the transformed value back to original bytes
|
||||
response = client.get(path2, MIMETYPE_BINARY);
|
||||
response = client.get(path2, Constants.MIMETYPE_BINARY);
|
||||
assertEquals(response.getCode(), 200);
|
||||
value = response.getBody();
|
||||
assertTrue(Bytes.equals(value, VALUE_2));
|
|
@ -28,6 +28,7 @@ import javax.xml.bind.JAXBException;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.rest.client.Client;
|
||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||
import org.apache.hadoop.hbase.rest.client.Response;
|
||||
|
@ -35,34 +36,40 @@ import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel;
|
|||
import org.apache.hadoop.hbase.rest.model.VersionModel;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
public class TestVersionResource extends HBaseRESTClusterTestBase {
|
||||
static final Log LOG = LogFactory.getLog(TestVersionResource.class);
|
||||
public class TestVersionResource {
|
||||
private static final Log LOG = LogFactory.getLog(TestVersionResource.class);
|
||||
|
||||
Client client;
|
||||
JAXBContext context;
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
|
||||
public TestVersionResource() throws JAXBException {
|
||||
super();
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
context = JAXBContext.newInstance(
|
||||
VersionModel.class,
|
||||
StorageClusterVersionModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
client = new Client(new Cluster().add("localhost", testServletPort));
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
client.shutdown();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
void validate(VersionModel model) {
|
||||
private static void validate(VersionModel model) {
|
||||
assertNotNull(model);
|
||||
assertNotNull(model.getRESTVersion());
|
||||
assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
|
||||
|
@ -83,8 +90,9 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
|||
.getImplementationVersion());
|
||||
}
|
||||
|
||||
void doTestGetStargateVersionText() throws IOException {
|
||||
Response response = client.get("/version", MIMETYPE_TEXT);
|
||||
@Test
|
||||
public void testGetStargateVersionText() throws IOException {
|
||||
Response response = client.get("/version", Constants.MIMETYPE_TEXT);
|
||||
assertTrue(response.getCode() == 200);
|
||||
String body = Bytes.toString(response.getBody());
|
||||
assertTrue(body.length() > 0);
|
||||
|
@ -99,8 +107,9 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
|||
.getImplementationVersion()));
|
||||
}
|
||||
|
||||
void doTestGetStargateVersionXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/version", MIMETYPE_XML);
|
||||
@Test
|
||||
public void testGetStargateVersionXML() throws IOException, JAXBException {
|
||||
Response response = client.get("/version", Constants.MIMETYPE_XML);
|
||||
assertTrue(response.getCode() == 200);
|
||||
VersionModel model = (VersionModel)
|
||||
context.createUnmarshaller().unmarshal(
|
||||
|
@ -109,13 +118,15 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
|||
LOG.info("success retrieving Stargate version as XML");
|
||||
}
|
||||
|
||||
void doTestGetStargateVersionJSON() throws IOException {
|
||||
Response response = client.get("/version", MIMETYPE_JSON);
|
||||
@Test
|
||||
public void testGetStargateVersionJSON() throws IOException {
|
||||
Response response = client.get("/version", Constants.MIMETYPE_JSON);
|
||||
assertTrue(response.getCode() == 200);
|
||||
}
|
||||
|
||||
void doTestGetStargateVersionPB() throws IOException {
|
||||
Response response = client.get("/version", MIMETYPE_PROTOBUF);
|
||||
@Test
|
||||
public void testGetStargateVersionPB() throws IOException {
|
||||
Response response = client.get("/version", Constants.MIMETYPE_PROTOBUF);
|
||||
assertTrue(response.getCode() == 200);
|
||||
VersionModel model = new VersionModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
|
@ -123,14 +134,17 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
|||
LOG.info("success retrieving Stargate version as protobuf");
|
||||
}
|
||||
|
||||
void doTestGetStorageClusterVersionText() throws IOException {
|
||||
Response response = client.get("/version/cluster", MIMETYPE_TEXT);
|
||||
@Test
|
||||
public void testGetStorageClusterVersionText() throws IOException {
|
||||
Response response = client.get("/version/cluster",
|
||||
Constants.MIMETYPE_TEXT);
|
||||
assertTrue(response.getCode() == 200);
|
||||
}
|
||||
|
||||
void doTestGetStorageClusterVersionXML() throws IOException,
|
||||
@Test
|
||||
public void testGetStorageClusterVersionXML() throws IOException,
|
||||
JAXBException {
|
||||
Response response = client.get("/version/cluster", MIMETYPE_XML);
|
||||
Response response = client.get("/version/cluster",Constants.MIMETYPE_XML);
|
||||
assertTrue(response.getCode() == 200);
|
||||
StorageClusterVersionModel clusterVersionModel =
|
||||
(StorageClusterVersionModel)
|
||||
|
@ -141,18 +155,9 @@ public class TestVersionResource extends HBaseRESTClusterTestBase {
|
|||
LOG.info("success retrieving storage cluster version as XML");
|
||||
}
|
||||
|
||||
void doTestGetStorageClusterVersionJSON() throws IOException {
|
||||
Response response = client.get("/version/cluster", MIMETYPE_JSON);
|
||||
@Test
|
||||
public void doTestGetStorageClusterVersionJSON() throws IOException {
|
||||
Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON);
|
||||
assertTrue(response.getCode() == 200);
|
||||
}
|
||||
|
||||
public void testVersionResource() throws Exception {
|
||||
doTestGetStargateVersionText();
|
||||
doTestGetStargateVersionXML();
|
||||
doTestGetStargateVersionJSON();
|
||||
doTestGetStargateVersionPB();
|
||||
doTestGetStorageClusterVersionText();
|
||||
doTestGetStorageClusterVersionXML();
|
||||
doTestGetStorageClusterVersionJSON();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,24 @@
|
|||
|
||||
package org.apache.hadoop.hbase.rest.client;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.rest.HBaseRESTClusterTestBase;
|
||||
import org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility;
|
||||
import org.apache.hadoop.hbase.rest.client.Client;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class TestRemoteAdmin extends HBaseRESTClusterTestBase {
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
static final String TABLE_1 = "TestRemoteAdmin_Table_1";
|
||||
static final String TABLE_2 = "TestRemoteAdmin_Table_2";
|
||||
static final byte[] COLUMN_1 = Bytes.toBytes("a");
|
||||
public class TestRemoteAdmin {
|
||||
|
||||
private static final String TABLE_1 = "TestRemoteAdmin_Table_1";
|
||||
private static final String TABLE_2 = "TestRemoteAdmin_Table_2";
|
||||
private static final byte[] COLUMN_1 = Bytes.toBytes("a");
|
||||
|
||||
static final HTableDescriptor DESC_1;
|
||||
static {
|
||||
|
@ -44,17 +50,20 @@ public class TestRemoteAdmin extends HBaseRESTClusterTestBase {
|
|||
DESC_2.addFamily(new HColumnDescriptor(COLUMN_1));
|
||||
}
|
||||
|
||||
Client client;
|
||||
HBaseAdmin localAdmin;
|
||||
RemoteAdmin remoteAdmin;
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static HBaseAdmin localAdmin;
|
||||
private static RemoteAdmin remoteAdmin;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
localAdmin = new HBaseAdmin(conf);
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
localAdmin = TEST_UTIL.getHBaseAdmin();
|
||||
remoteAdmin = new RemoteAdmin(new Client(
|
||||
new Cluster().add("localhost", testServletPort)),
|
||||
conf);
|
||||
new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())),
|
||||
TEST_UTIL.getConfiguration());
|
||||
if (localAdmin.tableExists(TABLE_1)) {
|
||||
localAdmin.disableTable(TABLE_1);
|
||||
localAdmin.deleteTable(TABLE_1);
|
||||
|
@ -64,17 +73,20 @@ public class TestRemoteAdmin extends HBaseRESTClusterTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
assertFalse(remoteAdmin.isTableAvailable(TABLE_1));
|
||||
remoteAdmin.createTable(DESC_1);
|
||||
assertTrue(remoteAdmin.isTableAvailable(TABLE_1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTable() throws Exception {
|
||||
assertTrue(remoteAdmin.isTableAvailable(TABLE_2));
|
||||
remoteAdmin.deleteTable(TABLE_2);
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.KeyValue;
|
||||
|
@ -37,51 +38,57 @@ import org.apache.hadoop.hbase.client.Put;
|
|||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||
import org.apache.hadoop.hbase.client.Scan;
|
||||
import org.apache.hadoop.hbase.rest.HBaseRESTClusterTestBase;
|
||||
import org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility;
|
||||
import org.apache.hadoop.hbase.rest.client.Client;
|
||||
import org.apache.hadoop.hbase.rest.client.Cluster;
|
||||
import org.apache.hadoop.hbase.rest.client.RemoteHTable;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class TestRemoteTable extends HBaseRESTClusterTestBase {
|
||||
private static final Log LOG = LogFactory.getLog(HBaseRESTClusterTestBase.class);
|
||||
static final String TABLE = "TestRemoteTable";
|
||||
static final byte[] ROW_1 = Bytes.toBytes("testrow1");
|
||||
static final byte[] ROW_2 = Bytes.toBytes("testrow2");
|
||||
static final byte[] ROW_3 = Bytes.toBytes("testrow3");
|
||||
static final byte[] ROW_4 = Bytes.toBytes("testrow4");
|
||||
static final byte[] COLUMN_1 = Bytes.toBytes("a");
|
||||
static final byte[] COLUMN_2 = Bytes.toBytes("b");
|
||||
static final byte[] COLUMN_3 = Bytes.toBytes("c");
|
||||
static final byte[] QUALIFIER_1 = Bytes.toBytes("1");
|
||||
static final byte[] QUALIFIER_2 = Bytes.toBytes("2");
|
||||
static final byte[] QUALIFIER_3 = Bytes.toBytes("3");
|
||||
static final byte[] VALUE_1 = Bytes.toBytes("testvalue1");
|
||||
static final byte[] VALUE_2 = Bytes.toBytes("testvalue2");
|
||||
static final byte[] VALUE_3 = Bytes.toBytes("testvalue3");
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
static final long ONE_HOUR = 60 * 60 * 1000;
|
||||
static final long TS_2 = System.currentTimeMillis();
|
||||
static final long TS_1 = TS_2 - ONE_HOUR;
|
||||
public class TestRemoteTable {
|
||||
private static final Log LOG = LogFactory.getLog(TestRemoteTable.class);
|
||||
private static final String TABLE = "TestRemoteTable";
|
||||
private static final byte[] ROW_1 = Bytes.toBytes("testrow1");
|
||||
private static final byte[] ROW_2 = Bytes.toBytes("testrow2");
|
||||
private static final byte[] ROW_3 = Bytes.toBytes("testrow3");
|
||||
private static final byte[] ROW_4 = Bytes.toBytes("testrow4");
|
||||
private static final byte[] COLUMN_1 = Bytes.toBytes("a");
|
||||
private static final byte[] COLUMN_2 = Bytes.toBytes("b");
|
||||
private static final byte[] COLUMN_3 = Bytes.toBytes("c");
|
||||
private static final byte[] QUALIFIER_1 = Bytes.toBytes("1");
|
||||
private static final byte[] QUALIFIER_2 = Bytes.toBytes("2");
|
||||
private static final byte[] VALUE_1 = Bytes.toBytes("testvalue1");
|
||||
private static final byte[] VALUE_2 = Bytes.toBytes("testvalue2");
|
||||
|
||||
Client client;
|
||||
HBaseAdmin admin;
|
||||
RemoteHTable remoteTable;
|
||||
private static final long ONE_HOUR = 60 * 60 * 1000;
|
||||
private static final long TS_2 = System.currentTimeMillis();
|
||||
private static final long TS_1 = TS_2 - ONE_HOUR;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||
new HBaseRESTTestingUtility(TEST_UTIL.getConfiguration());
|
||||
private static RemoteHTable remoteTable;
|
||||
|
||||
admin = new HBaseAdmin(conf);
|
||||
LOG.info("Admin Connection=" + admin.getConnection() + ", " + admin.getConnection().getZooKeeperWatcher());
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
REST_TEST_UTIL.startServletContainer();
|
||||
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
|
||||
LOG.info("Admin Connection=" + admin.getConnection() + ", " +
|
||||
admin.getConnection().getZooKeeperWatcher());
|
||||
if (!admin.tableExists(TABLE)) {
|
||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||
htd.addFamily(new HColumnDescriptor(COLUMN_1));
|
||||
htd.addFamily(new HColumnDescriptor(COLUMN_2));
|
||||
htd.addFamily(new HColumnDescriptor(COLUMN_3));
|
||||
admin.createTable(htd);
|
||||
HTable table = new HTable(conf, TABLE);
|
||||
LOG.info("Table connection=" + table.getConnection() + ", " + admin.getConnection().getZooKeeperWatcher());
|
||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE);
|
||||
LOG.info("Table connection=" + table.getConnection() + ", " +
|
||||
admin.getConnection().getZooKeeperWatcher());
|
||||
Put put = new Put(ROW_1);
|
||||
put.add(COLUMN_1, QUALIFIER_1, TS_2, VALUE_1);
|
||||
table.put(put);
|
||||
|
@ -93,21 +100,26 @@ public class TestRemoteTable extends HBaseRESTClusterTestBase {
|
|||
table.flushCommits();
|
||||
}
|
||||
remoteTable = new RemoteHTable(
|
||||
new Client(new Cluster().add("localhost", testServletPort)),
|
||||
conf, TABLE, null);
|
||||
new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort())),
|
||||
TEST_UTIL.getConfiguration(), TABLE, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
remoteTable.close();
|
||||
super.tearDown();
|
||||
REST_TEST_UTIL.shutdownServletContainer();
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableDescriptor() throws IOException {
|
||||
HTableDescriptor local = new HTable(conf, TABLE).getTableDescriptor();
|
||||
HTableDescriptor local = new HTable(TEST_UTIL.getConfiguration(),
|
||||
TABLE).getTableDescriptor();
|
||||
assertEquals(remoteTable.getTableDescriptor(), local);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() throws IOException {
|
||||
Get get = new Get(ROW_1);
|
||||
Result result = remoteTable.get(get);
|
||||
|
@ -210,6 +222,7 @@ public class TestRemoteTable extends HBaseRESTClusterTestBase {
|
|||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPut() throws IOException {
|
||||
Put put = new Put(ROW_3);
|
||||
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||
|
|
Loading…
Reference in New Issue