avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1056425 - in /avro/trunk: CHANGES.txt lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
Date Fri, 07 Jan 2011 17:59:48 GMT
Author: cutting
Date: Fri Jan  7 17:59:47 2011
New Revision: 1056425

URL: http://svn.apache.org/viewvc?rev=1056425&view=rev
Log:
AVRO-722. Java: Fix ordering of calls to RPC plugins. Contributed by Stephen Gargan.

Added:
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1056425&r1=1056424&r2=1056425&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Jan  7 17:59:47 2011
@@ -115,6 +115,9 @@ Avro 1.5.0 (unreleased)
 
     AVRO-643. Java: Fix intermittent failures in TestTraceCollection. (cutting)
 
+    AVRO-722. Java: Fix ordering of calls to RPC plugins.
+    (Stephen Gargan via cutting)
+
 Avro 1.4.1 (13 October 2010)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java?rev=1056425&r1=1056424&r2=1056425&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java (original)
+++ avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java Fri Jan  7 17:59:47
2011
@@ -102,14 +102,15 @@ public abstract class Requestor {
       List<ByteBuffer> payload = bbo.getBufferList();
       
       writeHandshake(out);                       // prepend handshake if needed
-      META_WRITER.write(context.requestCallMeta(), out);
-      out.writeString(m.getName());               // write message name
       
       context.setRequestPayload(payload);
       for (RPCPlugin plugin : rpcMetaPlugins) {
         plugin.clientSendRequest(context);        // get meta-data from plugins
       }
-      
+      META_WRITER.write(context.requestCallMeta(), out);
+
+      out.writeString(m.getName());               // write message name
+
       bbo.append(payload);
       
       List<ByteBuffer> requestBytes = bbo.getBufferList();
@@ -134,7 +135,7 @@ public abstract class Requestor {
 
     if (m.isOneWay() && t.isConnected()) return null; // one-way w/ handshake
         
-    context.setRequestCallMeta(META_READER.read(null, in));
+    context.setResponseCallMeta(META_READER.read(null, in));
     
     if (!in.readBoolean()) {                      // no error
       Object response = readResponse(rm.getResponse(), in);

Added: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java?rev=1056425&view=auto
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
(added)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
Fri Jan  7 17:59:47 2011
@@ -0,0 +1,80 @@
+package org.apache.avro.ipc;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.avro.ipc.AvroRemoteException;
+import org.apache.avro.ipc.LocalTransceiver;
+import org.apache.avro.ipc.RPCContext;
+import org.apache.avro.ipc.RPCPlugin;
+import org.apache.avro.specific.SpecificRequestor;
+import org.apache.avro.specific.SpecificResponder;
+import org.apache.avro.test.Mail;
+import org.apache.avro.test.Message;
+import org.apache.avro.util.Utf8;
+import org.junit.Test;
+
+public class TestRpcPluginOrdering {
+
+  private static AtomicInteger orderCounter = new AtomicInteger();
+  
+  public class OrderPlugin extends RPCPlugin{
+
+    public void clientStartConnect(RPCContext context) {
+      assertEquals(0, orderCounter.getAndIncrement());
+    }
+    
+    public void clientSendRequest(RPCContext context) {
+      assertEquals(1, orderCounter.getAndIncrement());
+    }
+    
+    public void clientReceiveResponse(RPCContext context) {
+      assertEquals(6, orderCounter.getAndIncrement());
+    }
+
+    public void clientFinishConnect(RPCContext context) {
+      assertEquals(5, orderCounter.getAndIncrement());
+    }
+
+    public void serverConnecting(RPCContext context) {
+      assertEquals(2, orderCounter.getAndIncrement());
+    }
+
+    public void serverReceiveRequest(RPCContext context) {
+      assertEquals(3, orderCounter.getAndIncrement());
+    }
+
+    public void serverSendResponse(RPCContext context) {
+      assertEquals(4, orderCounter.getAndIncrement());
+    }
+  }
+  
+  @Test
+  public void testRpcPluginOrdering() throws Exception {
+    OrderPlugin plugin = new OrderPlugin();
+    
+    SpecificResponder responder = new SpecificResponder(Mail.class, new TestMailImpl());
+    SpecificRequestor requestor = new SpecificRequestor(Mail.class, new LocalTransceiver(responder));
+    responder.addRPCPlugin(plugin);
+    requestor.addRPCPlugin(plugin);
+    
+    Mail client = SpecificRequestor.getClient(Mail.class, requestor);
+    Message message = createTestMessage();
+    client.send(message);
+  }
+
+  private Message createTestMessage() {
+    Message message = new Message();
+    message.to = new Utf8("me@test.com");
+    message.from = new Utf8("you@test.com");
+    message.body = new Utf8("plugin testing");
+    return message;
+  }
+  
+  private static class TestMailImpl implements Mail{
+    public CharSequence send(Message message) throws AvroRemoteException {
+      return new Utf8("Received");
+    }
+  }
+}



Mime
View raw message