Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test of Future.join() with timeout.

  • Loading branch information...
commit ef2bbfe38445b0a18b37c25d61827dec4c5af5c8 1 parent 70a5d11
@rboulton rboulton authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 java/src/test/java/org/msgpack/rpc/FutureTest.java
View
13 java/src/test/java/org/msgpack/rpc/FutureTest.java
@@ -24,6 +24,7 @@
import org.msgpack.rpc.loop.*;
import org.msgpack.rpc.loop.netty.*;
import java.util.*;
+import java.util.concurrent.TimeUnit;
import junit.framework.*;
import org.junit.Test;
@@ -33,11 +34,16 @@ public TestHandler() { }
public String m1(String a1) {
return "ok"+a1;
}
+ public String m2(Integer time_millis) throws InterruptedException {
+ Thread.sleep(time_millis);
+ return "ok" + time_millis;
+ }
}
public interface TestInterface {
public Future<String> m1(String a1);
public Future<String> m1Async(String a1); // /Async$/ will be removed
+ public Future<String> m2(Integer time_millis);
}
@Test
@@ -55,14 +61,21 @@ public void testFuture() throws Exception {
Future<String> f1 = c.m1("a1");
Future<String> f2 = c.m1("a2");
Future<String> f3 = c.m1Async("a3");
+ Future<String> f4 = c.m2(5);
+ Future<String> f5 = c.m2(60000);
f3.join();
f1.join();
f2.join();
+ f4.join(500, TimeUnit.MILLISECONDS);
+ f5.join(500, TimeUnit.MILLISECONDS);
assertEquals(f1.get(), "ok"+"a1");
assertEquals(f2.get(), "ok"+"a2");
assertEquals(f3.get(), "ok"+"a3");
+ assertEquals(f4.get(), "ok"+"5");
+ assertTrue(f4.getError().isNilValue());
+ assertEquals(f5.getError().asRawValue().getString(), "timedout");
} finally {
svr.close();
Please sign in to comment.
Something went wrong with that request. Please try again.