From 3f423daca09cf22e955b1cc63d8d35ef93b43282 Mon Sep 17 00:00:00 2001 From: Gary Helmling Date: Tue, 15 Nov 2011 17:55:48 +0000 Subject: [PATCH] HBASE-4784 Handle void return types in CoprocessorProtocol methods git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1202336 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../hbase/client/coprocessor/ExecResult.java | 17 +----------- .../hadoop/hbase/regionserver/HRegion.java | 4 +-- .../TestServerCustomProtocol.java | 26 +++++++++++++++++++ 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4c50b64c2d3..e2ed8628b0a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -428,6 +428,8 @@ Release 0.92.0 - Unreleased in the case of RS offline HBASE-4777 Write back to client 'incompatible' if we show up with wrong version HBASE-4775 Remove -ea from all but tests; enable it if you need it testing + HBASE-4784 Void return types not handled correctly for CoprocessorProtocol + methods TESTS HBASE-4450 test for number of blocks read: to serve as baseline for expected diff --git a/src/main/java/org/apache/hadoop/hbase/client/coprocessor/ExecResult.java b/src/main/java/org/apache/hadoop/hbase/client/coprocessor/ExecResult.java index 8cbf646218e..065b3f22463 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/coprocessor/ExecResult.java +++ b/src/main/java/org/apache/hadoop/hbase/client/coprocessor/ExecResult.java @@ -48,15 +48,13 @@ import java.io.Serializable; */ public class ExecResult implements Writable { private byte[] regionName; - private Class valueType; private Object value; public ExecResult() { } - public ExecResult(byte[] region, Class valueType, Object value) { + public ExecResult(byte[] region, Object value) { this.regionName = region; - this.valueType = valueType; this.value = value; } @@ -73,24 +71,11 @@ public class ExecResult implements Writable { Bytes.writeByteArray(out, regionName); HbaseObjectWritable.writeObject(out, value, value != null ? value.getClass() : Writable.class, null); - Class alternativeSerializationClass; - if(value instanceof Writable){ - alternativeSerializationClass = Writable.class; - } else { - alternativeSerializationClass = Serializable.class; - } - out.writeUTF((valueType != null ? valueType : alternativeSerializationClass).getName()); } @Override public void readFields(DataInput in) throws IOException { regionName = Bytes.readByteArray(in); value = HbaseObjectWritable.readObject(in, null); - String className = in.readUTF(); - try { - valueType = Classes.extendedForName(className); - } catch (ClassNotFoundException e) { - throw new IOException("Unable to find class of type: " + className ); - } } } diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index c7f4ca64a93..00fd0863a55 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -4292,13 +4292,11 @@ public class HRegion implements HeapSize { // , Writable{ CoprocessorProtocol handler = protocolHandlers.getInstance(protocol); Object value; - Class returnType; try { Method method = protocol.getMethod( call.getMethodName(), call.getParameterClasses()); method.setAccessible(true); - returnType = method.getReturnType(); value = method.invoke(handler, call.getParameters()); } catch (InvocationTargetException e) { @@ -4318,7 +4316,7 @@ public class HRegion implements HeapSize { // , Writable{ throw ioe; } - return new ExecResult(getRegionName(), returnType, value); + return new ExecResult(getRegionName(), value); } /* diff --git a/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java b/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java index 668673224c8..95d3916d8d9 100644 --- a/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java +++ b/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerCustomProtocol.java @@ -54,6 +54,7 @@ public class TestServerCustomProtocol { public int getPingCount(); public int incrementCount(int diff); public String hello(String name); + public void noop(); } /* Test protocol implementation */ @@ -87,6 +88,11 @@ public class TestServerCustomProtocol { return "Hello, "+name; } + @Override + public void noop() { + // do nothing, just test void return type + } + @Override public ProtocolSignature getProtocolSignature( String protocol, long version, int clientMethodsHashCode) @@ -324,6 +330,26 @@ public class TestServerCustomProtocol { verifyRegionResults(table, results, null, ROW_C); } + @Test + public void testVoidReturnType() throws Throwable { + HTable table = new HTable(util.getConfiguration(), TEST_TABLE); + + Map results = table.coprocessorExec(PingProtocol.class, + ROW_A, ROW_C, + new Batch.Call(){ + public Object call(PingProtocol instance) { + instance.noop(); + return null; + } + }); + + assertEquals("Should have results from three regions", 3, results.size()); + // all results should be null + for (Object v : results.values()) { + assertNull(v); + } + } + private void verifyRegionResults(HTable table, Map results, byte[] row) throws Exception { verifyRegionResults(table, results, "pong", row);