THRIFT-945. java: TAsyncClient class's currentMethod is never set, hence a second call on the same client will fail if a previous call is ongoing.
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
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index 073828b..4e32a37 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -2440,7 +2440,6 @@
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 @@
// 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;
diff --git a/lib/java/src/org/apache/thrift/async/TAsyncClient.java b/lib/java/src/org/apache/thrift/async/TAsyncClient.java
index 0355f80..5c05aaa 100644
--- a/lib/java/src/org/apache/thrift/async/TAsyncClient.java
+++ b/lib/java/src/org/apache/thrift/async/TAsyncClient.java
@@ -25,7 +25,7 @@
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
index 0000000..d812382
--- /dev/null
+++ b/lib/java/test/org/apache/thrift/async/TestTAsyncClient.java
@@ -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
+ }
+ }
+}