HBASE-19846 Fix findbugs and error-prone warnings in hbase-rest (branch-2)

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Peter Somogyi 2018-01-25 13:56:37 +01:00 committed by tedyu
parent ce50830a0a
commit aeffca497b
37 changed files with 508 additions and 382 deletions

View File

@ -27,14 +27,15 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.rest.model.CellModel;
import org.apache.hadoop.hbase.rest.model.CellSetModel;
import org.apache.hadoop.hbase.rest.model.RowModel;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@InterfaceAudience.Private
public class MultiRowResource extends ResourceBase implements Constants {
@ -83,7 +84,7 @@ public class MultiRowResource extends ResourceBase implements Constants {
if (this.columns != null) {
for (int i = 0; i < this.columns.length; i++) {
rowSpec.addColumn(this.columns[i].getBytes());
rowSpec.addColumn(Bytes.toBytes(this.columns[i]));
}
}

View File

@ -23,17 +23,17 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.util.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@InterfaceAudience.Private
public class RowResultGenerator extends ResultGenerator {
@ -83,9 +83,11 @@ public class RowResultGenerator extends ResultGenerator {
}
}
@Override
public void close() {
}
@Override
public boolean hasNext() {
if (cache != null) {
return true;
@ -96,6 +98,7 @@ public class RowResultGenerator extends ResultGenerator {
return valuesI.hasNext();
}
@Override
public Cell next() {
if (cache != null) {
Cell kv = cache;
@ -112,10 +115,12 @@ public class RowResultGenerator extends ResultGenerator {
}
}
@Override
public void putBack(Cell kv) {
this.cache = kv;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove not supported");
}

View File

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

View File

@ -27,9 +27,6 @@ import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableNotEnabledException;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.UnknownScannerException;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
@ -38,6 +35,9 @@ import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.rest.model.ScannerModel;
import org.apache.hadoop.hbase.security.visibility.Authorizations;
import org.apache.hadoop.util.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@InterfaceAudience.Private
public class ScannerResultGenerator extends ResultGenerator {
@ -115,6 +115,7 @@ public class ScannerResultGenerator extends ResultGenerator {
return id;
}
@Override
public void close() {
if (scanner != null) {
scanner.close();
@ -122,6 +123,7 @@ public class ScannerResultGenerator extends ResultGenerator {
}
}
@Override
public boolean hasNext() {
if (cache != null) {
return true;
@ -145,6 +147,7 @@ public class ScannerResultGenerator extends ResultGenerator {
return cached != null;
}
@Override
public Cell next() {
if (cache != null) {
Cell kv = cache;
@ -187,10 +190,12 @@ public class ScannerResultGenerator extends ResultGenerator {
return null;
}
@Override
public void putBack(Cell kv) {
this.cache = kv;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove not supported");
}

View File

@ -19,6 +19,8 @@
package org.apache.hadoop.hbase.rest.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
@ -30,12 +32,12 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Representation of a row. A row is a related set of cells, grouped by common
@ -77,7 +79,7 @@ public class RowModel implements ProtobufMessageHandler, Serializable {
* @param key the row key
*/
public RowModel(final String key) {
this(key.getBytes());
this(Bytes.toBytes(key));
}
/**
@ -95,7 +97,7 @@ public class RowModel implements ProtobufMessageHandler, Serializable {
* @param cells the cells
*/
public RowModel(final String key, final List<CellModel> cells) {
this(key.getBytes(), cells);
this(Bytes.toBytes(key), cells);
}
/**

View File

@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import javax.ws.rs.Consumes;
@ -63,7 +64,7 @@ public class ProtobufMessageBodyConsumer
throws IOException, WebApplicationException {
ProtobufMessageHandler obj = null;
try {
obj = type.newInstance();
obj = type.getDeclaredConstructor().newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int read;
@ -78,9 +79,8 @@ public class ProtobufMessageBodyConsumer
inputStream);
}
obj = obj.getObjectFromMessage(baos.toByteArray());
} catch (InstantiationException e) {
throw new WebApplicationException(e);
} catch (IllegalAccessException e) {
} catch (InstantiationException | NoSuchMethodException | InvocationTargetException
| IllegalAccessException e) {
throw new WebApplicationException(e);
}
return obj;

View File

@ -31,8 +31,9 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.rest.Constants;
import org.apache.yetus.audience.InterfaceAudience;
/**
* An adapter between Jersey and Object.toString(). Hooks up plain text output
@ -64,6 +65,6 @@ public class PlainTextMessageBodyProducer
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream outStream)
throws IOException, WebApplicationException {
outStream.write(object.toString().getBytes());
outStream.write(Bytes.toBytes(object.toString()));
}
}

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.hbase.rest.provider.producer;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
@ -32,9 +31,9 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.rest.Constants;
import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
import org.apache.yetus.audience.InterfaceAudience;
/**
* An adapter between Jersey and ProtobufMessageHandler implementors. Hooks up
@ -61,6 +60,7 @@ public class ProtobufMessageBodyProducer
return -1;
}
@Override
public void writeTo(ProtobufMessageHandler m, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)

View File

@ -154,7 +154,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()));
@ -167,7 +167,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()));
@ -180,7 +180,7 @@ 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(200, response1.getCode());
assertEquals(Constants.MIMETYPE_XML, response1.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response1.getBody()));
@ -237,7 +237,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());
@ -250,7 +250,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());
@ -536,7 +536,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 JacksonJaxbJsonProvider()
.locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
@ -550,7 +550,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

@ -59,39 +59,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

@ -55,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<>();
@ -148,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<>();
@ -181,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
@ -220,44 +220,44 @@ 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
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;
@ -270,7 +270,7 @@ public class TestGetAndPutResource extends RowResourceBase {
assertTrue(foundTimestampHeader);
response = deleteRow(TABLE, ROW_3);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
}
@Test
@ -278,13 +278,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
@ -302,10 +302,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);
@ -314,7 +314,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
@ -330,7 +330,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);
}
@ -340,13 +340,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
@ -374,7 +371,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);
@ -383,9 +380,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
@ -411,7 +408,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);
@ -420,9 +417,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
@ -467,7 +464,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
@ -485,7 +482,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
@ -513,7 +510,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);
@ -522,9 +519,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
@ -532,13 +529,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,
@ -571,14 +568,14 @@ 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;
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response
.getBody()));
CellSetModel cellSet =
(CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertTrue(cellSet.getRows().size() == 1);
assertTrue(cellSet.getRows().get(0).getCells().size() == 3);
List<CellModel> cells = cellSet.getRows().get(0).getCells();
@ -587,7 +584,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) {
@ -627,7 +624,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();
@ -636,16 +633,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
@ -673,7 +670,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();
@ -684,7 +681,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()));
@ -695,114 +692,114 @@ 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

@ -99,7 +99,7 @@ public class TestGzipFilter {
headers[0] = new BasicHeader("Content-Type", Constants.MIMETYPE_BINARY);
headers[1] = new BasicHeader("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));
@ -114,7 +114,7 @@ public class TestGzipFilter {
headers[0] = new BasicHeader("Accept", Constants.MIMETYPE_BINARY);
headers[1] = new BasicHeader("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,15 +131,14 @@ public class TestGzipFilter {
headers[0] = new BasicHeader("Content-Type", Constants.MIMETYPE_XML);
headers[1] = new BasicHeader("Accept", Constants.MIMETYPE_JSON);
headers[2] = new BasicHeader("Accept-Encoding", "gzip");
Response response = client.post("/" + TABLE + "/scanner", headers,
"<Scanner/>".getBytes());
assertEquals(response.getCode(), 201);
Response response = client.post("/" + TABLE + "/scanner", headers, Bytes.toBytes("<Scanner/>"));
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

@ -18,10 +18,26 @@
*/
package org.apache.hadoop.hbase.rest;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import static org.junit.Assert.assertEquals;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import java.io.IOException;
import java.util.Collection;
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 org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.rest.client.Client;
import org.apache.hadoop.hbase.rest.client.Cluster;
@ -32,6 +48,8 @@ import org.apache.hadoop.hbase.rest.model.RowModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -39,19 +57,6 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
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.Collection;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import static org.junit.Assert.assertEquals;
@Category({RestTests.class, MediumTests.class})
@RunWith(Parameterized.class)
public class TestMultiRowResource {
@ -144,7 +149,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);
@ -171,7 +176,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);
@ -198,7 +203,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 JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class);
@ -227,7 +232,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 JacksonJaxbJsonProvider().locateMapper(CellSetModel.class,
MediaType.APPLICATION_JSON_TYPE);
CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class);

View File

@ -135,7 +135,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;
@ -161,7 +161,7 @@ public class TestScannerResource {
}
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
return count;
}
@ -217,7 +217,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);
@ -225,28 +225,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
@ -261,7 +261,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);
@ -269,28 +269,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
@ -304,7 +304,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);
@ -312,13 +312,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);
@ -341,23 +341,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
@ -371,7 +371,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
@ -383,7 +383,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.getAdmin().disableTable(TABLE_TO_BE_DISABLED);

View File

@ -49,7 +49,6 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.FilterList.Operator;
@ -122,8 +121,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 {
@ -230,13 +229,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()));
@ -252,7 +251,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)
@ -265,20 +264,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;
@ -319,20 +318,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

@ -17,11 +17,27 @@
*/
package org.apache.hadoop.hbase.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
@ -53,21 +69,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@Category({RestTests.class, MediumTests.class})
public class TestScannersWithLabels {
private static final TableName TABLE = TableName.valueOf("TestScannersWithLabels");
@ -163,6 +164,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)) {
@ -197,14 +199,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());
// With no content in the payload, the 'Content-Type' header is not echo back
}
@ -222,18 +224,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

