From: Bryan Duxbury Date: Wed, 6 Oct 2010 00:28:10 +0000 (+0000) Subject: THRIFT-945. java: TAsyncClient class's currentMethod is never set, hence a second... X-Git-Tag: 0.6.0~136 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=1df96ce22fcfa3cbc2700eb4be29e5d457167d15;p=common%2Fthrift.git 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 073828b1..4e32a379 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -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; diff --git a/lib/java/src/org/apache/thrift/async/TAsyncClient.java b/lib/java/src/org/apache/thrift/async/TAsyncClient.java index 0355f802..5c05aaa7 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 @@ 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 index 00000000..d8123820 --- /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 + } + } +}