avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1130505 - in /avro/branches/branch-1.5: ./ lang/java/ipc/src/main/java/org/apache/avro/ipc/ lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/ lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ lang/java/ipc/src/main/java/org/a...
Date Thu, 02 Jun 2011 11:52:08 GMT
Author: cutting
Date: Thu Jun  2 11:52:07 2011
New Revision: 1130505

URL: http://svn.apache.org/viewvc?rev=1130505&view=rev
Log:
Merge -c 1130503 from trunk  to 1.5 branch.  Fixes: AVRO-832.

Modified:
    avro/branches/branch-1.5/   (props changed)
    avro/branches/branch-1.5/CHANGES.txt
    avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
    avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
    avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
    avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
    avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
    avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
    avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java

Propchange: avro/branches/branch-1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun  2 11:52:07 2011
@@ -1 +1 @@
-/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548,1095550,1096798,1097916,1097927,1097968,1097974,1102332,1102335,1124127,1124971,1129053,1129071,1129697-1129706,1129729
+/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548,1095550,1096798,1097916,1097927,1097968,1097974,1102332,1102335,1124127,1124971,1129053,1129071,1129697-1129706,1129729,1130503

Modified: avro/branches/branch-1.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/CHANGES.txt?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/CHANGES.txt (original)
+++ avro/branches/branch-1.5/CHANGES.txt Thu Jun  2 11:52:07 2011
@@ -31,6 +31,9 @@ Avro 1.5.2 (unreleased)
 
     AVRO-809. Java: Fix reflect for classes that have no package. (cutting)
 
+    AVRO-832. Java: Fix RPC client to correctly perform schema
+    resolution on message responses.  (cutting)
+
 Avro 1.5.1 (3 May 2011)
 
   NEW FEATURES

