Package io.apigee.trireme.core

Examples of io.apigee.trireme.core.NodeEnvironment


    @Test
    public void testStdoutSharing()
        throws NodeException, InterruptedException, ExecutionException, TimeoutException
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        NodeEnvironment env = new NodeEnvironment();
        env.setSandbox(new Sandbox().setStdout(out));

        String msg1 = "This is script number 1";
        NodeScript ns1 =
            env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
                             new String[] { "stdout", msg1 });

        String msg2 = "This is script number two";
        NodeScript ns2 =
            env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
                             new String[] { "stdout", msg2 });

        try {
            ScriptFuture f1 = ns1.execute();
            ScriptFuture f2 = ns2.execute();

            ScriptStatus result1 = f1.get(SCRIPT_TIMEOUT_SECS, TimeUnit.SECONDS);
            assertEquals(0, result1.getExitCode());
            ScriptStatus result2 = f2.get(SCRIPT_TIMEOUT_SECS, TimeUnit.SECONDS);
            assertEquals(0, result2.getExitCode());

            String stream = new String(out.toByteArray(), UTF8);

            assertTrue(stream.equals(msg1 + '\n' + msg2 + '\n') ||
                       stream.equals(msg2 + '\n' + msg1 + '\n'));

        } finally {
            ns1.close();
            ns2.close();
            env.close();
        }
    }
View Full Code Here


     */
    @Test
    public void testExtraClassShutter()
            throws NodeException, ExecutionException, InterruptedException, IOException
    {
        NodeEnvironment env = new NodeEnvironment();

        env.setSandbox(new Sandbox().setExtraClassShutter(new ClassShutter() {
            @Override
            public boolean visibleToScripts(String fullClassName) {
                return true;
            }
        }));

        File scriptFile = new File("./target/test-classes/tests/extraclassshuttertest.js");
        NodeScript script = env.createScript(scriptFile.getName(),
                                             scriptFile,
                                             new String[] {
                                                     scriptFile.getCanonicalPath()
                                             });
        ScriptStatus status = script.execute().get();
View Full Code Here

    private NodeEnvironment env;

    @Before
    public void createEnvironment()
    {
        env = new NodeEnvironment();
    }
View Full Code Here

    @Test
    public void testScriptTimeout()
        throws InterruptedException, ExecutionException, NodeException
    {

        NodeEnvironment rootEnv = new NodeEnvironment();
        rootEnv.setScriptTimeLimit(1, TimeUnit.SECONDS);
        NodeScript script = rootEnv.createScript("endlesscpu.js",
                                             new File("./target/test-classes/tests/endlesscpu.js"),
                                             null);
        try {
            script.execute().get();
            assertFalse("Expected a time out exception", true);
View Full Code Here

    public void testChroot()
        throws InterruptedException, ExecutionException, NodeException, IOException
    {
        Sandbox sb = new Sandbox();
        sb.setFilesystemRoot("./target/test-classes");
        NodeEnvironment rootEnv = new NodeEnvironment();
        rootEnv.setSandbox(sb);
        NodeScript script = rootEnv.createScript("chroottest.js",
                                             new File("./target/test-classes/tests/chroottest.js"),
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

            return;
        }
        Sandbox sb = new Sandbox();
        sb.setFilesystemRoot("./target");
        sb.setWorkingDirectory("./test-classes");
        NodeEnvironment rootEnv = new NodeEnvironment();
        rootEnv.setSandbox(sb);
        NodeScript script = rootEnv.createScript("chroottest.js",
                                             new File("./target/test-classes/tests/chroottest.js"),
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

            return;
        }
        Sandbox sb = new Sandbox();
        sb.setFilesystemRoot("./target");
        sb.setWorkingDirectory("/test-classes");
        NodeEnvironment rootEnv = new NodeEnvironment();
        rootEnv.setSandbox(sb);
        NodeScript script = rootEnv.createScript("chroottest.js",
                                             new File("./target/test-classes/tests/chroottest.js"),
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

            System.out.println("Absolute mounts not yet supported on Windows");
            return;
        }
        Sandbox sb = new Sandbox();
        sb.setFilesystemRoot("./target/test-classes");
        NodeEnvironment rootEnv = new NodeEnvironment();
        rootEnv.setSandbox(sb);
        NodeScript script = rootEnv.createScript("chroottest.js",
                                             new File("./target/test-classes/tests/builtinmoduletest.js").getAbsoluteFile(),
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

    public void testChrootModules()
        throws InterruptedException, ExecutionException, NodeException, IOException
    {
        Sandbox sb = new Sandbox();
        sb.setFilesystemRoot("./target/test-classes");
        NodeEnvironment rootEnv = new NodeEnvironment();
        rootEnv.setSandbox(sb);
        NodeScript script = rootEnv.createScript("moduletest.js",
                                             new File("./target/test-classes/tests/moduletest.js"),
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

    @Test
    public void testHttpPolicy()
        throws InterruptedException, ExecutionException, NodeException, IOException
    {
        NodeEnvironment localEnv = new NodeEnvironment();
        Sandbox sb = new Sandbox();
        sb.setNetworkPolicy(new RejectInPolicy());
        localEnv.setSandbox(sb);
        NodeScript script = localEnv.createScript("httppolicylisten.js",
                                             new File("./target/test-classes/tests/httppolicylisten.js"),
                                             null);
        ScriptStatus status = script.execute().get();
        assertEquals(0, status.getExitCode());
    }
View Full Code Here

TOP

Related Classes of io.apigee.trireme.core.NodeEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.