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());
}
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());
}
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();
}
Aggregations