You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2010/10/06 19:46:05 UTC
svn commit: r1005185 - in /hbase/branches/0.20: ./
src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/
src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/
src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/
Author: apurtell
Date: Wed Oct 6 17:46:04 2010
New Revision: 1005185
URL: http://svn.apache.org/viewvc?rev=1005185&view=rev
Log:
HBASE-2906 [rest/stargate] URI decoding in RowResource
Modified:
hbase/branches/0.20/CHANGES.txt
hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java
hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java
hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java
hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java
hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/TestRowResource.java
Modified: hbase/branches/0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.20/CHANGES.txt?rev=1005185&r1=1005184&r2=1005185&view=diff
==============================================================================
--- hbase/branches/0.20/CHANGES.txt (original)
+++ hbase/branches/0.20/CHANGES.txt Wed Oct 6 17:46:04 2010
@@ -7,6 +7,7 @@ Release 0.20.7 - Unreleased
NoSuchColumnFamilyException (Andrew Purtell via J-D)
HBASE-2942 Custom filters should not require registration in
HBaseObjectWritable (Gary Helmling via Andrew Purtell)
+ HBASE-2906 [rest/stargate] URI decoding in RowResource
IMPROVEMENTS
HBASE-2988 Support alternate compression for major compactions
Modified: hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java?rev=1005185&r1=1005184&r2=1005185&view=diff
==============================================================================
--- hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java (original)
+++ hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowResource.java Wed Oct 6 17:46:04 2010
@@ -21,7 +21,6 @@
package org.apache.hadoop.hbase.stargate;
import java.io.IOException;
-import java.net.URLDecoder;
import java.util.List;
import javax.ws.rs.Consumes;
@@ -69,8 +68,11 @@ public class RowResource extends Resourc
throws IOException {
super();
this.tableName = table;
- this.rowspec = new RowSpec(URLDecoder.decode(rowspec,
- HConstants.UTF8_ENCODING));
+ this.rowspec = new RowSpec(rowspec);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("new RowResource: table=" + this.tableName + "rowspec=" +
+ this.rowspec);
+ }
if (versions != null) {
this.rowspec.setMaxVersions(Integer.valueOf(versions));
}
Modified: hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java?rev=1005185&r1=1005184&r2=1005185&view=diff
==============================================================================
--- hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java (original)
+++ hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/RowSpec.java Wed Oct 6 17:46:04 2010
@@ -20,6 +20,8 @@
package org.apache.hadoop.hbase.stargate;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.util.Collection;
import java.util.TreeSet;
@@ -59,32 +61,29 @@ public class RowSpec {
private int parseRowKeys(final String path, int i)
throws IllegalArgumentException {
- StringBuilder startRow = new StringBuilder();
- StringBuilder endRow = null;
+ String startRow = null, endRow = null;
try {
+ StringBuilder sb = new StringBuilder();
char c;
- boolean doEndRow = false;
while (i < path.length() && (c = path.charAt(i)) != '/') {
- if (c == ',') {
- doEndRow = true;
- i++;
- break;
- }
- startRow.append(c);
+ sb.append(c);
i++;
}
i++;
- this.row = Bytes.toBytes(startRow.toString());
- if (doEndRow) {
- endRow = new StringBuilder();
- while ((c = path.charAt(i)) != '/') {
- endRow.append(c);
- i++;
- }
- i++;
+ startRow = sb.toString();
+ int idx = startRow.indexOf(',');
+ if (idx != -1) {
+ startRow = URLDecoder.decode(startRow.substring(0, idx),
+ HConstants.UTF8_ENCODING);
+ endRow = URLDecoder.decode(startRow.substring(idx + 1),
+ HConstants.UTF8_ENCODING);
+ } else {
+ startRow = URLDecoder.decode(startRow, HConstants.UTF8_ENCODING);
}
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(e);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
}
// HBase does not support wildcards on row keys so we will emulate a
// suffix glob by synthesizing appropriate start and end row keys for
@@ -94,7 +93,7 @@ public class RowSpec {
throw new IllegalArgumentException("invalid path: start row "+
"specified with wildcard");
this.row = Bytes.toBytes(startRow.substring(0,
- startRow.lastIndexOf("*")));
+ startRow.lastIndexOf("*")));
this.endRow = new byte[this.row.length + 1];
System.arraycopy(this.row, 0, this.endRow, 0, this.row.length);
this.endRow[this.row.length] = (byte)255;
@@ -115,37 +114,41 @@ public class RowSpec {
try {
char c;
StringBuilder column = new StringBuilder();
- boolean hasColon = false;
while (i < path.length() && (c = path.charAt(i)) != '/') {
if (c == ',') {
if (column.length() < 1) {
throw new IllegalArgumentException("invalid path");
}
- if (!hasColon) {
- column.append(':');
+ String s = URLDecoder.decode(column.toString(),
+ HConstants.UTF8_ENCODING);
+ if (!s.contains(":")) {
+ this.columns.add(Bytes.toBytes(s + ":"));
+ } else {
+ this.columns.add(Bytes.toBytes(s));
}
- this.columns.add(Bytes.toBytes(column.toString()));
- column = new StringBuilder();
- hasColon = false;
+ column.setLength(0);
i++;
continue;
}
- if (c == ':') {
- hasColon = true;
- }
column.append(c);
i++;
}
i++;
// trailing list entry
if (column.length() > 1) {
- if (!hasColon) {
- column.append(':');
+ String s = URLDecoder.decode(column.toString(),
+ HConstants.UTF8_ENCODING);
+ if (!s.contains(":")) {
+ this.columns.add(Bytes.toBytes(s + ":"));
+ } else {
+ this.columns.add(Bytes.toBytes(s));
}
- this.columns.add(Bytes.toBytes(column.toString()));
}
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(e);
+ } catch (UnsupportedEncodingException e) {
+ // shouldn't happen
+ throw new RuntimeException(e);
}
return i;
}
@@ -168,7 +171,8 @@ public class RowSpec {
i++;
}
try {
- time0 = Long.valueOf(stamp.toString());
+ time0 = Long.valueOf(URLDecoder.decode(stamp.toString(),
+ HConstants.UTF8_ENCODING));
} catch (NumberFormatException e) {
throw new IllegalArgumentException(e);
}
@@ -180,7 +184,8 @@ public class RowSpec {
i++;
}
try {
- time1 = Long.valueOf(stamp.toString());
+ time1 = Long.valueOf(URLDecoder.decode(stamp.toString(),
+ HConstants.UTF8_ENCODING));
} catch (NumberFormatException e) {
throw new IllegalArgumentException(e);
}
@@ -190,6 +195,9 @@ public class RowSpec {
}
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(e);
+ } catch (UnsupportedEncodingException e) {
+ // shouldn't happen
+ throw new RuntimeException(e);
}
if (time1 != 0) {
startTime = time0;
@@ -201,32 +209,45 @@ public class RowSpec {
}
private int parseQueryParams(final String path, int i) {
- while (i < path.length()) {
- char c = path.charAt(i);
+ if (i >= path.length()) {
+ return i;
+ }
+ StringBuilder query = new StringBuilder();
+ try {
+ query.append(URLDecoder.decode(path.substring(i),
+ HConstants.UTF8_ENCODING));
+ } catch (UnsupportedEncodingException e) {
+ // should not happen
+ throw new RuntimeException(e);
+ }
+ i += query.length();
+ int j = 0;
+ while (j < query.length()) {
+ char c = query.charAt(j);
if (c != '?' && c != '&') {
break;
}
- if (++i > path.length()) {
- break;
+ if (++j > query.length()) {
+ throw new IllegalArgumentException("malformed query parameter");
}
- char what = path.charAt(i);
- if (++i > path.length()) {
+ char what = query.charAt(j);
+ if (++j > query.length()) {
break;
}
- c = path.charAt(i);
+ c = query.charAt(j);
if (c != '=') {
throw new IllegalArgumentException("malformed query parameter");
}
- if (++i > path.length()) {
+ if (++j > query.length()) {
break;
}
switch (what) {
case 'm': {
StringBuilder sb = new StringBuilder();
- while (i <= path.length()) {
- c = path.charAt(i);
+ while (j <= query.length()) {
+ c = query.charAt(i);
if (c < '0' || c > '9') {
- i--;
+ j--;
break;
}
sb.append(c);
@@ -235,10 +256,10 @@ public class RowSpec {
} break;
case 'n': {
StringBuilder sb = new StringBuilder();
- while (i <= path.length()) {
- c = path.charAt(i);
+ while (j <= query.length()) {
+ c = query.charAt(i);
if (c < '0' || c > '9') {
- i--;
+ j--;
break;
}
sb.append(c);
Modified: hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java?rev=1005185&r1=1005184&r2=1005185&view=diff
==============================================================================
--- hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java (original)
+++ hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/TableResource.java Wed Oct 6 17:46:04 2010
@@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.stargate
import java.io.IOException;
+import javax.ws.rs.Encoded;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
@@ -62,7 +63,9 @@ public class TableResource extends Resou
@Path("{rowspec: .+}")
public RowResource getRowResource(
- final @PathParam("rowspec") String rowspec,
+ // We need the @Encoded decorator so Jersey won't urldecode before
+ // the RowSpec constructor has a chance to parse
+ final @PathParam("rowspec") @Encoded String rowspec,
final @QueryParam("v") String versions) throws IOException {
return new RowResource(table, rowspec, versions);
}
Modified: hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java?rev=1005185&r1=1005184&r2=1005185&view=diff
==============================================================================
--- hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java (original)
+++ hbase/branches/0.20/src/contrib/stargate/src/java/org/apache/hadoop/hbase/stargate/client/Client.java Wed Oct 6 17:46:04 2010
@@ -93,11 +93,10 @@ public class Client {
* @param cluster the cluster definition
* @param method the transaction method
* @param headers HTTP header values to send
- * @param path the path
+ * @param path the properly urlencoded path
* @return the HTTP response code
* @throws IOException
*/
- @SuppressWarnings("deprecation")
public int executePathOnly(Cluster cluster, HttpMethod method,
Header[] headers, String path) throws IOException {
IOException lastException;
@@ -113,7 +112,7 @@ public class Client {
sb.append("http://");
sb.append(cluster.lastHost);
sb.append(path);
- URI uri = new URI(sb.toString());
+ URI uri = new URI(sb.toString(), true);
return executeURI(method, headers, uri.toString());
} catch (IOException e) {
lastException = e;
@@ -126,14 +125,13 @@ public class Client {
* Execute a transaction method given a complete URI.
* @param method the transaction method
* @param headers HTTP header values to send
- * @param uri the URI
+ * @param uri a properly urlencoded URI
* @return the HTTP response code
* @throws IOException
*/
- @SuppressWarnings("deprecation")
public int executeURI(HttpMethod method, Header[] headers, String uri)
throws IOException {
- method.setURI(new URI(uri));
+ method.setURI(new URI(uri, true));
if (headers != null) {
for (Header header: headers) {
method.addRequestHeader(header);
@@ -156,7 +154,7 @@ public class Client {
* @param cluster the cluster definition
* @param method the HTTP method
* @param headers HTTP header values to send
- * @param path the path or URI
+ * @param path the properly urlencoded path or URI
* @return the HTTP response code
* @throws IOException
*/
Modified: hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/TestRowResource.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/TestRowResource.java?rev=1005185&r1=1005184&r2=1005185&view=diff
==============================================================================
--- hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/TestRowResource.java (original)
+++ hbase/branches/0.20/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/TestRowResource.java Wed Oct 6 17:46:04 2010
@@ -44,45 +44,43 @@ import org.apache.hadoop.hbase.stargate.
import org.apache.hadoop.hbase.util.Bytes;
public class TestRowResource extends MiniClusterTestCase {
- private static final String TABLE = "TestRowResource";
- private static final String COLUMN_1 = "a:";
- private static final String COLUMN_2 = "b:";
- private static final String ROW_1 = "testrow1";
- private static final String VALUE_1 = "testvalue1";
- private static final String ROW_2 = "testrow2";
- private static final String VALUE_2 = "testvalue2";
- private static final String ROW_3 = "testrow3";
- private static final String VALUE_3 = "testvalue3";
- private static final String ROW_4 = "testrow4";
- private static final String VALUE_4 = "testvalue4";
-
- private Client client;
- private JAXBContext context;
- private Marshaller marshaller;
- private Unmarshaller unmarshaller;
- private HBaseAdmin admin;
+ static final String TABLE = "TestRowResource";
+ static final String CFA = "a";
+ static final String CFB = "b";
+ static final String COLUMN_1 = CFA + ":1";
+ static final String COLUMN_2 = CFB + ":2";
+ static final String ROW_1 = "testrow1";
+ static final String VALUE_1 = "testvalue1";
+ static final String ROW_2 = "testrow2";
+ static final String VALUE_2 = "testvalue2";
+ static final String ROW_3 = "testrow3";
+ static final String VALUE_3 = "testvalue3";
+ static final String ROW_4 = "testrow4";
+ static final String VALUE_4 = "testvalue4";
+
+ Client client;
+ JAXBContext context;
+ Marshaller marshaller;
+ Unmarshaller unmarshaller;
+ HBaseAdmin admin;
- public TestRowResource() throws JAXBException {
- super();
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
context = JAXBContext.newInstance(
CellModel.class,
CellSetModel.class,
RowModel.class);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
client = new Client(new Cluster().add("localhost", testServletPort));
admin = new HBaseAdmin(conf);
if (admin.tableExists(TABLE)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
- htd.addFamily(new HColumnDescriptor(COLUMN_1));
- htd.addFamily(new HColumnDescriptor(COLUMN_2));
+ htd.addFamily(new HColumnDescriptor(CFA));
+ htd.addFamily(new HColumnDescriptor(CFB));
admin.createTable(htd);
}
@@ -92,7 +90,7 @@ public class TestRowResource extends Min
super.tearDown();
}
- private Response deleteRow(String table, String row) throws IOException {
+ Response deleteRow(String table, String row) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@@ -103,7 +101,7 @@ public class TestRowResource extends Min
return response;
}
- private Response deleteValue(String table, String row, String column)
+ Response deleteValue(String table, String row, String column)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@@ -117,7 +115,7 @@ public class TestRowResource extends Min
return response;
}
- private Response getValueXML(String table, String row, String column)
+ Response getValueXML(String table, String row, String column)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@@ -126,11 +124,15 @@ public class TestRowResource extends Min
path.append(row);
path.append('/');
path.append(column);
- Response response = client.get(path.toString(), MIMETYPE_XML);
+ return getValueXML(path.toString());
+ }
+
+ Response getValueXML(String url) throws IOException {
+ Response response = client.get(url, MIMETYPE_XML);
return response;
}
- private Response getValuePB(String table, String row, String column)
+ Response getValuePB(String table, String row, String column)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
@@ -139,12 +141,16 @@ public class TestRowResource extends Min
path.append(row);
path.append('/');
path.append(column);
- Response response = client.get(path.toString(), MIMETYPE_PROTOBUF);
+ return getValuePB(path.toString());
+ }
+
+ Response getValuePB(String url) throws IOException {
+ Response response = client.get(url, MIMETYPE_PROTOBUF);
return response;
}
- private Response putValueXML(String table, String row, String column,
- String value) throws IOException, JAXBException {
+ Response putValueXML(String table, String row, String column, String value)
+ throws IOException, JAXBException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@@ -152,20 +158,26 @@ public class TestRowResource extends Min
path.append(row);
path.append('/');
path.append(column);
+ return putValueXML(path.toString(), table, row, column, value);
+ }
+
+ Response putValueXML(String url, String table, String row, String column,
+ String value) throws IOException, JAXBException {
RowModel rowModel = new RowModel(row);
- rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(column),
+ Bytes.toBytes(value)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
marshaller.marshal(cellSetModel, writer);
- Response response = client.put(path.toString(), MIMETYPE_XML,
+ Response response = client.put(url, MIMETYPE_XML,
Bytes.toBytes(writer.toString()));
Thread.yield();
return response;
}
- private void checkValueXML(String table, String row, String column,
- String value) throws IOException, JAXBException {
+ void checkValueXML(String table, String row, String column, String value)
+ throws IOException, JAXBException {
Response response = getValueXML(table, row, column);
assertEquals(response.getCode(), 200);
CellSetModel cellSet = (CellSetModel)
@@ -176,8 +188,20 @@ public class TestRowResource extends Min
assertEquals(Bytes.toString(cell.getValue()), value);
}
- private Response putValuePB(String table, String row, String column,
- String value) throws IOException {
+ void checkValueXML(String url, String table, String row, String column,
+ String value) throws IOException, JAXBException {
+ Response response = getValueXML(url);
+ assertEquals(response.getCode(), 200);
+ CellSetModel cellSet = (CellSetModel)
+ unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
+ RowModel rowModel = cellSet.getRows().get(0);
+ CellModel cell = rowModel.getCells().get(0);
+ assertEquals(Bytes.toString(cell.getColumn()), column);
+ assertEquals(Bytes.toString(cell.getValue()), value);
+ }
+
+ Response putValuePB(String table, String row, String column, String value)
+ throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@@ -185,18 +209,24 @@ public class TestRowResource extends Min
path.append(row);
path.append('/');
path.append(column);
+ return putValuePB(path.toString(), table, row, column, value);
+ }
+
+ Response putValuePB(String url, String table, String row, String column,
+ String value) throws IOException {
RowModel rowModel = new RowModel(row);
- rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(column),
+ Bytes.toBytes(value)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
- Response response = client.put(path.toString(), MIMETYPE_PROTOBUF,
+ Response response = client.put(url, MIMETYPE_PROTOBUF,
cellSetModel.createProtobufOutput());
Thread.yield();
return response;
}
- private void checkValuePB(String table, String row, String column,
- String value) throws IOException {
+ void checkValuePB(String table, String row, String column, String value)
+ throws IOException {
Response response = getValuePB(table, row, column);
assertEquals(response.getCode(), 200);
CellSetModel cellSet = new CellSetModel();
@@ -207,7 +237,19 @@ public class TestRowResource extends Min
assertEquals(Bytes.toString(cell.getValue()), value);
}
- public void testDelete() throws IOException, JAXBException {
+ void checkValuePB(String url, String table, String row, String column,
+ String value) throws IOException {
+ Response response = getValuePB(url);
+ assertEquals(response.getCode(), 200);
+ CellSetModel cellSet = new CellSetModel();
+ cellSet.getObjectFromMessage(response.getBody());
+ RowModel rowModel = cellSet.getRows().get(0);
+ CellModel cell = rowModel.getCells().get(0);
+ assertEquals(Bytes.toString(cell.getColumn()), column);
+ assertEquals(Bytes.toString(cell.getValue()), value);
+ }
+
+ void doTestDelete() throws IOException, JAXBException {
Response response;
response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
@@ -231,7 +273,7 @@ public class TestRowResource extends Min
assertEquals(response.getCode(), 404);
}
- public void testSingleCellGetPutXML() throws IOException, JAXBException {
+ void doTestSingleCellGetPutXML() throws IOException, JAXBException {
Response response = getValueXML(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
@@ -246,7 +288,7 @@ public class TestRowResource extends Min
assertEquals(response.getCode(), 200);
}
- public void testSingleCellGetPutPB() throws IOException, JAXBException {
+ void doTestSingleCellGetPutPB() throws IOException, JAXBException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(response.getCode(), 404);
@@ -265,7 +307,7 @@ public class TestRowResource extends Min
assertEquals(response.getCode(), 200);
}
- public void testSingleCellGetPutBinary() throws IOException {
+ void doTestSingleCellGetPutBinary() throws IOException {
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
final byte[] body = Bytes.toBytes(VALUE_3);
Response response = client.put(path, MIMETYPE_BINARY, body);
@@ -288,7 +330,7 @@ public class TestRowResource extends Min
assertEquals(response.getCode(), 200);
}
- public void testSingleCellGetJSON() throws IOException, JAXBException {
+ void doTestSingleCellGetJSON() throws IOException, JAXBException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, MIMETYPE_BINARY,
Bytes.toBytes(VALUE_4));
@@ -300,21 +342,25 @@ public class TestRowResource extends Min
assertEquals(response.getCode(), 200);
}
- public void testURLEncodedKey() throws IOException, JAXBException {
- String encodedKey = URLEncoder.encode("http://www.google.com/",
- HConstants.UTF8_ENCODING);
+ public void doTestURLEncodedKey() throws IOException, JAXBException {
+ String urlKey = "http://example.com/foo";
+ StringBuilder path = new StringBuilder();
+ path.append('/');
+ path.append(TABLE);
+ path.append('/');
+ path.append(URLEncoder.encode(urlKey, HConstants.UTF8_ENCODING));
+ path.append('/');
+ path.append(COLUMN_1);
Response response;
- response = putValueXML(TABLE, encodedKey, COLUMN_1, VALUE_1);
+ response = putValueXML(path.toString(), TABLE, urlKey, COLUMN_1,
+ VALUE_1);
assertEquals(response.getCode(), 200);
- response = putValuePB(TABLE, encodedKey, COLUMN_2, VALUE_2);
- assertEquals(response.getCode(), 200);
- checkValuePB(TABLE, encodedKey, COLUMN_1, VALUE_1);
- checkValueXML(TABLE, encodedKey, COLUMN_2, VALUE_2);
+ checkValueXML(path.toString(), TABLE, urlKey, COLUMN_1, VALUE_1);
}
- public void testNoSuchCF() throws IOException, JAXBException {
- final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
- final String badPath = "/" + TABLE + "/" + ROW_1 + "/BAD";
+ public void doTestNoSuchCF() throws IOException, JAXBException {
+ final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
+ final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
Response response = client.post(goodPath, MIMETYPE_BINARY,
Bytes.toBytes(VALUE_1));
assertEquals(response.getCode(), 200);
@@ -323,17 +369,21 @@ public class TestRowResource extends Min
assertEquals(client.get(goodPath, MIMETYPE_BINARY).getCode(), 200);
}
- public void testMultiCellGetPutXML() throws IOException, JAXBException {
+ void doTestMultiCellGetPutXML() throws IOException, JAXBException {
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
+ Bytes.toBytes(VALUE_1)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
+ Bytes.toBytes(VALUE_2)));
cellSetModel.addRow(rowModel);
rowModel = new RowModel(ROW_2);
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
+ Bytes.toBytes(VALUE_3)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
+ Bytes.toBytes(VALUE_4)));
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
marshaller.marshal(cellSetModel, writer);
@@ -357,17 +407,21 @@ public class TestRowResource extends Min
assertEquals(response.getCode(), 200);
}
- public void testMultiCellGetPutPB() throws IOException {
+ void doTestMultiCellGetPutPB() throws IOException {
String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
+ Bytes.toBytes(VALUE_1)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
+ Bytes.toBytes(VALUE_2)));
cellSetModel.addRow(rowModel);
rowModel = new RowModel(ROW_2);
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
- rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1),
+ Bytes.toBytes(VALUE_3)));
+ rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2),
+ Bytes.toBytes(VALUE_4)));
cellSetModel.addRow(rowModel);
Response response = client.put(path, MIMETYPE_PROTOBUF,
cellSetModel.createProtobufOutput());
@@ -388,4 +442,16 @@ public class TestRowResource extends Min
response = deleteRow(TABLE, ROW_2);
assertEquals(response.getCode(), 200);
}
+
+ public void testRowResource() throws Exception {
+ doTestDelete();
+ doTestSingleCellGetPutXML();
+ doTestSingleCellGetPutPB();
+ doTestSingleCellGetPutBinary();
+ doTestSingleCellGetJSON();
+ doTestURLEncodedKey();
+ doTestNoSuchCF();
+ doTestMultiCellGetPutXML();
+ doTestMultiCellGetPutPB();
+ }
}