String locatorURI = "http://" + host + ":" + port;
InvokerLocator locator = new InvokerLocator(locatorURI);
HashMap serverConfig = new HashMap();
serverConfig.put(ServerInvoker.MAX_NUM_ONEWAY_THREADS_KEY, "2");
serverConfig.put(ServerInvoker.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "1");
Connector connector = new Connector(locator, serverConfig);
connector.create();
TestHandler handler = new TestHandler();
connector.addInvocationHandler("test", handler);
connector.start();
HashMap clientConfig = new HashMap();
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
Client client = new Client(locator, clientConfig);
client.connect();
Object response = client.invoke(FAST);
assertEquals(FAST, response);
long start = System.currentTimeMillis();
// This invocation should run in pooled thread 1.
log.info("making 1st oneway invocation");
client.invokeOneway(SLOW + "1", null, false);
poolCounter++;
// Wait for connection to return to pool.
Thread.sleep(500);
// This invocation should run in pooled thread 2.
log.info("making 2nd oneway invocation");
client.invokeOneway(SLOW + "2", null, false);
// Wait for connection to return to pool.
Thread.sleep(500);
// This invocation should use the pooled connection and go into the queue.
log.info("making 3rd oneway invocation");
client.invokeOneway(SLOW + "3", null, false);
assertTrue((System.currentTimeMillis() - start < 2000));
Thread.sleep(2000);
log.info("handler.count: " + handler.startedCount);
assertEquals(3, handler.startedCount);
// This invocation should run in the ServerThread, and will not return
// until after a response is received.
log.info("making 4th oneway invocation");
client.invokeOneway(SLOW + "4", null, false);
log.info("made 4th oneway invocation");
log.info("wait: " + (System.currentTimeMillis() - start));
assertTrue((System.currentTimeMillis() - start >= 8000));
// By the time the 4th oneway invocation returns, the 3rd oneway invocation
// should have started.
assertEquals(5, handler.startedCount);
assertEquals(4, handler.finishedCount);
Thread.sleep(3000);
assertEquals(5, handler.finishedCount);
client.disconnect();
connector.stop();
log.info(getName() + " PASSES");
}