Modified: avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
Thu Jun  2 11:52:07 2011
@@ -150,7 +150,7 @@ public abstract class Requestor {
     context.setResponseCallMeta(META_READER.read(null, in));
     
     if (!in.readBoolean()) {                      // no error
-      Object response = readResponse(rm.getResponse(), in);
+      Object response = readResponse(rm.getResponse(), m.getResponse(), in);
       context.setResponse(response);
       for (RPCPlugin plugin : rpcMetaPlugins) {
         plugin.clientReceiveResponse(context);
@@ -158,7 +158,7 @@ public abstract class Requestor {
       return response;
       
     } else {
-      Exception error = readError(rm.getErrors(), in);
+      Exception error = readError(rm.getErrors(), m.getErrors(), in);
       context.setError(error);
       for (RPCPlugin plugin : rpcMetaPlugins) {
         plugin.clientReceiveResponse(context);
@@ -275,12 +275,22 @@ public abstract class Requestor {
   public abstract void writeRequest(Schema schema, Object request,
                                     Encoder out) throws IOException;
 
+  @Deprecated                                     // for compatibility in 1.5
+  public Object readResponse(Schema schema, Decoder in) throws IOException {
+    return readResponse(schema, schema, in);
+  }
+
   /** Reads a response message. */
-  public abstract Object readResponse(Schema schema, Decoder in)
+  public abstract Object readResponse(Schema writer, Schema reader, Decoder in)
     throws IOException;
 
+  @Deprecated                                     // for compatibility in 1.5
+  public Object readError(Schema schema, Decoder in) throws IOException {
+    return readError(schema, schema, in);
+  }
+
   /** Reads an error message. */
-  public abstract Exception readError(Schema schema, Decoder in)
+  public abstract Exception readError(Schema writer, Schema reader, Decoder in)
     throws IOException;
 }
 

Modified: avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
Thu Jun  2 11:52:07 2011
@@ -59,14 +59,15 @@ public class GenericRequestor extends Re
   }
 
   @Override
-  public Object readResponse(Schema schema, Decoder in) throws IOException {
-    return new GenericDatumReader<Object>(schema).read(null, in);
+  public Object readResponse(Schema writer, Schema reader, Decoder in)
+    throws IOException {
+    return new GenericDatumReader<Object>(writer, reader).read(null, in);
   }
 
   @Override
-  public Exception readError(Schema schema, Decoder in)
+  public Exception readError(Schema writer, Schema reader, Decoder in)
     throws IOException {
-    Object error = new GenericDatumReader<Object>(schema).read(null,in);
+    Object error = new GenericDatumReader<Object>(writer, reader).read(null,in);
     if (error instanceof CharSequence)
       return new AvroRuntimeException(error.toString()); // system error
     return new AvroRemoteException(error);

Modified: avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/reflect/ReflectRequestor.java
Thu Jun  2 11:52:07 2011
@@ -50,8 +50,8 @@ public class ReflectRequestor extends Sp
   }
 
   @Override
-  protected DatumReader<Object> getDatumReader(Schema schema) {
-    return new ReflectDatumReader<Object>(schema);
+  protected DatumReader<Object> getDatumReader(Schema writer, Schema reader) {
+    return new ReflectDatumReader<Object>(writer, reader);
   }
 
   /** Create a proxy instance whose methods invoke RPCs. */

Modified: avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
Thu Jun  2 11:52:07 2011
@@ -59,8 +59,13 @@ public class SpecificRequestor extends R
     return new SpecificDatumWriter<Object>(schema);
   }
 
+  @Deprecated                                     // for compatibility in 1.5
   protected DatumReader<Object> getDatumReader(Schema schema) {
-    return new SpecificDatumReader<Object>(schema);
+    return getDatumReader(schema, schema);
+  }
+
+  protected DatumReader<Object> getDatumReader(Schema writer, Schema reader) {
+    return new SpecificDatumReader<Object>(writer, reader);
   }
 
   @Override
@@ -73,14 +78,15 @@ public class SpecificRequestor extends R
   }
     
   @Override
-  public Object readResponse(Schema schema, Decoder in) throws IOException {
-    return getDatumReader(schema).read(null, in);
+  public Object readResponse(Schema writer, Schema reader, Decoder in)
+    throws IOException {
+    return getDatumReader(writer, reader).read(null, in);
   }
 
   @Override
-  public Exception readError(Schema schema, Decoder in)
+  public Exception readError(Schema writer, Schema reader, Decoder in)
     throws IOException {
-    Object value = getDatumReader(schema).read(null, in);
+    Object value = getDatumReader(writer, reader).read(null, in);
     if (value instanceof Exception)
       return (Exception)value;
     return new AvroRuntimeException(value.toString());

Modified: avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
Thu Jun  2 11:52:07 2011
@@ -44,6 +44,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
 
+import org.codehaus.jackson.node.BooleanNode;
+
 public class TestProtocolGeneric {
   private static final Logger LOG
     = LoggerFactory.getLogger(TestProtocolGeneric.class);
@@ -211,6 +213,50 @@ public class TestProtocolGeneric {
     }
   }
 
+  @Test
+  /** Construct and use a different protocol whose "echo" response has an extra
+      field to check that correct schema is used to parse response. */
+  public void testResponseChange() throws IOException {
+
+    List<Field> fields = new ArrayList<Field>();
+    for (Field f : PROTOCOL.getType("TestRecord").getFields())
+      fields.add(new Field(f.name(), f.schema(), null, null));
+    fields.add(new Field("extra", Schema.create(Schema.Type.BOOLEAN),
+                         null, BooleanNode.TRUE));
+    Schema record =
+      Schema.createRecord("TestRecord", null, "org.apache.avro.test", false);
+    record.setFields(fields);
+
+    Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
+    List<Field> params = new ArrayList<Field>();
+    params.add(new Field("record", record, null, null));
+
+    Protocol.Message message =
+      protocol.createMessage("echo", null, Schema.createRecord(params),
+                             record,
+                             Schema.createUnion(new ArrayList<Schema>()));
+    protocol.getMessages().put("echo", message);
+    Transceiver t
+      = new SocketTransceiver(new InetSocketAddress(server.getPort()));
+    try {
+      GenericRequestor r = new GenericRequestor(protocol, t);
+      GenericRecord args = new GenericData.Record(message.getRequest());
+      GenericRecord rec = new GenericData.Record(record);
+      rec.put("name", new Utf8("foo"));
+      rec.put("kind", new GenericData.EnumSymbol
+              (PROTOCOL.getType("Kind"), "BAR"));
+      rec.put("hash", new GenericData.Fixed
+              (PROTOCOL.getType("MD5"),
+               new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}));
+      rec.put("extra", Boolean.TRUE);
+      args.put("record", rec);
+      GenericRecord response = (GenericRecord)r.request("echo", args);
+      assertEquals(rec, response);
+    } finally {
+      t.close();
+    }
+  }
+
   @AfterClass
   public static void testStopServer() throws IOException {
     client.close();

Modified: avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
Thu Jun  2 11:52:07 2011
@@ -48,6 +48,7 @@ public class TestSaslAnonymous extends T
   }
 
   @Override public void testHandshake() throws IOException {}
+  @Override public void testResponseChange() throws IOException {}
 
   public interface ProtoInterface {
     byte[] test(byte[] b);

Modified: avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java?rev=1130505&r1=1130504&r2=1130505&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslDigestMd5.java
Thu Jun  2 11:52:07 2011
@@ -163,5 +163,6 @@ public class TestSaslDigestMd5 extends T
   }
 
   @Override public void testHandshake() throws IOException {}
+  @Override public void testResponseChange() throws IOException {}
 
 }



Mime
View raw message