AsyncServicePool implements com.bazaarvoice.ostrich.AsyncServicePool<S> { @Override public <R> Future<R> execute(final RetryPolicy retryPolicy, final ServiceCallback<S, R> callback) { return _executor.submit(new Callable<R>() { @Override public R call() throws Exception { return _pool.execute(retryPolicy, callback); } }); } AsyncServicePool(Ticker ticker, ServicePool<S> pool, boolean shutdownPoolOnClose,
                            ExecutorService executor, boolean shutdownExecutorOnClose, MetricRegistry metrics); @Override void close(); @Override Future<R> execute(final RetryPolicy retryPolicy, final ServiceCallback<S, R> callback); @Override Future<R> execute(final PartitionContext partitionContext, final RetryPolicy retryPolicy,
                                 final ServiceCallback<S, R> callback); @Override Collection<Future<R>> executeOnAll(RetryPolicy retry, ServiceCallback<S, R> callback); @Override Collection<Future<R>> executeOn(ServiceEndPointPredicate predicate, final RetryPolicy retry,
                                               final ServiceCallback<S, R> callback); @Override int getNumValidEndPoints(); @Override int getNumBadEndPoints();  }
@SuppressWarnings("unchecked") @Test public void testSubmitsCallableToExecutor() { AsyncServicePool<Service> pool = newAsyncPool(); pool.execute(NEVER_RETRY, mock(ServiceCallback.class)); verify(_mockExecutor).submit(any(Callable.class)); }
@SuppressWarnings("unchecked") @Test public void testExecutesCallbackInPool() { AsyncServicePool<Service> pool = newAsyncPool(MoreExecutors.newDirectExecutorService()); ServiceCallback<Service, Void> callback = (ServiceCallback<Service, Void>) mock(ServiceCallback.class); pool.execute(NEVER_RETRY, callback); verify(_mockPool).execute(same(NEVER_RETRY), same(callback)); }
@SuppressWarnings("unchecked") @Test public void testExecutesPartitionContextInPool() { AsyncServicePool<Service> pool = newAsyncPool(MoreExecutors.newDirectExecutorService()); ServiceCallback<Service, Void> callback = (ServiceCallback<Service, Void>) mock(ServiceCallback.class); PartitionContext context = mock(PartitionContext.class); pool.execute(context, NEVER_RETRY, callback); verify(_mockPool).execute(same(context), same(NEVER_RETRY), same(callback)); }