private FakeCallback callAsyncRpc(Request request, ErrorReason reason,
boolean hasListener) {
SocketRpcController controller = new SocketRpcController();
DelayedExecutor executor = new DelayedExecutor();
TestService service = TestService.newStub(
new RpcChannelImpl(connectionFactory, executor));
FakeCallback callback = new FakeCallback();
service.testMethod(controller, request, callback);
assertEquals(hasListener, executor.listener != null);
if (hasListener) {
// Callback should not be called yet since it is async
assertFalse(callback.invoked);