Search in sources :

Example 26 with Process2

use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.

the class LoadBalancerBasic1Test method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-basic-1");
    AssertUtils.replaceInFile(new File(base, "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/"));
        addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000);
        addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001);
        Thread.sleep(1000);
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        getAndAssert(204, "http://localhost:9010/clustermanager/up?host=localhost&port=4002");
        AssertUtils.assertContains("localhost:4002", getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 27 with Process2

use of com.predic8.membrane.examples.Process2 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)

Example 28 with Process2

use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.

the class LoadBalancerClient2Test method controlNodeViaScript.

private void controlNodeViaScript(int expectedReturnCode, File base, String command, String nodeHost, int nodePort) throws IOException, InterruptedException {
    String line;
    if (Process2.isWindows())
        line = "cmd /c lbclient.bat " + command + " " + nodeHost + " " + nodePort;
    else
        line = "bash lbclient.sh " + command + " " + nodeHost + " " + nodePort;
    Process2 lbclient = new Process2.Builder().in(base).executable(line).start();
    try {
        Assert.assertEquals(expectedReturnCode, lbclient.waitFor(30000));
    } finally {
        lbclient.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString)

Example 29 with Process2

use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.

the class LoadBalancerStaticTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-static");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        for (int i = 0; i < 7; i++) Assert.assertEquals(i % 3 + 1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 30 with Process2

use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.

the class LoggingCSVTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("logging-csv");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
    } finally {
        sl.killScript();
    }
    assertContains("text/html", readFileToString(new File(baseDir, "log.csv")));
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Aggregations

Process2 (com.predic8.membrane.examples.Process2)37 Test (org.junit.Test)36 File (java.io.File)30 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)4 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)4 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)3 AssertUtils.replaceInFile (com.predic8.membrane.test.AssertUtils.replaceInFile)2 OtpProvider (com.predic8.membrane.core.interceptor.authentication.session.totp.OtpProvider)1 FilenameFilter (java.io.FilenameFilter)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1