use of com.predic8.membrane.core.services.DummyWebServiceInterceptor 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.services.DummyWebServiceInterceptor in project service-proxy by membrane.
the class LoadBalancingWithClusterManagerTest method startNode.
private DummyWebServiceInterceptor startNode(HttpRouter node, int port) throws Exception {
DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor();
node.addUserFeatureInterceptor(service1);
node.getRuleManager().addProxyAndOpenPortIfNew(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80));
node.init();
return service1;
}
use of com.predic8.membrane.core.services.DummyWebServiceInterceptor in project service-proxy by membrane.
the class LoadBalancingWithClusterManagerTest method nodesTest.
@Test
public void nodesTest() throws Exception {
node1 = new HttpRouter();
node2 = new HttpRouter();
node3 = new HttpRouter();
DummyWebServiceInterceptor service1 = startNode(node1, 2000);
DummyWebServiceInterceptor service2 = startNode(node2, 3000);
DummyWebServiceInterceptor service3 = startNode(node3, 4000);
startLB();
sendNotification("up", 2000);
sendNotification("up", 3000);
// goes to service one
assertEquals(200, post("/getBankwithSession555555.xml"));
assertEquals(1, service1.getCount());
assertEquals(0, service2.getCount());
// goes to service 1 again
assertEquals(200, post("/getBankwithSession555555.xml"));
assertEquals(2, service1.getCount());
assertEquals(0, service2.getCount());
// goes to service 2
assertEquals(200, post("/getBankwithSession444444.xml"));
assertEquals(2, service1.getCount());
assertEquals(1, service2.getCount());
sendNotification("down", 2000);
// goes to service 2 because service 1 is down
assertEquals(200, post("/getBankwithSession555555.xml"));
assertEquals(2, service1.getCount());
assertEquals(2, service2.getCount());
sendNotification("up", 4000);
assertEquals(0, service3.getCount());
// goes to service 3
assertEquals(200, post("/getBankwithSession666666.xml"));
assertEquals(2, service1.getCount());
assertEquals(2, service2.getCount());
assertEquals(1, service3.getCount());
// goes to service 2
assertEquals(200, post("/getBankwithSession555555.xml"));
// goes to service 2
assertEquals(200, post("/getBankwithSession444444.xml"));
// goes to service 3
assertEquals(200, post("/getBankwithSession666666.xml"));
assertEquals(2, service1.getCount());
assertEquals(4, service2.getCount());
assertEquals(2, service3.getCount());
}
Aggregations