Search in sources :

Example 1 with Process2

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

the class ACLTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("acl");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
        String result = getAndAssert(404, "http://localhost:2000/contacts/");
        // this request succeeds through membrane, but fails on the backend with 404
        AssertUtils.assertContains("Tomcat", result);
        getAndAssert(403, "http://localhost:2000/open-source/");
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 2 with Process2

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

the class CustomInterceptorTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("custom-interceptor");
    BufferLogger b = new BufferLogger();
    Process2 ant = new Process2.Builder().in(baseDir).executable("ant compile").withWatcher(b).start();
    try {
        int exitCode = ant.waitFor(60000);
        if (exitCode != 0)
            throw new RuntimeException("Ant exited with code " + exitCode + ": " + b.toString());
    } finally {
        ant.killScript();
    }
    FileUtils.copyDirectoryToDirectory(new File(baseDir, "build/classes"), getMembraneHome());
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        SubstringWaitableConsoleEvent invoked = new SubstringWaitableConsoleEvent(sl, "MyInterceptor invoked");
        getAndAssert200("http://localhost:2000/");
        assertTrue(invoked.occurred());
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) BufferLogger(com.predic8.membrane.examples.util.BufferLogger) File(java.io.File) SubstringWaitableConsoleEvent(com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent) Test(org.junit.Test)

Example 3 with Process2

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

the class GroovyTest method test.

@Test
public void test() throws IOException, InterruptedException {
    Process2 sl = new Process2.Builder().in(getExampleDir("groovy")).script("service-proxy").waitForMembrane().start();
    try {
        SubstringWaitableConsoleEvent groovyCalled = new SubstringWaitableConsoleEvent(sl, "X-Groovy header added with value :Groovy interceptor");
        getAndAssert200("http://localhost:2000/");
        assertTrue(groovyCalled.occurred());
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) SubstringWaitableConsoleEvent(com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent) Test(org.junit.Test)

Example 4 with Process2

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

the class LoadBalancerSession3Test method test.

/**
 * The test as described in README.txt, but "wsimport" (previously called by ant)
 * was removed and is run directly from this test before everything else. Thereby
 * we can use a Maven dependency on wsimport and do not have to download it ourselves.
 */
@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-session-3");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    AssertUtils.replaceInFile(new File(base, "src/com/predic8/chat/Client.java"), "8080", "3023");
    AssertUtils.replaceInFile(new File(base, "data/ChatService.wsdl"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        File buildXML = new File(base, "build.xml");
        // remove <exec...</exec> from build.xml
        String s = Pattern.compile("<exec.*</exec>", Pattern.DOTALL).matcher(FileUtils.readFileToString(buildXML)).replaceAll("");
        FileUtils.writeStringToFile(buildXML, s);
        File classes = new File(base, "build" + File.separator + "classes");
        classes.mkdirs();
        File source = new File(base, "src");
        source.mkdirs();
        // run "wsimport" generating java sources
        Assert.assertTrue(new com.sun.tools.ws.wscompile.WsimportTool(System.out).run(new String[] { "-quiet", "-Xnocompile", new File(base, "data" + File.separator + "ChatService.wsdl").getAbsolutePath(), "-s", source.getAbsolutePath() }));
        // call "ant compile" now so that both antNodeX processes do call it at the same time
        BufferLogger loggerCompile = new BufferLogger();
        Process2 antCompile = new Process2.Builder().in(base).withWatcher(loggerCompile).executable("ant compile").start();
        try {
            int result = antCompile.waitFor(60000);
            if (result != 0)
                throw new AssertionError("'ant compile' returned non-zero " + result + ":\r\n" + loggerCompile.toString());
        } finally {
            antCompile.killScript();
        }
        BufferLogger loggerNode1 = new BufferLogger();
        BufferLogger loggerNode2 = new BufferLogger();
        Process2 antNode1 = new Process2.Builder().in(base).withWatcher(loggerNode1).executable("ant run-node1").start();
        try {
            Process2 antNode2 = new Process2.Builder().in(base).withWatcher(loggerNode2).executable("ant run-node2").start();
            try {
                LoadBalancerUtil.addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000);
                LoadBalancerUtil.addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001);
                // wait for nodes to come up
                Thread.sleep(1000);
                Process2 antClient = new Process2.Builder().in(base).executable("ant run-client -Dlogin=jim").start();
                try {
                    antClient.waitFor(60000);
                } finally {
                    antClient.killScript();
                }
            } finally {
                antNode2.killScript();
            }
        } finally {
            antNode1.killScript();
        }
        AssertUtils.assertContains("Hallo World", loggerNode1.toString());
        AssertUtils.assertContainsNot("Hallo World", loggerNode2.toString());
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) BufferLogger(com.predic8.membrane.examples.util.BufferLogger) File(java.io.File) Test(org.junit.Test)

Example 5 with Process2

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

the class LoadBalancerMultiple4Test method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-multiple-4");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8081", "3024");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        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"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        assertEquals(4, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        assertEquals(4, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        String status = getAndAssert200("http://localhost:9000/admin/clusters/show?balancer=balancer1&cluster=Default");
        assertNodeStatus(status, "localhost", 4000, "UP");
        assertNodeStatus(status, "localhost", 4001, "UP");
        getAndAssert(204, "http://localhost:9010/clustermanager/down?balancer=balancer1&host=localhost&port=4001");
        Thread.sleep(1000);
        status = getAndAssert200("http://localhost:9000/admin/clusters/show?balancer=balancer1&cluster=Default");
        assertNodeStatus(status, "localhost", 4000, "UP");
        assertNodeStatus(status, "localhost", 4001, "DOWN");
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(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)

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