avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r980187 - in /avro/trunk: ./ lang/java/src/java/org/apache/avro/generic/ lang/java/src/java/org/apache/avro/reflect/ lang/java/src/java/org/apache/avro/specific/ lang/java/src/test/java/org/apache/avro/
Date Wed, 28 Jul 2010 19:44:50 GMT
Author: cutting
Date: Wed Jul 28 19:44:50 2010
New Revision: 980187

URL: http://svn.apache.org/viewvc?rev=980187&view=rev
Log:
AVRO-573.  Java: Fix various bugs with undeclared RPC exceptions.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericRequestor.java
    avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectResponder.java
    avro/trunk/lang/java/src/java/org/apache/avro/specific/SpecificRequestor.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolGeneric.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolReflect.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolSpecific.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Jul 28 19:44:50 2010
@@ -100,6 +100,8 @@ Avro 1.4.0 (unreleased)
 
     AVRO-589. ClassCastException: org.apache.avro.io.parsing.Symbol$Alternative cannot be
cast to org.apache.avro.io.parsing.Symbol$UnionAdjustAction (thiru)
 
+    AVRO-573. Java: Fix various bugs with undeclared RPC exceptions. (cutting)
+
 Avro 1.3.3 (7 June 2010)
 
   IMPROVEMENTS

Modified: avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericRequestor.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericRequestor.java?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericRequestor.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericRequestor.java Wed Jul 28
19:44:50 2010
@@ -22,11 +22,13 @@ import java.io.IOException;
 
 import org.apache.avro.Protocol;
 import org.apache.avro.Schema;
+import org.apache.avro.AvroRuntimeException;
 import org.apache.avro.io.Decoder;
 import org.apache.avro.io.Encoder;
 import org.apache.avro.ipc.AvroRemoteException;
 import org.apache.avro.ipc.Requestor;
 import org.apache.avro.ipc.Transceiver;
+import org.apache.avro.util.Utf8;
 
 /** {@link Requestor} implementation for generic Java data. */
 public class GenericRequestor extends Requestor {
@@ -61,9 +63,12 @@ public class GenericRequestor extends Re
   }
 
   @Override
-  public AvroRemoteException readError(Schema schema, Decoder in)
+  public Exception readError(Schema schema, Decoder in)
     throws IOException {
-    return new AvroRemoteException(new GenericDatumReader<Object>(schema).read(null,in));
+    Object error = new GenericDatumReader<Object>(schema).read(null,in);
+    if (error instanceof Utf8)
+      return new AvroRuntimeException(error.toString()); // system error
+    return new AvroRemoteException(error);
   }
 
 }

Modified: avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectResponder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectResponder.java?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectResponder.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectResponder.java Wed Jul 28
19:44:50 2010
@@ -18,11 +18,15 @@
 
 package org.apache.avro.reflect;
 
+import java.io.IOException;
+
 import org.apache.avro.Schema;
 import org.apache.avro.Protocol;
+import org.apache.avro.io.Encoder;
 import org.apache.avro.io.DatumReader;
 import org.apache.avro.io.DatumWriter;
 import org.apache.avro.specific.SpecificResponder;
+import org.apache.avro.util.Utf8;
 
 /** {@link org.apache.avro.ipc.Responder} for existing interfaces.*/
 public class ReflectResponder extends SpecificResponder {
@@ -44,5 +48,14 @@ public class ReflectResponder extends Sp
     return new ReflectDatumReader<Object>(schema);
   }
 
-}
+  @Override
+  public void writeError(Schema schema, Object error,
+                         Encoder out) throws IOException {
+    if (error instanceof Utf8)
+      error = error.toString();                   // system error: convert
+    super.writeError(schema, error, out);
+  }
 
+
+
+}

Modified: avro/trunk/lang/java/src/java/org/apache/avro/specific/SpecificRequestor.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/specific/SpecificRequestor.java?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/specific/SpecificRequestor.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/specific/SpecificRequestor.java Wed Jul
28 19:44:50 2010
@@ -25,11 +25,11 @@ import java.lang.reflect.InvocationHandl
 
 import org.apache.avro.Protocol;
 import org.apache.avro.Schema;
+import org.apache.avro.AvroRuntimeException;
 import org.apache.avro.io.DatumReader;
 import org.apache.avro.io.DatumWriter;
 import org.apache.avro.io.Decoder;
 import org.apache.avro.io.Encoder;
-import org.apache.avro.ipc.AvroRemoteException;
 import org.apache.avro.ipc.Transceiver;
 import org.apache.avro.ipc.Requestor;
 
