Package io.apigee.trireme.core

Examples of io.apigee.trireme.core.NodeScript


        Sandbox sb = new Sandbox();
        sb.setStderr(out);
        env.setSandbox(sb);

        String msg = "Hello, World!";
        NodeScript ns =
            env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
                             new String[] { "stderr", msg });

        try {
            ScriptFuture f = ns.execute();
            ScriptStatus result = f.get(SCRIPT_TIMEOUT_SECS, TimeUnit.SECONDS);
            assertEquals(0, result.getExitCode());

            String stream = new String(out.toByteArray(), UTF8);
            assertEquals(msg + '\n', stream);
        } finally {
            ns.close();
            env.close();
        }
    }
View Full Code Here


        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
        ByteArrayOutputStream out2 = new ByteArrayOutputStream();

        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 });
        ns1.setSandbox(new Sandbox().setStdout(out1));

        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 });
        ns2.setSandbox(new Sandbox().setStdout(out2));

        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 stream1 = new String(out1.toByteArray(), UTF8);
            String stream2 = new String(out2.toByteArray(), UTF8);

            assertEquals(msg1 + '\n', stream1);
            assertEquals(msg2 + '\n', stream2);

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

        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

                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();
        assertEquals(0, status.getExitCode());
        script.close();
    }
View Full Code Here

    @Test
    public void testHello()
        throws InterruptedException, ExecutionException, NodeException
    {
        NodeScript script = env.createScript("test.js",
                                             "console.log(\'Hello, World!\');process.exit(0);  ",
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

    @Test
    public void testModuleLoadAndSetName()
        throws InterruptedException, ExecutionException, NodeException
    {
        NodeScript script = env.createScript("moduletest",
                                             new File("./target/test-classes/tests/moduletest.js"),
                                             null);
        script.setDisplayName("ModuleLoadDisplayNameTest");
        ScriptStatus status = script.execute().get();
        assertEquals(0, status.getExitCode());
        script.close();
    }
View Full Code Here

        throws InterruptedException, ExecutionException, NodeException, IOException
    {
        InputStream modIn = this.getClass().getResourceAsStream("/tests/moduleteststring.js");
        assertNotNull(modIn);
        String source = Utils.readStream(modIn);
        NodeScript script = env.createScript("moduleteststring.js",
                                             source,
                                             null);
        ScriptStatus stat = script.execute().get();
        assertEquals(0, stat.getExitCode());
    }
View Full Code Here

    @Test
    public void testCancellation()
        throws InterruptedException, ExecutionException, NodeException
    {
        NodeScript script = env.createScript("endless.js",
                                             new File("./target/test-classes/tests/endless.js"),
                                             null);
        final ScriptFuture status = script.execute();
        status.setListener(new ScriptStatusListener()
        {
            @Override
            public void onComplete(NodeScript script, ScriptStatus s)
            {
View Full Code Here

    @Test
    public void testTimeout()
        throws InterruptedException, ExecutionException, NodeException
    {
        NodeScript script = env.createScript("endless.js",
                                             new File("./target/test-classes/tests/endless.js"),
                                             null);
        final ScriptFuture status = script.execute();
        status.setListener(new ScriptStatusListener()
        {
            @Override
            public void onComplete(NodeScript script, ScriptStatus s)
            {
View Full Code Here

    @Test
    public void testCancellationWithInterrupt()
        throws InterruptedException, ExecutionException, NodeException
    {
        NodeScript script = env.createScript("endless.js",
                                             new File("./target/test-classes/tests/endless.js"),
                                             null);
        final ScriptFuture status = script.execute();
        status.setListener(new ScriptStatusListener()
        {
            @Override
            public void onComplete(NodeScript script, ScriptStatus s)
            {
View Full Code Here

TOP

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

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.