HBASE-19239 Fix findbugs and error-prone issues

Fixes for hbase-rest
This commit is contained in:
Andrew Purtell 2017-11-16 13:00:20 -08:00
parent e95f94a72d
commit 3436ed957c
31 changed files with 365 additions and 331 deletions

View File

@ -377,6 +377,7 @@ public class RowSpec {
this.endTime = endTime;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("{startRow => '");

View File

@ -18,6 +18,8 @@
*/
package org.apache.hadoop.hbase.rest;
import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -78,7 +80,7 @@ public class HBaseRESTTestingUtility {
conf.set(RESTServer.REST_CSRF_BROWSER_USERAGENTS_REGEX_KEY, ".*");
RESTServer.addCSRFFilter(context, conf);
HttpServerUtil.constrainHttpMethods(context);
LOG.info("Loaded filter classes :" + filterClasses);
LOG.info("Loaded filter classes :" + Arrays.toString(filterClasses));
// start the server
server.start();
// get the port

View File

@ -487,10 +487,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
return clazz;
}
@Override
protected void map(NullWritable key, PeInputSplit value, final Context context)
throws IOException, InterruptedException {
Status status = new Status() {
@Override
public void setStatus(String msg) {
context.setStatus(msg);
}
@ -632,6 +633,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
long elapsedTime = pe.runOneClient(cmd, index * perClientRows,
perClientRows, R,
flushCommits, writeToWAL, useTags, noOfTags, connection, new Status() {
@Override
public void setStatus(final String msg) throws IOException {
LOG.info("client-" + getName() + " " + msg);
}
@ -952,6 +954,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
super(conf, options, status);
}
@Override
void testSetup() throws IOException {
this.table = connection.getTable(tableName);
}
@ -971,10 +974,12 @@ public class PerformanceEvaluation extends Configured implements Tool {
this.flushCommits = options.isFlushCommits();
}
@Override
void testSetup() throws IOException {
this.mutator = connection.getBufferedMutator(tableName);
}
@Override
void testTakedown() throws IOException {
if (flushCommits) {
this.mutator.flush();
@ -1323,6 +1328,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
private void runNIsOne(final Class<? extends Test> cmd) {
Status status = new Status() {
@Override
public void setStatus(String msg) throws IOException {
LOG.info(msg);
}

View File

@ -151,7 +151,7 @@ public class RowResourceBase {
protected static void checkValueXML(String url, String table, String row,
String column, String value) throws IOException, JAXBException {
Response response = getValueXML(url);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -164,7 +164,7 @@ public class RowResourceBase {
protected static void checkValueXML(String table, String row, String column,
String value) throws IOException, JAXBException {
Response response = getValueXML(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -176,11 +176,11 @@ public class RowResourceBase {
protected static void checkIncrementValueXML(String table, String row, String column,
long value) throws IOException, JAXBException {
Response response1 = getValueXML(table, row, column);
assertEquals(response1.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response1.getHeader("content-type"));
Response response = getValueXML(table, row, column);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response1.getBody()));
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
RowModel rowModel = cellSet.getRows().get(0);
CellModel cell = rowModel.getCells().get(0);
assertEquals(Bytes.toString(cell.getColumn()), column);
@ -234,7 +234,7 @@ public class RowResourceBase {
protected static void checkValuePB(String table, String row, String column,
String value) throws IOException {
Response response = getValuePB(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
@ -247,7 +247,7 @@ public class RowResourceBase {
protected static void checkIncrementValuePB(String table, String row, String column,
long value) throws IOException {
Response response = getValuePB(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
@ -533,7 +533,7 @@ public class RowResourceBase {
protected static void checkValueJSON(String table, String row, String column,
String value) throws IOException, JAXBException {
Response response = getValueJson(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonProvider()
.locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
@ -547,7 +547,7 @@ public class RowResourceBase {
protected static void checkIncrementValueJSON(String table, String row, String column,
long value) throws IOException, JAXBException {
Response response = getValueJson(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonJaxbJsonProvider()
.locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);

View File

@ -35,7 +35,7 @@ public class TestDeleteRow extends RowResourceBase {
@Test
public void testDeleteNonExistentColumn() throws Exception {
Response response = putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = checkAndDeleteJson(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(304, response.getCode());
@ -61,39 +61,39 @@ public class TestDeleteRow extends RowResourceBase {
@Test
public void testDeleteXML() throws IOException, JAXBException {
Response response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = putValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = deleteValue(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
response = getValueXML(TABLE, ROW_1, COLUMN_2);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//Delete a row in non existent table
response = deleteValue("dummy", ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//Delete non existent column
response = deleteValue(TABLE, ROW_1, "dummy");
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
}
}

View File

@ -25,10 +25,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URLEncoder;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBException;
@ -57,92 +55,92 @@ public class TestGetAndPutResource extends RowResourceBase {
conf.set("hbase.rest.readonly", "true");
Response response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_2);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_2);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
response = deleteValue(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
conf.set("hbase.rest.readonly", "false");
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteValue(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testSingleCellGetPutXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
response = checkAndDeleteXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testSingleCellGetPutPB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2);
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2, VALUE_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3, VALUE_4);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_4);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testMultipleCellCheckPutPB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// Add 2 Columns to setup the test
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
HashMap<String,String> otherCells = new HashMap<String, String>();
@ -150,32 +148,32 @@ public class TestGetAndPutResource extends RowResourceBase {
// On Success update both the cells
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_3, otherCells);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_3);
// On Failure, we dont update any cells
response = checkAndPutValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_4, otherCells);
assertEquals(response.getCode(), 304);
assertEquals(304, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_3);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testMultipleCellCheckPutXML() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// Add 2 Columns to setup the test
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
HashMap<String,String> otherCells = new HashMap<String, String>();
@ -183,36 +181,36 @@ public class TestGetAndPutResource extends RowResourceBase {
// On Success update both the cells
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_3, otherCells);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_3);
// On Failure, we dont update any cells
response = checkAndPutValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1, VALUE_4, otherCells);
assertEquals(response.getCode(), 304);
assertEquals(304, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_3);
checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_3);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// Add 3 Columns to setup the test
response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = putValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
// Deletes the following columns based on Column1 check
@ -222,44 +220,45 @@ public class TestGetAndPutResource extends RowResourceBase {
// On Success update both the cells
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1, cellsToDelete);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = getValuePB(TABLE, ROW_1, COLUMN_2);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
response = getValuePB(TABLE, ROW_1, COLUMN_3);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
response = putValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
response = putValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
// On Failure, we dont update any cells
response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_3, cellsToDelete);
assertEquals(response.getCode(), 304);
assertEquals(304, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2);
checkValuePB(TABLE, ROW_1, COLUMN_3, VALUE_3);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@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, Constants.MIMETYPE_BINARY, body);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
Thread.yield();
response = client.get(path, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
assertTrue(Bytes.equals(response.getBody(), body));
boolean foundTimestampHeader = false;
@ -272,7 +271,7 @@ public class TestGetAndPutResource extends RowResourceBase {
assertTrue(foundTimestampHeader);
response = deleteRow(TABLE, ROW_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -280,13 +279,13 @@ public class TestGetAndPutResource extends RowResourceBase {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, Constants.MIMETYPE_BINARY,
Bytes.toBytes(VALUE_4));
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -304,10 +303,10 @@ public class TestGetAndPutResource extends RowResourceBase {
String jsonString = jsonMapper.writeValueAsString(cellSetModel);
Response response = client.put(path, Constants.MIMETYPE_JSON,
Bytes.toBytes(jsonString));
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
CellSetModel cellSet = jsonMapper.readValue(response.getBody(), CellSetModel.class);
assertTrue(cellSet.getRows().size() == 1);
@ -316,7 +315,7 @@ public class TestGetAndPutResource extends RowResourceBase {
assertEquals(VALUE_2 , Bytes.toString(cell.getValue()));
assertEquals(2L , cell.getTimestamp());
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -332,7 +331,7 @@ public class TestGetAndPutResource extends RowResourceBase {
Response response;
response = putValueXML(path.toString(), TABLE, urlKey, COLUMN_1,
VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
}
@ -342,13 +341,10 @@ public class TestGetAndPutResource extends RowResourceBase {
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
Bytes.toBytes(VALUE_1));
assertEquals(response.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);
assertEquals(200, response.getCode());
assertEquals(200, client.get(goodPath, Constants.MIMETYPE_BINARY).getCode());
assertEquals(404, client.get(badPath, Constants.MIMETYPE_BINARY).getCode());
assertEquals(200, client.get(goodPath, Constants.MIMETYPE_BINARY).getCode());
}
@Test
@ -376,7 +372,7 @@ public class TestGetAndPutResource extends RowResourceBase {
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// check that all of the values were created
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
@ -385,9 +381,9 @@ public class TestGetAndPutResource extends RowResourceBase {
checkValueXML(TABLE, ROW_2, COLUMN_2, VALUE_4);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -413,7 +409,7 @@ public class TestGetAndPutResource extends RowResourceBase {
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// check that all of the values were created
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
@ -422,9 +418,9 @@ public class TestGetAndPutResource extends RowResourceBase {
checkValuePB(TABLE, ROW_2, COLUMN_2, VALUE_4);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -469,7 +465,7 @@ public class TestGetAndPutResource extends RowResourceBase {
Response response = client.put(path, Constants.MIMETYPE_XML,
Bytes.toBytes(writer.toString()));
assertEquals(response.getCode(), 400);
assertEquals(400, response.getCode());
}
@Test
@ -487,7 +483,7 @@ public class TestGetAndPutResource extends RowResourceBase {
Response response = client.put(path, Constants.MIMETYPE_XML,
Bytes.toBytes(writer.toString()));
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
}
@Test
@ -515,7 +511,7 @@ public class TestGetAndPutResource extends RowResourceBase {
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// check that all of the values were created
checkValueJSON(TABLE, ROW_1, COLUMN_1, VALUE_1);
@ -524,9 +520,9 @@ public class TestGetAndPutResource extends RowResourceBase {
checkValueJSON(TABLE, ROW_2, COLUMN_2, VALUE_4);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -534,13 +530,13 @@ public class TestGetAndPutResource extends RowResourceBase {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, Constants.MIMETYPE_BINARY,
Bytes.toBytes(VALUE_4));
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
UserProvider userProvider = UserProvider.instantiate(conf);
METRICS_ASSERT.assertCounterGt("requests", 2l,
@ -573,7 +569,7 @@ public class TestGetAndPutResource extends RowResourceBase {
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// Try getting all the column values at once.
path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "," + COLUMN_2 + "," + COLUMN_3;
@ -589,7 +585,7 @@ public class TestGetAndPutResource extends RowResourceBase {
assertTrue(containsCellModel(cells, COLUMN_2, VALUE_2));
assertTrue(containsCellModel(cells, COLUMN_3, VALUE_2));
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
private boolean containsCellModel(List<CellModel> cells, String column, String value) {
@ -629,7 +625,7 @@ public class TestGetAndPutResource extends RowResourceBase {
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// check that all of the values were created
StringBuilder query = new StringBuilder();
@ -638,16 +634,16 @@ public class TestGetAndPutResource extends RowResourceBase {
query.append('/');
query.append("testrow*");
response = client.get(query.toString(), Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertTrue(cellSet.getRows().size() == 2);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -675,7 +671,7 @@ public class TestGetAndPutResource extends RowResourceBase {
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
// check that all of the values were created
StringBuilder query = new StringBuilder();
@ -686,7 +682,7 @@ public class TestGetAndPutResource extends RowResourceBase {
query.append('/');
query.append(COLUMN_1);
response = client.get(query.toString(), Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -697,114 +693,113 @@ public class TestGetAndPutResource extends RowResourceBase {
assertEquals(COLUMN_1, Bytes.toString(row.getCells().get(0).getColumn()));
}
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testAppendXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//append cell
response = appendValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = appendValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1 + VALUE_2);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testAppendPB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//append cell
response = appendValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = appendValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1 + VALUE_2);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testAppendJSON() throws IOException, JAXBException {
Response response = getValueJson(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//append cell
response = appendValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
response = appendValueJson(TABLE, ROW_1, COLUMN_1, VALUE_2);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1 + VALUE_2);
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testIncrementXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//append single cell
response = incrementValueXML(TABLE, ROW_1, COLUMN_1, VALUE_5);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkIncrementValueXML(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5));
response = incrementValueXML(TABLE, ROW_1, COLUMN_1, VALUE_6);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkIncrementValueXML(TABLE, ROW_1, COLUMN_1,
Long.parseLong(VALUE_5) + Long.parseLong(VALUE_6));
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testIncrementPB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//append cell
response = incrementValuePB(TABLE, ROW_1, COLUMN_1, VALUE_5);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkIncrementValuePB(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5));
response = incrementValuePB(TABLE, ROW_1, COLUMN_1, VALUE_6);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkIncrementValuePB(TABLE, ROW_1, COLUMN_1,
Long.parseLong(VALUE_5) + Long.parseLong(VALUE_6));
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testIncrementJSON() throws IOException, JAXBException {
Response response = getValueJson(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
//append cell
response = incrementValueJson(TABLE, ROW_1, COLUMN_1, VALUE_5);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkIncrementValueJSON(TABLE, ROW_1, COLUMN_1, Long.parseLong(VALUE_5));
response = incrementValueJson(TABLE, ROW_1, COLUMN_1, VALUE_6);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
checkIncrementValueJSON(TABLE, ROW_1, COLUMN_1,
Long.parseLong(VALUE_5) + Long.parseLong(VALUE_6));
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
}

View File

@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@ -98,7 +99,7 @@ public class TestGzipFilter {
headers[0] = new Header("Content-Type", Constants.MIMETYPE_BINARY);
headers[1] = new Header("Content-Encoding", "gzip");
Response response = client.put(path, headers, value_1_gzip);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
Table table = TEST_UTIL.getConnection().getTable(TABLE);
Get get = new Get(Bytes.toBytes(ROW_1));
@ -113,7 +114,7 @@ public class TestGzipFilter {
headers[0] = new Header("Accept", Constants.MIMETYPE_BINARY);
headers[1] = new Header("Accept-Encoding", "gzip");
response = client.get(path, headers);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
ByteArrayInputStream bis = new ByteArrayInputStream(response.getBody());
GZIPInputStream is = new GZIPInputStream(bis);
value = new byte[VALUE_1.length];
@ -131,11 +132,11 @@ public class TestGzipFilter {
headers[0] = new Header("Accept", Constants.MIMETYPE_BINARY);
headers[1] = new Header("Accept-Encoding", "gzip");
Response response = client.get("/" + TABLE + "/" + ROW_1 + "/" + COLUMN_2, headers);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
String contentEncoding = response.getHeader("Content-Encoding");
assertTrue(contentEncoding == null || !contentEncoding.contains("gzip"));
response = client.get("/" + TABLE, headers);
assertEquals(response.getCode(), 405);
assertEquals(405, response.getCode());
contentEncoding = response.getHeader("Content-Encoding");
assertTrue(contentEncoding == null || !contentEncoding.contains("gzip"));
}
@ -146,14 +147,14 @@ public class TestGzipFilter {
headers[1] = new Header("Accept", Constants.MIMETYPE_JSON);
headers[2] = new Header("Accept-Encoding", "gzip");
Response response = client.post("/" + TABLE + "/scanner", headers,
"<Scanner/>".getBytes());
assertEquals(response.getCode(), 201);
"<Scanner/>".getBytes(StandardCharsets.UTF_8));
assertEquals(201, response.getCode());
String scannerUrl = response.getLocation();
assertNotNull(scannerUrl);
response = client.get(scannerUrl);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
response = client.get(scannerUrl);
assertEquals(response.getCode(), 204);
assertEquals(204, response.getCode());
}
}

View File

@ -43,8 +43,6 @@ import org.junit.runners.Parameterized;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@ -72,9 +70,8 @@ public class TestMultiRowResource {
private static final HBaseRESTTestingUtility REST_TEST_UTIL = new HBaseRESTTestingUtility();
private static Client client;
@SuppressWarnings("unused")
private static JAXBContext context;
private static Marshaller marshaller;
private static Unmarshaller unmarshaller;
private static Configuration conf;
private static Header extraHdr = null;
@ -104,8 +101,6 @@ public class TestMultiRowResource {
CellModel.class,
CellSetModel.class,
RowModel.class);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
Admin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TABLE)) {
@ -148,7 +143,7 @@ public class TestMultiRowResource {
Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
client.delete(row_5_url, extraHdr);
@ -175,7 +170,7 @@ public class TestMultiRowResource {
Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
client.delete(row_5_url, extraHdr);
@ -202,7 +197,7 @@ public class TestMultiRowResource {
client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr);
Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
ObjectMapper mapper =
new JacksonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class);
@ -231,7 +226,7 @@ public class TestMultiRowResource {
client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr);
Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
ObjectMapper mapper = new JacksonProvider().locateMapper(CellSetModel.class,
MediaType.APPLICATION_JSON_TYPE);
CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class);

View File

@ -38,8 +38,6 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.httpclient.Header;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
@ -68,7 +66,7 @@ import org.junit.experimental.categories.Category;
@Category(MediumTests.class)
public class TestScannerResource {
private static final Log LOG = LogFactory.getLog(TestScannerResource.class);
private static final TableName TABLE = TableName.valueOf("TestScannerResource");
private static final TableName TABLE_TO_BE_DISABLED = TableName.valueOf("ScannerResourceDisable");
private static final String NONEXISTENT_TABLE = "ThisTableDoesNotExist";
@ -134,7 +132,7 @@ public class TestScannerResource {
model.setBatch(100);
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
int count = 0;
@ -160,7 +158,7 @@ public class TestScannerResource {
}
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
return count;
}
@ -216,7 +214,7 @@ public class TestScannerResource {
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
String scannerURI = response.getLocation();
assertNull(scannerURI);
@ -224,28 +222,28 @@ public class TestScannerResource {
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML,
body);
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// confirm batch size conformance
assertEquals(countCellSet(cellSet), BATCH_SIZE);
assertEquals(BATCH_SIZE, countCellSet(cellSet));
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -260,7 +258,7 @@ public class TestScannerResource {
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
String scannerURI = response.getLocation();
assertNull(scannerURI);
@ -268,28 +266,28 @@ public class TestScannerResource {
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
// confirm batch size conformance
assertEquals(countCellSet(cellSet), BATCH_SIZE);
assertEquals(BATCH_SIZE, countCellSet(cellSet));
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -303,7 +301,7 @@ public class TestScannerResource {
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
String scannerURI = response.getLocation();
assertNull(scannerURI);
@ -311,13 +309,13 @@ public class TestScannerResource {
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell
response = client.get(scannerURI, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
// verify that data was returned
assertTrue(response.getBody().length > 0);
@ -340,23 +338,23 @@ public class TestScannerResource {
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
public void testFullTableScan() throws IOException {
ScannerModel model = new ScannerModel();
model.addColumn(Bytes.toBytes(COLUMN_1));
assertEquals(fullTableScan(model), expectedRows1);
assertEquals(expectedRows1, fullTableScan(model));
model = new ScannerModel();
model.addColumn(Bytes.toBytes(COLUMN_2));
assertEquals(fullTableScan(model), expectedRows2);
assertEquals(expectedRows2, fullTableScan(model));
}
@Test
@ -370,7 +368,7 @@ public class TestScannerResource {
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
assertEquals(404, response.getCode());
}
// performs table scan during which the underlying table is disabled
@ -382,7 +380,7 @@ public class TestScannerResource {
model.setCaching(1);
Response response = client.put("/" + TABLE_TO_BE_DISABLED + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
TEST_UTIL.getHBaseAdmin().disableTable(TABLE_TO_BE_DISABLED);

View File

@ -113,8 +113,8 @@ public class TestScannersWithFilters {
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;
private static long numRows = (long) ROWS_ONE.length + ROWS_TWO.length;
private static long colsPerRow = (long) FAMILIES.length * QUALIFIERS_ONE.length;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@ -221,13 +221,13 @@ public class TestScannersWithFilters {
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cells = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -243,7 +243,7 @@ public class TestScannersWithFilters {
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
private static void verifyScanFull(Scan s, KeyValue [] kvs)
@ -256,20 +256,20 @@ public class TestScannersWithFilters {
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
int row = 0;
int idx = 0;
@ -310,20 +310,20 @@ public class TestScannersWithFilters {
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
Iterator<RowModel> i = cellSet.getRows().iterator();
int j = 0;

View File

@ -26,7 +26,6 @@ import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -166,6 +165,7 @@ public class TestScannersWithLabels {
private static void createLabels() throws IOException, InterruptedException {
PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
@Override
public VisibilityLabelsResponse run() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) {
@ -200,14 +200,14 @@ public class TestScannersWithLabels {
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
// Respond with 204 as there are no cells to be retrieved
assertEquals(response.getCode(), 204);
assertEquals(204, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
}
@ -225,18 +225,18 @@ public class TestScannersWithLabels {
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
// Respond with 204 as there are no cells to be retrieved
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response
.getBody()));
assertEquals(countCellSet(cellSet), 5);
assertEquals(5, countCellSet(cellSet));
}
}

View File

@ -25,12 +25,9 @@ import java.io.IOException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.rest.client.Client;
import org.apache.hadoop.hbase.rest.client.Cluster;
import org.apache.hadoop.hbase.rest.client.Response;
@ -46,7 +43,6 @@ import org.junit.experimental.categories.Category;
@Category(MediumTests.class)
public class TestStatusResource {
private static final Log LOG = LogFactory.getLog(TestStatusResource.class);
private static final byte[] META_REGION_NAME = Bytes.toBytes(TableName.META_TABLE_NAME+",,1");
@ -96,7 +92,7 @@ public class TestStatusResource {
@Test
public void testGetClusterStatusXML() throws IOException, JAXBException {
Response response = client.get("/status/cluster", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
StorageClusterStatusModel model = (StorageClusterStatusModel)
context.createUnmarshaller().unmarshal(
@ -107,13 +103,13 @@ public class TestStatusResource {
@Test
public void testGetClusterStatusPB() throws IOException {
Response response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());
validate(model);
response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());

View File

@ -127,13 +127,13 @@ public class TestTableResource {
admin.split(TABLE);
// give some time for the split to happen
long timeout = EnvironmentEdgeManager.currentTime() + (15 * 1000);
TEST_UTIL.waitFor(timeout, 250, new Waiter.Predicate<IOException>() {
TEST_UTIL.waitFor(15 * 1000, 250, new Waiter.Predicate<IOException>() {
@Override
public boolean evaluate() throws IOException {
List<HRegionLocation> regionLocations = regionLocator.getAllRegionLocations();
return regionLocations.size() == 2 && regionLocations.get(0).getServerName() != null
&& regionLocations.get(1).getServerName() != null;
return regionLocations != null &&
regionLocations.size() == 2 && regionLocations.get(0).getServerName() != null &&
regionLocations.get(1).getServerName() != null;
}
});
m = regionLocator.getAllRegionLocations();
@ -199,14 +199,14 @@ public class TestTableResource {
@Test
public void testTableListText() throws IOException {
Response response = client.get("/", Constants.MIMETYPE_TEXT);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
}
@Test
public void testTableListXML() throws IOException, JAXBException {
Response response = client.get("/", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
TableListModel model = (TableListModel)
context.createUnmarshaller()
@ -217,20 +217,20 @@ public class TestTableResource {
@Test
public void testTableListJSON() throws IOException {
Response response = client.get("/", Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
@Test
public void testTableListPB() throws IOException, JAXBException {
Response response = client.get("/", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
TableListModel model = new TableListModel();
model.getObjectFromMessage(response.getBody());
checkTableList(model);
response = client.get("/", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new TableListModel();
model.getObjectFromMessage(response.getBody());
@ -240,14 +240,14 @@ public class TestTableResource {
@Test
public void testTableInfoText() throws IOException {
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_TEXT);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
}
@Test
public void testTableInfoXML() throws IOException, JAXBException {
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
TableInfoModel model = (TableInfoModel)
context.createUnmarshaller()
@ -258,20 +258,20 @@ public class TestTableResource {
@Test
public void testTableInfoJSON() throws IOException {
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
@Test
public void testTableInfoPB() throws IOException, JAXBException {
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
TableInfoModel model = new TableInfoModel();
model.getObjectFromMessage(response.getBody());
checkTableInfo(model);
response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new TableInfoModel();
model.getObjectFromMessage(response.getBody());
@ -279,4 +279,3 @@ public class TestTableResource {
}
}

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -278,12 +279,14 @@ public class TestTableScan {
// install the callback on all ClientSideCellSetModel instances
unmarshaller.setListener(new Unmarshaller.Listener() {
@Override
public void beforeUnmarshal(Object target, Object parent) {
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(listener);
}
}
@Override
public void afterUnmarshal(Object target, Object parent) {
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(null);
@ -485,7 +488,8 @@ public class TestTableScan {
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
assertEquals("aab", new String(model.getRows().get(0).getCells().get(0).getValue()));
assertEquals("aab", new String(model.getRows().get(0).getCells().get(0).getValue(),
StandardCharsets.UTF_8));
}
@Test
@ -503,7 +507,8 @@ public class TestTableScan {
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
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));
}
@ -522,7 +527,8 @@ public class TestTableScan {
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
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));
}
@Test
@ -541,7 +547,8 @@ public class TestTableScan {
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
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));
}
@Test
@ -606,10 +613,10 @@ public class TestTableScan {
RowModel rowModel = rowModels.get(i);
RowModel reversedRowModel = reversedRowModels.get(i);
assertEquals(new String(rowModel.getKey(), "UTF-8"),
new String(reversedRowModel.getKey(), "UTF-8"));
assertEquals(new String(rowModel.getCells().get(0).getValue(), "UTF-8"),
new String(reversedRowModel.getCells().get(0).getValue(), "UTF-8"));
assertEquals(new String(rowModel.getKey(), StandardCharsets.UTF_8),
new String(reversedRowModel.getKey(), StandardCharsets.UTF_8));
assertEquals(new String(rowModel.getCells().get(0).getValue(), StandardCharsets.UTF_8),
new String(reversedRowModel.getCells().get(0).getValue(), StandardCharsets.UTF_8));
}
}
@ -658,7 +665,7 @@ public class TestTableScan {
public void setCellSetModelListener(final Listener l) {
row = (l == null) ? null : new ArrayList<RowModel>() {
private static final long serialVersionUID = 1L;
@Override
public boolean add(RowModel o) {
l.handleRowModel(ClientSideCellSetModel.this, o);
listenerInvoked = true;

View File

@ -78,7 +78,7 @@ public class TestVersionResource {
private static void validate(VersionModel model) {
assertNotNull(model);
assertNotNull(model.getRESTVersion());
assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
assertEquals(RESTServlet.VERSION_STRING, model.getRESTVersion());
String osVersion = model.getOSVersion();
assertNotNull(osVersion);
assertTrue(osVersion.contains(System.getProperty("os.name")));

View File

@ -23,6 +23,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.xml.bind.UnmarshalException;
import org.apache.commons.logging.Log;
@ -48,7 +50,7 @@ public class TestXmlParsing {
+ "<ClusterVersion Version=\"2.0.0\"/>";
Client client = mock(Client.class);
RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null);
Response resp = new Response(200, null, xml.getBytes());
Response resp = new Response(200, null, xml.getBytes(StandardCharsets.UTF_8));
when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);
@ -64,7 +66,7 @@ public class TestXmlParsing {
+ " <ClusterVersion>&xee;</ClusterVersion>";
Client client = mock(Client.class);
RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null);
Response resp = new Response(200, null, externalEntitiesXml.getBytes());
Response resp = new Response(200, null, externalEntitiesXml.getBytes(StandardCharsets.UTF_8));
when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);

View File

@ -43,6 +43,7 @@ public class TestCellModel extends TestModelBase<CellModel> {
"{\"column\":\"dGVzdGNvbHVtbg==\",\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVl\"}";
}
@Override
protected CellModel buildTestModel() {
CellModel model = new CellModel();
model.setColumn(COLUMN);
@ -51,21 +52,25 @@ public class TestCellModel extends TestModelBase<CellModel> {
return model;
}
@Override
protected void checkModel(CellModel model) {
assertTrue(Bytes.equals(model.getColumn(), COLUMN));
assertTrue(Bytes.equals(model.getValue(), VALUE));
assertTrue(model.hasUserTimestamp());
assertEquals(model.getTimestamp(), TIMESTAMP);
assertEquals(TIMESTAMP, model.getTimestamp());
}
@Override
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Override
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Override
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}

View File

@ -80,6 +80,7 @@ public class TestCellSetModel extends TestModelBase<CellSetModel> {
"\"timestamp\":1245393318192,\"$\":\"dGVzdHZhbHVlMw==\"}]}]}";
}
@Override
protected CellSetModel buildTestModel() {
CellSetModel model = new CellSetModel();
RowModel row;
@ -95,6 +96,7 @@ public class TestCellSetModel extends TestModelBase<CellSetModel> {
return model;
}
@Override
protected void checkModel(CellSetModel model) {
Iterator<RowModel> rows = model.getRows().iterator();
RowModel row = rows.next();
@ -104,7 +106,7 @@ public class TestCellSetModel extends TestModelBase<CellSetModel> {
assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
assertTrue(Bytes.equals(VALUE1, cell.getValue()));
assertTrue(cell.hasUserTimestamp());
assertEquals(cell.getTimestamp(), TIMESTAMP1);
assertEquals(TIMESTAMP1, cell.getTimestamp());
assertFalse(cells.hasNext());
row = rows.next();
assertTrue(Bytes.equals(ROW2, row.getKey()));
@ -113,26 +115,28 @@ public class TestCellSetModel extends TestModelBase<CellSetModel> {
assertTrue(Bytes.equals(COLUMN2, cell.getColumn()));
assertTrue(Bytes.equals(VALUE2, cell.getValue()));
assertTrue(cell.hasUserTimestamp());
assertEquals(cell.getTimestamp(), TIMESTAMP2);
assertEquals(TIMESTAMP2, cell.getTimestamp());
cell = cells.next();
assertTrue(Bytes.equals(COLUMN3, cell.getColumn()));
assertTrue(Bytes.equals(VALUE3, cell.getValue()));
assertTrue(cell.hasUserTimestamp());
assertEquals(cell.getTimestamp(), TIMESTAMP3);
assertEquals(TIMESTAMP3, cell.getTimestamp());
assertFalse(cells.hasNext());
}
@Override
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Override
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Override
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}
}

View File

@ -47,6 +47,7 @@ public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
"\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}";
}
@Override
protected ColumnSchemaModel buildTestModel() {
ColumnSchemaModel model = new ColumnSchemaModel();
model.setName(COLUMN_NAME);
@ -60,18 +61,19 @@ public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
return model;
}
@Override
protected void checkModel(ColumnSchemaModel model) {
assertEquals(model.getName(), COLUMN_NAME);
assertEquals(model.__getBlockcache(), BLOCKCACHE);
assertEquals(model.__getBlocksize(), BLOCKSIZE);
assertEquals(model.__getBloomfilter(), BLOOMFILTER);
assertEquals(COLUMN_NAME, model.getName());
assertEquals(BLOCKCACHE, model.__getBlockcache());
assertEquals(BLOCKSIZE, model.__getBlocksize());
assertEquals(BLOOMFILTER, model.__getBloomfilter());
assertTrue(model.__getCompression().equalsIgnoreCase(COMPRESSION));
assertEquals(model.__getInMemory(), IN_MEMORY);
assertEquals(model.__getTTL(), TTL);
assertEquals(model.__getVersions(), VERSIONS);
assertEquals(IN_MEMORY, model.__getInMemory());
assertEquals(TTL, model.__getTTL());
assertEquals(VERSIONS, model.__getVersions());
}
@Override
public void testFromPB() throws Exception {
}
}

View File

@ -93,7 +93,7 @@ public abstract class TestModelBase<T> extends TestCase {
protected T fromPB(String pb) throws
Exception {
return (T)clazz.getMethod("getObjectFromMessage", byte[].class).invoke(
clazz.newInstance(),
clazz.getDeclaredConstructor().newInstance(),
Base64.decode(AS_PB));
}

View File

@ -53,6 +53,7 @@ public class TestNamespacesInstanceModel extends TestModelBase<NamespacesInstanc
"\"KEY_1\":\"VALUE_1\",\"KEY_2\":\"VALUE_2\"}}";
}
@Override
protected NamespacesInstanceModel buildTestModel() {
return buildTestModel(NAMESPACE_NAME, NAMESPACE_PROPERTIES);
}
@ -65,6 +66,7 @@ public class TestNamespacesInstanceModel extends TestModelBase<NamespacesInstanc
return model;
}
@Override
protected void checkModel(NamespacesInstanceModel model) {
checkModel(model, NAMESPACE_NAME, NAMESPACE_PROPERTIES);
}
@ -81,17 +83,20 @@ public class TestNamespacesInstanceModel extends TestModelBase<NamespacesInstanc
}
@Test
@Override
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Test
@Override
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Test
@Override
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}
}
}

View File

@ -46,6 +46,7 @@ public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
AS_JSON = "{\"Namespace\":[\"testNamespace1\",\"testNamespace2\"]}";
}
@Override
protected NamespacesModel buildTestModel() {
return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2);
}
@ -56,6 +57,7 @@ public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
return model;
}
@Override
protected void checkModel(NamespacesModel model) {
checkModel(model, NAMESPACE_NAME_1, NAMESPACE_NAME_2);
}
@ -69,16 +71,19 @@ public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
}
@Test
@Override
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Test
@Override
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Test
@Override
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}

View File

@ -21,8 +21,6 @@ package org.apache.hadoop.hbase.rest.model;
import java.util.Iterator;
import javax.xml.bind.JAXBContext;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
@ -36,8 +34,6 @@ public class TestRowModel extends TestModelBase<RowModel> {
private static final byte[] VALUE1 = Bytes.toBytes("testvalue1");
private static final long TIMESTAMP1 = 1245219839331L;
private JAXBContext context;
public TestRowModel() throws Exception {
super(RowModel.class);
AS_XML =
@ -49,6 +45,7 @@ public class TestRowModel extends TestModelBase<RowModel> {
"\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVlMQ==\"}]}";
}
@Override
protected RowModel buildTestModel() {
RowModel model = new RowModel();
model.setKey(ROW1);
@ -56,6 +53,7 @@ public class TestRowModel extends TestModelBase<RowModel> {
return model;
}
@Override
protected void checkModel(RowModel model) {
assertTrue(Bytes.equals(ROW1, model.getKey()));
Iterator<CellModel> cells = model.getCells().iterator();
@ -63,7 +61,7 @@ public class TestRowModel extends TestModelBase<RowModel> {
assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
assertTrue(Bytes.equals(VALUE1, cell.getValue()));
assertTrue(cell.hasUserTimestamp());
assertEquals(cell.getTimestamp(), TIMESTAMP1);
assertEquals(TIMESTAMP1, cell.getTimestamp());
assertFalse(cells.hasNext());
}

View File

@ -57,6 +57,7 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
+ "JDj/////B0joB1IHcHJpdmF0ZVIGcHVibGljWAA=";
}
@Override
protected ScannerModel buildTestModel() {
ScannerModel model = new ScannerModel();
model.setStartRow(START_ROW);
@ -73,6 +74,7 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
return model;
}
@Override
protected void checkModel(ScannerModel model) {
assertTrue(Bytes.equals(model.getStartRow(), START_ROW));
assertTrue(Bytes.equals(model.getEndRow(), END_ROW));
@ -86,11 +88,11 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
}
assertTrue(foundCol1);
assertTrue(foundCol2);
assertEquals(model.getStartTime(), START_TIME);
assertEquals(model.getEndTime(), END_TIME);
assertEquals(model.getBatch(), BATCH);
assertEquals(model.getCaching(), CACHING);
assertEquals(model.getCacheBlocks(), CACHE_BLOCKS);
assertEquals(START_TIME, model.getStartTime());
assertEquals(END_TIME, model.getEndTime());
assertEquals(BATCH, model.getBatch());
assertEquals(CACHING, model.getCaching());
assertEquals(CACHE_BLOCKS, model.getCacheBlocks());
boolean foundLabel1 = false;
boolean foundLabel2 = false;
if (model.getLabels() != null && model.getLabels().size() > 0) {

View File

@ -73,6 +73,7 @@ public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterS
"\"heapSizeMB\":512,\"maxHeapSizeMB\":1024}],\"DeadNodes\":[]}";
}
@Override
protected StorageClusterStatusModel buildTestModel() {
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.setRegions(2);
@ -86,59 +87,59 @@ public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterS
return model;
}
@Override
protected void checkModel(StorageClusterStatusModel model) {
assertEquals(model.getRegions(), 2);
assertEquals(model.getRequests(), 0);
assertEquals(model.getAverageLoad(), 1.0);
assertEquals(2, model.getRegions());
assertEquals(0, model.getRequests());
assertEquals(1.0, model.getAverageLoad(), 0.0);
Iterator<StorageClusterStatusModel.Node> nodes =
model.getLiveNodes().iterator();
StorageClusterStatusModel.Node node = nodes.next();
assertEquals(node.getName(), "test1");
assertEquals(node.getStartCode(), 1245219839331L);
assertEquals(node.getHeapSizeMB(), 128);
assertEquals(node.getMaxHeapSizeMB(), 1024);
assertEquals("test1", node.getName());
assertEquals(1245219839331L, node.getStartCode());
assertEquals(128, node.getHeapSizeMB());
assertEquals(1024, node.getMaxHeapSizeMB());
Iterator<StorageClusterStatusModel.Node.Region> regions =
node.getRegions().iterator();
StorageClusterStatusModel.Node.Region region = regions.next();
assertTrue(Bytes.toString(region.getName()).equals(
"hbase:root,,0"));
assertEquals(region.getStores(), 1);
assertEquals(region.getStorefiles(), 1);
assertEquals(region.getStorefileSizeMB(), 0);
assertEquals(region.getMemstoreSizeMB(), 0);
assertEquals(region.getStorefileIndexSizeMB(), 0);
assertEquals(region.getReadRequestsCount(), 1);
assertEquals(region.getWriteRequestsCount(), 2);
assertEquals(region.getRootIndexSizeKB(), 1);
assertEquals(region.getTotalStaticIndexSizeKB(), 1);
assertEquals(region.getTotalStaticBloomSizeKB(), 1);
assertEquals(region.getTotalCompactingKVs(), 1);
assertEquals(region.getCurrentCompactedKVs(), 1);
assertEquals(1, region.getStores());
assertEquals(1, region.getStorefiles());
assertEquals(0, region.getStorefileSizeMB());
assertEquals(0, region.getMemstoreSizeMB());
assertEquals(0, region.getStorefileIndexSizeMB());
assertEquals(1, region.getReadRequestsCount());
assertEquals(2, region.getWriteRequestsCount());
assertEquals(1, region.getRootIndexSizeKB());
assertEquals(1, region.getTotalStaticIndexSizeKB());
assertEquals(1, region.getTotalStaticBloomSizeKB());
assertEquals(1, region.getTotalCompactingKVs());
assertEquals(1, region.getCurrentCompactedKVs());
assertFalse(regions.hasNext());
node = nodes.next();
assertEquals(node.getName(), "test2");
assertEquals(node.getStartCode(), 1245239331198L);
assertEquals(node.getHeapSizeMB(), 512);
assertEquals(node.getMaxHeapSizeMB(), 1024);
assertEquals("test2", node.getName());
assertEquals(1245239331198L, node.getStartCode());
assertEquals(512, node.getHeapSizeMB());
assertEquals(1024, node.getMaxHeapSizeMB());
regions = node.getRegions().iterator();
region = regions.next();
assertEquals(Bytes.toString(region.getName()),
TableName.META_TABLE_NAME+",,1246000043724");
assertEquals(region.getStores(), 1);
assertEquals(region.getStorefiles(), 1);
assertEquals(region.getStorefileSizeMB(), 0);
assertEquals(region.getMemstoreSizeMB(), 0);
assertEquals(region.getStorefileIndexSizeMB(), 0);
assertEquals(region.getReadRequestsCount(), 1);
assertEquals(region.getWriteRequestsCount(), 2);
assertEquals(region.getRootIndexSizeKB(), 1);
assertEquals(region.getTotalStaticIndexSizeKB(), 1);
assertEquals(region.getTotalStaticBloomSizeKB(), 1);
assertEquals(region.getTotalCompactingKVs(), 1);
assertEquals(region.getCurrentCompactedKVs(), 1);
assertEquals(1, region.getStores());
assertEquals(1, region.getStorefiles());
assertEquals(0, region.getStorefileSizeMB());
assertEquals(0, region.getMemstoreSizeMB());
assertEquals(0, region.getStorefileIndexSizeMB());
assertEquals(1, region.getReadRequestsCount());
assertEquals(2, region.getWriteRequestsCount());
assertEquals(1, region.getRootIndexSizeKB());
assertEquals(1, region.getTotalStaticIndexSizeKB());
assertEquals(1, region.getTotalStaticBloomSizeKB());
assertEquals(1, region.getTotalCompactingKVs());
assertEquals(1, region.getCurrentCompactedKVs());
assertFalse(regions.hasNext());
assertFalse(nodes.hasNext());
}
}

View File

@ -35,14 +35,16 @@ public class TestStorageClusterVersionModel extends TestModelBase<StorageCluster
AS_JSON = "{\"Version\": \"0.0.1-testing\"}";
}
@Override
protected StorageClusterVersionModel buildTestModel() {
StorageClusterVersionModel model = new StorageClusterVersionModel();
model.setVersion(VERSION);
return model;
}
@Override
protected void checkModel(StorageClusterVersionModel model) {
assertEquals(model.getVersion(), VERSION);
assertEquals(VERSION, model.getVersion());
}
@Override

View File

@ -23,7 +23,7 @@ import java.util.Iterator;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
@ -54,6 +54,7 @@ public class TestTableInfoModel extends TestModelBase<TableInfoModel> {
"startKey\":\"YWJyYWNhZGJyYQ==\"}]}";
}
@Override
protected TableInfoModel buildTestModel() {
TableInfoModel model = new TableInfoModel();
model.setName(TABLE);
@ -61,25 +62,32 @@ public class TestTableInfoModel extends TestModelBase<TableInfoModel> {
return model;
}
@Override
protected void checkModel(TableInfoModel model) {
assertEquals(model.getName(), TABLE);
assertEquals(TABLE, model.getName());
Iterator<TableRegionModel> regions = model.getRegions().iterator();
TableRegionModel region = regions.next();
assertTrue(Bytes.equals(region.getStartKey(), START_KEY));
assertTrue(Bytes.equals(region.getEndKey(), END_KEY));
assertEquals(region.getId(), ID);
assertEquals(region.getLocation(), LOCATION);
assertEquals(ID, region.getId());
assertEquals(LOCATION, region.getLocation());
assertFalse(regions.hasNext());
}
@Test
@Override
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Test
@Override
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Test
@Override
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}

View File

@ -43,6 +43,7 @@ public class TestTableListModel extends TestModelBase<TableListModel> {
"{\"table\":[{\"name\":\"table1\"},{\"name\":\"table2\"},{\"name\":\"table3\"}]}";
}
@Override
protected TableListModel buildTestModel() {
TableListModel model = new TableListModel();
model.add(new TableModel(TABLE1));
@ -51,15 +52,15 @@ public class TestTableListModel extends TestModelBase<TableListModel> {
return model;
}
@Override
protected void checkModel(TableListModel model) {
Iterator<TableModel> tables = model.getTables().iterator();
TableModel table = tables.next();
assertEquals(table.getName(), TABLE1);
assertEquals(TABLE1, table.getName());
table = tables.next();
assertEquals(table.getName(), TABLE2);
assertEquals(TABLE2, table.getName());
table = tables.next();
assertEquals(table.getName(), TABLE3);
assertEquals(TABLE3, table.getName());
assertFalse(tables.hasNext());
}
}

View File

@ -48,20 +48,22 @@ public class TestTableRegionModel extends TestModelBase<TableRegionModel> {
"startKey\":\"YWJyYWNhZGJyYQ==\"}";
}
@Override
protected TableRegionModel buildTestModel() {
TableRegionModel model =
new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION);
return model;
}
@Override
protected void checkModel(TableRegionModel model) {
assertTrue(Bytes.equals(model.getStartKey(), START_KEY));
assertTrue(Bytes.equals(model.getEndKey(), END_KEY));
assertEquals(model.getId(), ID);
assertEquals(model.getLocation(), LOCATION);
assertEquals(model.getName(),
TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) +
".ad9860f031282c46ed431d7af8f94aca.");
assertEquals(ID, model.getId());
assertEquals(LOCATION, model.getLocation());
assertEquals(TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) +
".ad9860f031282c46ed431d7af8f94aca.",
model.getName());
}
public void testGetName() {

View File

@ -21,8 +21,6 @@ package org.apache.hadoop.hbase.rest.model;
import java.util.Iterator;
import javax.xml.bind.JAXBContext;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.experimental.categories.Category;
@ -37,8 +35,6 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
TestColumnSchemaModel testColumnSchemaModel;
private JAXBContext context;
public TestTableSchemaModel() throws Exception {
super(TableSchemaModel.class);
testColumnSchemaModel = new TestColumnSchemaModel();
@ -63,6 +59,7 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
"\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\",\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}]}";
}
@Override
protected TableSchemaModel buildTestModel() {
return buildTestModel(TABLE_NAME);
}
@ -77,15 +74,16 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
return model;
}
@Override
protected void checkModel(TableSchemaModel model) {
checkModel(model, TABLE_NAME);
}
public void checkModel(TableSchemaModel model, String tableName) {
assertEquals(model.getName(), tableName);
assertEquals(model.__getIsMeta(), IS_META);
assertEquals(model.__getIsRoot(), IS_ROOT);
assertEquals(model.__getReadOnly(), READONLY);
assertEquals(tableName, model.getName());
assertEquals(IS_META, model.__getIsMeta());
assertEquals(IS_ROOT, model.__getIsRoot());
assertEquals(READONLY, model.__getReadOnly());
Iterator<ColumnSchemaModel> families = model.getColumns().iterator();
assertTrue(families.hasNext());
ColumnSchemaModel family = families.next();
@ -93,17 +91,19 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
assertFalse(families.hasNext());
}
@Override
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Override
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Override
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}
}

View File

@ -21,12 +21,7 @@ package org.apache.hadoop.hbase.rest.model;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Assume;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import javax.servlet.ServletContext;
@Category(SmallTests.class)
public class TestVersionModel extends TestModelBase<VersionModel> {
@ -55,6 +50,7 @@ public class TestVersionModel extends TestModelBase<VersionModel> {
"REST\":\"0.0.1\",\"Server\":\"6.1.14\"}";
}
@Override
protected VersionModel buildTestModel() {
VersionModel model = new VersionModel();
model.setRESTVersion(REST_VERSION);
@ -65,12 +61,13 @@ public class TestVersionModel extends TestModelBase<VersionModel> {
return model;
}
@Override
protected void checkModel(VersionModel model) {
assertEquals(model.getRESTVersion(), REST_VERSION);
assertEquals(model.getOSVersion(), OS_VERSION);
assertEquals(model.getJVMVersion(), JVM_VERSION);
assertEquals(model.getServerVersion(), JETTY_VERSION);
assertEquals(model.getJerseyVersion(), JERSEY_VERSION);
assertEquals(REST_VERSION, model.getRESTVersion());
assertEquals(OS_VERSION, model.getOSVersion());
assertEquals(JVM_VERSION, model.getJVMVersion());
assertEquals(JETTY_VERSION, model.getServerVersion());
assertEquals(JERSEY_VERSION, model.getJerseyVersion());
}
}