Skip to content

Commit

Permalink
Add test of Future.join() with timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
rboulton committed Apr 5, 2012
1 parent 70a5d11 commit ef2bbfe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions java/src/test/java/org/msgpack/rpc/FutureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit ef2bbfe

Please sign in to comment.