Package io.apigee.trireme.core

Examples of io.apigee.trireme.core.NodeEnvironment


    private NodeEnvironment env;

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


    private static NodeEnvironment env;

    @BeforeClass
    public static void init()
    {
        env = new NodeEnvironment();
    }
View Full Code Here

    @BeforeClass
    public static void init()
        throws NodeException
    {
        env = new NodeEnvironment();
    }
View Full Code Here

    @Test
    public void testAppMemory()
        throws NodeException, InterruptedException, IOException
    {
        long before = getMemoryUsed();
        NodeEnvironment env = new NodeEnvironment();
        NodeScript script = env.createScript("server.js", new File("./target/test-classes/dogs/server.js"), null);
        ScriptFuture scriptFuture = script.execute();
        Utils.awaitPortOpen(PORT);
        long after = getMemoryUsed();
        System.out.println("Added " + (after - before) + " bytes after starting one script");
        scriptFuture.cancel(true);
View Full Code Here

    @Test
    public void testAppMemoryManyTimes()
        throws NodeException, InterruptedException, IOException
    {
        long before = getMemoryUsed();
        NodeEnvironment env = new NodeEnvironment();
        ArrayList<ScriptFuture> futures = new ArrayList<ScriptFuture>();

        System.out.print("Starting...");
        int p = PORT + 1;
        for (int i = 0; i < NUMSCRIPTS; i++) {
            NodeScript script = env.createScript("server.js", new File("./target/test-classes/dogs/server.js"),
                                                 new String[] { String.valueOf(p) });
            futures.add(script.execute());
            p++;
            System.out.print(i + " ");
            System.out.flush();
View Full Code Here

    @Test
    public void testAppMemoryManyTimesWithCache()
        throws NodeException, InterruptedException, IOException
    {
        long before = getMemoryUsed();
        NodeEnvironment env = new NodeEnvironment();
        env.setDefaultClassCache();
        ArrayList<ScriptFuture> futures = new ArrayList<ScriptFuture>();

        System.out.print("Starting with cache...");
        int p = PORT + 1;
        for (int i = 0; i < NUMSCRIPTS; i++) {
            NodeScript script = env.createScript("server.js", new File("./target/test-classes/dogs/server.js"),
                                                 new String[] { String.valueOf(p) });
            futures.add(script.execute());
            p++;
            System.out.print(i + " ");
            System.out.flush();
        }
        System.out.println();

        System.out.print("Waiting...");
        p = PORT + 1;
        for (int i = 0; i < NUMSCRIPTS; i++) {
            Utils.awaitPortOpen(p);
            p++;
            System.out.print(i + " ");
            System.out.flush();
        }
        System.out.println();

        long after = getMemoryUsed();
        System.out.println("Added " + (after - before) + " bytes after starting " + NUMSCRIPTS +
                           " scripts with class cache");
        System.out.println(env.getClassCache().toString());

        for (ScriptFuture f : futures) {
            f.cancel(true);
        }
    }
View Full Code Here

    @Test
    public void testGetWeather()
        throws IOException, NodeException, InterruptedException, ExecutionException
    {
        NodeEnvironment env = new NodeEnvironment();
        if (useNetty) {
            env.setHttpContainer(new NettyHttpContainer());
        }
        // Use separate ports between netty and non-netty because netty might take a while to close them
        int port = PORT + (useNetty ? 1 : 0);
        NodeScript script = env.createScript("server.js", new File("./target/test-classes/argo/server.js"),
                                             new String[] { String.valueOf(port) });
        ScriptFuture scriptFuture = script.execute();
        System.out.println("Waiting for the port to open. useNetty = " + useNetty);
        Utils.awaitPortOpen(port);
View Full Code Here

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

        String msg = "Hello, World!";
        NodeScript ns =
            env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
                             new String[] { "stdout", 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

    @Test
    public void testRedirectStderr()
        throws NodeException, InterruptedException, ExecutionException, TimeoutException
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        NodeEnvironment env = new NodeEnvironment();
        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

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

        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

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.