Search in sources :

Example 11 with Cluster

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();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Exchange (com.predic8.membrane.core.exchange.Exchange)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Process2 (com.predic8.membrane.examples.Process2)3 File (java.io.File)3 Cluster (com.predic8.membrane.core.interceptor.balancer.Cluster)2 StringWriter (java.io.StringWriter)2 Balancer (com.predic8.membrane.core.interceptor.balancer.Balancer)1 URLParamUtil.createQueryString (com.predic8.membrane.core.util.URLParamUtil.createQueryString)1 URISyntaxException (java.net.URISyntaxException)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1