Package io.apigee.trireme.core

Examples of io.apigee.trireme.core.ScriptStatus


        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);
View Full Code Here


        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'));
View Full Code Here

        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

        throws NodeException, InterruptedException, ExecutionException
    {
        NodeScript script = env.createScript(name,
                                             new File("target/test-classes/scripts/" + name),
                                             null);
        ScriptStatus status = script.execute().get();
        assertEquals(0, status.getExitCode());
        script.close();
    }
View Full Code Here

                ns.setPrintEval(printEval);
            } else {
                ns = env.createScript(scriptArgs, runRepl);
            }

            ScriptStatus status;
            try {
                Future<ScriptStatus> future = ns.execute();
                status = future.get();
            } finally {
                ns.close();
            }

            if (status.hasCause()) {
                printException(status.getCause());
            }

            return status.getExitCode();
        } catch (NodeException ne) {
            ne.printStackTrace(System.err);
            return 99;
        } catch (InterruptedException ie) {
            return 99;
View Full Code Here

    {
        System.out.println("Running " + name + "...");
        NodeScript script = env.createScript(name,
                                             new File("./target/test-classes/tests/" + name),
                                             null);
        ScriptStatus status = script.execute().get();
        System.out.println("  " + name + " returned " + status.getExitCode());
        assertEquals(0, status.getExitCode());
    }
View Full Code Here

        return (ScriptStatus)ret;
    }

    protected ScriptStatus runScript(Context cx)
    {
        ScriptStatus status;

        if (scriptObject.getDisplayName() != null) {
            try {
                Thread.currentThread().setName("Trireme: " + scriptObject.getDisplayName());
            } catch (SecurityException ignore) {
            }
        }

        cx.putThreadLocal(RUNNER, this);
        now = System.currentTimeMillis();

        try {
            // All scripts get their own global scope. This is a lot safer than sharing them in case a script wants
            // to add to the prototype of String or Date or whatever (as they often do)
            // This uses a bit more memory and in theory slows down script startup but in practice it is
            // a drop in the bucket.
            scope = cx.initStandardObjects();

            // Lazy first-time init of the node version.
            registry.load(cx);

            try {
                initGlobals(cx);
            } catch (NodeException ne) {
                return new ScriptStatus(ne);
            } finally {
                initialized.countDown();
            }

            if ((scriptFile == null) && (script == null)) {
                // Just have trireme.js process "process.argv"
                process.setForceRepl(forceRepl);
                setArgv(null);
            } else if (scriptFile == null) {
                // If the script was passed as a string, pretend that "-e" was used to "eval" it.
                // We also get here if we were called by "executeModule".
                process.setEval(script);
                process.setPrintEval(scriptObject.isPrintEval());
                setArgv(scriptFileName);
            } else {
                // Otherwise, assume that the script was the second argument to "argv".
                setArgv(scriptFileName);
            }

            // Run "trireme.js," which is our equivalent of "node.js". It returns a function that takes
            // "process". When done, we may have ticks to execute.
            Script mainScript = registry.getMainScript();
            Function main = (Function)mainScript.exec(cx, scope);

            boolean timing = startTiming(cx);
            try {
                main.call(cx, scope, scope, new Object[] { process });
            } catch (RhinoException re) {
                boolean handled = handleScriptException(cx, re);
                if (!handled) {
                    throw re;
                }
            } finally {
                if (timing) {
                    endTiming(cx);
                }
            }

            status = mainLoop(cx);

        } catch (NodeExitException ne) {
            // This exception is thrown by process.exit()
            status = ne.getStatus();
        } catch (IOException ioe) {
            log.debug("I/O exception processing script: {}", ioe);
            status = new ScriptStatus(ioe);
        } catch (Throwable t) {
            log.debug("Unexpected script error: {}", t);
            status = new ScriptStatus(t);
        }

        log.debug("Script exiting with exit code {}", status.getExitCode());

        if (!status.hasCause() && !process.isExiting()) {
            // Fire the exit callback, but only if we aren't exiting due to an unhandled exception, and "exit"
            // wasn't already fired because we called "exit"
            try {
                process.setExiting(true);
                process.fireExit(cx, status.getExitCode());
            } catch (NodeExitException ee) {
                // Exit called exit -- allow it to replace the exit code
                log.debug("Script replacing exit code with {}", ee.getCode());
                status = ee.getStatus();
            } catch (RhinoException re) {
                // Many of the unit tests fire exceptions inside exit.
                status = new ScriptStatus(re);
            }
        }

        closeCloseables(cx);
        try {
View Full Code Here

                // This exception is thrown by process.exit()
                return ne.getStatus();
            } catch (RhinoException re) {
                // All domain and process-wide error handling happened before we got here, so
                // if we get a RhinoException here, then we know that it is fatal.
                return new ScriptStatus(re);
            }
        }
        return ScriptStatus.OK;
    }
View Full Code Here

        }
        NodeScript script = env.createScript(name,
                                             new File("./target/test-classes/tests/" + name),
                                             null);
        script.setEnvironment(scriptEnv);
        ScriptStatus status = script.execute().get();
        assertEquals(0, status.getExitCode());
    }
View Full Code Here

        }
        NodeScript script = env.createScript(name,
                                             new File("./target/test-classes/tests/" + name),
                                             null);
        script.setEnvironment(scriptEnv);
        ScriptStatus status = script.execute().get();
        assertEquals(0, status.getExitCode());
    }
View Full Code Here

TOP

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

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.