@ -18,6 +18,10 @@
*/
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.IOException;
import java.io.StringWriter;
@ -26,11 +30,8 @@ import java.util.Collection;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
@ -43,9 +44,8 @@ import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -220,11 +220,11 @@ public class TestSchemaResource {
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
model.createProtobufOutput(), extraHdr);
assertNotNull(extraHdr);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
// retrieve the schema and validate it
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
model = new TableSchemaModel();
model.getObjectFromMessage(response.getBody());
@ -232,7 +232,7 @@ public class TestSchemaResource {
// retrieve the schema and validate it with alternate pbuf type
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"));
model = new TableSchemaModel();
model.getObjectFromMessage(response.getBody());
@ -246,14 +246,14 @@ public class TestSchemaResource {
// test delete schema operation is forbidden in read-only mode
response = client.delete(schemaPath, extraHdr);
assertEquals(response.getCode(), 403);
assertEquals(403, response.getCode());
// return read-only setting back to default
conf.set("hbase.rest.readonly", "false");
// delete the table and make sure HBase concurs
response = client.delete(schemaPath, extraHdr);
assertEquals(response.getCode(), 200);
assertEquals(200, response.getCode());
assertFalse(admin.tableExists(TableName.valueOf(TABLE2)));
}

View File

@ -18,6 +18,11 @@
*/
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 static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -35,9 +40,6 @@ import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -108,7 +110,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(
@ -119,13 +121,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

@ -32,12 +32,12 @@ import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
@ -123,7 +123,7 @@ public class TestTableResource {
RegionLocator regionLocator = connection.getRegionLocator(TABLE);
List<HRegionLocation> m = regionLocator.getAllRegionLocations();
assertEquals(m.size(), 1);
assertEquals(1, m.size());
// tell the master to split the table
admin.split(TABLE);
// give some time for the split to happen
@ -142,7 +142,7 @@ public class TestTableResource {
}
// should have two regions now
assertEquals(m.size(), 2);
assertEquals(2, m.size());
regionMap = m;
LOG.info("regions: " + regionMap);
regionLocator.close();
@ -202,14 +202,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()
@ -220,20 +220,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());
@ -243,14 +243,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()
@ -261,20 +261,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());

View File

@ -22,12 +22,19 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import java.io.DataInputStream;
import java.io.EOFException;
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;
@ -70,12 +77,6 @@ import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
@Category({RestTests.class, MediumTests.class})
public class TestTableScan {
private static final Logger LOG = LoggerFactory.getLogger(TestTableScan.class);
@ -283,12 +284,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);
@ -460,7 +463,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
@ -478,7 +482,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
@ -496,7 +501,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
@ -515,7 +521,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
@ -633,6 +640,7 @@ public class TestTableScan {
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

@ -18,6 +18,13 @@
*/
package org.apache.hadoop.hbase.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -34,17 +41,9 @@ import org.apache.hadoop.hbase.rest.model.VersionModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.glassfish.jersey.servlet.ServletContainer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -79,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

@ -29,6 +29,7 @@ import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.rest.Constants;
import org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@ -48,7 +49,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, Bytes.toBytes(xml));
when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);
@ -64,7 +65,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, Bytes.toBytes(externalEntitiesXml));
when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);

