Add testAsync to ThriftTest.thrift which verifies async void works properly.
Summary:
- testAsync takes a number of seconds to sleep. The test client makes sure
that the RPC returns in less than 0.2 seconds even though it asks the server
to sleep for 3 seconds.
- Implemented this test for C++ and Java.
Test Plan:
- ran cpp TestServer and TestClient and verified functionality
- tested cpp and java test server/client against each other - tests passed
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665484 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index 9056465..a549fa7 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -90,6 +90,9 @@
/* Multiple exceptions specifier */
Xtruct testMultiException(string arg0, string arg1) throws(Xception err1, Xception2 err2)
+
+ /* Test async void */
+ async void testAsync(1:i32 secondsToSleep)
}
service SecondService
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index 9b350b0..2b8cced 100644
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -430,6 +430,19 @@
printf(" exception\nFAILURE\n");
}
+ /* test async void */
+ {
+ printf("testClient.testAsync(3) =>");
+ uint64_t startAsync = now();
+ testClient.testAsync(3);
+ uint64_t elapsed = now() - startAsync;
+ if (elapsed > 200 * 1000) { // 0.2 seconds
+ printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0);
+ } else {
+ printf(" success - took %.2f ms\n", (double)elapsed/1000.0);
+ }
+ }
+
uint64_t stop = now();
uint64_t tot = stop-start;
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 773225e..14a8a8e 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -255,6 +255,12 @@
return;
}
}
+
+ void testAsync(int sleepFor) {
+ printf("testAsync(%d): Sleeping...\n", sleepFor);
+ sleep(sleepFor);
+ printf("testAsync(%d): done sleeping!\n", sleepFor);
+ }
};
int main(int argc, char **argv) {
diff --git a/test/java/src/TestClient.java b/test/java/src/TestClient.java
index 85aac9e..4e0482a 100644
--- a/test/java/src/TestClient.java
+++ b/test/java/src/TestClient.java
@@ -357,6 +357,22 @@
}
System.out.print("}\n");
+ // Test async
+ System.out.print("testAsync(3)...");
+ long startAsync = System.nanoTime();
+ testClient.testAsync(3);
+ long asyncElapsedMillis = (System.nanoTime() - startAsync) / 1000000;
+ if (asyncElapsedMillis > 200) {
+ throw new Exception("Async test failed: took " +
+ Long.toString(asyncElapsedMillis) +
+ "ms");
+ } else {
+ System.out.println("Success - took " +
+ Long.toString(asyncElapsedMillis) +
+ "ms");
+ }
+
+
long stop = System.nanoTime();
long tot = stop-start;
diff --git a/test/java/src/TestServer.java b/test/java/src/TestServer.java
index 21003b1..92fd4d2 100644
--- a/test/java/src/TestServer.java
+++ b/test/java/src/TestServer.java
@@ -234,6 +234,17 @@
return result;
}
+ public void testAsync(int sleepFor) {
+ System.out.println("testAsync(" + Integer.toString(sleepFor) +
+ ") => sleeping...");
+ try {
+ Thread.sleep(sleepFor * 1000);
+ System.out.println("Done sleeping!");
+ } catch (InterruptedException ie) {
+ throw new RuntimeException(ie);
+ }
+ }
+
} // class TestHandler
public static void main(String [] args) {