Search in sources :

Example 6 with RoundRobinStrategy

use of com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy in project service-proxy by membrane.

the class LoadBalancingInterceptorTest method testRoundRobinDispachingStrategy.

@Test
public void testRoundRobinDispachingStrategy() throws Exception {
    balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
    HttpClient client = new HttpClient();
    client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    PostMethod vari = getPostMethod();
    int status = client.executeMethod(vari);
    // System.out.println(new String(vari.getResponseBody()));
    assertEquals(200, status);
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(0, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(1, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(2, mockInterceptor1.getCount());
    assertEquals(1, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(2, mockInterceptor1.getCount());
    assertEquals(2, mockInterceptor2.getCount());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test) Http11Test(com.predic8.membrane.integration.Http11Test)

Aggregations

Http11Test (com.predic8.membrane.integration.Http11Test)4 HttpClient (org.apache.commons.httpclient.HttpClient)4 Test (org.junit.Test)4 HttpRouter (com.predic8.membrane.core.HttpRouter)2 Exchange (com.predic8.membrane.core.exchange.Exchange)2 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)2 Outcome (com.predic8.membrane.core.interceptor.Outcome)2 RoundRobinStrategy (com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 Before (org.junit.Before)2 ByThreadStrategy (com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy)1 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)1 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)1