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
This commit is contained in:
Gary Helmling 2011-11-15 17:55:48 +00:00
parent 48c16d1d66
commit 3f423daca0
4 changed files with 30 additions and 19 deletions

View File

@ -428,6 +428,8 @@ Release 0.92.0 - Unreleased
in the case of RS offline in the case of RS offline
HBASE-4777 Write back to client 'incompatible' if we show up with wrong version 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-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 TESTS
HBASE-4450 test for number of blocks read: to serve as baseline for expected HBASE-4450 test for number of blocks read: to serve as baseline for expected

View File

@ -48,15 +48,13 @@ import java.io.Serializable;
*/ */
public class ExecResult implements Writable { public class ExecResult implements Writable {
private byte[] regionName; private byte[] regionName;
private Class<?> valueType;
private Object value; private Object value;
public ExecResult() { public ExecResult() {
} }
public ExecResult(byte[] region, Class<?> valueType, Object value) { public ExecResult(byte[] region, Object value) {
this.regionName = region; this.regionName = region;
this.valueType = valueType;
this.value = value; this.value = value;
} }
@ -73,24 +71,11 @@ public class ExecResult implements Writable {
Bytes.writeByteArray(out, regionName); Bytes.writeByteArray(out, regionName);
HbaseObjectWritable.writeObject(out, value, HbaseObjectWritable.writeObject(out, value,
value != null ? value.getClass() : Writable.class, null); 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 @Override
public void readFields(DataInput in) throws IOException { public void readFields(DataInput in) throws IOException {
regionName = Bytes.readByteArray(in); regionName = Bytes.readByteArray(in);
value = HbaseObjectWritable.readObject(in, null); 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 );
}
} }
} }

View File

@ -4292,13 +4292,11 @@ public class HRegion implements HeapSize { // , Writable{
CoprocessorProtocol handler = protocolHandlers.getInstance(protocol); CoprocessorProtocol handler = protocolHandlers.getInstance(protocol);
Object value; Object value;
Class<?> returnType;
try { try {
Method method = protocol.getMethod( Method method = protocol.getMethod(
call.getMethodName(), call.getParameterClasses()); call.getMethodName(), call.getParameterClasses());
method.setAccessible(true); method.setAccessible(true);
returnType = method.getReturnType();
value = method.invoke(handler, call.getParameters()); value = method.invoke(handler, call.getParameters());
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
@ -4318,7 +4316,7 @@ public class HRegion implements HeapSize { // , Writable{
throw ioe; throw ioe;
} }
return new ExecResult(getRegionName(), returnType, value); return new ExecResult(getRegionName(), value);
} }
/* /*

View File

@ -54,6 +54,7 @@ public class TestServerCustomProtocol {
public int getPingCount(); public int getPingCount();
public int incrementCount(int diff); public int incrementCount(int diff);
public String hello(String name); public String hello(String name);
public void noop();
} }
/* Test protocol implementation */ /* Test protocol implementation */
@ -87,6 +88,11 @@ public class TestServerCustomProtocol {
return "Hello, "+name; return "Hello, "+name;
} }
@Override
public void noop() {
// do nothing, just test void return type
}
@Override @Override
public ProtocolSignature getProtocolSignature( public ProtocolSignature getProtocolSignature(
String protocol, long version, int clientMethodsHashCode) String protocol, long version, int clientMethodsHashCode)
@ -324,6 +330,26 @@ public class TestServerCustomProtocol {
verifyRegionResults(table, results, null, ROW_C); verifyRegionResults(table, results, null, ROW_C);
} }
@Test
public void testVoidReturnType() 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;
}
});
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, private void verifyRegionResults(HTable table,
Map<byte[],String> results, byte[] row) throws Exception { Map<byte[],String> results, byte[] row) throws Exception {
verifyRegionResults(table, results, "pong", row); verifyRegionResults(table, results, "pong", row);