HBASE-9435 Fix jersey serialization/deserialization of json objects
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1520179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f515772c1f
commit
f8252c4bb1
|
@ -124,7 +124,7 @@ public class RemoteHTable implements HTableInterface {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (startTime != 0 && endTime != Long.MAX_VALUE) {
|
||||
if (startTime >= 0 && endTime != Long.MAX_VALUE) {
|
||||
sb.append('/');
|
||||
sb.append(startTime);
|
||||
if (startTime != endTime) {
|
||||
|
|
|
@ -22,6 +22,8 @@ package org.apache.hadoop.hbase.rest.model;
|
|||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
@ -33,6 +35,7 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
|
|||
import org.apache.hadoop.hbase.rest.protobuf.generated.CellMessage.Cell;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
||||
/**
|
||||
* Representation of a cell. A cell is a single value associated a column and
|
||||
|
@ -54,12 +57,21 @@ import com.google.protobuf.ByteString;
|
|||
* </pre>
|
||||
*/
|
||||
@XmlRootElement(name="Cell")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@InterfaceAudience.Private
|
||||
public class CellModel implements ProtobufMessageHandler, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private long timestamp = HConstants.LATEST_TIMESTAMP;
|
||||
@JsonProperty("column")
|
||||
@XmlAttribute
|
||||
private byte[] column;
|
||||
|
||||
@JsonProperty("timestamp")
|
||||
@XmlAttribute
|
||||
private long timestamp = HConstants.LATEST_TIMESTAMP;
|
||||
|
||||
@JsonProperty("$")
|
||||
@XmlValue
|
||||
private byte[] value;
|
||||
|
||||
/**
|
||||
|
@ -123,7 +135,6 @@ public class CellModel implements ProtobufMessageHandler, Serializable {
|
|||
/**
|
||||
* @return the column
|
||||
*/
|
||||
@XmlAttribute
|
||||
public byte[] getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
@ -146,7 +157,6 @@ public class CellModel implements ProtobufMessageHandler, Serializable {
|
|||
/**
|
||||
* @return the timestamp
|
||||
*/
|
||||
@XmlAttribute
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
@ -161,7 +171,6 @@ public class CellModel implements ProtobufMessageHandler, Serializable {
|
|||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlValue
|
||||
public byte[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
|
@ -69,11 +71,13 @@ import com.google.protobuf.ByteString;
|
|||
* </pre>
|
||||
*/
|
||||
@XmlRootElement(name="CellSet")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@InterfaceAudience.Private
|
||||
public class CellSetModel implements Serializable, ProtobufMessageHandler {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@XmlElement(name="Row")
|
||||
private List<RowModel> rows;
|
||||
|
||||
/**
|
||||
|
@ -102,7 +106,6 @@ public class CellSetModel implements Serializable, ProtobufMessageHandler {
|
|||
/**
|
||||
* @return the rows
|
||||
*/
|
||||
@XmlElement(name="Row")
|
||||
public List<RowModel> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ import javax.xml.namespace.QName;
|
|||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.codehaus.jackson.annotate.JsonAnyGetter;
|
||||
import org.codehaus.jackson.annotate.JsonAnySetter;
|
||||
|
||||
/**
|
||||
* Representation of a column family schema.
|
||||
|
@ -67,6 +69,7 @@ public class ColumnSchemaModel implements Serializable {
|
|||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public void addAttribute(String name, Object value) {
|
||||
attrs.put(new QName(name), value);
|
||||
}
|
||||
|
@ -92,6 +95,7 @@ public class ColumnSchemaModel implements Serializable {
|
|||
* @return the map for holding unspecified (user) attributes
|
||||
*/
|
||||
@XmlAnyAttribute
|
||||
@JsonAnyGetter
|
||||
public Map<QName,Object> getAny() {
|
||||
return attrs;
|
||||
}
|
||||
|
|
|
@ -24,12 +24,15 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
||||
/**
|
||||
* Representation of a row. A row is a related set of cells, grouped by common
|
||||
|
@ -47,13 +50,20 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
|
|||
* </pre>
|
||||
*/
|
||||
@XmlRootElement(name="Row")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@InterfaceAudience.Private
|
||||
public class RowModel implements ProtobufMessageHandler, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonProperty("key")
|
||||
@XmlAttribute
|
||||
private byte[] key;
|
||||
|
||||
@JsonProperty("Cell")
|
||||
@XmlElement(name="Cell")
|
||||
private List<CellModel> cells = new ArrayList<CellModel>();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
|
@ -106,7 +116,6 @@ public class RowModel implements ProtobufMessageHandler, Serializable {
|
|||
/**
|
||||
* @return the row key
|
||||
*/
|
||||
@XmlAttribute
|
||||
public byte[] getKey() {
|
||||
return key;
|
||||
}
|
||||
|
@ -121,7 +130,6 @@ public class RowModel implements ProtobufMessageHandler, Serializable {
|
|||
/**
|
||||
* @return the cells
|
||||
*/
|
||||
@XmlElement(name="Cell")
|
||||
public List<CellModel> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.apache.hadoop.hbase.rest.model;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonValue;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
@ -60,8 +62,17 @@ public class StorageClusterVersionModel implements Serializable {
|
|||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@JsonValue
|
||||
@Override
|
||||
public String toString() {
|
||||
return version;
|
||||
}
|
||||
|
||||
//needed for jackson deserialization
|
||||
private static StorageClusterVersionModel valueOf(String value) {
|
||||
StorageClusterVersionModel versionModel
|
||||
= new StorageClusterVersionModel();
|
||||
versionModel.setVersion(value);
|
||||
return versionModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
|
|||
import org.apache.hadoop.hbase.rest.protobuf.generated.ColumnSchemaMessage.ColumnSchema;
|
||||
import org.apache.hadoop.hbase.rest.protobuf.generated.TableSchemaMessage.TableSchema;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.codehaus.jackson.annotate.JsonAnyGetter;
|
||||
import org.codehaus.jackson.annotate.JsonAnySetter;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
|
||||
/**
|
||||
* A representation of HBase table descriptors.
|
||||
|
@ -107,6 +110,7 @@ public class TableSchemaModel implements Serializable, ProtobufMessageHandler {
|
|||
* @param name attribute name
|
||||
* @param value attribute value
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public void addAttribute(String name, Object value) {
|
||||
attrs.put(new QName(name), value);
|
||||
}
|
||||
|
@ -151,6 +155,7 @@ public class TableSchemaModel implements Serializable, ProtobufMessageHandler {
|
|||
* @return the map for holding unspecified (user) attributes
|
||||
*/
|
||||
@XmlAnyAttribute
|
||||
@JsonAnyGetter
|
||||
public Map<QName,Object> getAny() {
|
||||
return attrs;
|
||||
}
|
||||
|
@ -337,6 +342,7 @@ public class TableSchemaModel implements Serializable, ProtobufMessageHandler {
|
|||
/**
|
||||
* @return a table descriptor
|
||||
*/
|
||||
@JsonIgnore
|
||||
public HTableDescriptor getTableDescriptor() {
|
||||
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(getName()));
|
||||
for (Map.Entry<QName, Object> e: getAny().entrySet()) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.rest.provider;
|
||||
|
||||
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
|
||||
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
//create a class in the defined resource package name
|
||||
//so it gets activated
|
||||
//Use jackson to take care of json
|
||||
//since it has better support for object
|
||||
//deserializaiton and less clunky to deal with
|
||||
@Provider
|
||||
public class JacksonProvider extends JacksonJaxbJsonProvider {
|
||||
}
|
|
@ -56,6 +56,7 @@ public class TestSchemaResource {
|
|||
private static Client client;
|
||||
private static JAXBContext context;
|
||||
private static Configuration conf;
|
||||
private static TestTableSchemaModel testTableSchemaModel;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
|
@ -64,6 +65,7 @@ public class TestSchemaResource {
|
|||
REST_TEST_UTIL.startServletContainer(conf);
|
||||
client = new Client(new Cluster().add("localhost",
|
||||
REST_TEST_UTIL.getServletPort()));
|
||||
testTableSchemaModel = new TestTableSchemaModel();
|
||||
context = JAXBContext.newInstance(
|
||||
ColumnSchemaModel.class,
|
||||
TableSchemaModel.class);
|
||||
|
@ -97,8 +99,8 @@ public class TestSchemaResource {
|
|||
assertFalse(admin.tableExists(TABLE1));
|
||||
|
||||
// create the table
|
||||
model = TestTableSchemaModel.buildTestModel(TABLE1);
|
||||
TestTableSchemaModel.checkModel(model, TABLE1);
|
||||
model = testTableSchemaModel.buildTestModel(TABLE1);
|
||||
testTableSchemaModel.checkModel(model, TABLE1);
|
||||
response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model));
|
||||
assertEquals(response.getCode(), 201);
|
||||
|
||||
|
@ -112,7 +114,14 @@ public class TestSchemaResource {
|
|||
assertEquals(response.getCode(), 200);
|
||||
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
|
||||
model = fromXML(response.getBody());
|
||||
TestTableSchemaModel.checkModel(model, TABLE1);
|
||||
testTableSchemaModel.checkModel(model, TABLE1);
|
||||
|
||||
// with json retrieve the schema and validate it
|
||||
response = client.get(schemaPath, Constants.MIMETYPE_JSON);
|
||||
assertEquals(response.getCode(), 200);
|
||||
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
|
||||
model = testTableSchemaModel.fromJSON(Bytes.toString(response.getBody()));
|
||||
testTableSchemaModel.checkModel(model, TABLE1);
|
||||
|
||||
// delete the table
|
||||
client.delete(schemaPath);
|
||||
|
@ -134,8 +143,8 @@ public class TestSchemaResource {
|
|||
assertFalse(admin.tableExists(TABLE2));
|
||||
|
||||
// create the table
|
||||
model = TestTableSchemaModel.buildTestModel(TABLE2);
|
||||
TestTableSchemaModel.checkModel(model, TABLE2);
|
||||
model = testTableSchemaModel.buildTestModel(TABLE2);
|
||||
testTableSchemaModel.checkModel(model, TABLE2);
|
||||
response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF,
|
||||
model.createProtobufOutput());
|
||||
assertEquals(response.getCode(), 201);
|
||||
|
@ -152,7 +161,7 @@ public class TestSchemaResource {
|
|||
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
|
||||
model = new TableSchemaModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
TestTableSchemaModel.checkModel(model, TABLE2);
|
||||
testTableSchemaModel.checkModel(model, TABLE2);
|
||||
|
||||
// retrieve the schema and validate it with alternate pbuf type
|
||||
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF_IETF);
|
||||
|
@ -160,7 +169,7 @@ public class TestSchemaResource {
|
|||
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
|
||||
model = new TableSchemaModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
TestTableSchemaModel.checkModel(model, TABLE2);
|
||||
testTableSchemaModel.checkModel(model, TABLE2);
|
||||
|
||||
// delete the table
|
||||
client.delete(schemaPath);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TestStatusResource {
|
|||
|
||||
private static void validate(StorageClusterStatusModel model) {
|
||||
assertNotNull(model);
|
||||
assertTrue(model.getRegions() >= 1);
|
||||
assertTrue(model.getRegions() + ">= 1", model.getRegions() >= 1);
|
||||
assertTrue(model.getRequests() >= 0);
|
||||
assertTrue(model.getAverageLoad() >= 0.0);
|
||||
assertNotNull(model.getLiveNodes());
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.io.StringWriter;
|
|||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import com.sun.jersey.api.json.JSONJAXBContext;
|
||||
import org.apache.hadoop.hbase.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.Base64;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
@ -34,28 +35,25 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestCellModel extends TestCase {
|
||||
public class TestCellModel extends TestModelBase<CellModel> {
|
||||
|
||||
private static final long TIMESTAMP = 1245219839331L;
|
||||
private static final byte[] COLUMN = Bytes.toBytes("testcolumn");
|
||||
private static final byte[] VALUE = Bytes.toBytes("testvalue");
|
||||
|
||||
private static final String AS_XML =
|
||||
"<Cell timestamp=\"1245219839331\"" +
|
||||
" column=\"dGVzdGNvbHVtbg==\">" +
|
||||
"dGVzdHZhbHVl</Cell>";
|
||||
public TestCellModel() throws Exception {
|
||||
super(CellModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Cell " +
|
||||
"column=\"dGVzdGNvbHVtbg==\" timestamp=\"1245219839331\">dGVzdHZhbHVl</Cell>";
|
||||
AS_PB =
|
||||
"Egp0ZXN0Y29sdW1uGOO6i+eeJCIJdGVzdHZhbHVl";
|
||||
|
||||
private static final String AS_PB =
|
||||
"Egp0ZXN0Y29sdW1uGOO6i+eeJCIJdGVzdHZhbHVl";
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestCellModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(CellModel.class);
|
||||
AS_JSON =
|
||||
"{\"column\":\"dGVzdGNvbHVtbg==\",\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVl\"}";
|
||||
}
|
||||
|
||||
private CellModel buildTestModel() {
|
||||
protected CellModel buildTestModel() {
|
||||
CellModel model = new CellModel();
|
||||
model.setColumn(COLUMN);
|
||||
model.setTimestamp(TIMESTAMP);
|
||||
|
@ -63,29 +61,7 @@ public class TestCellModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(CellModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private CellModel fromXML(String xml) throws JAXBException {
|
||||
return (CellModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(CellModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private CellModel fromPB(String pb) throws IOException {
|
||||
return (CellModel)
|
||||
new CellModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(CellModel model) {
|
||||
protected void checkModel(CellModel model) {
|
||||
assertTrue(Bytes.equals(model.getColumn(), COLUMN));
|
||||
assertTrue(Bytes.equals(model.getValue(), VALUE));
|
||||
assertTrue(model.hasUserTimestamp());
|
||||
|
|
|
@ -35,7 +35,7 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestCellSetModel extends TestCase {
|
||||
public class TestCellSetModel extends TestModelBase<CellSetModel> {
|
||||
|
||||
private static final byte[] ROW1 = Bytes.toBytes("testrow1");
|
||||
private static final byte[] COLUMN1 = Bytes.toBytes("testcolumn1");
|
||||
|
@ -49,36 +49,46 @@ public class TestCellSetModel extends TestCase {
|
|||
private static final byte[] VALUE3 = Bytes.toBytes("testvalue3");
|
||||
private static final long TIMESTAMP3 = 1245393318192L;
|
||||
|
||||
private static final String AS_XML =
|
||||
"<CellSet>" +
|
||||
"<Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell timestamp=\"1245219839331\" column=\"dGVzdGNvbHVtbjE=\">" +
|
||||
"dGVzdHZhbHVlMQ==</Cell>" +
|
||||
"</Row>" +
|
||||
"<Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell timestamp=\"1245239813319\" column=\"dGVzdGNvbHVtbjI=\">" +
|
||||
"dGVzdHZhbHVlMg==</Cell>" +
|
||||
"<Cell timestamp=\"1245393318192\" column=\"dGVzdGNvbHVtbjM=\">" +
|
||||
"dGVzdHZhbHVlMw==</Cell>" +
|
||||
"</Row>" +
|
||||
"</CellSet>";
|
||||
public TestCellSetModel() throws Exception {
|
||||
super(CellSetModel.class);
|
||||
AS_XML =
|
||||
"<CellSet>" +
|
||||
"<Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell timestamp=\"1245219839331\" column=\"dGVzdGNvbHVtbjE=\">" +
|
||||
"dGVzdHZhbHVlMQ==</Cell>" +
|
||||
"</Row>" +
|
||||
"<Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell timestamp=\"1245239813319\" column=\"dGVzdGNvbHVtbjI=\">" +
|
||||
"dGVzdHZhbHVlMg==</Cell>" +
|
||||
"<Cell timestamp=\"1245393318192\" column=\"dGVzdGNvbHVtbjM=\">" +
|
||||
"dGVzdHZhbHVlMw==</Cell>" +
|
||||
"</Row>" +
|
||||
"</CellSet>";
|
||||
|
||||
private static final String AS_PB =
|
||||
"CiwKCHRlc3Ryb3cxEiASC3Rlc3Rjb2x1bW4xGOO6i+eeJCIKdGVzdHZhbHVlMQpOCgh0ZXN0cm93" +
|
||||
"MRIgEgt0ZXN0Y29sdW1uMhjHyc7wniQiCnRlc3R2YWx1ZTISIBILdGVzdGNvbHVtbjMYsOLnuZ8k" +
|
||||
"Igp0ZXN0dmFsdWUz";
|
||||
AS_PB =
|
||||
"CiwKCHRlc3Ryb3cxEiASC3Rlc3Rjb2x1bW4xGOO6i+eeJCIKdGVzdHZhbHVlMQpOCgh0ZXN0cm93" +
|
||||
"MRIgEgt0ZXN0Y29sdW1uMhjHyc7wniQiCnRlc3R2YWx1ZTISIBILdGVzdGNvbHVtbjMYsOLnuZ8k" +
|
||||
"Igp0ZXN0dmFsdWUz";
|
||||
|
||||
private JAXBContext context;
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CellSet>" +
|
||||
"<Row key=\"dGVzdHJvdzE=\"><Cell column=\"dGVzdGNvbHVtbjE=\" timestamp=\"1245219839331\">" +
|
||||
"dGVzdHZhbHVlMQ==</Cell></Row><Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell column=\"dGVzdGNvbHVtbjI=\" timestamp=\"1245239813319\">" +
|
||||
"dGVzdHZhbHVlMg==</Cell>" +
|
||||
"<Cell column=\"dGVzdGNvbHVtbjM=\" timestamp=\"1245393318192\">dGVzdHZhbHVlMw==</Cell>" +
|
||||
"</Row></CellSet>";
|
||||
|
||||
public TestCellSetModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(
|
||||
CellModel.class,
|
||||
CellSetModel.class,
|
||||
RowModel.class);
|
||||
AS_JSON =
|
||||
"{\"Row\":[{\"key\":\"dGVzdHJvdzE=\"," +
|
||||
"\"Cell\":[{\"column\":\"dGVzdGNvbHVtbjE=\",\"timestamp\":1245219839331," +
|
||||
"\"$\":\"dGVzdHZhbHVlMQ==\"}]},{\"key\":\"dGVzdHJvdzE=\"," +
|
||||
"\"Cell\":[{\"column\":\"dGVzdGNvbHVtbjI=\",\"timestamp\":1245239813319," +
|
||||
"\"$\":\"dGVzdHZhbHVlMg==\"},{\"column\":\"dGVzdGNvbHVtbjM=\"," +
|
||||
"\"timestamp\":1245393318192,\"$\":\"dGVzdHZhbHVlMw==\"}]}]}";
|
||||
}
|
||||
|
||||
private CellSetModel buildTestModel() {
|
||||
protected CellSetModel buildTestModel() {
|
||||
CellSetModel model = new CellSetModel();
|
||||
RowModel row;
|
||||
row = new RowModel();
|
||||
|
@ -93,29 +103,7 @@ public class TestCellSetModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(CellSetModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private CellSetModel fromXML(String xml) throws JAXBException {
|
||||
return (CellSetModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(CellSetModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private CellSetModel fromPB(String pb) throws IOException {
|
||||
return (CellSetModel)
|
||||
new CellSetModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(CellSetModel model) {
|
||||
protected void checkModel(CellSetModel model) {
|
||||
Iterator<RowModel> rows = model.getRows().iterator();
|
||||
RowModel row = rows.next();
|
||||
assertTrue(Bytes.equals(ROW1, row.getKey()));
|
||||
|
|
|
@ -27,10 +27,12 @@ import javax.xml.bind.JAXBException;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.hadoop.hbase.SmallTests;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestColumnSchemaModel extends TestCase {
|
||||
public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
|
||||
|
||||
protected static final String COLUMN_NAME = "testcolumn";
|
||||
protected static final boolean BLOCKCACHE = true;
|
||||
|
@ -41,24 +43,20 @@ public class TestColumnSchemaModel extends TestCase {
|
|||
protected static final int TTL = 86400;
|
||||
protected static final int VERSIONS = 1;
|
||||
|
||||
protected static final String AS_XML =
|
||||
"<ColumnSchema name=\"testcolumn\"" +
|
||||
" BLOCKSIZE=\"16384\"" +
|
||||
" BLOOMFILTER=\"NONE\"" +
|
||||
" BLOCKCACHE=\"true\"" +
|
||||
" COMPRESSION=\"GZ\"" +
|
||||
" VERSIONS=\"1\"" +
|
||||
" TTL=\"86400\"" +
|
||||
" IN_MEMORY=\"false\"/>";
|
||||
public TestColumnSchemaModel() throws Exception {
|
||||
super(ColumnSchemaModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ColumnSchema " +
|
||||
"name=\"testcolumn\" BLOCKSIZE=\"16384\" BLOOMFILTER=\"NONE\" BLOCKCACHE=\"true\" " +
|
||||
"COMPRESSION=\"GZ\" VERSIONS=\"1\" TTL=\"86400\" IN_MEMORY=\"false\"/>";
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestColumnSchemaModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(ColumnSchemaModel.class);
|
||||
AS_JSON =
|
||||
"{\"name\":\"testcolumn\",\"BLOCKSIZE\":\"16384\",\"BLOOMFILTER\":\"NONE\"," +
|
||||
"\"BLOCKCACHE\":\"true\",\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\"," +
|
||||
"\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}";
|
||||
}
|
||||
|
||||
protected static ColumnSchemaModel buildTestModel() {
|
||||
protected ColumnSchemaModel buildTestModel() {
|
||||
ColumnSchemaModel model = new ColumnSchemaModel();
|
||||
model.setName(COLUMN_NAME);
|
||||
model.__setBlockcache(BLOCKCACHE);
|
||||
|
@ -71,19 +69,7 @@ public class TestColumnSchemaModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(ColumnSchemaModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private ColumnSchemaModel fromXML(String xml) throws JAXBException {
|
||||
return (ColumnSchemaModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
protected static void checkModel(ColumnSchemaModel model) {
|
||||
protected void checkModel(ColumnSchemaModel model) {
|
||||
assertEquals(model.getName(), COLUMN_NAME);
|
||||
assertEquals(model.__getBlockcache(), BLOCKCACHE);
|
||||
assertEquals(model.__getBlocksize(), BLOCKSIZE);
|
||||
|
@ -94,13 +80,7 @@ public class TestColumnSchemaModel extends TestCase {
|
|||
assertEquals(model.__getVersions(), VERSIONS);
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
public void testFromPB() throws Exception {
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase.rest.model;
|
||||
|
||||
import com.sun.jersey.api.json.JSONJAXBContext;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.hadoop.hbase.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.apache.hadoop.hbase.util.Bytes;
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
import org.codehaus.jackson.JsonParseException;
|
||||
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
|
||||
import org.codehaus.jackson.map.AnnotationIntrospector;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.map.SerializationConfig;
|
||||
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
|
||||
import org.codehaus.jackson.node.ObjectNode;
|
||||
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
|
||||
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 java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public abstract class TestModelBase<T> extends TestCase {
|
||||
|
||||
protected String AS_XML;
|
||||
|
||||
protected String AS_PB;
|
||||
|
||||
protected String AS_JSON;
|
||||
|
||||
protected JAXBContext context;
|
||||
|
||||
protected Class<?> clazz;
|
||||
|
||||
protected ObjectMapper mapper;
|
||||
|
||||
protected TestModelBase(Class<?> clazz) throws Exception {
|
||||
super();
|
||||
this.clazz = clazz;
|
||||
context = new JAXBContextResolver().getContext(clazz);
|
||||
mapper = new JacksonJaxbJsonProvider().locateMapper(clazz,
|
||||
MediaType.APPLICATION_JSON_TYPE);
|
||||
}
|
||||
|
||||
protected abstract T buildTestModel();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected String toXML(T model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
protected String toJSON(T model) throws JAXBException, IOException {
|
||||
StringWriter writer = new StringWriter();
|
||||
mapper.writeValue(writer, model);
|
||||
// original marshaller, uncomment this and comment mapper to verify backward compatibility
|
||||
// ((JSONJAXBContext)context).createJSONMarshaller().marshallToJSON(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public T fromJSON(String json) throws JAXBException, IOException {
|
||||
return (T)
|
||||
mapper.readValue(json, clazz);
|
||||
}
|
||||
|
||||
public T fromXML(String xml) throws JAXBException {
|
||||
return (T)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected byte[] toPB(ProtobufMessageHandler model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
protected T fromPB(String pb) throws
|
||||
Exception {
|
||||
return (T)clazz.getMethod("getObjectFromMessage", byte[].class).invoke(
|
||||
clazz.newInstance(),
|
||||
Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
protected abstract void checkModel(T model);
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
}
|
||||
|
||||
public void testFromPB() throws Exception {
|
||||
checkModel(fromPB(AS_PB));
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
public void testToXML() throws Exception {
|
||||
assertEquals(AS_XML, toXML(buildTestModel()));
|
||||
}
|
||||
|
||||
public void testToJSON() throws Exception {
|
||||
try {
|
||||
ObjectNode expObj = mapper.readValue(AS_JSON, ObjectNode.class);
|
||||
ObjectNode actObj = mapper.readValue(toJSON(buildTestModel()), ObjectNode.class);
|
||||
assertEquals(expObj, actObj);
|
||||
} catch(Exception e) {
|
||||
assertEquals(AS_JSON, toJSON(buildTestModel()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJSON() throws Exception {
|
||||
checkModel(fromJSON(AS_JSON));
|
||||
}
|
||||
}
|
||||
|
|
@ -33,48 +33,34 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestRowModel extends TestCase {
|
||||
public class TestRowModel extends TestModelBase<RowModel> {
|
||||
|
||||
private static final byte[] ROW1 = Bytes.toBytes("testrow1");
|
||||
private static final byte[] COLUMN1 = Bytes.toBytes("testcolumn1");
|
||||
private static final byte[] VALUE1 = Bytes.toBytes("testvalue1");
|
||||
private static final long TIMESTAMP1 = 1245219839331L;
|
||||
|
||||
private static final String AS_XML =
|
||||
"<Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell timestamp=\"1245219839331\" column=\"dGVzdGNvbHVtbjE=\">" +
|
||||
"dGVzdHZhbHVlMQ==</Cell>" +
|
||||
"</Row>";
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestRowModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(
|
||||
CellModel.class,
|
||||
RowModel.class);
|
||||
public TestRowModel() throws Exception {
|
||||
super(RowModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Row key=\"dGVzdHJvdzE=\">" +
|
||||
"<Cell column=\"dGVzdGNvbHVtbjE=\" timestamp=\"1245219839331\">dGVzdHZhbHVlMQ==</Cell></Row>";
|
||||
|
||||
AS_JSON =
|
||||
"{\"key\":\"dGVzdHJvdzE=\",\"Cell\":[{\"column\":\"dGVzdGNvbHVtbjE=\"," +
|
||||
"\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVlMQ==\"}]}";
|
||||
}
|
||||
|
||||
private RowModel buildTestModel() {
|
||||
protected RowModel buildTestModel() {
|
||||
RowModel model = new RowModel();
|
||||
model.setKey(ROW1);
|
||||
model.addCell(new CellModel(COLUMN1, TIMESTAMP1, VALUE1));
|
||||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(RowModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private RowModel fromXML(String xml) throws JAXBException {
|
||||
return (RowModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
private void checkModel(RowModel model) {
|
||||
protected void checkModel(RowModel model) {
|
||||
assertTrue(Bytes.equals(ROW1, model.getKey()));
|
||||
Iterator<CellModel> cells = model.getCells().iterator();
|
||||
CellModel cell = cells.next();
|
||||
|
@ -85,13 +71,9 @@ public class TestRowModel extends TestCase {
|
|||
assertFalse(cells.hasNext());
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
@Override
|
||||
public void testFromPB() throws Exception {
|
||||
//do nothing row model has no PB
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestScannerModel extends TestCase {
|
||||
public class TestScannerModel extends TestModelBase<ScannerModel> {
|
||||
private static final byte[] START_ROW = Bytes.toBytes("abracadabra");
|
||||
private static final byte[] END_ROW = Bytes.toBytes("zzyzx");
|
||||
private static final byte[] COLUMN1 = Bytes.toBytes("column1");
|
||||
|
@ -44,29 +44,25 @@ public class TestScannerModel extends TestCase {
|
|||
private static final int CACHING = 1000;
|
||||
private static final int BATCH = 100;
|
||||
|
||||
private static final String AS_XML =
|
||||
"<Scanner startTime=\"1245219839331\"" +
|
||||
" startRow=\"YWJyYWNhZGFicmE=\"" +
|
||||
" endTime=\"1245393318192\"" +
|
||||
" endRow=\"enp5eng=\"" +
|
||||
" batch=\"100\"" +
|
||||
" caching=\"1000\">" +
|
||||
"<column>Y29sdW1uMQ==</column>" +
|
||||
"<column>Y29sdW1uMjpmb28=</column>" +
|
||||
"</Scanner>";
|
||||
public TestScannerModel() throws Exception {
|
||||
super(ScannerModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||
"<Scanner batch=\"100\" caching=\"1000\" endRow=\"enp5eng=\" endTime=\"1245393318192\" " +
|
||||
"maxVersions=\"2147483647\" startRow=\"YWJyYWNhZGFicmE=\" startTime=\"1245219839331\">" +
|
||||
"<column>Y29sdW1uMQ==</column><column>Y29sdW1uMjpmb28=</column></Scanner>";
|
||||
|
||||
private static final String AS_PB =
|
||||
"CgthYnJhY2FkYWJyYRIFenp5engaB2NvbHVtbjEaC2NvbHVtbjI6Zm9" +
|
||||
"vIGQo47qL554kMLDi57mfJDj/////B0joBw==";
|
||||
AS_JSON =
|
||||
"{\"batch\":100,\"caching\":1000,\"endRow\":\"enp5eng=\",\"endTime\":1245393318192,"+
|
||||
"\"maxVersions\":2147483647,\"startRow\":\"YWJyYWNhZGFicmE=\",\"startTime\":1245219839331,"+
|
||||
"\"column\":[\"Y29sdW1uMQ==\",\"Y29sdW1uMjpmb28=\"]}";
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestScannerModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(ScannerModel.class);
|
||||
AS_PB =
|
||||
"CgthYnJhY2FkYWJyYRIFenp5engaB2NvbHVtbjEaC2NvbHVtbjI6Zm9vIGQo47qL554kMLDi57mf" +
|
||||
"JDj/////B0joBw==";
|
||||
}
|
||||
|
||||
private ScannerModel buildTestModel() {
|
||||
protected ScannerModel buildTestModel() {
|
||||
ScannerModel model = new ScannerModel();
|
||||
model.setStartRow(START_ROW);
|
||||
model.setEndRow(END_ROW);
|
||||
|
@ -79,29 +75,7 @@ public class TestScannerModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(ScannerModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private ScannerModel fromXML(String xml) throws JAXBException {
|
||||
return (ScannerModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(ScannerModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private ScannerModel fromPB(String pb) throws IOException {
|
||||
return (ScannerModel)
|
||||
new ScannerModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(ScannerModel model) {
|
||||
protected void checkModel(ScannerModel model) {
|
||||
assertTrue(Bytes.equals(model.getStartRow(), START_ROW));
|
||||
assertTrue(Bytes.equals(model.getEndRow(), END_ROW));
|
||||
boolean foundCol1 = false, foundCol2 = false;
|
||||
|
@ -120,16 +94,5 @@ public class TestScannerModel extends TestCase {
|
|||
assertEquals(model.getCaching(), CACHING);
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
public void testFromPB() throws Exception {
|
||||
checkModel(fromPB(AS_PB));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,60 +19,62 @@
|
|||
|
||||
package org.apache.hadoop.hbase.rest.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.hadoop.hbase.SmallTests;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.util.Base64;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestStorageClusterStatusModel extends TestCase {
|
||||
public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterStatusModel> {
|
||||
|
||||
private static final String AS_XML =
|
||||
"<ClusterStatus requests=\"0\" regions=\"2\" averageLoad=\"1.0\">" +
|
||||
"<DeadNodes/>" +
|
||||
"<LiveNodes><Node startCode=\"1245219839331\" requests=\"0\"" +
|
||||
" name=\"test1\" maxHeapSizeMB=\"1024\" heapSizeMB=\"128\">" +
|
||||
"<Region stores=\"1\" storefiles=\"1\" storefileSizeMB=\"0\"" +
|
||||
" storefileIndexSizeMB=\"0\" name=\"aGJhc2U6cm9vdCwsMA==\"" +
|
||||
" memstoreSizeMB=\"0\" readRequestsCount=\"1\"" +
|
||||
" writeRequestsCount=\"2\" rootIndexSizeKB=\"1\"" +
|
||||
" totalStaticIndexSizeKB=\"1\" totalStaticBloomSizeKB=\"1\"" +
|
||||
" totalCompactingKVs=\"1\" currentCompactedKVs=\"1\"/></Node>" +
|
||||
"<Node startCode=\"1245239331198\" requests=\"0\" name=\"test2\"" +
|
||||
" maxHeapSizeMB=\"1024\" heapSizeMB=\"512\">" +
|
||||
"<Region stores=\"1\" storefiles=\"1\" storefileSizeMB=\"0\"" +
|
||||
" storefileIndexSizeMB=\"0\" name=\"aGJhc2U6bWV0YSwsMTI0NjAwMDA0MzcyNA==\"" +
|
||||
" memstoreSizeMB=\"0\" readRequestsCount=\"1\"" +
|
||||
" writeRequestsCount=\"2\" rootIndexSizeKB=\"1\"" +
|
||||
" totalStaticIndexSizeKB=\"1\" totalStaticBloomSizeKB=\"1\"" +
|
||||
" totalCompactingKVs=\"1\" currentCompactedKVs=\"1\"/></Node>"+
|
||||
"</LiveNodes></ClusterStatus>";
|
||||
public TestStorageClusterStatusModel() throws Exception {
|
||||
super(StorageClusterStatusModel.class);
|
||||
|
||||
private static final String AS_PB =
|
||||
"Cj8KBXRlc3QxEOO6i+eeJBgAIIABKIAIMicKDWhiYXNlOnJvb3QsLDAQARgBIAAoADAAOAFAAkgB"+
|
||||
"UAFYAWABaAEKSwoFdGVzdDIQ/pKx8J4kGAAggAQogAgyMwoZaGJhc2U6bWV0YSwsMTI0NjAwMDA0"+
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||
"<ClusterStatus averageLoad=\"1.0\" regions=\"2\" requests=\"0\">" +
|
||||
"<DeadNodes/><LiveNodes>" +
|
||||
"<Node heapSizeMB=\"128\" maxHeapSizeMB=\"1024\" name=\"test1\" requests=\"0\" startCode=\"1245219839331\">" +
|
||||
"<Region currentCompactedKVs=\"1\" memstoreSizeMB=\"0\" name=\"aGJhc2U6cm9vdCwsMA==\" readRequestsCount=\"1\" " +
|
||||
"rootIndexSizeKB=\"1\" storefileIndexSizeMB=\"0\" storefileSizeMB=\"0\" storefiles=\"1\" stores=\"1\" " +
|
||||
"totalCompactingKVs=\"1\" totalStaticBloomSizeKB=\"1\" totalStaticIndexSizeKB=\"1\" writeRequestsCount=\"2\"/>" +
|
||||
"</Node>" +
|
||||
"<Node heapSizeMB=\"512\" maxHeapSizeMB=\"1024\" name=\"test2\" requests=\"0\" startCode=\"1245239331198\">" +
|
||||
"<Region currentCompactedKVs=\"1\" memstoreSizeMB=\"0\" name=\"aGJhc2U6bWV0YSwsMTI0NjAwMDA0MzcyNA==\" " +
|
||||
"readRequestsCount=\"1\" rootIndexSizeKB=\"1\" storefileIndexSizeMB=\"0\" storefileSizeMB=\"0\" " +
|
||||
"storefiles=\"1\" stores=\"1\" totalCompactingKVs=\"1\" totalStaticBloomSizeKB=\"1\" " +
|
||||
"totalStaticIndexSizeKB=\"1\" writeRequestsCount=\"2\"/></Node></LiveNodes></ClusterStatus>";
|
||||
|
||||
AS_PB =
|
||||
"Cj8KBXRlc3QxEOO6i+eeJBgAIIABKIAIMicKDWhiYXNlOnJvb3QsLDAQARgBIAAoADAAOAFAAkgB" +
|
||||
"UAFYAWABaAEKSwoFdGVzdDIQ/pKx8J4kGAAggAQogAgyMwoZaGJhc2U6bWV0YSwsMTI0NjAwMDA0" +
|
||||
"MzcyNBABGAEgACgAMAA4AUACSAFQAVgBYAFoARgCIAApAAAAAAAA8D8=";
|
||||
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestStorageClusterStatusModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(StorageClusterStatusModel.class);
|
||||
//Using jackson will break json backward compatibilty for this representation
|
||||
//but the original one was broken as it would only print one Node element
|
||||
//so the format itself was broken
|
||||
AS_JSON =
|
||||
"{\"regions\":2,\"requests\":0,\"averageLoad\":1.0,\"LiveNodes\":[{\"name\":\"test1\"," +
|
||||
"\"Region\":[{\"name\":\"aGJhc2U6cm9vdCwsMA==\",\"stores\":1,\"storefiles\":1," +
|
||||
"\"storefileSizeMB\":0,\"memstoreSizeMB\":0,\"storefileIndexSizeMB\":0," +
|
||||
"\"readRequestsCount\":1,\"writeRequestsCount\":2,\"rootIndexSizeKB\":1," +
|
||||
"\"totalStaticIndexSizeKB\":1,\"totalStaticBloomSizeKB\":1,\"totalCompactingKVs\":1," +
|
||||
"\"currentCompactedKVs\":1}],\"requests\":0,\"startCode\":1245219839331," +
|
||||
"\"heapSizeMB\":128,\"maxHeapSizeMB\":1024},{\"name\":\"test2\"," +
|
||||
"\"Region\":[{\"name\":\"aGJhc2U6bWV0YSwsMTI0NjAwMDA0MzcyNA==\",\"stores\":1," +
|
||||
"\"storefiles\":1,\"storefileSizeMB\":0,\"memstoreSizeMB\":0,\"storefileIndexSizeMB\":0," +
|
||||
"\"readRequestsCount\":1,\"writeRequestsCount\":2,\"rootIndexSizeKB\":1," +
|
||||
"\"totalStaticIndexSizeKB\":1,\"totalStaticBloomSizeKB\":1,\"totalCompactingKVs\":1," +
|
||||
"\"currentCompactedKVs\":1}],\"requests\":0,\"startCode\":1245239331198," +
|
||||
"\"heapSizeMB\":512,\"maxHeapSizeMB\":1024}],\"DeadNodes\":[]}";
|
||||
}
|
||||
|
||||
private StorageClusterStatusModel buildTestModel() {
|
||||
protected StorageClusterStatusModel buildTestModel() {
|
||||
StorageClusterStatusModel model = new StorageClusterStatusModel();
|
||||
model.setRegions(2);
|
||||
model.setRequests(0);
|
||||
|
@ -85,29 +87,7 @@ public class TestStorageClusterStatusModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(StorageClusterStatusModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private StorageClusterStatusModel fromXML(String xml) throws JAXBException {
|
||||
return (StorageClusterStatusModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(StorageClusterStatusModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private StorageClusterStatusModel fromPB(String pb) throws IOException {
|
||||
return (StorageClusterStatusModel)
|
||||
new StorageClusterStatusModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(StorageClusterStatusModel model) {
|
||||
protected void checkModel(StorageClusterStatusModel model) {
|
||||
assertEquals(model.getRegions(), 2);
|
||||
assertEquals(model.getRequests(), 0);
|
||||
assertEquals(model.getAverageLoad(), 1.0);
|
||||
|
@ -161,18 +141,5 @@ public class TestStorageClusterStatusModel extends TestCase {
|
|||
assertFalse(regions.hasNext());
|
||||
assertFalse(nodes.hasNext());
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
public void testFromPB() throws Exception {
|
||||
checkModel(fromPB(AS_PB));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -30,48 +30,31 @@ import org.apache.hadoop.hbase.SmallTests;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestStorageClusterVersionModel extends TestCase {
|
||||
public class TestStorageClusterVersionModel extends TestModelBase<StorageClusterVersionModel> {
|
||||
private static final String VERSION = "0.0.1-testing";
|
||||
|
||||
private static final String AS_XML =
|
||||
"<ClusterVersion>" + VERSION + "</ClusterVersion>";
|
||||
public TestStorageClusterVersionModel() throws Exception {
|
||||
super(StorageClusterVersionModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"+
|
||||
"<ClusterVersion>" + VERSION + "</ClusterVersion>";
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestStorageClusterVersionModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(StorageClusterVersionModel.class);
|
||||
AS_JSON = "\"0.0.1-testing\"";
|
||||
}
|
||||
|
||||
private StorageClusterVersionModel buildTestModel() {
|
||||
protected StorageClusterVersionModel buildTestModel() {
|
||||
StorageClusterVersionModel model = new StorageClusterVersionModel();
|
||||
model.setVersion(VERSION);
|
||||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(StorageClusterVersionModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private StorageClusterVersionModel fromXML(String xml) throws JAXBException {
|
||||
return (StorageClusterVersionModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
private void checkModel(StorageClusterVersionModel model) {
|
||||
protected void checkModel(StorageClusterVersionModel model) {
|
||||
assertEquals(model.getVersion(), VERSION);
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
@Override
|
||||
public void testFromPB() throws Exception {
|
||||
//ignore test no pb
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -35,65 +35,41 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestTableInfoModel extends TestCase {
|
||||
public class TestTableInfoModel extends TestModelBase<TableInfoModel> {
|
||||
private static final String TABLE = "testtable";
|
||||
private static final byte[] START_KEY = Bytes.toBytes("abracadbra");
|
||||
private static final byte[] END_KEY = Bytes.toBytes("zzyzx");
|
||||
private static final long ID = 8731042424L;
|
||||
private static final String LOCATION = "testhost:9876";
|
||||
|
||||
private static final String AS_XML =
|
||||
"<TableInfo name=\"testtable\">" +
|
||||
"<Region location=\"testhost:9876\"" +
|
||||
" endKey=\"enp5eng=\"" +
|
||||
" startKey=\"YWJyYWNhZGJyYQ==\"" +
|
||||
" id=\"8731042424\"" +
|
||||
" name=\"testtable,abracadbra,8731042424\"/>" +
|
||||
"</TableInfo>";
|
||||
|
||||
private static final String AS_PB =
|
||||
"Cgl0ZXN0dGFibGUSSQofdGVzdHRhYmxlLGFicmFjYWRicmEsODczMTA0MjQyNBIKYWJyYWNhZGJy" +
|
||||
"YRoFenp5engg+MSkwyAqDXRlc3Rob3N0Ojk4NzY=";
|
||||
public TestTableInfoModel() throws Exception {
|
||||
super(TableInfoModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><TableInfo " +
|
||||
"name=\"testtable\"><Region endKey=\"enp5eng=\" id=\"8731042424\" " +
|
||||
"location=\"testhost:9876\" " +
|
||||
"name=\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\" " +
|
||||
"startKey=\"YWJyYWNhZGJyYQ==\"/></TableInfo>";
|
||||
|
||||
private JAXBContext context;
|
||||
AS_PB =
|
||||
"Cgl0ZXN0dGFibGUSSQofdGVzdHRhYmxlLGFicmFjYWRicmEsODczMTA0MjQyNBIKYWJyYWNhZGJy" +
|
||||
"YRoFenp5engg+MSkwyAqDXRlc3Rob3N0Ojk4NzY=";
|
||||
|
||||
public TestTableInfoModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(
|
||||
TableInfoModel.class,
|
||||
TableRegionModel.class);
|
||||
AS_JSON =
|
||||
"{\"name\":\"testtable\",\"Region\":[{\"endKey\":\"enp5eng=\",\"id\":8731042424," +
|
||||
"\"location\":\"testhost:9876\",\"" +
|
||||
"name\":\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\",\"" +
|
||||
"startKey\":\"YWJyYWNhZGJyYQ==\"}]}";
|
||||
}
|
||||
|
||||
private TableInfoModel buildTestModel() {
|
||||
protected TableInfoModel buildTestModel() {
|
||||
TableInfoModel model = new TableInfoModel();
|
||||
model.setName(TABLE);
|
||||
model.add(new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION));
|
||||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(TableInfoModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private TableInfoModel fromXML(String xml) throws JAXBException {
|
||||
return (TableInfoModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(TableInfoModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private TableInfoModel fromPB(String pb) throws IOException {
|
||||
return (TableInfoModel)
|
||||
new TableInfoModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(TableInfoModel model) {
|
||||
protected void checkModel(TableInfoModel model) {
|
||||
assertEquals(model.getName(), TABLE);
|
||||
Iterator<TableRegionModel> regions = model.getRegions().iterator();
|
||||
TableRegionModel region = regions.next();
|
||||
|
|
|
@ -34,27 +34,24 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestTableListModel extends TestCase {
|
||||
public class TestTableListModel extends TestModelBase<TableListModel> {
|
||||
private static final String TABLE1 = "table1";
|
||||
private static final String TABLE2 = "table2";
|
||||
private static final String TABLE3 = "table3";
|
||||
|
||||
private static final String AS_XML =
|
||||
"<TableList><table name=\"table1\"/><table name=\"table2\"/>" +
|
||||
"<table name=\"table3\"/></TableList>";
|
||||
|
||||
private static final String AS_PB = "CgZ0YWJsZTEKBnRhYmxlMgoGdGFibGUz";
|
||||
public TestTableListModel() throws Exception {
|
||||
super(TableListModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><TableList><table " +
|
||||
"name=\"table1\"/><table name=\"table2\"/><table name=\"table3\"/></TableList>";
|
||||
|
||||
private JAXBContext context;
|
||||
AS_PB = "CgZ0YWJsZTEKBnRhYmxlMgoGdGFibGUz";
|
||||
|
||||
public TestTableListModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(
|
||||
TableListModel.class,
|
||||
TableModel.class);
|
||||
AS_JSON =
|
||||
"{\"table\":[{\"name\":\"table1\"},{\"name\":\"table2\"},{\"name\":\"table3\"}]}";
|
||||
}
|
||||
|
||||
private TableListModel buildTestModel() {
|
||||
protected TableListModel buildTestModel() {
|
||||
TableListModel model = new TableListModel();
|
||||
model.add(new TableModel(TABLE1));
|
||||
model.add(new TableModel(TABLE2));
|
||||
|
@ -62,29 +59,7 @@ public class TestTableListModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(TableListModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private TableListModel fromXML(String xml) throws JAXBException {
|
||||
return (TableListModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(TableListModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private TableListModel fromPB(String pb) throws IOException {
|
||||
return (TableListModel)
|
||||
new TableListModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(TableListModel model) {
|
||||
protected void checkModel(TableListModel model) {
|
||||
Iterator<TableModel> tables = model.getTables().iterator();
|
||||
TableModel table = tables.next();
|
||||
assertEquals(table.getName(), TABLE1);
|
||||
|
@ -94,18 +69,5 @@ public class TestTableListModel extends TestCase {
|
|||
assertEquals(table.getName(), TABLE3);
|
||||
assertFalse(tables.hasNext());
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
public void testFromPB() throws Exception {
|
||||
checkModel(fromPB(AS_PB));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -32,46 +32,35 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestTableRegionModel extends TestCase {
|
||||
public class TestTableRegionModel extends TestModelBase<TableRegionModel> {
|
||||
private static final String TABLE = "testtable";
|
||||
private static final byte[] START_KEY = Bytes.toBytes("abracadbra");
|
||||
private static final byte[] END_KEY = Bytes.toBytes("zzyzx");
|
||||
private static final long ID = 8731042424L;
|
||||
private static final String LOCATION = "testhost:9876";
|
||||
|
||||
private static final String AS_XML =
|
||||
"<Region location=\"testhost:9876\"" +
|
||||
" endKey=\"enp5eng=\"" +
|
||||
" startKey=\"YWJyYWNhZGJyYQ==\"" +
|
||||
" id=\"8731042424\"" +
|
||||
" name=\"testtable,abracadbra,8731042424\"/>";
|
||||
public TestTableRegionModel() throws Exception {
|
||||
super(TableRegionModel.class);
|
||||
|
||||
private JAXBContext context;
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Region endKey=\"enp5eng=\" " +
|
||||
"id=\"8731042424\" location=\"testhost:9876\" " +
|
||||
"name=\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\" " +
|
||||
"startKey=\"YWJyYWNhZGJyYQ==\"/>";
|
||||
|
||||
public TestTableRegionModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(TableRegionModel.class);
|
||||
AS_JSON =
|
||||
"{\"endKey\":\"enp5eng=\",\"id\":8731042424,\"location\":\"testhost:9876\"," +
|
||||
"\"name\":\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\",\"" +
|
||||
"startKey\":\"YWJyYWNhZGJyYQ==\"}";
|
||||
}
|
||||
|
||||
private TableRegionModel buildTestModel() {
|
||||
protected TableRegionModel buildTestModel() {
|
||||
TableRegionModel model =
|
||||
new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION);
|
||||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(TableRegionModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private TableRegionModel fromXML(String xml) throws JAXBException {
|
||||
return (TableRegionModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
private void checkModel(TableRegionModel model) {
|
||||
protected void checkModel(TableRegionModel model) {
|
||||
assertTrue(Bytes.equals(model.getStartKey(), START_KEY));
|
||||
assertTrue(Bytes.equals(model.getEndKey(), END_KEY));
|
||||
assertEquals(model.getId(), ID);
|
||||
|
@ -81,10 +70,6 @@ public class TestTableRegionModel extends TestCase {
|
|||
".ad9860f031282c46ed431d7af8f94aca.");
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
}
|
||||
|
||||
public void testGetName() {
|
||||
TableRegionModel model = buildTestModel();
|
||||
String modelName = model.getName();
|
||||
|
@ -100,9 +85,9 @@ public class TestTableRegionModel extends TestCase {
|
|||
assertEquals(name, model.getName());
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
@Override
|
||||
public void testFromPB() throws Exception {
|
||||
//no pb ignore
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -30,81 +30,66 @@ import javax.xml.bind.JAXBException;
|
|||
import org.apache.hadoop.hbase.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.Base64;
|
||||
|
||||
import org.apache.hadoop.hbase.rest.model.TableSchemaModel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestTableSchemaModel extends TestCase {
|
||||
public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
|
||||
|
||||
public static final String TABLE_NAME = "testTable";
|
||||
private static final boolean IS_META = false;
|
||||
private static final boolean IS_ROOT = false;
|
||||
private static final boolean READONLY = false;
|
||||
|
||||
private static final String AS_XML =
|
||||
"<TableSchema name=\"testTable\"" +
|
||||
" IS_META=\"false\"" +
|
||||
" IS_ROOT=\"false\"" +
|
||||
" READONLY=\"false\">" +
|
||||
TestColumnSchemaModel.AS_XML +
|
||||
"</TableSchema>";
|
||||
|
||||
private static final String AS_PB =
|
||||
"Cgl0ZXN0VGFibGUSEAoHSVNfTUVUQRIFZmFsc2USEAoHSVNfUk9PVBIFZmFsc2USEQoIUkVBRE9O" +
|
||||
"TFkSBWZhbHNlGpcBCgp0ZXN0Y29sdW1uEhIKCUJMT0NLU0laRRIFMTYzODQSEwoLQkxPT01GSUxU" +
|
||||
"RVISBE5PTkUSEgoKQkxPQ0tDQUNIRRIEdHJ1ZRIRCgtDT01QUkVTU0lPThICR1oSDQoIVkVSU0lP" +
|
||||
"TlMSATESDAoDVFRMEgU4NjQwMBISCglJTl9NRU1PUlkSBWZhbHNlGICjBSABKgJHWigA";
|
||||
TestColumnSchemaModel testColumnSchemaModel;
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestTableSchemaModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(
|
||||
ColumnSchemaModel.class,
|
||||
TableSchemaModel.class);
|
||||
public TestTableSchemaModel() throws Exception {
|
||||
super(TableSchemaModel.class);
|
||||
testColumnSchemaModel = new TestColumnSchemaModel();
|
||||
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||
"<TableSchema name=\"testTable\" IS_META=\"false\" IS_ROOT=\"false\" READONLY=\"false\">" +
|
||||
"<ColumnSchema name=\"testcolumn\" BLOCKSIZE=\"16384\" BLOOMFILTER=\"NONE\" " +
|
||||
"BLOCKCACHE=\"true\" COMPRESSION=\"GZ\" VERSIONS=\"1\" TTL=\"86400\" IN_MEMORY=\"false\"/>" +
|
||||
"</TableSchema>";
|
||||
|
||||
AS_PB =
|
||||
"Cgl0ZXN0VGFibGUSEAoHSVNfTUVUQRIFZmFsc2USEAoHSVNfUk9PVBIFZmFsc2USEQoIUkVBRE9O" +
|
||||
"TFkSBWZhbHNlGpcBCgp0ZXN0Y29sdW1uEhIKCUJMT0NLU0laRRIFMTYzODQSEwoLQkxPT01GSUxU" +
|
||||
"RVISBE5PTkUSEgoKQkxPQ0tDQUNIRRIEdHJ1ZRIRCgtDT01QUkVTU0lPThICR1oSDQoIVkVSU0lP" +
|
||||
"TlMSATESDAoDVFRMEgU4NjQwMBISCglJTl9NRU1PUlkSBWZhbHNlGICjBSABKgJHWigA";
|
||||
|
||||
AS_JSON =
|
||||
"{\"name\":\"testTable\",\"IS_META\":\"false\",\"IS_ROOT\":\"false\"," +
|
||||
"\"READONLY\":\"false\",\"ColumnSchema\":[{\"name\":\"testcolumn\"," +
|
||||
"\"BLOCKSIZE\":\"16384\",\"BLOOMFILTER\":\"NONE\",\"BLOCKCACHE\":\"true\"," +
|
||||
"\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\",\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}]}";
|
||||
}
|
||||
|
||||
public static TableSchemaModel buildTestModel() {
|
||||
protected TableSchemaModel buildTestModel() {
|
||||
return buildTestModel(TABLE_NAME);
|
||||
}
|
||||
|
||||
public static TableSchemaModel buildTestModel(String name) {
|
||||
public TableSchemaModel buildTestModel(String name) {
|
||||
TableSchemaModel model = new TableSchemaModel();
|
||||
model.setName(name);
|
||||
model.__setIsMeta(IS_META);
|
||||
model.__setIsRoot(IS_ROOT);
|
||||
model.__setReadOnly(READONLY);
|
||||
model.addColumnFamily(TestColumnSchemaModel.buildTestModel());
|
||||
model.addColumnFamily(testColumnSchemaModel.buildTestModel());
|
||||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(TableSchemaModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private TableSchemaModel fromXML(String xml) throws JAXBException {
|
||||
return (TableSchemaModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(TableSchemaModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private TableSchemaModel fromPB(String pb) throws IOException {
|
||||
return (TableSchemaModel)
|
||||
new TableSchemaModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
public static void checkModel(TableSchemaModel model) {
|
||||
protected void checkModel(TableSchemaModel model) {
|
||||
checkModel(model, TABLE_NAME);
|
||||
}
|
||||
|
||||
public static void checkModel(TableSchemaModel model, String tableName) {
|
||||
public void checkModel(TableSchemaModel model, String tableName) {
|
||||
assertEquals(model.getName(), tableName);
|
||||
assertEquals(model.__getIsMeta(), IS_META);
|
||||
assertEquals(model.__getIsRoot(), IS_ROOT);
|
||||
|
@ -112,7 +97,7 @@ public class TestTableSchemaModel extends TestCase {
|
|||
Iterator<ColumnSchemaModel> families = model.getColumns().iterator();
|
||||
assertTrue(families.hasNext());
|
||||
ColumnSchemaModel family = families.next();
|
||||
TestColumnSchemaModel.checkModel(family);
|
||||
testColumnSchemaModel.checkModel(family);
|
||||
assertFalse(families.hasNext());
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import junit.framework.TestCase;
|
|||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestVersionModel extends TestCase {
|
||||
public class TestVersionModel extends TestModelBase<VersionModel> {
|
||||
private static final String REST_VERSION = "0.0.1";
|
||||
private static final String OS_VERSION =
|
||||
"Linux 2.6.18-128.1.6.el5.centos.plusxen amd64";
|
||||
|
@ -42,25 +42,24 @@ public class TestVersionModel extends TestCase {
|
|||
private static final String JETTY_VERSION = "6.1.14";
|
||||
private static final String JERSEY_VERSION = "1.1.0-ea";
|
||||
|
||||
private static final String AS_XML =
|
||||
"<Version REST=\"" + REST_VERSION + "\"" +
|
||||
" OS=\"" + OS_VERSION + "\"" +
|
||||
" JVM=\"" + JVM_VERSION + "\"" +
|
||||
" Server=\"" + JETTY_VERSION + "\"" +
|
||||
" Jersey=\"" + JERSEY_VERSION + "\"/>";
|
||||
public TestVersionModel() throws Exception {
|
||||
super(VersionModel.class);
|
||||
AS_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Version JVM=\"Sun " +
|
||||
"Microsystems Inc. 1.6.0_13-11.3-b02\" Jersey=\"1.1.0-ea\" " +
|
||||
"OS=\"Linux 2.6.18-128.1.6.el5.centos.plusxen amd64\" REST=\"0.0.1\" Server=\"6.1.14\"/>";
|
||||
|
||||
private static final String AS_PB =
|
||||
"CgUwLjAuMRInU3VuIE1pY3Jvc3lzdGVtcyBJbmMuIDEuNi4wXzEzLTExLjMtYjAyGi1MaW51eCAy" +
|
||||
"LjYuMTgtMTI4LjEuNi5lbDUuY2VudG9zLnBsdXN4ZW4gYW1kNjQiBjYuMS4xNCoIMS4xLjAtZWE=";
|
||||
AS_PB =
|
||||
"CgUwLjAuMRInU3VuIE1pY3Jvc3lzdGVtcyBJbmMuIDEuNi4wXzEzLTExLjMtYjAyGi1MaW51eCAy" +
|
||||
"LjYuMTgtMTI4LjEuNi5lbDUuY2VudG9zLnBsdXN4ZW4gYW1kNjQiBjYuMS4xNCoIMS4xLjAtZWE=";
|
||||
|
||||
private JAXBContext context;
|
||||
|
||||
public TestVersionModel() throws JAXBException {
|
||||
super();
|
||||
context = JAXBContext.newInstance(VersionModel.class);
|
||||
AS_JSON =
|
||||
"{\"JVM\":\"Sun Microsystems Inc. 1.6.0_13-11.3-b02\",\"Jersey\":\"1.1.0-ea\"," +
|
||||
"\"OS\":\"Linux 2.6.18-128.1.6.el5.centos.plusxen amd64\",\"" +
|
||||
"REST\":\"0.0.1\",\"Server\":\"6.1.14\"}";
|
||||
}
|
||||
|
||||
private VersionModel buildTestModel() {
|
||||
protected VersionModel buildTestModel() {
|
||||
VersionModel model = new VersionModel();
|
||||
model.setRESTVersion(REST_VERSION);
|
||||
model.setOSVersion(OS_VERSION);
|
||||
|
@ -70,47 +69,12 @@ public class TestVersionModel extends TestCase {
|
|||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String toXML(VersionModel model) throws JAXBException {
|
||||
StringWriter writer = new StringWriter();
|
||||
context.createMarshaller().marshal(model, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
private VersionModel fromXML(String xml) throws JAXBException {
|
||||
return (VersionModel)
|
||||
context.createUnmarshaller().unmarshal(new StringReader(xml));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private byte[] toPB(VersionModel model) {
|
||||
return model.createProtobufOutput();
|
||||
}
|
||||
|
||||
private VersionModel fromPB(String pb) throws IOException {
|
||||
return (VersionModel)
|
||||
new VersionModel().getObjectFromMessage(Base64.decode(AS_PB));
|
||||
}
|
||||
|
||||
private void checkModel(VersionModel model) {
|
||||
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);
|
||||
}
|
||||
|
||||
public void testBuildModel() throws Exception {
|
||||
checkModel(buildTestModel());
|
||||
}
|
||||
|
||||
public void testFromXML() throws Exception {
|
||||
checkModel(fromXML(AS_XML));
|
||||
}
|
||||
|
||||
public void testFromPB() throws Exception {
|
||||
checkModel(fromPB(AS_PB));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue