Search in sources :

Example 6 with AsyncMethodCallback

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);
}
Also used : TearDown(com.google.common.testing.TearDown) AsyncMethodCallback(org.apache.thrift.async.AsyncMethodCallback) Amount(com.twitter.common.quantity.Amount) Method(java.lang.reflect.Method) CountDownLatch(java.util.concurrent.CountDownLatch) TTimeoutException(com.twitter.common.thrift.TTimeoutException) Nullable(javax.annotation.Nullable)

Aggregations

AsyncMethodCallback (org.apache.thrift.async.AsyncMethodCallback)6 Test (org.junit.Test)4 TTransportException (org.apache.thrift.transport.TTransportException)3 Capture (org.easymock.Capture)3 TearDown (com.google.common.testing.TearDown)2 Method (java.lang.reflect.Method)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Amount (com.twitter.common.quantity.Amount)1 StatsProvider (com.twitter.common.stats.StatsProvider)1 TTimeoutException (com.twitter.common.thrift.TTimeoutException)1 AsyncIface (com.twitter.common.thrift.ThriftFactoryTest.GoodService.AsyncIface)1 Caller (com.twitter.common.thrift.callers.Caller)1 DeadlineCaller (com.twitter.common.thrift.callers.DeadlineCaller)1 DebugCaller (com.twitter.common.thrift.callers.DebugCaller)1 RetryingCaller (com.twitter.common.thrift.callers.RetryingCaller)1 StatTrackingCaller (com.twitter.common.thrift.callers.StatTrackingCaller)1 ThriftCaller (com.twitter.common.thrift.callers.ThriftCaller)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 InetSocketAddress (java.net.InetSocketAddress)1