assert agent1.isStarted() : "agent1 should have been started";
assert agent2.isStarted() : "agent2 should have been started";
RemotePojoInvocationFuture future = new RemotePojoInvocationFuture();
ClientRemotePojoFactory factory = agent1.getClientCommandSender().getClientRemotePojoFactory();
factory.setAsynch(false, future); // false should still honor annotations - we'll make sure that's true in this test
ITestAnnotatedPojo pojo = factory.getRemotePojo(ITestAnnotatedPojo.class);
pojo.volatileMethod("first test");
assert "first test".equals(future.get());
assert future.isDone();
long stopwatch = System.currentTimeMillis();
assert "first test".equals(future.get(10, TimeUnit.SECONDS)); // make sure its still there
long test_duration = System.currentTimeMillis() - stopwatch;
assert test_duration < 750L : "get should have returned immediately: " + test_duration;
assert future.isDone();
future.reset();
assert !future.isDone();
stopwatch = System.currentTimeMillis();
try {
future.get(2, TimeUnit.SECONDS);
assert false : "The get should have timed out";
} catch (TimeoutException toe) {
}
test_duration = System.currentTimeMillis() - stopwatch;
assert (test_duration > 1900L) && (test_duration < 2500L) : "Should have timed out after 2 seconds: "
+ test_duration;
// we want to call throwThrowable asynchronously but it isn't annotated that way, so force async
// calling this isn't enough - all existing proxies remain as-is - this call only affects newly created remote pojo proxies
factory.setAsynch(true, future);
factory.setIgnoreAnnotations(true);
// test throwing an Error
Error err = new Error("bogus error for testing");
// side-test - show that the proxy isn't forcing all methods to be async.
try {
pojo.throwThrowable(err);
assert false : "Should have called this synchronously which should have thrown Error";
} catch (Error error) {
// to be expected, the remote pojo proxy is still configured to call throwThrowable synchronously
}
// now let's get a new remote pojo proxy that is forced to call everything asynchronously
pojo = factory.getRemotePojo(ITestAnnotatedPojo.class);
pojo.throwThrowable(err);
try {
future.get();
assert false : "Should have thrown an exception";