View File

@ -19,6 +19,10 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -48,6 +52,7 @@ public class TestCellModel extends TestModelBase<CellModel> {
"{\"column\":\"dGVzdGNvbHVtbg==\",\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVl\"}";
}
@Override
protected CellModel buildTestModel() {
CellModel model = new CellModel();
model.setColumn(COLUMN);
@ -56,21 +61,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

@ -19,6 +19,10 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.apache.hadoop.hbase.testclassification.RestTests;
@ -81,6 +85,7 @@ public class TestCellSetModel extends TestModelBase<CellSetModel> {
"\"timestamp\":1245393318192,\"$\":\"dGVzdHZhbHVlMw==\"}]}]}";
}
@Override
protected CellSetModel buildTestModel() {
CellSetModel model = new CellSetModel();
RowModel row;
@ -96,6 +101,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();
@ -105,7 +111,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()));
@ -114,23 +120,26 @@ 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

@ -19,8 +19,12 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category({RestTests.class, SmallTests.class})
@ -48,6 +52,7 @@ public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
"\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}";
}
@Override
protected ColumnSchemaModel buildTestModel() {
ColumnSchemaModel model = new ColumnSchemaModel();
model.setName(COLUMN_NAME);
@ -61,6 +66,7 @@ public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
return model;
}
@Override
protected void checkModel(ColumnSchemaModel model) {
assertEquals("name", COLUMN_NAME, model.getName());
assertEquals("block cache", BLOCKCACHE, model.__getBlockcache());
@ -72,6 +78,8 @@ public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
assertEquals("versions", VERSIONS, model.__getVersions());
}
@Override
@Test
public void testFromPB() throws Exception {
}
}

