### Question:
CallbackManagerWithTimeout implements CallbackManager { public int outstandingCallbacksCount() { return handlers.size(); } CallbackManagerWithTimeout(final Timer timer, final String name,
                                      boolean handleTimeouts,
                                      long timeOutMS, long checkInterval); @Override void registerCallbacks(final MethodCall<Object> methodCall); @Override void startReturnHandlerProcessor(final Queue<Response<Object>> responseQueue); @Override void handleResponse(final Response<Object> response); @Override void process(long currentTime); int outstandingCallbacksCount();  }### Answer:
@Test public void testWithServiceBundle() throws Exception { final ServiceBundleBuilder serviceBundleBuilder = ServiceBundleBuilder.serviceBundleBuilder(); serviceBundleBuilder.setCallbackManager(callbackManager); final ServiceBundle serviceBundle = serviceBundleBuilder.build(); serviceBundle.addServiceObject("abc", new MyService()); final IMyService myService = serviceBundle.createLocalProxy(IMyService.class, "abc"); serviceBundle.start(); final CountDownLatch countDownLatch = new CountDownLatch(1); callbackBuilder.setCallback(Object.class, o -> { result.set(o); countDownLatch.countDown(); }); myService.method1(callbackBuilder.build()); ServiceProxyUtils.flushServiceProxy(myService); Sys.sleep(500); assertEquals(1, callbackManagerWithTimeout.outstandingCallbacksCount()); continueMethod.countDown(); countDownLatch.await(20, TimeUnit.SECONDS); assertEquals(0, callbackManagerWithTimeout.outstandingCallbacksCount()); assertEquals("METHOD 1 RETURN", result.get()); }
@Test public void testWithServiceBundleManyMethods() throws Exception { final ServiceBundleBuilder serviceBundleBuilder = ServiceBundleBuilder.serviceBundleBuilder(); serviceBundleBuilder.getRequestQueueBuilder().setBatchSize(1000).setSize(1000); serviceBundleBuilder.setCallbackManager(callbackManager); final ServiceBundle serviceBundle = serviceBundleBuilder.build(); serviceBundle.addServiceObject("abc", new MyService()); final IMyService myService = serviceBundle.createLocalProxy(IMyService.class, "abc"); serviceBundle.start(); final int callCount = 1_000_000; final CountDownLatch countDownLatch = new CountDownLatch(callCount); callbackBuilder.setCallback(Object.class, o -> { result.set(o); countDownLatch.countDown(); }); for (int index = 0; index < callCount; index++) { myService.method1(callbackBuilder.build()); } ServiceProxyUtils.flushServiceProxy(myService); Sys.sleep(500); assertTrue(callbackManagerWithTimeout.outstandingCallbacksCount() > 1); continueMethod.countDown(); countDownLatch.await(200, TimeUnit.SECONDS); assertEquals(0, callbackManagerWithTimeout.outstandingCallbacksCount()); assertEquals("METHOD 1 RETURN", result.get()); }