Search in sources :

Example 1 with AMStatisticsCollector

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();
}
Also used : ArrayList(java.util.ArrayList) Request(com.predic8.membrane.core.http.Request) AMStatisticsCollector(com.predic8.membrane.core.interceptor.apimanagement.statistics.AMStatisticsCollector) Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Test(org.junit.Test)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)1 Request (com.predic8.membrane.core.http.Request)1 Response (com.predic8.membrane.core.http.Response)1 AMStatisticsCollector (com.predic8.membrane.core.interceptor.apimanagement.statistics.AMStatisticsCollector)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1