use of com.predic8.membrane.core.interceptor.apimanagement.statistics.AMStatisticsCollector in project service-proxy by membrane.
the class AMStatisticsCollectorTest method testThreadedStatisticCollection.
@Test
public void testThreadedStatisticCollection() throws InterruptedException {
final AMStatisticsCollector amSc = new AMStatisticsCollector();
amSc.setCollectTimeInSeconds(2);
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < 1000; i++) {
final int j = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Exchange exc = new Exchange(null);
exc.setRequest(new Request.Builder().header("Test", "Test").body("Hello").build());
exc.setResponse(new Response.ResponseBuilder().header("Test", "Test").body("Hello back").build());
exc.setProperty(Exchange.API_KEY, "junit-" + j);
exc.setRule(new ServiceProxy());
exc.getRule().setName("junit API");
for (int k = 0; k < 10; k++) {
amSc.addExchangeToQueue(exc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
threads.add(t);
t.start();
}
for (Thread t : threads) {
t.join();
}
Thread.sleep(amSc.getCollectTimeInSeconds() * 1000 * 2);
amSc.shutdown();
}
Aggregations