use of com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method testFailOverOnConnectionRefused.
@Test
public void testFailOverOnConnectionRefused() throws Exception {
balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(0, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(1, mockInterceptor2.getCount());
service1.shutdown();
Thread.sleep(1000);
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(2, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(3, mockInterceptor2.getCount());
}
use of com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method testFailOverOnStatus500.
@Test
public void testFailOverOnStatus500() throws Exception {
balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(0, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(1, mockInterceptor2.getCount());
((ServiceProxy) service1.getRuleManager().getRules().get(0)).getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.setResponse(Response.internalServerError().build());
return Outcome.ABORT;
}
});
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(2, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(3, mockInterceptor2.getCount());
}
use of com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
service1 = new HttpRouter();
mockInterceptor1 = new DummyWebServiceInterceptor();
ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "thomas-bayer.com", 80);
sp1.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp1.getInterceptors().add(mockInterceptor1);
service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
service1.init();
service2 = new HttpRouter();
mockInterceptor2 = new DummyWebServiceInterceptor();
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp2.getInterceptors().add(mockInterceptor2);
service2.getRuleManager().addProxyAndOpenPortIfNew(sp2);
service2.init();
balancer = new HttpRouter();
ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 7000), "thomas-bayer.com", 80);
balancingInterceptor = new LoadBalancingInterceptor();
balancingInterceptor.setName("Default");
sp3.getInterceptors().add(balancingInterceptor);
balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3);
enableFailOverOn5XX(balancer);
balancer.init();
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 2000);
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 3000);
roundRobinStrategy = new RoundRobinStrategy();
byThreadStrategy = new ByThreadStrategy();
}
use of com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method testExpect100Continue.
@Test
public void testExpect100Continue() throws Exception {
balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
HttpClient client = new HttpClient();
Http11Test.initExpect100ContinueWithFastFail(client);
PostMethod vari = getPostMethod();
int status = client.executeMethod(vari);
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());
}
use of com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy in project service-proxy by membrane.
the class MultipleLoadBalancersTest method setUp.
@Before
public void setUp() throws Exception {
service1 = new MockService(2001);
service2 = new MockService(2002);
service11 = new MockService(2011);
service12 = new MockService(2012);
balancer = new HttpRouter();
balancingInterceptor1 = createBalancingInterceptor(7000, "Default");
balancingInterceptor2 = createBalancingInterceptor(7001, "Balancer2");
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service1.port);
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service2.port);
BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service11.port);
BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service12.port);
roundRobinStrategy1 = new RoundRobinStrategy();
roundRobinStrategy2 = new RoundRobinStrategy();
}
Aggregations