@@ -80,7 +80,7 @@ public class SpecificRequestor extends R
     Object value = getDatumReader(schema).read(null, in);
     if (value instanceof Exception)
       return (Exception)value;
-    return new AvroRemoteException(value);
+    return new AvroRuntimeException(value.toString());
   }
 
   /** Create a proxy instance whose methods invoke RPCs. */

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolGeneric.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolGeneric.java?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolGeneric.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolGeneric.java Wed Jul 28
19:44:50 2010
@@ -58,6 +58,8 @@ public class TestProtocolGeneric {
     }
   }
 
+  private static boolean throwUndeclaredError;
+
   protected static class TestResponder extends GenericResponder {
     public TestResponder() { super(PROTOCOL); }
     public Object respond(Message message, Object request)
@@ -82,6 +84,7 @@ public class TestProtocolGeneric {
       }
 
       if ("error".equals(message.getName())) {
+        if (throwUndeclaredError) throw new RuntimeException("foo");
         GenericRecord error =
           new GenericData.Record(PROTOCOL.getType("TestError"));
         error.put("message", new Utf8("an error"));
@@ -159,6 +162,22 @@ public class TestProtocolGeneric {
   }
 
   @Test
+  public void testUndeclaredError() throws IOException {
+    this.throwUndeclaredError = true;
+    RuntimeException error = null;
+    GenericRecord params =
+      new GenericData.Record(PROTOCOL.getMessages().get("error").getRequest());
+    try {
+      requestor.request("error", params);
+    } catch (RuntimeException e) {
+      error = e;
+    } finally {
+      this.throwUndeclaredError = false;
+    }
+    assertNotNull(error);
+  }
+
+  @Test
   /** Construct and use a different protocol whose "hello" method has an extra
       argument to check that schema is sent to parse request. */
   public void testHandshake() throws IOException {

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolReflect.java?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolReflect.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolReflect.java Wed Jul 28
19:44:50 2010
@@ -53,12 +53,15 @@ public class TestProtocolReflect {
     void error() throws SimpleException;
   }
   
+  private static boolean throwUndeclaredError;
+
   public static class TestImpl implements Simple {
     public String hello(String greeting) { return "goodbye"; }
     public int add(int arg1, int arg2) { return arg1 + arg2; }
     public TestRecord echo(TestRecord record) { return record; }
     public byte[] echoBytes(byte[] data) { return data; }
     public void error() throws SimpleException {
+      if (throwUndeclaredError) throw new RuntimeException("foo");
       throw new SimpleException("foo");
     }
   }
@@ -119,6 +122,20 @@ public class TestProtocolReflect {
     assertEquals("foo", error.getMessage());
   }
 
+  @Test
+  public void testUndeclaredError() throws Exception {
+    this.throwUndeclaredError = true;
+    RuntimeException error = null;
+    try {
+      proxy.error();
+    } catch (RuntimeException e) {
+      error = e;
+    } finally {
+      this.throwUndeclaredError = false;
+    }
+    assertNotNull(error);
+  }
+
   @AfterClass
   public static void testStopServer() throws IOException {
     client.close();

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolSpecific.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolSpecific.java?rev=980187&r1=980186&r2=980187&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolSpecific.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolSpecific.java Wed Jul 28
19:44:50 2010
@@ -53,12 +53,15 @@ public class TestProtocolSpecific {
 
   public static int ackCount;
 
+  private static boolean throwUndeclaredError;
+
   public static class TestImpl implements Simple {
     public Utf8 hello(Utf8 greeting) { return new Utf8("goodbye"); }
     public int add(int arg1, int arg2) { return arg1 + arg2; }
     public TestRecord echo(TestRecord record) { return record; }
     public ByteBuffer echoBytes(ByteBuffer data) { return data; }
     public Void error() throws AvroRemoteException {
+      if (throwUndeclaredError) throw new RuntimeException("foo");
       TestError error = new TestError();
       error.message = new Utf8("an error");
       throw error;
@@ -143,6 +146,21 @@ public class TestProtocolSpecific {
   }
 
   @Test
+  public void testUndeclaredError() throws Exception {
+    this.throwUndeclaredError = true;
+    RuntimeException error = null;
+    try {
+      proxy.error();
+    } catch (RuntimeException e) {
+      error = e;
+    } finally {
+      this.throwUndeclaredError = false;
+    }
+    assertNotNull(error);
+  }
+
+
+  @Test
   public void testOneWay() throws IOException {
     ackCount = 0;
     proxy.ack();



Mime
View raw message