use of org.apache.thrift.async.AsyncMethodCallback in project commons by twitter.
the class DeadlineCallerTest method makeDeadline.
private DeadlineCaller makeDeadline(final boolean shouldTimeOut) {
final CountDownLatch cancelled = new CountDownLatch(1);
if (shouldTimeOut) {
addTearDown(new TearDown() {
@Override
public void tearDown() throws Exception {
// This will block forever if cancellation does not occur and interrupt the ~indefinite
// sleep.
cancelled.await();
}
});
}
Caller sleepyCaller = new CallerDecorator(caller, false) {
@Override
public Object call(Method method, Object[] args, @Nullable AsyncMethodCallback callback, @Nullable Amount<Long, Time> connectTimeoutOverride) throws Throwable {
if (shouldTimeOut) {
try {
Thread.sleep(Long.MAX_VALUE);
fail("Expected late work to be cancelled and interrupted");
} catch (InterruptedException e) {
cancelled.countDown();
}
}
return caller.call(method, args, callback, connectTimeoutOverride);
}
};
return new DeadlineCaller(sleepyCaller, false, executorService, DEADLINE);
}
Aggregations