use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.
the class LoadBalancerClient2Test method test.
@Test
public void test() throws IOException, InterruptedException {
File base = getExampleDir("loadbalancer-client-2");
AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
AssertUtils.replaceInFile(new File(base, "lb-client-secured.proxies.xml"), "8080", "3023");
Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
try {
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:4000/"));
assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:4001/"));
assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:4002/"));
addNodeViaScript(base, "localhost", 4000);
Thread.sleep(1000);
assertNodeStatus(getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"), "localhost", 4000, "UP");
addNodeViaScript(base, "localhost", 4001);
addNodeViaScript(base, "localhost", 4002);
Thread.sleep(100);
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
removeNodeViaScript(base, "localhost", 4000);
Thread.sleep(100);
assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
} finally {
sl.killScript();
}
sl = new Process2.Builder().in(base).script("service-proxy-secured").waitForMembrane().start();
try {
// 1 indicates failure
controlNodeViaScript(1, base, "up", "localhost", 4000);
File propFile = new File(base, "client.properties");
writeStringToFile(propFile, readFileToString(propFile).replace("#", ""));
Thread.sleep(1000);
addNodeViaScript(base, "localhost", 4000);
Thread.sleep(1000);
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "admin");
AssertUtils.assertContains("localhost:4000", getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"));
} finally {
sl.killScript();
}
}
Aggregations