You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nd...@apache.org on 2013/09/12 16:19:48 UTC
svn commit: r1522590 - in /hbase/trunk/hbase-server/src:
main/java/org/apache/hadoop/hbase/rest/RowSpec.java
test/java/org/apache/hadoop/hbase/rest/TestRowResource.java
Author: ndimiduk
Date: Thu Sep 12 14:19:47 2013
New Revision: 1522590
URL: http://svn.apache.org/r1522590
Log:
HBASE-9375 [REST] Querying row data gives all the available versions of a column (Vandana Ayyalasomayajula)
Modified:
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowSpec.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowSpec.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowSpec.java?rev=1522590&r1=1522589&r2=1522590&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowSpec.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowSpec.java Thu Sep 12 14:19:47 2013
@@ -46,7 +46,7 @@ public class RowSpec {
new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
private long startTime = DEFAULT_START_TIMESTAMP;
private long endTime = DEFAULT_END_TIMESTAMP;
- private int maxVersions = HColumnDescriptor.DEFAULT_VERSIONS;
+ private int maxVersions = 1;
private int maxValues = Integer.MAX_VALUE;
public RowSpec(String path) throws IllegalArgumentException {
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java?rev=1522590&r1=1522589&r2=1522590&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java Thu Sep 12 14:19:47 2013
@@ -52,7 +52,9 @@ import org.apache.hadoop.hbase.security.
import org.apache.hadoop.hbase.test.MetricsAssertHelper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -74,7 +76,7 @@ public class TestRowResource {
private static final String VALUE_4 = "testvalue4";
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- private static final HBaseRESTTestingUtility REST_TEST_UTIL =
+ private static final HBaseRESTTestingUtility REST_TEST_UTIL =
new HBaseRESTTestingUtility();
private static final MetricsAssertHelper METRICS_ASSERT =
CompatibilityFactory.getInstance(MetricsAssertHelper.class);
@@ -97,6 +99,10 @@ public class TestRowResource {
unmarshaller = context.createUnmarshaller();
client = new Client(new Cluster().add("localhost",
REST_TEST_UTIL.getServletPort()));
+ }
+
+ @Before
+ public void beforeMethod() throws Exception {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TABLE)) {
return;
@@ -107,13 +113,22 @@ public class TestRowResource {
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
public static void tearDownAfterClass() throws Exception {
REST_TEST_UTIL.shutdownServletContainer();
TEST_UTIL.shutdownMiniCluster();
}
- private static Response deleteRow(String table, String row)
+ private static Response deleteRow(String table, String row)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@@ -183,7 +198,7 @@ public class TestRowResource {
}
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;
}
@@ -721,5 +736,33 @@ public class TestRowResource {
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);
+ }
+
}