THRIFT-945. java: TAsyncClient class's currentMethod is never set, hence a second...
authorBryan Duxbury <bryanduxbury@apache.org>
Wed, 6 Oct 2010 00:28:10 +0000 (00:28 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Wed, 6 Oct 2010 00:28:10 +0000 (00:28 +0000)
This patch adds a test for the problem and fixes the issue by setting the current method after a call has been started.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1004865 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_java_generator.cc
lib/java/src/org/apache/thrift/async/TAsyncClient.java
lib/java/test/org/apache/thrift/async/TestTAsyncClient.java [new file with mode: 0644]

index 073828b..4e32a37 100644 (file)
@@ -2440,7 +2440,6 @@ void t_java_generator::generate_service_async_client(t_service* tservice) {
   string extends_client = "";
   if (tservice->get_extends() != NULL) {
     extends = type_name(tservice->get_extends()) + ".AsyncClient";
-    // extends_client = " extends " + extends + ".AsyncClient";
   }
 
   indent(f_service_) <<
@@ -2481,7 +2480,8 @@ void t_java_generator::generate_service_async_client(t_service* tservice) {
     // Main method body   
     indent(f_service_) << "public " << function_signature_async(*f_iter, false) << " throws TException {" << endl;
     indent(f_service_) << "  checkReady();" << endl;
-    indent(f_service_) << "  " << funclassname << " method_call = new " + funclassname + "(" << async_argument_list(*f_iter, arg_struct, ret_type) << ", this, protocolFactory, transport);" << endl;    
+    indent(f_service_) << "  " << funclassname << " method_call = new " + funclassname + "(" << async_argument_list(*f_iter, arg_struct, ret_type) << ", this, protocolFactory, transport);" << endl;
+    indent(f_service_) << "  this.currentMethod = method_call;" << endl;
     indent(f_service_) << "  manager.call(method_call);" << endl;
     indent(f_service_) << "}" << endl;
 
index 0355f80..5c05aaa 100644 (file)
@@ -25,7 +25,7 @@ public abstract class TAsyncClient {
   protected final TProtocolFactory protocolFactory;
   protected final TNonblockingTransport transport;
   protected final TAsyncClientManager manager;
-  private TAsyncMethodCall currentMethod;
+  protected TAsyncMethodCall currentMethod;
   private Throwable error;
   private long timeout;
 
diff --git a/lib/java/test/org/apache/thrift/async/TestTAsyncClient.java b/lib/java/test/org/apache/thrift/async/TestTAsyncClient.java
new file mode 100644 (file)
index 0000000..d812382
--- /dev/null
@@ -0,0 +1,27 @@
+package org.apache.thrift.async;
+
+import org.apache.thrift.TException;
+
+import junit.framework.TestCase;
+import thrift.test.Srv;
+import thrift.test.Srv.AsyncClient;
+
+public class TestTAsyncClient extends TestCase {
+  public void testRaisesExceptionWhenUsedConcurrently() throws Exception {
+    TAsyncClientManager mockClientManager = new TAsyncClientManager() {
+      @Override
+      public void call(TAsyncMethodCall method) throws TException {
+        // do nothing
+      }
+    };
+
+    Srv.AsyncClient c = new AsyncClient(null, mockClientManager, null);
+    c.Janky(0, null);
+    try {
+      c.checkReady();
+      fail("should have hit an exception");
+    } catch (Exception e) {
+      // awesome
+    }
+  }
+}