Search in sources :

Example 1 with DummyWebServiceInterceptor

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();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ByThreadStrategy(com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) RoundRobinStrategy(com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor) Before(org.junit.Before)

Example 2 with DummyWebServiceInterceptor

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;
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor)

Example 3 with DummyWebServiceInterceptor

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());
}
Also used : HttpRouter(com.predic8.membrane.core.HttpRouter) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor) Test(org.junit.Test)

Aggregations

DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)3 HttpRouter (com.predic8.membrane.core.HttpRouter)2 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)2 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)2 Exchange (com.predic8.membrane.core.exchange.Exchange)1 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)1 Outcome (com.predic8.membrane.core.interceptor.Outcome)1 ByThreadStrategy (com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy)1 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)1 RoundRobinStrategy (com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 Before (org.junit.Before)1 Test (org.junit.Test)1