use of org.apache.cxf.workqueue.AutomaticWorkQueueImpl in project cxf by apache.
the class AsyncHTTPConduitTest method testCallAsyncWithFullWorkQueue.
@Test
public void testCallAsyncWithFullWorkQueue() throws Exception {
Bus bus = BusFactory.getThreadDefaultBus();
WorkQueueManager workQueueManager = bus.getExtension(WorkQueueManager.class);
AutomaticWorkQueueImpl automaticWorkQueue1 = (AutomaticWorkQueueImpl) workQueueManager.getAutomaticWorkQueue();
updateAddressPort(g, PORT);
Client client = ClientProxy.getClient(g);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
int asyncExecuteTimeout = 500;
httpClientPolicy.setAsyncExecuteTimeout(asyncExecuteTimeout);
http.setClient(httpClientPolicy);
long repeat = automaticWorkQueue1.getHighWaterMark() + automaticWorkQueue1.getMaxSize() + 1;
CountDownLatch initialThreadsLatch = new CountDownLatch(automaticWorkQueue1.getHighWaterMark());
CountDownLatch doneLatch = new CountDownLatch((int) repeat);
AtomicInteger threadCount = new AtomicInteger();
for (long i = 0; i < repeat; i++) {
g.greetMeLaterAsync(-50, res -> {
try {
int myCount = threadCount.getAndIncrement();
if (myCount < automaticWorkQueue1.getHighWaterMark()) {
// Sleep long enough so that the workqueue will fill up and then
// handleResponseOnWorkqueue will fail for the calls from both
// responseReceived and consumeContent
Thread.sleep(3L * asyncExecuteTimeout);
initialThreadsLatch.countDown();
} else {
Thread.sleep(50);
}
initialThreadsLatch.await();
doneLatch.countDown();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
doneLatch.await(30, TimeUnit.SECONDS);
assertEquals("All responses should be handled eventually", 0, doneLatch.getCount());
}
use of org.apache.cxf.workqueue.AutomaticWorkQueueImpl in project jbossws-cxf by jbossws.
the class BusHolder method createWorkQueue.
private static AutomaticWorkQueue createWorkQueue(String name, Map<String, String> props) {
int mqs = parseInt(props.get(Constants.CXF_QUEUE_MAX_QUEUE_SIZE_PROP), 256);
int initialThreads = parseInt(props.get(Constants.CXF_QUEUE_INITIAL_THREADS_PROP), 0);
int highWaterMark = parseInt(props.get(Constants.CXF_QUEUE_HIGH_WATER_MARK_PROP), 25);
int lowWaterMark = parseInt(props.get(Constants.CXF_QUEUE_LOW_WATER_MARK_PROP), 5);
long dequeueTimeout = parseLong(props.get(Constants.CXF_QUEUE_DEQUEUE_TIMEOUT_PROP), 2 * 60 * 1000L);
return new AutomaticWorkQueueImpl(mqs, initialThreads, highWaterMark, lowWaterMark, dequeueTimeout, name);
}
Aggregations