ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: ignite-648: kill processes correctly.
Date Mon, 13 Apr 2015 12:31:35 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-648 15a9b4f0a -> 7739e8db0


ignite-648: kill processes correctly.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7739e8db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7739e8db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7739e8db

Branch: refs/heads/ignite-648
Commit: 7739e8db0b8974c067964f1378ca2b96fd6da1dc
Parents: 15a9b4f
Author: Artem Shutak <ashutak@gridgain.com>
Authored: Mon Apr 13 15:31:29 2015 +0300
Committer: Artem Shutak <ashutak@gridgain.com>
Committed: Mon Apr 13 15:31:29 2015 +0300

----------------------------------------------------------------------
 .../internal/multijvm/IgniteNodeRunner.java     |  12 ++-
 .../ignite/internal/multijvm/MultiJvmTest.java  | 102 +++++--------------
 2 files changed, 30 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7739e8db/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/IgniteNodeRunner.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/IgniteNodeRunner.java
b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/IgniteNodeRunner.java
index f728e1f..0e4f5a5 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/IgniteNodeRunner.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/IgniteNodeRunner.java
@@ -18,20 +18,22 @@
 package org.apache.ignite.internal.multijvm;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
 
 /**
  * Run ignite node. 
  */
 public class IgniteNodeRunner {
     public static void main(String[] args) throws Exception {
-        System.out.println("args=" + args);
-        System.out.println("args == null =" + args == null);
-        System.out.println("args.len =" + args.length);
-        System.out.println("args[0] =" + args[0]);
+        X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
 
         assert args != null;
         assert args.length == 1;
-        
+
+        X.println("Starting Ignite Node...");
+
         String cfg = args[0];
 
         Ignition.start(cfg);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7739e8db/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/MultiJvmTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/MultiJvmTest.java
b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/MultiJvmTest.java
index d61c877..8e9f455 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/MultiJvmTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/MultiJvmTest.java
@@ -17,117 +17,61 @@
 
 package org.apache.ignite.internal.multijvm;
 
-import org.apache.ignite.*;
 import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.testframework.junits.common.*;
 
-import java.io.*;
 import java.util.*;
 
 /**
  * Multi JVM tests. 
  */
 public class MultiJvmTest extends GridCommonAbstractTest {
-    /**
-     * Runs given class as separate java process.
-     *
-     * @param runnerCls Runner class
-     * @param b
-     * @throws Exception If failed.
-     */
-    protected void runJavaProcess(Class<?> runnerCls, boolean wait) throws Exception
{
-        Process ps = GridJavaProcess.exec(
-            runnerCls,
-            null,
-            null,
-            null,
-            null,
-            Collections.<String>emptyList(),
-            System.getProperty("surefire.test.class.path")
-        ).getProcess();
-
-        readStreams(ps);
-
-        int code = 0;
-        
-        if (wait)
-            code = ps.waitFor();
-
-        assertEquals("Returned code have to be 0.", 0, code);
+    /** Proces name to process map. */
+    private final Map<String, GridJavaProcess> nodes = new HashMap<>();
+    
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest(); 
     }
 
-    /**
-     * Read information from process streams.
-     *
-     * @param proc Process.
-     * @throws IOException If an I/O error occurs.
-     */
-    private void readStreams(final Process proc) throws IOException {
-        Thread reader = new Thread(new Runnable() {
-            @Override public void run() {
-                try {
-                    BufferedReader stdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
-
-                    String s;
-
-                    while ((s = stdOut.readLine()) != null)
-                        System.out.println("OUT>>>>>> " + s);
-
-                    BufferedReader errOut = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
-
-                    while ((s = errOut.readLine()) != null)
-                        System.out.println("ERR>>>>>> " + s);
-                }
-                catch (IOException e) {
-                    // No-op.
-                }
-            }
-        });
-        
-        reader.setDaemon(true);
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        for (GridJavaProcess process : nodes.values())
+            process.kill();
         
-        reader.start();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMultiNode() throws Exception {
-        runJavaProcess(IgniteNodeRunner.class, false);
+        nodes.clear();
         
-        Ignition.stopAll(true);
+        super.afterTest(); 
     }
 
     /**
      * @throws Exception If failed.
      */
     public void testRunProcess() throws Exception {
-        runIgniteProcess("node1", "modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml");
-        
-        Thread.sleep(20_000);
+        runIgniteProcess("JvmNode1", "modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml");
+
+        Thread.sleep(10_000);
     }
 
-    private void runIgniteProcess(String nodeName, String cfg) throws Exception {
-        GridJavaProcess.exec(
+    private GridJavaProcess runIgniteProcess(final String nodeName, String cfg) throws Exception
{
+        GridJavaProcess ps = GridJavaProcess.exec(
             IgniteNodeRunner.class,
             cfg, // Params.
             log,
             // Optional closure to be called each time wrapped process prints line to system.out
or system.err.
             new IgniteInClosure<String>() {
                 @Override public void apply(String s) {
-                    log.info(s);
-                }
-            },
-//            Optional closure to be called when process termination is detected.
-            new GridAbsClosure() {
-                @Override public void apply() {
-                    Ignition.stopAll(true);
+                    log.info("[" + nodeName + "] " + s);
                 }
             },
+            null,
             Collections.<String>emptyList(), // JVM Args.
             System.getProperty("surefire.test.class.path")
         );
+        
+        nodes.put(nodeName, ps);
+        
+        return ps;
     }
 }


Mime
View raw message