final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50,
TimeUnit.MILLISECONDS)
.setMaxPoolSize(20);
ClientRequestExecutorPool clientRequestExecutorPool = new ClientRequestExecutorPool(config.getMaxPoolSize(),
(int) config.getTimeout(TimeUnit.MILLISECONDS),
100,
1000);
try {
ResourceFactory<SocketDestination, ClientRequestExecutor> factory = clientRequestExecutorPool.getFactory();
final AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor> test = new AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor>() {
@Override
protected void doSomethingWithResource(SocketDestination key,
ClientRequestExecutor resource)
throws Exception {
Thread.sleep(100);
int random = (int) (Math.random() * 10);
if(random >= 5)
resource.close();
}
@Override
protected SocketDestination getRequestKey() throws Exception {
return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
}
};
// borrow timeout >> doSomething() no timeout expected
TestStats testStats = test.startTest(factory, config, 50, 200);
assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
server.stop();
} finally {
clientRequestExecutorPool.close();
}
}