Search in sources :

Example 6 with AssertUtils.replaceInFile

use of com.predic8.membrane.test.AssertUtils.replaceInFile 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 7 with AssertUtils.replaceInFile

use of com.predic8.membrane.test.AssertUtils.replaceInFile 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 8 with AssertUtils.replaceInFile

use of com.predic8.membrane.test.AssertUtils.replaceInFile in project service-proxy by membrane.

the class SSLServer method test.

@Test
public void test() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyManagementException {
    File baseDir = getExampleDir("ssl-server");
    AssertUtils.replaceInFile(new File(baseDir, "proxies.xml"), "443", "3023");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        AssertUtils.trustAnyHTTPSServer(3023);
        assertContains("wsdl:documentation", getAndAssert200("https://localhost:3023/axis2/services/BLZService?wsdl"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Aggregations

Process2 (com.predic8.membrane.examples.Process2)8 File (java.io.File)8 Test (org.junit.Test)8 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1