You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/12/21 05:29:44 UTC
svn commit: r1424808 [3/3] - in /hbase/trunk:
hbase-protocol/src/main/protobuf/
hbase-server/src/main/java/org/apache/hadoop/hbase/client/
hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/
hbase-server/src/main/java/org/apache/hadoop/hbas...
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java?rev=1424808&r1=1424807&r2=1424808&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java Fri Dec 21 04:29:43 2012
@@ -292,25 +292,4 @@ public class TestProtobufUtil {
Scan scan = ProtobufUtil.toScan(proto);
assertEquals(scanBuilder.build(), ProtobufUtil.toScan(scan));
}
-
- /**
- * Test basic Exec conversions.
- *
- * @throws IOException
- */
- @Test
- public void testExec() throws IOException {
- ClientProtos.Exec.Builder execBuilder = ClientProtos.Exec.newBuilder();
- execBuilder.setRow(ByteString.copyFromUtf8("row"));
- execBuilder.setProtocolName(ColumnAggregationEndpoint.class.getName());
- execBuilder.setMethodName("sum");
- execBuilder.addParameter(ProtobufUtil.toParameter(Bytes.toBytes("f")));
- execBuilder.addParameter(ProtobufUtil.toParameter(Bytes.toBytes("c")));
-
- ClientProtos.Exec proto = execBuilder.build();
- Exec exec = ProtobufUtil.toExec(proto);
- execBuilder = ClientProtos.Exec.newBuilder(ProtobufUtil.toExec(exec));
- execBuilder.clearProperty(); // remove properties added by default
- assertEquals(proto, execBuilder.build());
- }
}
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java?rev=1424808&r1=1424807&r2=1424808&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java Fri Dec 21 04:29:43 2012
@@ -18,96 +18,114 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
-import org.apache.hadoop.hbase.*;
-import org.apache.hadoop.hbase.client.Get;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.Coprocessor;
+import org.apache.hadoop.hbase.CoprocessorEnvironment;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.MediumTests;
+import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
-import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
-import org.apache.hadoop.hbase.ipc.ProtocolSignature;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.CountRequest;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.CountResponse;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.HelloRequest;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.HelloResponse;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.IncrementCountRequest;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.IncrementCountResponse;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.NoopRequest;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.NoopResponse;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.PingRequest;
+import org.apache.hadoop.hbase.coprocessor.protobuf.generated.PingProtos.PingResponse;
+import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.JVMClusterUtil;
-import org.apache.hadoop.hbase.ipc.VersionedProtocol;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-
-import com.google.common.collect.Lists;
import org.junit.experimental.categories.Category;
+import com.google.protobuf.RpcCallback;
+import com.google.protobuf.RpcController;
+import com.google.protobuf.Service;
+import com.google.protobuf.ServiceException;
+
@Category(MediumTests.class)
public class TestServerCustomProtocol {
- /* Test protocol */
- public static interface PingProtocol extends CoprocessorProtocol {
- public String ping();
- public int getPingCount();
- public int incrementCount(int diff);
- public String hello(String name);
- public void noop();
- }
+ private static final Log LOG = LogFactory.getLog(TestServerCustomProtocol.class);
+ static final String WHOAREYOU = "Who are you?";
+ static final String NOBODY = "nobody";
+ static final String HELLO = "Hello, ";
/* Test protocol implementation */
- public static class PingHandler implements Coprocessor, PingProtocol, VersionedProtocol {
- static long VERSION = 1;
+ public static class PingHandler extends PingProtos.PingService
+ implements Coprocessor, CoprocessorService {
private int counter = 0;
- @Override
- public String ping() {
- counter++;
- return "pong";
- }
@Override
- public int getPingCount() {
- return counter;
+ public void start(CoprocessorEnvironment env) throws IOException {
+ if (env instanceof RegionCoprocessorEnvironment) return;
+ throw new CoprocessorException("Must be loaded on a table region!");
}
@Override
- public int incrementCount(int diff) {
- counter += diff;
- return counter;
+ public void stop(CoprocessorEnvironment env) throws IOException {
+ // Nothing to do.
}
@Override
- public String hello(String name) {
- if (name == null) {
- return "Who are you?";
- } else if ("nobody".equals(name)) {
- return null;
- }
- return "Hello, "+name;
+ public void ping(RpcController controller, PingRequest request,
+ RpcCallback<PingResponse> done) {
+ this.counter++;
+ done.run(PingResponse.newBuilder().setPong("pong").build());
}
@Override
- public void noop() {
- // do nothing, just test void return type
+ public void count(RpcController controller, CountRequest request,
+ RpcCallback<CountResponse> done) {
+ done.run(CountResponse.newBuilder().setCount(this.counter).build());
}
@Override
- public ProtocolSignature getProtocolSignature(
- String protocol, long version, int clientMethodsHashCode)
- throws IOException {
- return new ProtocolSignature(VERSION, null);
+ public void increment(RpcController controller,
+ IncrementCountRequest request, RpcCallback<IncrementCountResponse> done) {
+ this.counter += request.getDiff();
+ done.run(IncrementCountResponse.newBuilder().setCount(this.counter).build());
}
@Override
- public long getProtocolVersion(String s, long l) throws IOException {
- return VERSION;
+ public void hello(RpcController controller, HelloRequest request,
+ RpcCallback<HelloResponse> done) {
+ if (!request.hasName()) done.run(HelloResponse.newBuilder().setResponse(WHOAREYOU).build());
+ else if (request.getName().equals(NOBODY)) done.run(HelloResponse.newBuilder().build());
+ else done.run(HelloResponse.newBuilder().setResponse(HELLO + request.getName()).build());
}
@Override
- public void start(CoprocessorEnvironment env) throws IOException {
+ public void noop(RpcController controller, NoopRequest request,
+ RpcCallback<NoopResponse> done) {
+ done.run(NoopResponse.newBuilder().build());
}
@Override
- public void stop(CoprocessorEnvironment env) throws IOException {
+ public Service getService() {
+ return this;
}
}
@@ -122,19 +140,16 @@ public class TestServerCustomProtocol {
private static final byte[] ROW_BC = Bytes.toBytes("bcc");
private static HBaseTestingUtility util = new HBaseTestingUtility();
- private static MiniHBaseCluster cluster = null;
@BeforeClass
public static void setupBeforeClass() throws Exception {
util.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
- PingHandler.class.getName());
- util.startMiniCluster(1);
- cluster = util.getMiniHBaseCluster();
+ PingHandler.class.getName());
+ util.startMiniCluster();
HTable table = util.createTable(TEST_TABLE, TEST_FAMILY);
util.createMultiRegions(util.getConfiguration(), table, TEST_FAMILY,
- new byte[][]{ HConstants.EMPTY_BYTE_ARRAY,
- ROW_B, ROW_C});
+ new byte[][]{ HConstants.EMPTY_BYTE_ARRAY, ROW_B, ROW_C});
Put puta = new Put( ROW_A );
puta.add(TEST_FAMILY, Bytes.toBytes("col1"), Bytes.toBytes(1));
@@ -155,156 +170,249 @@ public class TestServerCustomProtocol {
}
@Test
- public void testSingleProxy() throws Exception {
+ public void testSingleProxy() throws Throwable {
HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
-
- PingProtocol pinger = table.coprocessorProxy(PingProtocol.class, ROW_A);
- String result = pinger.ping();
- assertEquals("Invalid custom protocol response", "pong", result);
- result = pinger.hello("George");
- assertEquals("Invalid custom protocol response", "Hello, George", result);
- result = pinger.hello(null);
- assertEquals("Should handle NULL parameter", "Who are you?", result);
- result = pinger.hello("nobody");
- assertNull(result);
- int cnt = pinger.getPingCount();
- assertTrue("Count should be incremented", cnt > 0);
- int newcnt = pinger.incrementCount(5);
- assertEquals("Counter should have incremented by 5", cnt+5, newcnt);
+ Map<byte [], String> results = ping(table, null, null);
+ // There are three regions so should get back three results.
+ assertEquals(3, results.size());
+ for (Map.Entry<byte [], String> e: results.entrySet()) {
+ assertEquals("Invalid custom protocol response", "pong", e.getValue());
+ }
+ hello(table, "George", HELLO + "George");
+ LOG.info("Did george");
+ hello(table, null, "Who are you?");
+ LOG.info("Who are you");
+ hello(table, NOBODY, null);
+ LOG.info(NOBODY);
+ Map<byte [], Integer> intResults = table.coprocessorService(PingProtos.PingService.class,
+ null, null,
+ new Batch.Call<PingProtos.PingService, Integer>() {
+ @Override
+ public Integer call(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.CountResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.CountResponse>();
+ instance.count(null, PingProtos.CountRequest.newBuilder().build(), rpcCallback);
+ return rpcCallback.get().getCount();
+ }
+ });
+ int count = -1;
+ for (Map.Entry<byte [], Integer> e: intResults.entrySet()) {
+ assertTrue(e.getValue() > 0);
+ count = e.getValue();
+ }
+ final int diff = 5;
+ intResults = table.coprocessorService(PingProtos.PingService.class,
+ null, null,
+ new Batch.Call<PingProtos.PingService, Integer>() {
+ @Override
+ public Integer call(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.IncrementCountResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.IncrementCountResponse>();
+ instance.increment(null, PingProtos.IncrementCountRequest.newBuilder().setDiff(diff).build(),
+ rpcCallback);
+ return rpcCallback.get().getCount();
+ }
+ });
+ // There are three regions so should get back three results.
+ assertEquals(3, results.size());
+ for (Map.Entry<byte [], Integer> e: intResults.entrySet()) {
+ assertTrue(e.getValue() == count + diff);
+ }
+ table.close();
}
- @Test
- public void testSingleMethod() throws Throwable {
- HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
+ private Map<byte [], String> hello(final HTable table, final String send, final String response)
+ throws ServiceException, Throwable {
+ Map<byte [], String> results = hello(table, send);
+ for (Map.Entry<byte [], String> e: results.entrySet()) {
+ assertEquals("Invalid custom protocol response", response, e.getValue());
+ }
+ return results;
+ }
- List<? extends Row> rows = Lists.newArrayList(
- new Get(ROW_A), new Get(ROW_B), new Get(ROW_C));
+ private Map<byte [], String> hello(final HTable table, final String send)
+ throws ServiceException, Throwable {
+ return hello(table, send, null, null);
+ }
+
+ private Map<byte [], String> hello(final HTable table, final String send, final byte [] start,
+ final byte [] end)
+ throws ServiceException, Throwable {
+ return table.coprocessorService(PingProtos.PingService.class,
+ start, end,
+ new Batch.Call<PingProtos.PingService, String>() {
+ @Override
+ public String call(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.HelloResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.HelloResponse>();
+ PingProtos.HelloRequest.Builder builder = PingProtos.HelloRequest.newBuilder();
+ if (send != null) builder.setName(send);
+ instance.hello(null, builder.build(), rpcCallback);
+ PingProtos.HelloResponse r = rpcCallback.get();
+ return r != null && r.hasResponse()? r.getResponse(): null;
+ }
+ });
+ }
- Batch.Call<PingProtocol,String> call = Batch.forMethod(PingProtocol.class,
- "ping");
- Map<byte[],String> results =
- table.coprocessorExec(PingProtocol.class, ROW_A, ROW_C, call);
+ private Map<byte [], String> compoundOfHelloAndPing(final HTable table, final byte [] start,
+ final byte [] end)
+ throws ServiceException, Throwable {
+ return table.coprocessorService(PingProtos.PingService.class,
+ start, end,
+ new Batch.Call<PingProtos.PingService, String>() {
+ @Override
+ public String call(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.HelloResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.HelloResponse>();
+ PingProtos.HelloRequest.Builder builder = PingProtos.HelloRequest.newBuilder();
+ // Call ping on same instance. Use result calling hello on same instance.
+ builder.setName(doPing(instance));
+ instance.hello(null, builder.build(), rpcCallback);
+ PingProtos.HelloResponse r = rpcCallback.get();
+ return r != null && r.hasResponse()? r.getResponse(): null;
+ }
+ });
+ }
+ private Map<byte [], String> noop(final HTable table, final byte [] start,
+ final byte [] end)
+ throws ServiceException, Throwable {
+ return table.coprocessorService(PingProtos.PingService.class, start, end,
+ new Batch.Call<PingProtos.PingService, String>() {
+ @Override
+ public String call(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.NoopResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.NoopResponse>();
+ PingProtos.NoopRequest.Builder builder = PingProtos.NoopRequest.newBuilder();
+ instance.noop(null, builder.build(), rpcCallback);
+ rpcCallback.get();
+ // Looks like null is expected when void. That is what the test below is looking for
+ return null;
+ }
+ });
+ }
+ @Test
+ public void testSingleMethod() throws Throwable {
+ HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
+ Map<byte [], String> results = table.coprocessorService(PingProtos.PingService.class,
+ null, ROW_A,
+ new Batch.Call<PingProtos.PingService, String>() {
+ @Override
+ public String call(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.PingResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.PingResponse>();
+ instance.ping(null, PingProtos.PingRequest.newBuilder().build(), rpcCallback);
+ return rpcCallback.get().getPong();
+ }
+ });
+ // Should have gotten results for 1 of the three regions only since we specified
+ // rows from 1 region
+ assertEquals(1, results.size());
verifyRegionResults(table, results, ROW_A);
- verifyRegionResults(table, results, ROW_B);
- verifyRegionResults(table, results, ROW_C);
-
- Batch.Call<PingProtocol,String> helloCall =
- Batch.forMethod(PingProtocol.class, "hello", "NAME");
- results =
- table.coprocessorExec(PingProtocol.class, ROW_A, ROW_C, helloCall);
-
+ final String name = "NAME";
+ results = hello(table, name, null, ROW_A);
+ // Should have gotten results for 1 of the three regions only since we specified
+ // rows from 1 region
+ assertEquals(1, results.size());
verifyRegionResults(table, results, "Hello, NAME", ROW_A);
- verifyRegionResults(table, results, "Hello, NAME", ROW_B);
- verifyRegionResults(table, results, "Hello, NAME", ROW_C);
+ table.close();
}
@Test
public void testRowRange() throws Throwable {
HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
-
- // test empty range
- Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
- null, null, new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.ping();
- }
- });
- // should contain all three rows/regions
+ for (Entry<HRegionInfo, ServerName> e: table.getRegionLocations().entrySet()) {
+ LOG.info("Region " + e.getKey().getRegionNameAsString() + ", servername=" + e.getValue());
+ }
+ // Here are what regions looked like on a run:
+ //
+ // test,,1355943549657.c65d4822d8bdecc033a96451f3a0f55d.
+ // test,bbb,1355943549661.110393b070dd1ed93441e0bc9b3ffb7e.
+ // test,ccc,1355943549665.c3d6d125141359cbbd2a43eaff3cdf74.
+
+ Map<byte [], String> results = ping(table, null, ROW_A);
+ // Should contain first region only.
+ assertEquals(1, results.size());
verifyRegionResults(table, results, ROW_A);
- verifyRegionResults(table, results, ROW_B);
- verifyRegionResults(table, results, ROW_C);
- // test start row + empty end
- results = table.coprocessorExec(PingProtocol.class, ROW_BC, null,
- new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.ping();
- }
- });
+ // Test start row + empty end
+ results = ping(table, ROW_BC, null);
+ assertEquals(2, results.size());
// should contain last 2 regions
- HRegionLocation loc = table.getRegionLocation(ROW_A);
+ HRegionLocation loc = table.getRegionLocation(ROW_A, true);
assertNull("Should be missing region for row aaa (prior to start row)",
- results.get(loc.getRegionInfo().getRegionName()));
+ results.get(loc.getRegionInfo().getRegionName()));
verifyRegionResults(table, results, ROW_B);
verifyRegionResults(table, results, ROW_C);
// test empty start + end
- results = table.coprocessorExec(PingProtocol.class, null, ROW_BC,
- new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.ping();
- }
- });
+ results = ping(table, null, ROW_BC);
// should contain the first 2 regions
+ assertEquals(2, results.size());
verifyRegionResults(table, results, ROW_A);
verifyRegionResults(table, results, ROW_B);
- loc = table.getRegionLocation(ROW_C);
+ loc = table.getRegionLocation(ROW_C, true);
assertNull("Should be missing region for row ccc (past stop row)",
results.get(loc.getRegionInfo().getRegionName()));
// test explicit start + end
- results = table.coprocessorExec(PingProtocol.class, ROW_AB, ROW_BC,
- new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.ping();
- }
- });
+ results = ping(table, ROW_AB, ROW_BC);
// should contain first 2 regions
+ assertEquals(2, results.size());
verifyRegionResults(table, results, ROW_A);
verifyRegionResults(table, results, ROW_B);
- loc = table.getRegionLocation(ROW_C);
+ loc = table.getRegionLocation(ROW_C, true);
assertNull("Should be missing region for row ccc (past stop row)",
results.get(loc.getRegionInfo().getRegionName()));
// test single region
- results = table.coprocessorExec(PingProtocol.class, ROW_B, ROW_BC,
- new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.ping();
- }
- });
+ results = ping(table, ROW_B, ROW_BC);
// should only contain region bbb
+ assertEquals(1, results.size());
verifyRegionResults(table, results, ROW_B);
- loc = table.getRegionLocation(ROW_A);
+ loc = table.getRegionLocation(ROW_A, true);
assertNull("Should be missing region for row aaa (prior to start)",
results.get(loc.getRegionInfo().getRegionName()));
- loc = table.getRegionLocation(ROW_C);
+ loc = table.getRegionLocation(ROW_C, true);
assertNull("Should be missing region for row ccc (past stop row)",
results.get(loc.getRegionInfo().getRegionName()));
+ table.close();
+ }
+
+ private Map<byte [], String> ping(final HTable table, final byte [] start, final byte [] end)
+ throws ServiceException, Throwable {
+ return table.coprocessorService(PingProtos.PingService.class, start, end,
+ new Batch.Call<PingProtos.PingService, String>() {
+ @Override
+ public String call(PingProtos.PingService instance) throws IOException {
+ return doPing(instance);
+ }
+ });
+ }
+
+ private static String doPing(PingProtos.PingService instance) throws IOException {
+ BlockingRpcCallback<PingProtos.PingResponse> rpcCallback =
+ new BlockingRpcCallback<PingProtos.PingResponse>();
+ instance.ping(null, PingProtos.PingRequest.newBuilder().build(), rpcCallback);
+ return rpcCallback.get().getPong();
}
@Test
- public void testCompountCall() throws Throwable {
+ public void testCompoundCall() throws Throwable {
HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
-
- Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
- ROW_A, ROW_C,
- new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.hello(instance.ping());
- }
- });
-
+ Map<byte [], String> results = compoundOfHelloAndPing(table, ROW_A, ROW_C);
verifyRegionResults(table, results, "Hello, pong", ROW_A);
verifyRegionResults(table, results, "Hello, pong", ROW_B);
verifyRegionResults(table, results, "Hello, pong", ROW_C);
+ table.close();
}
@Test
public void testNullCall() throws Throwable {
HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
-
- Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
- ROW_A, ROW_C,
- new Batch.Call<PingProtocol,String>() {
- public String call(PingProtocol instance) {
- return instance.hello(null);
- }
- });
-
+ Map<byte[],String> results = hello(table, null, ROW_A, ROW_C);
verifyRegionResults(table, results, "Who are you?", ROW_A);
verifyRegionResults(table, results, "Who are you?", ROW_B);
verifyRegionResults(table, results, "Who are you?", ROW_C);
@@ -313,33 +421,16 @@ public class TestServerCustomProtocol {
@Test
public void testNullReturn() throws Throwable {
HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
-
- Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
- ROW_A, ROW_C,
- new Batch.Call<PingProtocol,String>(){
- public String call(PingProtocol instance) {
- return instance.hello("nobody");
- }
- });
-
+ Map<byte[],String> results = hello(table, "nobody", ROW_A, ROW_C);
verifyRegionResults(table, results, null, ROW_A);
verifyRegionResults(table, results, null, ROW_B);
verifyRegionResults(table, results, null, ROW_C);
}
@Test
- public void testVoidReturnType() throws Throwable {
+ public void testEmptyReturnType() throws Throwable {
HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
-
- Map<byte[],Object> results = table.coprocessorExec(PingProtocol.class,
- ROW_A, ROW_C,
- new Batch.Call<PingProtocol,Object>(){
- public Object call(PingProtocol instance) {
- instance.noop();
- return null;
- }
- });
-
+ Map<byte[],String> results = noop(table, ROW_A, ROW_C);
assertEquals("Should have results from three regions", 3, results.size());
// all results should be null
for (Object v : results.values()) {
@@ -353,16 +444,19 @@ public class TestServerCustomProtocol {
}
private void verifyRegionResults(HTable table,
- Map<byte[],String> results, String expected, byte[] row)
+ Map<byte[], String> results, String expected, byte[] row)
throws Exception {
- HRegionLocation loc = table.getRegionLocation(row);
+ for (Map.Entry<byte [], String> e: results.entrySet()) {
+ LOG.info("row=" + Bytes.toString(row) + ", expected=" + expected +
+ ", result key=" + Bytes.toString(e.getKey()) +
+ ", value=" + e.getValue());
+ }
+ HRegionLocation loc = table.getRegionLocation(row, true);
byte[] region = loc.getRegionInfo().getRegionName();
assertTrue("Results should contain region " +
- Bytes.toStringBinary(region)+" for row '"+Bytes.toStringBinary(row)+"'",
- results.containsKey(region));
+ Bytes.toStringBinary(region) + " for row '" + Bytes.toStringBinary(row)+ "'",
+ results.containsKey(region));
assertEquals("Invalid result for row '"+Bytes.toStringBinary(row)+"'",
- expected, results.get(region));
+ expected, results.get(region));
}
-
}
-
Added: hbase/trunk/hbase-server/src/test/protobuf/ColumnAggregationProtocol.proto
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/protobuf/ColumnAggregationProtocol.proto?rev=1424808&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/protobuf/ColumnAggregationProtocol.proto (added)
+++ hbase/trunk/hbase-server/src/test/protobuf/ColumnAggregationProtocol.proto Fri Dec 21 04:29:43 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.
+ */
+// Coprocessor test
+option java_package = "org.apache.hadoop.hbase.coprocessor.protobuf.generated";
+option java_outer_classname = "ColumnAggregationProtos";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+message SumRequest {
+ required bytes family = 1;
+ optional bytes qualifier = 2;
+}
+
+message SumResponse {
+ required int64 sum = 1;
+}
+
+service ColumnAggregationService {
+ rpc sum(SumRequest) returns(SumResponse);
+}
Added: hbase/trunk/hbase-server/src/test/protobuf/PingProtocol.proto
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/protobuf/PingProtocol.proto?rev=1424808&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/protobuf/PingProtocol.proto (added)
+++ hbase/trunk/hbase-server/src/test/protobuf/PingProtocol.proto Fri Dec 21 04:29:43 2012
@@ -0,0 +1,66 @@
+/**
+ * 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.
+ */
+// Coprocessor test
+option java_package = "org.apache.hadoop.hbase.coprocessor.protobuf.generated";
+option java_outer_classname = "PingProtos";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+message PingRequest {
+}
+
+message PingResponse {
+ required string pong = 1;
+}
+
+message CountRequest {
+}
+
+message CountResponse {
+ required int32 count = 1;
+}
+
+message IncrementCountRequest {
+ required int32 diff = 1;
+}
+
+message IncrementCountResponse {
+ required int32 count = 1;
+}
+
+message HelloRequest {
+ optional string name = 1;
+}
+
+message HelloResponse {
+ optional string response = 1;
+}
+
+message NoopRequest {
+}
+
+message NoopResponse {
+}
+
+service PingService {
+ rpc ping(PingRequest) returns(PingResponse);
+ rpc count(CountRequest) returns(CountResponse);
+ rpc increment(IncrementCountRequest) returns(IncrementCountResponse);
+ rpc hello(HelloRequest) returns(HelloResponse);
+ rpc noop(NoopRequest) returns(NoopResponse);
+}