private void callback(RpcClient client, RpcServer server, int timeout) {
        RequestBody b1 = new RequestBody(1, RequestBody.DEFAULT_CALLBACK_STR);
        final List<String> rets = new ArrayList<String>(1);
        final CountDownLatch latch = new CountDownLatch(1);
        try {
            if (null == server) {
                client.invokeWithCallback(addr, b1, new InvokeCallback() {
                    Executor executor = Executors.newCachedThreadPool();

                    @Override
                    public void onResponse(Object result) {
                        logger.warn("Result received in callback: " + result);
                        rets.add((String) result);
                        latch.countDown();
                    }

                    @Override
                    public void onException(Throwable e) {
                        logger.error("Process exception in callback.", e);
                        rets.add(e.getClass().getName());
                        latch.countDown();
                    }

                    @Override
                    public Executor getExecutor() {
                        return executor;
                    }

                }, timeout);
            } else {
                Connection conn = client.getConnection(addr, timeout);
                Assert.assertNotNull(serverConnectProcessor.getConnection());
                Connection serverConn = serverConnectProcessor.getConnection();
                server.invokeWithCallback(serverConn, b1, new InvokeCallback() {
                    Executor executor = Executors.newCachedThreadPool();

                    @Override
                    public void onResponse(Object result) {
                        logger.warn("Result received in callback: " + result);
                        rets.add((String) result);
                        latch.countDown();
                    }

                    @Override
                    public void onException(Throwable e) {
                        logger.error("Process exception in callback.", e);
                        rets.add(e.getClass().getName());
                        latch.countDown();
                    }

                    @Override
                    public Executor getExecutor() {
                        return executor;
                    }

                }, timeout);
            }

        } catch (RemotingException e) {
            logger.error("Other RemotingException but RpcServerTimeoutException occurred in sync",
                e);
            Assert.fail("Should not reach here!");
        } catch (InterruptedException e) {
            logger.error("InterruptedException but RpcServerTimeoutException occurred in sync", e);
            Assert.fail("Should not reach here!");
        }

        try {
            latch.await();
        } catch (InterruptedException e) {
            String errMsg = "InterruptedException caught in callback!";
            logger.error(errMsg, e);
            Assert.fail(errMsg);
        }
        Assert.assertEquals(InvokeTimeoutException.class.getName(), rets.get(0));
        rets.clear();
    }
the second request will timeout in work queue
src/test/java/com/alipay/remoting/rpc/timeout/ServerTimeoutSwitchTest.java