Search in sources :

Example 11 with LoadBalancingInterceptor

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

the class NodeOnlineCheckerTest method testPutNodesBackOnline.

@Test
public void testPutNodesBackOnline() throws InterruptedException {
    Node node = new Node("http://www.predic8.de", 80);
    Exchange exc = new Exchange(null);
    exc.getDestinations().add(0, "http://www.predic8.de:80");
    exc.setNodeStatusCode(0, 500);
    LoadBalancingInterceptor lbi = new LoadBalancingInterceptor();
    Cluster cl = lbi.getClusterManager().getClusters().get(0);
    cl.nodeUp(node);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    NodeOnlineChecker noc = new NodeOnlineChecker();
    lbi.setNodeOnlineChecker(noc);
    final int limit = 10;
    noc.setNodeCounterLimit5XX(limit);
    noc.setRetryTimeInSeconds(1);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    for (int i = 0; i < limit + 1; i++) {
        noc.handle(exc);
    }
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
    noc.putNodesBackUp();
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
    Thread.sleep(noc.getRetryTimeInSeconds() * 1000);
    noc.putNodesBackUp();
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 12 with LoadBalancingInterceptor

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

the class NodeOnlineCheckerTest method testExchangeWithBadStatuscode.

@Test
public void testExchangeWithBadStatuscode() {
    Node node = new Node("http://www.predic8.de", 80);
    Exchange exc = new Exchange(null);
    exc.getDestinations().add(0, "http://www.predic8.de:80");
    exc.setNodeStatusCode(0, 500);
    LoadBalancingInterceptor lbi = new LoadBalancingInterceptor();
    Cluster cl = lbi.getClusterManager().getClusters().get(0);
    cl.nodeUp(node);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    NodeOnlineChecker noc = new NodeOnlineChecker();
    lbi.setNodeOnlineChecker(noc);
    final int limit = 10;
    noc.setNodeCounterLimit5XX(limit);
    for (int i = 0; i < limit; i++) {
        noc.handle(exc);
    }
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    exc.setNodeStatusCode(0, 400);
    noc.handle(exc);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    exc.setNodeStatusCode(0, 500);
    for (int i = 0; i < limit + 1; i++) {
        noc.handle(exc);
    }
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 13 with LoadBalancingInterceptor

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

the class LoadBalancingWithClusterManagerTest method startLB.

private void startLB() throws Exception {
    LoadBalancingInterceptor lbi = new LoadBalancingInterceptor();
    lbi.setName("Default");
    XMLElementSessionIdExtractor extractor = new XMLElementSessionIdExtractor();
    extractor.setLocalName("session");
    extractor.setNamespace("http://predic8.com/session/");
    lbi.setSessionIdExtractor(extractor);
    ServiceProxy lbiRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3017), "thomas-bayer.com", 80);
    lbiRule.getInterceptors().add(lbi);
    ClusterNotificationInterceptor cni = new ClusterNotificationInterceptor();
    ServiceProxy cniRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3012), "thomas-bayer.com", 80);
    cniRule.getInterceptors().add(cni);
    lb = new HttpRouter();
    lb.getRuleManager().addProxyAndOpenPortIfNew(lbiRule);
    lb.getRuleManager().addProxyAndOpenPortIfNew(cniRule);
    lb.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) HttpRouter(com.predic8.membrane.core.HttpRouter)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)8 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)7 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)6 Exchange (com.predic8.membrane.core.exchange.Exchange)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Test (org.junit.Test)3 URISyntaxException (java.net.URISyntaxException)2 Before (org.junit.Before)2 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)1 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)1 Outcome (com.predic8.membrane.core.interceptor.Outcome)1 AccessControlInterceptor (com.predic8.membrane.core.interceptor.acl.AccessControlInterceptor)1 ByThreadStrategy (com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy)1 Node (com.predic8.membrane.core.interceptor.balancer.Node)1 RoundRobinStrategy (com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy)1 Rule (com.predic8.membrane.core.rules.Rule)1 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 BeansException (org.springframework.beans.BeansException)1