HBASE-23623 Reduced the number of Checkstyle violations in hbase-rest
Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
9d4ea24db5
commit
02d80b240b
@ -305,10 +305,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
return totalRows;
|
return totalRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getClients() {
|
|
||||||
return clients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFlushCommits() {
|
public boolean isFlushCommits() {
|
||||||
return flushCommits;
|
return flushCommits;
|
||||||
}
|
}
|
||||||
@ -486,11 +482,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void map(NullWritable key, PeInputSplit value, final Context context)
|
protected void map(NullWritable key, PeInputSplit value, final Context context)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
Status status = new Status() {
|
Status status = new Status() {
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(String msg) {
|
public void setStatus(String msg) {
|
||||||
context.setStatus(msg);
|
context.setStatus(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -631,7 +627,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
perClientRows, R,
|
perClientRows, R,
|
||||||
flushCommits, writeToWAL, useTags, noOfTags, connection, new Status() {
|
flushCommits, writeToWAL, useTags, noOfTags, connection, new Status() {
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(final String msg) throws IOException {
|
public void setStatus(final String msg) {
|
||||||
LOG.info("client-" + getName() + " " + msg);
|
LOG.info("client-" + getName() + " " + msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -781,7 +777,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
private int startRow;
|
private int startRow;
|
||||||
private int perClientRunRows;
|
private int perClientRunRows;
|
||||||
private int totalRows;
|
private int totalRows;
|
||||||
private int numClientThreads;
|
|
||||||
private TableName tableName;
|
private TableName tableName;
|
||||||
private boolean flushCommits;
|
private boolean flushCommits;
|
||||||
private boolean writeToWAL;
|
private boolean writeToWAL;
|
||||||
@ -789,13 +784,12 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
private int noOfTags;
|
private int noOfTags;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
TestOptions(int startRow, int perClientRunRows, int totalRows, int numClientThreads,
|
TestOptions(int startRow, int perClientRunRows, int totalRows, TableName tableName,
|
||||||
TableName tableName, boolean flushCommits, boolean writeToWAL, boolean useTags,
|
boolean flushCommits, boolean writeToWAL, boolean useTags,
|
||||||
int noOfTags, Connection connection) {
|
int noOfTags, Connection connection) {
|
||||||
this.startRow = startRow;
|
this.startRow = startRow;
|
||||||
this.perClientRunRows = perClientRunRows;
|
this.perClientRunRows = perClientRunRows;
|
||||||
this.totalRows = totalRows;
|
this.totalRows = totalRows;
|
||||||
this.numClientThreads = numClientThreads;
|
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
this.flushCommits = flushCommits;
|
this.flushCommits = flushCommits;
|
||||||
this.writeToWAL = writeToWAL;
|
this.writeToWAL = writeToWAL;
|
||||||
@ -816,10 +810,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
return totalRows;
|
return totalRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumClientThreads() {
|
|
||||||
return numClientThreads;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableName getTableName() {
|
public TableName getTableName() {
|
||||||
return tableName;
|
return tableName;
|
||||||
}
|
}
|
||||||
@ -1286,7 +1276,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
long totalElapsedTime;
|
long totalElapsedTime;
|
||||||
|
|
||||||
TestOptions options = new TestOptions(startRow, perClientRunRows,
|
TestOptions options = new TestOptions(startRow, perClientRunRows,
|
||||||
totalRows, N, tableName, flushCommits, writeToWAL, useTags, noOfTags, connection);
|
totalRows, tableName, flushCommits, writeToWAL, useTags, noOfTags, connection);
|
||||||
final Test t;
|
final Test t;
|
||||||
try {
|
try {
|
||||||
Constructor<? extends Test> constructor = cmd.getDeclaredConstructor(
|
Constructor<? extends Test> constructor = cmd.getDeclaredConstructor(
|
||||||
@ -1310,7 +1300,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
|||||||
private void runNIsOne(final Class<? extends Test> cmd) {
|
private void runNIsOne(final Class<? extends Test> cmd) {
|
||||||
Status status = new Status() {
|
Status status = new Status() {
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(String msg) throws IOException {
|
public void setStatus(String msg) {
|
||||||
LOG.info(msg);
|
LOG.info(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.rest;
|
package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@ -46,7 +45,6 @@ import org.junit.experimental.categories.Category;
|
|||||||
|
|
||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestGetAndPutResource extends RowResourceBase {
|
public class TestGetAndPutResource extends RowResourceBase {
|
||||||
|
|
||||||
private static final MetricsAssertHelper METRICS_ASSERT =
|
private static final MetricsAssertHelper METRICS_ASSERT =
|
||||||
CompatibilityFactory.getInstance(MetricsAssertHelper.class);
|
CompatibilityFactory.getInstance(MetricsAssertHelper.class);
|
||||||
|
|
||||||
@ -110,7 +108,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
public void testSingleCellGetPutPB() throws IOException, JAXBException {
|
public void testSingleCellGetPutPB() throws IOException, JAXBException {
|
||||||
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
||||||
assertEquals(404, response.getCode());
|
assertEquals(404, response.getCode());
|
||||||
|
|
||||||
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
|
||||||
@ -130,7 +128,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleCellCheckPutPB() throws IOException, JAXBException {
|
public void testMultipleCellCheckPutPB() throws IOException {
|
||||||
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
||||||
assertEquals(404, response.getCode());
|
assertEquals(404, response.getCode());
|
||||||
|
|
||||||
@ -143,7 +141,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
|
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
|
||||||
|
|
||||||
HashMap<String,String> otherCells = new HashMap<String, String>();
|
HashMap<String,String> otherCells = new HashMap<>();
|
||||||
otherCells.put(COLUMN_2,VALUE_3);
|
otherCells.put(COLUMN_2,VALUE_3);
|
||||||
|
|
||||||
// On Success update both the cells
|
// On Success update both the cells
|
||||||
@ -176,7 +174,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
|
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
|
||||||
|
|
||||||
HashMap<String,String> otherCells = new HashMap<String, String>();
|
HashMap<String,String> otherCells = new HashMap<>();
|
||||||
otherCells.put(COLUMN_2,VALUE_3);
|
otherCells.put(COLUMN_2,VALUE_3);
|
||||||
|
|
||||||
// On Success update both the cells
|
// On Success update both the cells
|
||||||
@ -196,7 +194,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
|
public void testMultipleCellCheckDeletePB() throws IOException {
|
||||||
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
|
||||||
assertEquals(404, response.getCode());
|
assertEquals(404, response.getCode());
|
||||||
|
|
||||||
@ -214,7 +212,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
|
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
|
||||||
|
|
||||||
// Deletes the following columns based on Column1 check
|
// Deletes the following columns based on Column1 check
|
||||||
HashMap<String,String> cellsToDelete = new HashMap<String, String>();
|
HashMap<String,String> cellsToDelete = new HashMap<>();
|
||||||
cellsToDelete.put(COLUMN_2,VALUE_2); // Value does not matter
|
cellsToDelete.put(COLUMN_2,VALUE_2); // Value does not matter
|
||||||
cellsToDelete.put(COLUMN_3,VALUE_3); // Value does not matter
|
cellsToDelete.put(COLUMN_3,VALUE_3); // Value does not matter
|
||||||
|
|
||||||
@ -249,7 +247,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleCellGetPutBinary() throws IOException {
|
public void testSingleCellGetPutBinary() throws IOException {
|
||||||
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
|
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
|
||||||
final byte[] body = Bytes.toBytes(VALUE_3);
|
final byte[] body = Bytes.toBytes(VALUE_3);
|
||||||
@ -275,7 +273,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleCellGetJSON() throws IOException, JAXBException {
|
public void testSingleCellGetJSON() throws IOException {
|
||||||
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
||||||
Response response = client.put(path, Constants.MIMETYPE_BINARY,
|
Response response = client.put(path, Constants.MIMETYPE_BINARY,
|
||||||
Bytes.toBytes(VALUE_4));
|
Bytes.toBytes(VALUE_4));
|
||||||
@ -289,7 +287,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLatestCellGetJSON() throws IOException, JAXBException {
|
public void testLatestCellGetJSON() throws IOException {
|
||||||
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
||||||
CellSetModel cellSetModel = new CellSetModel();
|
CellSetModel cellSetModel = new CellSetModel();
|
||||||
RowModel rowModel = new RowModel(ROW_4);
|
RowModel rowModel = new RowModel(ROW_4);
|
||||||
@ -336,7 +334,7 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoSuchCF() throws IOException, JAXBException {
|
public void testNoSuchCF() throws IOException {
|
||||||
final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
|
final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
|
||||||
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
|
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
|
||||||
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
|
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
|
||||||
@ -524,9 +522,9 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
response = deleteRow(TABLE, ROW_2);
|
response = deleteRow(TABLE, ROW_2);
|
||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetrics() throws IOException, JAXBException {
|
public void testMetrics() throws IOException {
|
||||||
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
|
||||||
Response response = client.put(path, Constants.MIMETYPE_BINARY,
|
Response response = client.put(path, Constants.MIMETYPE_BINARY,
|
||||||
Bytes.toBytes(VALUE_4));
|
Bytes.toBytes(VALUE_4));
|
||||||
@ -539,19 +537,19 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
|
|
||||||
UserProvider userProvider = UserProvider.instantiate(conf);
|
UserProvider userProvider = UserProvider.instantiate(conf);
|
||||||
METRICS_ASSERT.assertCounterGt("requests", 2l,
|
METRICS_ASSERT.assertCounterGt("requests", 2L,
|
||||||
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
||||||
|
|
||||||
METRICS_ASSERT.assertCounterGt("successfulGet", 0l,
|
METRICS_ASSERT.assertCounterGt("successfulGet", 0L,
|
||||||
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
||||||
|
|
||||||
METRICS_ASSERT.assertCounterGt("successfulPut", 0l,
|
METRICS_ASSERT.assertCounterGt("successfulPut", 0L,
|
||||||
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
||||||
|
|
||||||
METRICS_ASSERT.assertCounterGt("successfulDelete", 0l,
|
METRICS_ASSERT.assertCounterGt("successfulDelete", 0L,
|
||||||
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiColumnGetXML() throws Exception {
|
public void testMultiColumnGetXML() throws Exception {
|
||||||
String path = "/" + TABLE + "/fakerow";
|
String path = "/" + TABLE + "/fakerow";
|
||||||
@ -575,8 +573,8 @@ public class TestGetAndPutResource extends RowResourceBase {
|
|||||||
path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "," + COLUMN_2 + "," + COLUMN_3;
|
path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "," + COLUMN_2 + "," + COLUMN_3;
|
||||||
response = client.get(path, Constants.MIMETYPE_XML);
|
response = client.get(path, Constants.MIMETYPE_XML);
|
||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response
|
CellSetModel cellSet =
|
||||||
.getBody()));
|
(CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
|
||||||
assertTrue(cellSet.getRows().size() == 1);
|
assertTrue(cellSet.getRows().size() == 1);
|
||||||
assertTrue(cellSet.getRows().get(0).getCells().size() == 3);
|
assertTrue(cellSet.getRows().get(0).getCells().size() == 3);
|
||||||
List<CellModel> cells = cellSet.getRows().get(0).getCells();
|
List<CellModel> cells = cellSet.getRows().get(0).getCells();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
@ -18,6 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.rest;
|
package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -51,8 +55,6 @@ import org.apache.hadoop.hbase.rest.provider.JacksonProvider;
|
|||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -61,13 +63,13 @@ import org.junit.experimental.categories.Category;
|
|||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestNamespacesInstanceResource {
|
public class TestNamespacesInstanceResource {
|
||||||
private static String NAMESPACE1 = "TestNamespacesInstanceResource1";
|
private static String NAMESPACE1 = "TestNamespacesInstanceResource1";
|
||||||
private static Map<String,String> NAMESPACE1_PROPS = new HashMap<String,String>();
|
private static Map<String,String> NAMESPACE1_PROPS = new HashMap<>();
|
||||||
private static String NAMESPACE2 = "TestNamespacesInstanceResource2";
|
private static String NAMESPACE2 = "TestNamespacesInstanceResource2";
|
||||||
private static Map<String,String> NAMESPACE2_PROPS = new HashMap<String,String>();
|
private static Map<String,String> NAMESPACE2_PROPS = new HashMap<>();
|
||||||
private static String NAMESPACE3 = "TestNamespacesInstanceResource3";
|
private static String NAMESPACE3 = "TestNamespacesInstanceResource3";
|
||||||
private static Map<String,String> NAMESPACE3_PROPS = new HashMap<String,String>();
|
private static Map<String,String> NAMESPACE3_PROPS = new HashMap<>();
|
||||||
private static String NAMESPACE4 = "TestNamespacesInstanceResource4";
|
private static String NAMESPACE4 = "TestNamespacesInstanceResource4";
|
||||||
private static Map<String,String> NAMESPACE4_PROPS = new HashMap<String,String>();
|
private static Map<String,String> NAMESPACE4_PROPS = new HashMap<>();
|
||||||
|
|
||||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||||
@ -87,8 +89,8 @@ public class TestNamespacesInstanceResource {
|
|||||||
REST_TEST_UTIL.getServletPort()));
|
REST_TEST_UTIL.getServletPort()));
|
||||||
testNamespacesInstanceModel = new TestNamespacesInstanceModel();
|
testNamespacesInstanceModel = new TestNamespacesInstanceModel();
|
||||||
context = JAXBContext.newInstance(NamespacesInstanceModel.class, TableListModel.class);
|
context = JAXBContext.newInstance(NamespacesInstanceModel.class, TableListModel.class);
|
||||||
jsonMapper = new JacksonProvider()
|
jsonMapper = new JacksonProvider().locateMapper(NamespacesInstanceModel.class,
|
||||||
.locateMapper(NamespacesInstanceModel.class, MediaType.APPLICATION_JSON_TYPE);
|
MediaType.APPLICATION_JSON_TYPE);
|
||||||
NAMESPACE1_PROPS.put("key1", "value1");
|
NAMESPACE1_PROPS.put("key1", "value1");
|
||||||
NAMESPACE2_PROPS.put("key2a", "value2a");
|
NAMESPACE2_PROPS.put("key2a", "value2a");
|
||||||
NAMESPACE2_PROPS.put("key2b", "value2b");
|
NAMESPACE2_PROPS.put("key2b", "value2b");
|
||||||
@ -117,9 +119,9 @@ public class TestNamespacesInstanceResource {
|
|||||||
|
|
||||||
private NamespaceDescriptor findNamespace(Admin admin, String namespaceName) throws IOException{
|
private NamespaceDescriptor findNamespace(Admin admin, String namespaceName) throws IOException{
|
||||||
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
|
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
|
||||||
for(int i = 0; i < nd.length; i++){
|
for (NamespaceDescriptor namespaceDescriptor : nd) {
|
||||||
if(nd[i].getName().equals(namespaceName)){
|
if (namespaceDescriptor.getName().equals(namespaceName)) {
|
||||||
return nd[i];
|
return namespaceDescriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -129,18 +131,18 @@ public class TestNamespacesInstanceResource {
|
|||||||
checkNamespaceProperties(nd.getConfiguration(), testProps);
|
checkNamespaceProperties(nd.getConfiguration(), testProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNamespaceProperties(Map<String,String> namespaceProps,
|
private void checkNamespaceProperties(Map<String,String> namespaceProps,
|
||||||
Map<String,String> testProps){
|
Map<String,String> testProps){
|
||||||
assertTrue(namespaceProps.size() == testProps.size());
|
assertTrue(namespaceProps.size() == testProps.size());
|
||||||
for(String key: testProps.keySet()){
|
for (String key: testProps.keySet()) {
|
||||||
assertEquals(testProps.get(key), namespaceProps.get(key));
|
assertEquals(testProps.get(key), namespaceProps.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNamespaceTables(List<TableModel> namespaceTables, List<String> testTables){
|
private void checkNamespaceTables(List<TableModel> namespaceTables, List<String> testTables){
|
||||||
assertEquals(namespaceTables.size(), testTables.size());
|
assertEquals(namespaceTables.size(), testTables.size());
|
||||||
for(int i = 0 ; i < namespaceTables.size() ; i++){
|
for (TableModel namespaceTable : namespaceTables) {
|
||||||
String tableName = ((TableModel) namespaceTables.get(i)).getName();
|
String tableName = namespaceTable.getName();
|
||||||
assertTrue(testTables.contains(tableName));
|
assertTrue(testTables.contains(tableName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +176,7 @@ public class TestNamespacesInstanceResource {
|
|||||||
|
|
||||||
// Create namespace via admin.
|
// Create namespace via admin.
|
||||||
NamespaceDescriptor.Builder nsBuilder = NamespaceDescriptor.create(nsName);
|
NamespaceDescriptor.Builder nsBuilder = NamespaceDescriptor.create(nsName);
|
||||||
NamespaceDescriptor nsd = nsBuilder.build();
|
NamespaceDescriptor nsd = nsBuilder.build();
|
||||||
nsd.setConfiguration("key1", "value1");
|
nsd.setConfiguration("key1", "value1");
|
||||||
admin.createNamespace(nsd);
|
admin.createNamespace(nsd);
|
||||||
|
|
||||||
@ -189,7 +191,7 @@ public class TestNamespacesInstanceResource {
|
|||||||
table.addFamily(colDesc);
|
table.addFamily(colDesc);
|
||||||
admin.createTable(table);
|
admin.createTable(table);
|
||||||
|
|
||||||
Map<String, String> nsProperties = new HashMap<String,String>();
|
Map<String, String> nsProperties = new HashMap<>();
|
||||||
nsProperties.put("key1", "value1");
|
nsProperties.put("key1", "value1");
|
||||||
List<String> nsTables = Arrays.asList("table1", "table2");
|
List<String> nsTables = Arrays.asList("table1", "table2");
|
||||||
|
|
||||||
@ -357,7 +359,7 @@ public class TestNamespacesInstanceResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBException {
|
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException {
|
||||||
String namespacePath3 = "/namespaces/" + NAMESPACE3;
|
String namespacePath3 = "/namespaces/" + NAMESPACE3;
|
||||||
String namespacePath4 = "/namespaces/" + NAMESPACE4;
|
String namespacePath4 = "/namespaces/" + NAMESPACE4;
|
||||||
NamespacesInstanceModel model3;
|
NamespacesInstanceModel model3;
|
||||||
@ -412,7 +414,7 @@ public class TestNamespacesInstanceResource {
|
|||||||
// Check cannot post tables that already exist.
|
// Check cannot post tables that already exist.
|
||||||
response = client.post(namespacePath3, Constants.MIMETYPE_BINARY, new byte[]{});
|
response = client.post(namespacePath3, Constants.MIMETYPE_BINARY, new byte[]{});
|
||||||
assertEquals(403, response.getCode());
|
assertEquals(403, response.getCode());
|
||||||
response = client.post(namespacePath4, Constants.MIMETYPE_PROTOBUF,
|
response = client.post(namespacePath4, Constants.MIMETYPE_PROTOBUF,
|
||||||
model4.createProtobufOutput());
|
model4.createProtobufOutput());
|
||||||
assertEquals(403, response.getCode());
|
assertEquals(403, response.getCode());
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
@ -18,6 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.rest;
|
package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -36,8 +38,6 @@ import org.apache.hadoop.hbase.rest.model.TestNamespacesModel;
|
|||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -79,8 +79,8 @@ public class TestNamespacesResource {
|
|||||||
|
|
||||||
private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOException {
|
private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOException {
|
||||||
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
|
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
|
||||||
for(int i = 0; i < nd.length; i++) {
|
for (NamespaceDescriptor namespaceDescriptor : nd) {
|
||||||
if(nd[i].getName().equals(namespaceName)) {
|
if (namespaceDescriptor.getName().equals(namespaceName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ public class TestNamespacesResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamespaceListPBandDefault() throws IOException, JAXBException {
|
public void testNamespaceListPBandDefault() throws IOException {
|
||||||
String schemaPath = "/namespaces/";
|
String schemaPath = "/namespaces/";
|
||||||
NamespacesModel model;
|
NamespacesModel model;
|
||||||
Response response;
|
Response response;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/package org.apache.hadoop.hbase.rest;
|
*/
|
||||||
|
package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@ -91,7 +92,8 @@ public class TestScannersWithLabels {
|
|||||||
private static Unmarshaller unmarshaller;
|
private static Unmarshaller unmarshaller;
|
||||||
private static Configuration conf;
|
private static Configuration conf;
|
||||||
|
|
||||||
private static int insertData(TableName tableName, String column, double prob) throws IOException {
|
private static int insertData(TableName tableName, String column, double prob)
|
||||||
|
throws IOException {
|
||||||
byte[] k = new byte[3];
|
byte[] k = new byte[3];
|
||||||
byte[][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column));
|
byte[][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column));
|
||||||
|
|
||||||
@ -177,6 +179,7 @@ public class TestScannersWithLabels {
|
|||||||
};
|
};
|
||||||
SUPERUSER.runAs(action);
|
SUPERUSER.runAs(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setAuths() throws Exception {
|
private static void setAuths() throws Exception {
|
||||||
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
|
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
|
||||||
try (Connection conn = ConnectionFactory.createConnection(conf)) {
|
try (Connection conn = ConnectionFactory.createConnection(conf)) {
|
||||||
@ -185,6 +188,7 @@ public class TestScannersWithLabels {
|
|||||||
throw new IOException(t);
|
throw new IOException(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException {
|
public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException {
|
||||||
final int BATCH_SIZE = 5;
|
final int BATCH_SIZE = 5;
|
||||||
@ -237,5 +241,4 @@ public class TestScannersWithLabels {
|
|||||||
.getBody()));
|
.getBody()));
|
||||||
assertEquals(5, countCellSet(cellSet));
|
assertEquals(5, countCellSet(cellSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
@ -16,9 +15,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.rest;
|
package org.apache.hadoop.hbase.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@ -44,8 +46,6 @@ import org.apache.hadoop.hbase.rest.model.TableSchemaModel;
|
|||||||
import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
|
import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -67,7 +67,7 @@ public class TestSchemaResource {
|
|||||||
private static Configuration conf;
|
private static Configuration conf;
|
||||||
private static TestTableSchemaModel testTableSchemaModel;
|
private static TestTableSchemaModel testTableSchemaModel;
|
||||||
private static Header extraHdr = null;
|
private static Header extraHdr = null;
|
||||||
|
|
||||||
private static boolean csrfEnabled = true;
|
private static boolean csrfEnabled = true;
|
||||||
|
|
||||||
@Parameterized.Parameters
|
@Parameterized.Parameters
|
||||||
@ -130,27 +130,27 @@ public class TestSchemaResource {
|
|||||||
if (csrfEnabled) {
|
if (csrfEnabled) {
|
||||||
// test put operation is forbidden without custom header
|
// test put operation is forbidden without custom header
|
||||||
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model));
|
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model));
|
||||||
assertEquals(response.getCode(), 400);
|
assertEquals(400, response.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model), extraHdr);
|
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model), extraHdr);
|
||||||
assertEquals(response.getCode(), 201);
|
assertEquals(201, response.getCode());
|
||||||
|
|
||||||
// recall the same put operation but in read-only mode
|
// recall the same put operation but in read-only mode
|
||||||
conf.set("hbase.rest.readonly", "true");
|
conf.set("hbase.rest.readonly", "true");
|
||||||
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model), extraHdr);
|
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model), extraHdr);
|
||||||
assertEquals(response.getCode(), 403);
|
assertEquals(403, response.getCode());
|
||||||
|
|
||||||
// retrieve the schema and validate it
|
// retrieve the schema and validate it
|
||||||
response = client.get(schemaPath, Constants.MIMETYPE_XML);
|
response = client.get(schemaPath, Constants.MIMETYPE_XML);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(200, response.getCode());
|
||||||
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
|
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
|
||||||
model = fromXML(response.getBody());
|
model = fromXML(response.getBody());
|
||||||
testTableSchemaModel.checkModel(model, TABLE1);
|
testTableSchemaModel.checkModel(model, TABLE1);
|
||||||
|
|
||||||
// with json retrieve the schema and validate it
|
// with json retrieve the schema and validate it
|
||||||
response = client.get(schemaPath, Constants.MIMETYPE_JSON);
|
response = client.get(schemaPath, Constants.MIMETYPE_JSON);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(200, response.getCode());
|
||||||
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
|
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
|
||||||
model = testTableSchemaModel.fromJSON(Bytes.toString(response.getBody()));
|
model = testTableSchemaModel.fromJSON(Bytes.toString(response.getBody()));
|
||||||
testTableSchemaModel.checkModel(model, TABLE1);
|
testTableSchemaModel.checkModel(model, TABLE1);
|
||||||
@ -163,19 +163,19 @@ public class TestSchemaResource {
|
|||||||
|
|
||||||
// test delete schema operation is forbidden in read-only mode
|
// test delete schema operation is forbidden in read-only mode
|
||||||
response = client.delete(schemaPath, extraHdr);
|
response = client.delete(schemaPath, extraHdr);
|
||||||
assertEquals(response.getCode(), 403);
|
assertEquals(403, response.getCode());
|
||||||
|
|
||||||
// return read-only setting back to default
|
// return read-only setting back to default
|
||||||
conf.set("hbase.rest.readonly", "false");
|
conf.set("hbase.rest.readonly", "false");
|
||||||
|
|
||||||
// delete the table and make sure HBase concurs
|
// delete the table and make sure HBase concurs
|
||||||
response = client.delete(schemaPath, extraHdr);
|
response = client.delete(schemaPath, extraHdr);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(200, response.getCode());
|
||||||
assertFalse(admin.tableExists(TableName.valueOf(TABLE1)));
|
assertFalse(admin.tableExists(TableName.valueOf(TABLE1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
|
public void testTableCreateAndDeletePB() throws IOException {
|
||||||
String schemaPath = "/" + TABLE2 + "/schema";
|
String schemaPath = "/" + TABLE2 + "/schema";
|
||||||
TableSchemaModel model;
|
TableSchemaModel model;
|
||||||
Response response;
|
Response response;
|
||||||
@ -190,22 +190,22 @@ public class TestSchemaResource {
|
|||||||
if (csrfEnabled) {
|
if (csrfEnabled) {
|
||||||
// test put operation is forbidden without custom header
|
// test put operation is forbidden without custom header
|
||||||
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
|
||||||
assertEquals(response.getCode(), 400);
|
assertEquals(400, response.getCode());
|
||||||
}
|
}
|
||||||
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
|
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
|
||||||
model.createProtobufOutput(), extraHdr);
|
model.createProtobufOutput(), extraHdr);
|
||||||
assertEquals(response.getCode(), 201);
|
assertEquals(201, response.getCode());
|
||||||
|
|
||||||
// recall the same put operation but in read-only mode
|
// recall the same put operation but in read-only mode
|
||||||
conf.set("hbase.rest.readonly", "true");
|
conf.set("hbase.rest.readonly", "true");
|
||||||
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
|
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
|
||||||
model.createProtobufOutput(), extraHdr);
|
model.createProtobufOutput(), extraHdr);
|
||||||
assertNotNull(extraHdr);
|
assertNotNull(extraHdr);
|
||||||
assertEquals(response.getCode(), 403);
|
assertEquals(403, response.getCode());
|
||||||
|
|
||||||
// retrieve the schema and validate it
|
// retrieve the schema and validate it
|
||||||
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
|
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(200, response.getCode());
|
||||||
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
|
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
|
||||||
model = new TableSchemaModel();
|
model = new TableSchemaModel();
|
||||||
model.getObjectFromMessage(response.getBody());
|
model.getObjectFromMessage(response.getBody());
|
||||||
@ -213,7 +213,7 @@ public class TestSchemaResource {
|
|||||||
|
|
||||||
// retrieve the schema and validate it with alternate pbuf type
|
// retrieve the schema and validate it with alternate pbuf type
|
||||||
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF_IETF);
|
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF_IETF);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(200, response.getCode());
|
||||||
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
|
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
|
||||||
model = new TableSchemaModel();
|
model = new TableSchemaModel();
|
||||||
model.getObjectFromMessage(response.getBody());
|
model.getObjectFromMessage(response.getBody());
|
||||||
@ -227,16 +227,14 @@ public class TestSchemaResource {
|
|||||||
|
|
||||||
// test delete schema operation is forbidden in read-only mode
|
// test delete schema operation is forbidden in read-only mode
|
||||||
response = client.delete(schemaPath, extraHdr);
|
response = client.delete(schemaPath, extraHdr);
|
||||||
assertEquals(response.getCode(), 403);
|
assertEquals(403, response.getCode());
|
||||||
|
|
||||||
// return read-only setting back to default
|
// return read-only setting back to default
|
||||||
conf.set("hbase.rest.readonly", "false");
|
conf.set("hbase.rest.readonly", "false");
|
||||||
|
|
||||||
// delete the table and make sure HBase concurs
|
// delete the table and make sure HBase concurs
|
||||||
response = client.delete(schemaPath, extraHdr);
|
response = client.delete(schemaPath, extraHdr);
|
||||||
assertEquals(response.getCode(), 200);
|
assertEquals(200, response.getCode());
|
||||||
assertFalse(admin.tableExists(TableName.valueOf(TABLE2)));
|
assertFalse(admin.tableExists(TableName.valueOf(TABLE2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,13 +47,11 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.client.Admin;
|
import org.apache.hadoop.hbase.client.Admin;
|
||||||
import org.apache.hadoop.hbase.filter.Filter;
|
import org.apache.hadoop.hbase.filter.Filter;
|
||||||
@ -66,6 +64,7 @@ import org.apache.hadoop.hbase.rest.model.CellModel;
|
|||||||
import org.apache.hadoop.hbase.rest.model.CellSetModel;
|
import org.apache.hadoop.hbase.rest.model.CellSetModel;
|
||||||
import org.apache.hadoop.hbase.rest.model.RowModel;
|
import org.apache.hadoop.hbase.rest.model.RowModel;
|
||||||
import org.apache.hadoop.hbase.rest.provider.JacksonProvider;
|
import org.apache.hadoop.hbase.rest.provider.JacksonProvider;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@ -76,7 +75,6 @@ import org.xml.sax.XMLReader;
|
|||||||
|
|
||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestTableScan {
|
public class TestTableScan {
|
||||||
|
|
||||||
private static final TableName TABLE = TableName.valueOf("TestScanResource");
|
private static final TableName TABLE = TableName.valueOf("TestScanResource");
|
||||||
private static final String CFA = "a";
|
private static final String CFA = "a";
|
||||||
private static final String CFB = "b";
|
private static final String CFB = "b";
|
||||||
@ -96,7 +94,7 @@ public class TestTableScan {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
conf = TEST_UTIL.getConfiguration();
|
conf = TEST_UTIL.getConfiguration();
|
||||||
conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.class.getName());
|
conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.class.getName());
|
||||||
TEST_UTIL.startMiniCluster();
|
TEST_UTIL.startMiniCluster();
|
||||||
REST_TEST_UTIL.startServletContainer(conf);
|
REST_TEST_UTIL.startServletContainer(conf);
|
||||||
client = new Client(new Cluster().add("localhost",
|
client = new Client(new Cluster().add("localhost",
|
||||||
@ -122,7 +120,7 @@ public class TestTableScan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleScannerXML() throws IOException, JAXBException, XMLStreamException {
|
public void testSimpleScannerXML() throws IOException, JAXBException {
|
||||||
// Test scanning particular columns
|
// Test scanning particular columns
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("/*");
|
builder.append("/*");
|
||||||
@ -149,7 +147,7 @@ public class TestTableScan {
|
|||||||
response = client.get("/" + TABLE + builder.toString(),
|
response = client.get("/" + TABLE + builder.toString(),
|
||||||
Constants.MIMETYPE_XML);
|
Constants.MIMETYPE_XML);
|
||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
|
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
|
||||||
model = (CellSetModel) ush.unmarshal(response.getStream());
|
model = (CellSetModel) ush.unmarshal(response.getStream());
|
||||||
count = TestScannerResource.countCellSet(model);
|
count = TestScannerResource.countCellSet(model);
|
||||||
assertEquals(expectedRows1, count);
|
assertEquals(expectedRows1, count);
|
||||||
@ -198,7 +196,7 @@ public class TestTableScan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleScannerJson() throws IOException, JAXBException {
|
public void testSimpleScannerJson() throws IOException {
|
||||||
// Test scanning particular columns with limit.
|
// Test scanning particular columns with limit.
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("/*");
|
builder.append("/*");
|
||||||
@ -285,16 +283,16 @@ public class TestTableScan {
|
|||||||
unmarshaller.setListener(new Unmarshaller.Listener() {
|
unmarshaller.setListener(new Unmarshaller.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeUnmarshal(Object target, Object parent) {
|
public void beforeUnmarshal(Object target, Object parent) {
|
||||||
if (target instanceof ClientSideCellSetModel) {
|
if (target instanceof ClientSideCellSetModel) {
|
||||||
((ClientSideCellSetModel) target).setCellSetModelListener(listener);
|
((ClientSideCellSetModel) target).setCellSetModelListener(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterUnmarshal(Object target, Object parent) {
|
public void afterUnmarshal(Object target, Object parent) {
|
||||||
if (target instanceof ClientSideCellSetModel) {
|
if (target instanceof ClientSideCellSetModel) {
|
||||||
((ClientSideCellSetModel) target).setCellSetModelListener(null);
|
((ClientSideCellSetModel) target).setCellSetModelListener(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -396,7 +394,7 @@ public class TestTableScan {
|
|||||||
int rowCount = readProtobufStream(response.getStream());
|
int rowCount = readProtobufStream(response.getStream());
|
||||||
assertEquals(15, rowCount);
|
assertEquals(15, rowCount);
|
||||||
|
|
||||||
//Test with start row and end row.
|
//Test with start row and end row.
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
builder.append("/*");
|
builder.append("/*");
|
||||||
builder.append("?");
|
builder.append("?");
|
||||||
@ -455,7 +453,7 @@ public class TestTableScan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScanningUnknownColumnJson() throws IOException, JAXBException {
|
public void testScanningUnknownColumnJson() throws IOException {
|
||||||
// Test scanning particular columns with limit.
|
// Test scanning particular columns with limit.
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("/*");
|
builder.append("/*");
|
||||||
@ -471,7 +469,7 @@ public class TestTableScan {
|
|||||||
int count = TestScannerResource.countCellSet(model);
|
int count = TestScannerResource.countCellSet(model);
|
||||||
assertEquals(0, count);
|
assertEquals(0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleFilter() throws IOException, JAXBException {
|
public void testSimpleFilter() throws IOException, JAXBException {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -503,7 +501,7 @@ public class TestTableScan {
|
|||||||
builder.append("?");
|
builder.append("?");
|
||||||
builder.append(Constants.SCAN_FILTER + "="
|
builder.append(Constants.SCAN_FILTER + "="
|
||||||
+ URLEncoder.encode("QualifierFilter(=,'binary:1')", "UTF-8"));
|
+ URLEncoder.encode("QualifierFilter(=,'binary:1')", "UTF-8"));
|
||||||
Response response =
|
Response response =
|
||||||
client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
|
client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
|
||||||
assertEquals(200, response.getCode());
|
assertEquals(200, response.getCode());
|
||||||
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
|
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
|
||||||
@ -515,7 +513,6 @@ public class TestTableScan {
|
|||||||
StandardCharsets.UTF_8));
|
StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompoundFilter() throws IOException, JAXBException {
|
public void testCompoundFilter() throws IOException, JAXBException {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -554,7 +551,7 @@ public class TestTableScan {
|
|||||||
assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue(),
|
assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue(),
|
||||||
StandardCharsets.UTF_8));
|
StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeCustomFilter() throws IOException, JAXBException {
|
public void testNegativeCustomFilter() throws IOException, JAXBException {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -625,7 +622,7 @@ public class TestTableScan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testColumnWithEmptyQualifier() throws IOException, JAXBException {
|
public void testColumnWithEmptyQualifier() throws IOException {
|
||||||
// Test scanning with empty qualifier
|
// Test scanning with empty qualifier
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("/*");
|
builder.append("/*");
|
||||||
@ -670,7 +667,7 @@ public class TestTableScan {
|
|||||||
public CustomFilter(byte[] key) {
|
public CustomFilter(byte[] key) {
|
||||||
super(key);
|
super(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean filterRowKey(byte[] buffer, int offset, int length) {
|
public boolean filterRowKey(byte[] buffer, int offset, int length) {
|
||||||
int cmp = Bytes.compareTo(buffer, offset, length, this.key, 0, this.key.length);
|
int cmp = Bytes.compareTo(buffer, offset, length, this.key, 0, this.key.length);
|
||||||
@ -690,7 +687,6 @@ public class TestTableScan {
|
|||||||
@XmlRootElement(name = "CellSet")
|
@XmlRootElement(name = "CellSet")
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public static class ClientSideCellSetModel implements Serializable {
|
public static class ClientSideCellSetModel implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -707,25 +703,23 @@ public class TestTableScan {
|
|||||||
* is removed again.
|
* is removed again.
|
||||||
*/
|
*/
|
||||||
public void setCellSetModelListener(final Listener l) {
|
public void setCellSetModelListener(final Listener l) {
|
||||||
row = (l == null) ? null : new ArrayList<RowModel>() {
|
row = (l == null) ? null : new ArrayList<RowModel>() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@Override
|
|
||||||
public boolean add(RowModel o) {
|
@Override
|
||||||
l.handleRowModel(ClientSideCellSetModel.this, o);
|
public boolean add(RowModel o) {
|
||||||
listenerInvoked = true;
|
l.handleRowModel(ClientSideCellSetModel.this, o);
|
||||||
return false;
|
listenerInvoked = true;
|
||||||
}
|
return false;
|
||||||
};
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This listener is invoked every time a new row model is unmarshalled.
|
* This listener is invoked every time a new row model is unmarshalled.
|
||||||
*/
|
*/
|
||||||
public static interface Listener {
|
public interface Listener {
|
||||||
void handleRowModel(ClientSideCellSetModel helper, RowModel rowModel);
|
void handleRowModel(ClientSideCellSetModel helper, RowModel rowModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,13 +48,12 @@ import org.junit.experimental.categories.Category;
|
|||||||
*/
|
*/
|
||||||
@Category(SmallTests.class)
|
@Category(SmallTests.class)
|
||||||
public class TestRemoteHTableRetries {
|
public class TestRemoteHTableRetries {
|
||||||
|
|
||||||
private static final int SLEEP_TIME = 50;
|
private static final int SLEEP_TIME = 50;
|
||||||
private static final int RETRIES = 3;
|
private static final int RETRIES = 3;
|
||||||
private static final long MAX_TIME = SLEEP_TIME * (RETRIES - 1);
|
private static final long MAX_TIME = SLEEP_TIME * (RETRIES - 1);
|
||||||
|
|
||||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||||
|
|
||||||
private static final byte[] ROW_1 = Bytes.toBytes("testrow1");
|
private static final byte[] ROW_1 = Bytes.toBytes("testrow1");
|
||||||
private static final byte[] COLUMN_1 = Bytes.toBytes("a");
|
private static final byte[] COLUMN_1 = Bytes.toBytes("a");
|
||||||
private static final byte[] QUALIFIER_1 = Bytes.toBytes("1");
|
private static final byte[] QUALIFIER_1 = Bytes.toBytes("1");
|
||||||
@ -62,7 +61,7 @@ public class TestRemoteHTableRetries {
|
|||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
private RemoteHTable remoteTable;
|
private RemoteHTable remoteTable;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
client = mock(Client.class);
|
client = mock(Client.class);
|
||||||
@ -86,7 +85,7 @@ public class TestRemoteHTableRetries {
|
|||||||
public void tearDownAfterClass() throws Exception {
|
public void tearDownAfterClass() throws Exception {
|
||||||
remoteTable.close();
|
remoteTable.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
public void testDelete() throws Exception {
|
||||||
testTimedOutCall(new CallExecutor() {
|
testTimedOutCall(new CallExecutor() {
|
||||||
@ -98,7 +97,7 @@ public class TestRemoteHTableRetries {
|
|||||||
});
|
});
|
||||||
verify(client, times(RETRIES)).delete(anyString());
|
verify(client, times(RETRIES)).delete(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
testTimedOutGetCall(new CallExecutor() {
|
testTimedOutGetCall(new CallExecutor() {
|
||||||
@ -119,14 +118,13 @@ public class TestRemoteHTableRetries {
|
|||||||
});
|
});
|
||||||
verify(client, times(RETRIES)).put(anyString(), anyString(), any(byte[].class));
|
verify(client, times(RETRIES)).put(anyString(), anyString(), any(byte[].class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiRowPut() throws Exception {
|
public void testMultiRowPut() throws Exception {
|
||||||
testTimedOutCall(new CallExecutor() {
|
testTimedOutCall(new CallExecutor() {
|
||||||
@Override
|
@Override
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
Put[] puts = { new Put(Bytes.toBytes("Row1")),
|
Put[] puts = { new Put(Bytes.toBytes("Row1")), new Put(Bytes.toBytes("Row2")) };
|
||||||
new Put(Bytes.toBytes("Row2")) };
|
|
||||||
remoteTable.put(Arrays.asList(puts));
|
remoteTable.put(Arrays.asList(puts));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -143,7 +141,7 @@ public class TestRemoteHTableRetries {
|
|||||||
});
|
});
|
||||||
verify(client, times(RETRIES)).post(anyString(), anyString(), any(byte[].class));
|
verify(client, times(RETRIES)).post(anyString(), anyString(), any(byte[].class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckAndPut() throws Exception {
|
public void testCheckAndPut() throws Exception {
|
||||||
testTimedOutCall(new CallExecutor() {
|
testTimedOutCall(new CallExecutor() {
|
||||||
@ -165,16 +163,16 @@ public class TestRemoteHTableRetries {
|
|||||||
Put put = new Put(ROW_1);
|
Put put = new Put(ROW_1);
|
||||||
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
Delete delete= new Delete(ROW_1);
|
Delete delete= new Delete(ROW_1);
|
||||||
remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete );
|
remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testTimedOutGetCall(CallExecutor callExecutor) throws Exception {
|
private void testTimedOutGetCall(CallExecutor callExecutor) throws Exception {
|
||||||
testTimedOutCall(callExecutor);
|
testTimedOutCall(callExecutor);
|
||||||
verify(client, times(RETRIES)).get(anyString(), anyString());
|
verify(client, times(RETRIES)).get(anyString(), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testTimedOutCall(CallExecutor callExecutor) throws Exception {
|
private void testTimedOutCall(CallExecutor callExecutor) throws Exception {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
@ -186,8 +184,7 @@ public class TestRemoteHTableRetries {
|
|||||||
assertTrue((System.currentTimeMillis() - start) > MAX_TIME);
|
assertTrue((System.currentTimeMillis() - start) > MAX_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface CallExecutor {
|
private interface CallExecutor {
|
||||||
void run() throws Exception;
|
void run() throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
@ -16,7 +15,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.rest.client;
|
package org.apache.hadoop.hbase.rest.client;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@ -60,7 +58,6 @@ import org.junit.experimental.categories.Category;
|
|||||||
|
|
||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestRemoteTable {
|
public class TestRemoteTable {
|
||||||
|
|
||||||
// Verify that invalid URL characters and arbitrary bytes are escaped when
|
// Verify that invalid URL characters and arbitrary bytes are escaped when
|
||||||
// constructing REST URLs per HBASE-7621. RemoteHTable should support row keys
|
// constructing REST URLs per HBASE-7621. RemoteHTable should support row keys
|
||||||
// and qualifiers containing any byte for all table operations.
|
// and qualifiers containing any byte for all table operations.
|
||||||
@ -97,7 +94,7 @@ public class TestRemoteTable {
|
|||||||
private static final long TS_1 = TS_2 - ONE_HOUR;
|
private static final long TS_1 = TS_2 - ONE_HOUR;
|
||||||
|
|
||||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||||
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
private static final HBaseRESTTestingUtility REST_TEST_UTIL =
|
||||||
new HBaseRESTTestingUtility();
|
new HBaseRESTTestingUtility();
|
||||||
private RemoteHTable remoteTable;
|
private RemoteHTable remoteTable;
|
||||||
|
|
||||||
@ -111,7 +108,10 @@ public class TestRemoteTable {
|
|||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
Admin admin = TEST_UTIL.getHBaseAdmin();
|
Admin admin = TEST_UTIL.getHBaseAdmin();
|
||||||
if (admin.tableExists(TABLE)) {
|
if (admin.tableExists(TABLE)) {
|
||||||
if (admin.isTableEnabled(TABLE)) admin.disableTable(TABLE);
|
if (admin.isTableEnabled(TABLE)) {
|
||||||
|
admin.disableTable(TABLE);
|
||||||
|
}
|
||||||
|
|
||||||
admin.deleteTable(TABLE);
|
admin.deleteTable(TABLE);
|
||||||
}
|
}
|
||||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||||
@ -130,16 +130,16 @@ public class TestRemoteTable {
|
|||||||
table.put(put);
|
table.put(put);
|
||||||
}
|
}
|
||||||
remoteTable = new RemoteHTable(
|
remoteTable = new RemoteHTable(
|
||||||
new Client(new Cluster().add("localhost",
|
new Client(new Cluster().add("localhost",
|
||||||
REST_TEST_UTIL.getServletPort())),
|
REST_TEST_UTIL.getServletPort())),
|
||||||
TEST_UTIL.getConfiguration(), TABLE.toBytes());
|
TEST_UTIL.getConfiguration(), TABLE.toBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void after() throws Exception {
|
public void after() throws Exception {
|
||||||
remoteTable.close();
|
remoteTable.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDownAfterClass() throws Exception {
|
public static void tearDownAfterClass() throws Exception {
|
||||||
REST_TEST_UTIL.shutdownServletContainer();
|
REST_TEST_UTIL.shutdownServletContainer();
|
||||||
@ -216,7 +216,6 @@ public class TestRemoteTable {
|
|||||||
assertTrue(Bytes.equals(VALUE_2, value2));
|
assertTrue(Bytes.equals(VALUE_2, value2));
|
||||||
|
|
||||||
// test timestamp
|
// test timestamp
|
||||||
|
|
||||||
get = new Get(ROW_2);
|
get = new Get(ROW_2);
|
||||||
get.addFamily(COLUMN_1);
|
get.addFamily(COLUMN_1);
|
||||||
get.addFamily(COLUMN_2);
|
get.addFamily(COLUMN_2);
|
||||||
@ -229,7 +228,6 @@ public class TestRemoteTable {
|
|||||||
assertNull(value2);
|
assertNull(value2);
|
||||||
|
|
||||||
// test timerange
|
// test timerange
|
||||||
|
|
||||||
get = new Get(ROW_2);
|
get = new Get(ROW_2);
|
||||||
get.addFamily(COLUMN_1);
|
get.addFamily(COLUMN_1);
|
||||||
get.addFamily(COLUMN_2);
|
get.addFamily(COLUMN_2);
|
||||||
@ -242,7 +240,6 @@ public class TestRemoteTable {
|
|||||||
assertNull(value2);
|
assertNull(value2);
|
||||||
|
|
||||||
// test maxVersions
|
// test maxVersions
|
||||||
|
|
||||||
get = new Get(ROW_2);
|
get = new Get(ROW_2);
|
||||||
get.addFamily(COLUMN_1);
|
get.addFamily(COLUMN_1);
|
||||||
get.setMaxVersions(2);
|
get.setMaxVersions(2);
|
||||||
@ -263,7 +260,7 @@ public class TestRemoteTable {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiGet() throws Exception {
|
public void testMultiGet() throws Exception {
|
||||||
ArrayList<Get> gets = new ArrayList<Get>();
|
ArrayList<Get> gets = new ArrayList<>();
|
||||||
gets.add(new Get(ROW_1));
|
gets.add(new Get(ROW_1));
|
||||||
gets.add(new Get(ROW_2));
|
gets.add(new Get(ROW_2));
|
||||||
Result[] results = remoteTable.get(gets);
|
Result[] results = remoteTable.get(gets);
|
||||||
@ -273,7 +270,7 @@ public class TestRemoteTable {
|
|||||||
assertEquals(2, results[1].size());
|
assertEquals(2, results[1].size());
|
||||||
|
|
||||||
//Test Versions
|
//Test Versions
|
||||||
gets = new ArrayList<Get>();
|
gets = new ArrayList<>();
|
||||||
Get g = new Get(ROW_1);
|
Get g = new Get(ROW_1);
|
||||||
g.setMaxVersions(3);
|
g.setMaxVersions(3);
|
||||||
gets.add(g);
|
gets.add(g);
|
||||||
@ -285,13 +282,13 @@ public class TestRemoteTable {
|
|||||||
assertEquals(3, results[1].size());
|
assertEquals(3, results[1].size());
|
||||||
|
|
||||||
//404
|
//404
|
||||||
gets = new ArrayList<Get>();
|
gets = new ArrayList<>();
|
||||||
gets.add(new Get(Bytes.toBytes("RESALLYREALLYNOTTHERE")));
|
gets.add(new Get(Bytes.toBytes("RESALLYREALLYNOTTHERE")));
|
||||||
results = remoteTable.get(gets);
|
results = remoteTable.get(gets);
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
assertEquals(0, results.length);
|
assertEquals(0, results.length);
|
||||||
|
|
||||||
gets = new ArrayList<Get>();
|
gets = new ArrayList<>();
|
||||||
gets.add(new Get(Bytes.toBytes("RESALLYREALLYNOTTHERE")));
|
gets.add(new Get(Bytes.toBytes("RESALLYREALLYNOTTHERE")));
|
||||||
gets.add(new Get(ROW_1));
|
gets.add(new Get(ROW_1));
|
||||||
gets.add(new Get(ROW_2));
|
gets.add(new Get(ROW_2));
|
||||||
@ -314,8 +311,7 @@ public class TestRemoteTable {
|
|||||||
assertTrue(Bytes.equals(VALUE_1, value));
|
assertTrue(Bytes.equals(VALUE_1, value));
|
||||||
|
|
||||||
// multiput
|
// multiput
|
||||||
|
List<Put> puts = new ArrayList<>();
|
||||||
List<Put> puts = new ArrayList<Put>();
|
|
||||||
put = new Put(ROW_3);
|
put = new Put(ROW_3);
|
||||||
put.add(COLUMN_2, QUALIFIER_2, VALUE_2);
|
put.add(COLUMN_2, QUALIFIER_2, VALUE_2);
|
||||||
puts.add(put);
|
puts.add(put);
|
||||||
@ -341,8 +337,9 @@ public class TestRemoteTable {
|
|||||||
value = result.getValue(COLUMN_2, QUALIFIER_2);
|
value = result.getValue(COLUMN_2, QUALIFIER_2);
|
||||||
assertNotNull(value);
|
assertNotNull(value);
|
||||||
assertTrue(Bytes.equals(VALUE_2, value));
|
assertTrue(Bytes.equals(VALUE_2, value));
|
||||||
|
|
||||||
assertTrue(Bytes.equals(Bytes.toBytes("TestRemoteTable" + VALID_TABLE_NAME_CHARS), remoteTable.getTableName()));
|
assertTrue(Bytes.equals(Bytes.toBytes("TestRemoteTable" + VALID_TABLE_NAME_CHARS),
|
||||||
|
remoteTable.getTableName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -425,13 +422,13 @@ public class TestRemoteTable {
|
|||||||
assertNull(value1);
|
assertNull(value1);
|
||||||
assertNull(value2);
|
assertNull(value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test RemoteHTable.Scanner
|
* Test RemoteHTable.Scanner
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testScanner() throws IOException {
|
public void testScanner() throws IOException {
|
||||||
List<Put> puts = new ArrayList<Put>();
|
List<Put> puts = new ArrayList<>();
|
||||||
Put put = new Put(ROW_1);
|
Put put = new Put(ROW_1);
|
||||||
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
puts.add(put);
|
puts.add(put);
|
||||||
@ -466,7 +463,7 @@ public class TestRemoteTable {
|
|||||||
results = scanner.next(1);
|
results = scanner.next(1);
|
||||||
assertNull(results);
|
assertNull(results);
|
||||||
scanner.close();
|
scanner.close();
|
||||||
|
|
||||||
scanner = remoteTable.getScanner(COLUMN_1);
|
scanner = remoteTable.getScanner(COLUMN_1);
|
||||||
results = scanner.next(4);
|
results = scanner.next(4);
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
@ -477,7 +474,7 @@ public class TestRemoteTable {
|
|||||||
assertTrue(Bytes.equals(ROW_4, results[3].getRow()));
|
assertTrue(Bytes.equals(ROW_4, results[3].getRow()));
|
||||||
|
|
||||||
scanner.close();
|
scanner.close();
|
||||||
|
|
||||||
scanner = remoteTable.getScanner(COLUMN_1,QUALIFIER_1);
|
scanner = remoteTable.getScanner(COLUMN_1,QUALIFIER_1);
|
||||||
results = scanner.next(4);
|
results = scanner.next(4);
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
@ -488,9 +485,8 @@ public class TestRemoteTable {
|
|||||||
assertTrue(Bytes.equals(ROW_4, results[3].getRow()));
|
assertTrue(Bytes.equals(ROW_4, results[3].getRow()));
|
||||||
scanner.close();
|
scanner.close();
|
||||||
assertTrue(remoteTable.isAutoFlush());
|
assertTrue(remoteTable.isAutoFlush());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckAndDelete() throws IOException {
|
public void testCheckAndDelete() throws IOException {
|
||||||
Get get = new Get(ROW_1);
|
Get get = new Get(ROW_1);
|
||||||
@ -511,18 +507,16 @@ public class TestRemoteTable {
|
|||||||
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
remoteTable.put(put);
|
remoteTable.put(put);
|
||||||
|
|
||||||
assertTrue(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1,
|
assertTrue(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, put));
|
||||||
put));
|
assertFalse(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_2, put));
|
||||||
assertFalse(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_2,
|
|
||||||
put));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test RemoteHable.Scanner.iterator method
|
* Test RemoteHable.Scanner.iterator method
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIteratorScaner() throws IOException {
|
public void testIteratorScaner() throws IOException {
|
||||||
List<Put> puts = new ArrayList<Put>();
|
List<Put> puts = new ArrayList<>();
|
||||||
Put put = new Put(ROW_1);
|
Put put = new Put(ROW_1);
|
||||||
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
puts.add(put);
|
puts.add(put);
|
||||||
@ -547,7 +541,7 @@ public class TestRemoteTable {
|
|||||||
}
|
}
|
||||||
assertEquals(4, counter);
|
assertEquals(4, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test a some methods of class Response.
|
* Test a some methods of class Response.
|
||||||
*/
|
*/
|
||||||
@ -569,13 +563,14 @@ public class TestRemoteTable {
|
|||||||
response.setHeaders(headers);
|
response.setHeaders(headers);
|
||||||
assertEquals("value1.1", response.getHeader("header1"));
|
assertEquals("value1.1", response.getHeader("header1"));
|
||||||
response.setBody(Bytes.toBytes("body"));
|
response.setBody(Bytes.toBytes("body"));
|
||||||
assertTrue(response.hasBody());
|
assertTrue(response.hasBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests keeping a HBase scanner alive for long periods of time. Each call to next() should reset
|
* Tests keeping a HBase scanner alive for long periods of time. Each call to next() should reset
|
||||||
* the ConnectionCache timeout for the scanner's connection
|
* the ConnectionCache timeout for the scanner's connection.
|
||||||
* @throws Exception
|
*
|
||||||
|
* @throws Exception if starting the servlet container or disabling or truncating the table fails
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testLongLivedScan() throws Exception {
|
public void testLongLivedScan() throws Exception {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
@ -16,7 +15,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.rest.model;
|
package org.apache.hadoop.hbase.rest.model;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
@ -106,5 +104,4 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
|
|||||||
assertTrue(foundLabel2);
|
assertTrue(foundLabel2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
@ -16,7 +15,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.rest.model;
|
package org.apache.hadoop.hbase.rest.model;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -29,7 +27,6 @@ import org.junit.experimental.categories.Category;
|
|||||||
|
|
||||||
@Category(SmallTests.class)
|
@Category(SmallTests.class)
|
||||||
public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterStatusModel> {
|
public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterStatusModel> {
|
||||||
|
|
||||||
public TestStorageClusterStatusModel() throws Exception {
|
public TestStorageClusterStatusModel() throws Exception {
|
||||||
super(StorageClusterStatusModel.class);
|
super(StorageClusterStatusModel.class);
|
||||||
|
|
||||||
@ -99,7 +96,7 @@ public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterS
|
|||||||
assertEquals(1245219839331L, node.getStartCode());
|
assertEquals(1245219839331L, node.getStartCode());
|
||||||
assertEquals(128, node.getHeapSizeMB());
|
assertEquals(128, node.getHeapSizeMB());
|
||||||
assertEquals(1024, node.getMaxHeapSizeMB());
|
assertEquals(1024, node.getMaxHeapSizeMB());
|
||||||
Iterator<StorageClusterStatusModel.Node.Region> regions =
|
Iterator<StorageClusterStatusModel.Node.Region> regions =
|
||||||
node.getRegions().iterator();
|
node.getRegions().iterator();
|
||||||
StorageClusterStatusModel.Node.Region region = regions.next();
|
StorageClusterStatusModel.Node.Region region = regions.next();
|
||||||
assertTrue(Bytes.toString(region.getName()).equals(
|
assertTrue(Bytes.toString(region.getName()).equals(
|
||||||
@ -138,7 +135,7 @@ public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterS
|
|||||||
assertEquals(1, region.getTotalStaticBloomSizeKB());
|
assertEquals(1, region.getTotalStaticBloomSizeKB());
|
||||||
assertEquals(1, region.getTotalCompactingKVs());
|
assertEquals(1, region.getTotalCompactingKVs());
|
||||||
assertEquals(1, region.getCurrentCompactedKVs());
|
assertEquals(1, region.getCurrentCompactedKVs());
|
||||||
|
|
||||||
assertFalse(regions.hasNext());
|
assertFalse(regions.hasNext());
|
||||||
assertFalse(nodes.hasNext());
|
assertFalse(nodes.hasNext());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user