View File

@ -18,26 +18,30 @@
package org.apache.hadoop.hbase.rest.model;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
import org.apache.hadoop.hbase.rest.provider.JAXBContextResolver;
import org.apache.hadoop.hbase.util.Base64;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
@Category({RestTests.class, SmallTests.class})
public abstract class TestModelBase<T> extends TestCase {
public abstract class TestModelBase<T> {
protected String AS_XML;
@ -94,29 +98,34 @@ 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));
}
protected abstract void checkModel(T model);
@Test
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Test
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}
@Test
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Test
public void testToXML() throws Exception {
// Uses fromXML to check model because XML element ordering can be random.
checkModel(fromXML(toXML(buildTestModel())));
}
@Test
public void testToJSON() throws Exception {
try {
ObjectNode expObj = mapper.readValue(AS_JSON, ObjectNode.class);
@ -127,6 +136,7 @@ public abstract class TestModelBase<T> extends TestCase {
}
}
@Test
public void testFromJSON() throws Exception {
checkModel(fromJSON(AS_JSON));
}

View File

@ -19,6 +19,9 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import java.util.HashMap;
import java.util.Map;
@ -53,6 +56,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 +69,7 @@ public class TestNamespacesInstanceModel extends TestModelBase<NamespacesInstanc
return model;
}
@Override
protected void checkModel(NamespacesInstanceModel model) {
checkModel(model, NAMESPACE_NAME, NAMESPACE_PROPERTIES);
}
@ -80,16 +85,19 @@ public class TestNamespacesInstanceModel extends TestModelBase<NamespacesInstanc
}
}
@Override
@Test
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Override
@Test
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Override
@Test
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));

View File

@ -19,6 +19,9 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
@ -47,6 +50,7 @@ public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
AS_JSON = "{\"Namespace\":[\"testNamespace1\",\"testNamespace2\"]}";
}
@Override
protected NamespacesModel buildTestModel() {
return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2);
}
@ -57,6 +61,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 +74,19 @@ public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
}
}
@Override
@Test
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Override
@Test
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Override
@Test
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));

