HBASE-9375 [REST] Querying row data gives all the available versions of a column (Vandana Ayyalasomayajula)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1522590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ndimiduk 2013-09-12 14:19:47 +00:00
parent 37e9a86396
commit d70829a110
2 changed files with 47 additions and 4 deletions

View File

@ -46,7 +46,7 @@ public class RowSpec {
new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR); new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
private long startTime = DEFAULT_START_TIMESTAMP; private long startTime = DEFAULT_START_TIMESTAMP;
private long endTime = DEFAULT_END_TIMESTAMP; private long endTime = DEFAULT_END_TIMESTAMP;
private int maxVersions = HColumnDescriptor.DEFAULT_VERSIONS; private int maxVersions = 1;
private int maxValues = Integer.MAX_VALUE; private int maxValues = Integer.MAX_VALUE;
public RowSpec(String path) throws IllegalArgumentException { public RowSpec(String path) throws IllegalArgumentException {

View File

@ -52,7 +52,9 @@ import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.test.MetricsAssertHelper; import org.apache.hadoop.hbase.test.MetricsAssertHelper;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@ -74,7 +76,7 @@ public class TestRowResource {
private static final String VALUE_4 = "testvalue4"; private static final String VALUE_4 = "testvalue4";
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final HBaseRESTTestingUtility REST_TEST_UTIL = private static final HBaseRESTTestingUtility REST_TEST_UTIL =
new HBaseRESTTestingUtility(); new HBaseRESTTestingUtility();
private static final MetricsAssertHelper METRICS_ASSERT = private static final MetricsAssertHelper METRICS_ASSERT =
CompatibilityFactory.getInstance(MetricsAssertHelper.class); CompatibilityFactory.getInstance(MetricsAssertHelper.class);
@ -97,6 +99,10 @@ public class TestRowResource {
unmarshaller = context.createUnmarshaller(); unmarshaller = context.createUnmarshaller();
client = new Client(new Cluster().add("localhost", client = new Client(new Cluster().add("localhost",
REST_TEST_UTIL.getServletPort())); REST_TEST_UTIL.getServletPort()));
}
@Before
public void beforeMethod() throws Exception {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TABLE)) { if (admin.tableExists(TABLE)) {
return; return;
@ -107,13 +113,22 @@ public class TestRowResource {
admin.createTable(htd); admin.createTable(htd);
} }
@After
public void afterMethod() throws Exception {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TABLE)) {
admin.disableTable(TABLE);
admin.deleteTable(TABLE);
}
}
@AfterClass @AfterClass
public static void tearDownAfterClass() throws Exception { public static void tearDownAfterClass() throws Exception {
REST_TEST_UTIL.shutdownServletContainer(); REST_TEST_UTIL.shutdownServletContainer();
TEST_UTIL.shutdownMiniCluster(); TEST_UTIL.shutdownMiniCluster();
} }
private static Response deleteRow(String table, String row) private static Response deleteRow(String table, String row)
throws IOException { throws IOException {
StringBuilder path = new StringBuilder(); StringBuilder path = new StringBuilder();
path.append('/'); path.append('/');
@ -183,7 +198,7 @@ public class TestRowResource {
} }
private static Response getValuePB(String url) throws IOException { private static Response getValuePB(String url) throws IOException {
Response response = client.get(url, Constants.MIMETYPE_PROTOBUF); Response response = client.get(url, Constants.MIMETYPE_PROTOBUF);
return response; return response;
} }
@ -721,5 +736,33 @@ public class TestRowResource {
assertEquals(response.getCode(), 400); assertEquals(response.getCode(), 400);
} }
@Test
public void testLatestCellGetXML() throws IOException, JAXBException {
final String path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
CellModel cellOne = new CellModel(Bytes.toBytes(COLUMN_1), 1L, Bytes.toBytes(VALUE_1));
CellModel cellTwo = new CellModel(Bytes.toBytes(COLUMN_1), 2L, Bytes.toBytes(VALUE_2));
rowModel.addCell(cellOne);
rowModel.addCell(cellTwo);
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
marshaller.marshal(cellSetModel, writer);
Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
assertEquals(response.getCode(), 200);
response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response
.getBody()));
assertTrue(cellSet.getRows().size() == 1);
assertTrue(cellSet.getRows().get(0).getCells().size() == 1);
CellModel cell = cellSet.getRows().get(0).getCells().get(0);
assertEquals(VALUE_2, Bytes.toString(cell.getValue()));
assertEquals(2L, cell.getTimestamp());
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
}
} }