View File

@ -19,9 +19,11 @@
package org.apache.hadoop.hbase.rest.model;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import javax.xml.bind.JAXBContext;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
@ -41,8 +43,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 =
@ -54,6 +54,7 @@ public class TestRowModel extends TestModelBase<RowModel> {
"\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVlMQ==\"}]}";
}
@Override
protected RowModel buildTestModel() {
RowModel model = new RowModel();
model.setKey(ROW1);
@ -61,6 +62,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();
@ -68,7 +70,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

@ -19,6 +19,9 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
@ -58,6 +61,7 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
+ "JDj/////B0joB1IHcHJpdmF0ZVIGcHVibGljWAA=";
}
@Override
protected ScannerModel buildTestModel() {
ScannerModel model = new ScannerModel();
model.setStartRow(START_ROW);
@ -74,6 +78,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));
@ -87,11 +92,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

@ -19,6 +19,10 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.apache.hadoop.hbase.testclassification.RestTests;
@ -74,6 +78,7 @@ public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterS
"\"heapSizeMB\":512,\"maxHeapSizeMB\":1024}],\"DeadNodes\":[]}";
}
@Override
protected StorageClusterStatusModel buildTestModel() {
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.setRegions(2);
@ -87,56 +92,57 @@ 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.getStorefileIndexSizeKB(), 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.getStorefileIndexSizeKB());
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.getStorefileIndexSizeKB(), 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.getStorefileIndexSizeKB());
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

@ -19,6 +19,8 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.experimental.categories.Category;
@ -36,14 +38,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

@ -19,6 +19,10 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.apache.hadoop.hbase.testclassification.RestTests;
@ -55,6 +59,7 @@ public class TestTableInfoModel extends TestModelBase<TableInfoModel> {
"startKey\":\"YWJyYWNhZGJyYQ==\"}]}";
}
@Override
protected TableInfoModel buildTestModel() {
TableInfoModel model = new TableInfoModel();
model.setName(TABLE);
@ -62,25 +67,29 @@ 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());
}
@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

@ -19,6 +19,9 @@
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.Iterator;
import org.apache.hadoop.hbase.testclassification.RestTests;
@ -44,6 +47,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));
@ -52,14 +56,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

@ -19,11 +19,16 @@
package org.apache.hadoop.hbase.rest.model;
import org.apache.hadoop.hbase.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.RestTests;
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({RestTests.class, SmallTests.class})
@ -49,22 +54,25 @@ 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(ID, model.getId());
assertEquals(LOCATION, model.getLocation());
assertEquals(model.getName(),
TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) +
".ad9860f031282c46ed431d7af8f94aca.");
}
@Test
public void testGetName() {
TableRegionModel model = buildTestModel();
String modelName = model.getName();
@ -73,6 +81,7 @@ public class TestTableRegionModel extends TestModelBase<TableRegionModel> {
assertEquals(modelName, hri.getRegionNameAsString());
}
@Test
public void testSetName() {
TableRegionModel model = buildTestModel();
String name = model.getName();

View File

@ -19,13 +19,16 @@
package org.apache.hadoop.hbase.rest.model;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import javax.xml.bind.JAXBContext;
import java.util.Iterator;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -41,8 +44,6 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
TestColumnSchemaModel testColumnSchemaModel;
private JAXBContext context;
public TestTableSchemaModel() throws Exception {
super(TableSchemaModel.class);
testColumnSchemaModel = new TestColumnSchemaModel();
@ -67,6 +68,7 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
"\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\",\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}]}";
}
@Override
protected TableSchemaModel buildTestModel() {
return buildTestModel(TABLE_NAME);
}
@ -81,15 +83,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(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();
@ -97,14 +100,20 @@ public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
assertFalse(families.hasNext());
}
@Override
@Test
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
@Override
@Test
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
@Override
@Test
public void testFromPB() throws Exception {
checkModel(fromPB(AS_PB));
}

View File

@ -18,15 +18,11 @@
*/
package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals;
import org.apache.hadoop.hbase.testclassification.RestTests;
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({RestTests.class, SmallTests.class})
public class TestVersionModel extends TestModelBase<VersionModel> {
@ -55,6 +51,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 +62,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());
}
}