ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/2] incubator-ignite git commit: ignite-648: implement simple test
Date Tue, 14 Apr 2015 13:15:23 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-648 fcd9ce2ee -> 95e31bcfc


ignite-648: implement simple test


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

Branch: refs/heads/ignite-648
Commit: 6ea7f3dfb01510a8c0f39b8591ef82535c23299d
Parents: fcd9ce2
Author: Artem Shutak <ashutak@gridgain.com>
Authored: Mon Apr 13 18:58:05 2015 +0300
Committer: Artem Shutak <ashutak@gridgain.com>
Committed: Mon Apr 13 18:58:05 2015 +0300

----------------------------------------------------------------------
 .../CachePartitionedMultyJvmSelfTest.java       | 92 +++++---------------
 .../ignite/internal/multijvm/CheckInCache.java  | 41 +++++++++
 .../internal/multijvm/IgniteNodeRunner.java     | 61 +++++++++++--
 .../ignite/internal/multijvm/MultiJvmTest.java  | 40 ++++++---
 .../ignite/internal/multijvm/PutInCache.java    | 36 ++++++++
 .../ignite/internal/multijvm/example-cache.xml  |  2 +
 6 files changed, 186 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6ea7f3df/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CachePartitionedMultyJvmSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CachePartitionedMultyJvmSelfTest.java
b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CachePartitionedMultyJvmSelfTest.java
index c757d09..95a22cf 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CachePartitionedMultyJvmSelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CachePartitionedMultyJvmSelfTest.java
@@ -13,73 +13,27 @@ package org.apache.ignite.internal.multijvm;
  * Test cases for multi-jvm tests.
  */
 public class CachePartitionedMultyJvmSelfTest extends MultiJvmTest{
-//    /**
-//     * @throws Exception If test failed.
-//     */
-//    public void testBasicPut() throws Exception {
-//        runIgniteProcess("ignite1", "cfg");
-//
-//        checkPuts(3, ignite1);
-//    }
-//
-//    /**
-//     * @throws Exception If test fails.
-//     */
-//    public void testMultiJvmPut() throws Exception {
-//        checkPuts(1, ignite1, ignite2, ignite3);
-//        checkPuts(1, ignite2, ignite1, ignite3);
-//        checkPuts(1, ignite3, ignite1, ignite2);
-//    }
-//
-//    /**
-//     * Checks cache puts.
-//     *
-//     * @param cnt Count of puts.
-//     * @param ignites Grids.
-//     * @throws Exception If check fails.
-//     */
-//    private void checkPuts(int cnt, Ignite... ignites) throws Exception {
-//        CountDownLatch latch = new CountDownLatch(ignites.length * cnt);
-//
-//        CacheEventListener lsnr = new CacheEventListener(latch, EVT_CACHE_OBJECT_PUT);
-//
-//        for (Ignite ignite : ignites)
-//            addListener(ignite, lsnr);
-//
-//        IgniteCache<Integer, String> cache1 = ignites[0].cache(null);
-//
-//        for (int i = 1; i <= cnt; i++)
-//            cache1.put(i, "val" + i);
-//
-//        for (int i = 1; i <= cnt; i++) {
-//            String v = cache1.get(i);
-//
-//            assert v != null;
-//            assert v.equals("val" + i);
-//        }
-//
-//        latch.await(10, SECONDS);
-//
-//        for (Ignite ignite : ignites) {
-//            IgniteCache<Integer, String> cache = ignite.cache(null);
-//
-//            if (cache == cache1)
-//                continue;
-//
-//            for (int i = 1; i <= cnt; i++) {
-//                String v = cache.get(i);
-//
-//                assert v != null;
-//                assert v.equals("val" + i);
-//            }
-//        }
-//
-//        assert !cache1.isLocalLocked(1, false);
-//        assert !cache1.isLocalLocked(2, false);
-//        assert !cache1.isLocalLocked(3, false);
-//
-//        for (Ignite ignite : ignites)
-//            ignite.events().stopLocalListen(lsnr);
-//    }
-//
+    private static final String IGNITE_NODE_1 = "IGNITE_NODE_1";
+    private static final String IGNITE_NODE_2 = "IGNITE_NODE_2";
+    private static final String IGNITE_NODE_3 = "IGNITE_NODE_3";
+    private static final String CFG = "modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml";
+
+    @Override protected void beforeTestsStarted() throws Exception {
+        runIgniteProcess(IGNITE_NODE_1, CFG);
+        runIgniteProcess(IGNITE_NODE_2, CFG);
+        runIgniteProcess(IGNITE_NODE_3, CFG);
+    }
+
+    /**
+     * @throws Exception If test fails.
+     */
+    public void testMultiJvmPut() throws Exception {
+        executeTaskAndWaitForFinish(IGNITE_NODE_1, PutInCache.class, 1);
+        
+        executeTaskAndWaitForFinish(IGNITE_NODE_1, CheckInCache.class, 1);
+
+        executeTaskAndWaitForFinish(IGNITE_NODE_2, CheckInCache.class, 1);
+        
+        executeTaskAndWaitForFinish(IGNITE_NODE_3, CheckInCache.class, 1);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6ea7f3df/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CheckInCache.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CheckInCache.java
b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CheckInCache.java
new file mode 100644
index 0000000..031cfd0
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/CheckInCache.java
@@ -0,0 +1,41 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.internal.multijvm;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.util.typedef.*;
+
+import static junit.framework.TestCase.*;
+
+/**
+ * TODO: Add class description.
+ *
+ * @author @java.author
+ * @version @java.version
+ */
+public class CheckInCache implements IgniteNodeRunner.Task {
+    /** {@inheritDoc} */
+    @Override public boolean execute(Ignite ignite, String... args) {
+        int cnt = Integer.valueOf(args[0]);
+        
+        IgniteCache<Integer, String> cache = ignite.cache(null);
+
+        for (int i = 1; i <= cnt; i++) {
+            String v = cache.get(i);
+
+            assertNotNull(v);
+            assertEquals("val" + i, v);
+
+            X.println(">>>>> Got=" + "val" + i);
+        }
+        
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6ea7f3df/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 0e4f5a5..0e33baa 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
@@ -22,20 +22,69 @@ import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 
+import java.io.*;
+
 /**
  * Run ignite node. 
  */
 public class IgniteNodeRunner {
+    public static final String TASK_EXECUTED = "Event.TaskExecuted";
+    public static final String EXECUTE_TASK = "Cmd.ExecuteTask=";
+    public static final String TASK_ARGS = ", Cmd.TaskArgs=";
+    public static final String STOP = "Cmd.Stop";
+
     public static void main(String[] args) throws Exception {
-        X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
+        try {
+            X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
+
+            assert args != null;
+            assert args.length >= 1;
+
+            X.println("Starting Ignite Node...");
 
-        assert args != null;
-        assert args.length == 1;
+            String cfg = args[0];
 
-        X.println("Starting Ignite Node...");
+            Ignite ignite = Ignition.start(cfg);
 
-        String cfg = args[0];
+            // Read commands.
+            String cmd;
 
-        Ignition.start(cfg);
+            final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+
+            boolean running = true;
+
+            while (running) {
+                cmd = br.readLine();
+    
+                X.println(">>>>> Got cmd [" + cmd + ']');
+    
+                if (cmd.startsWith(EXECUTE_TASK)) {
+                    String taskClsName = cmd.substring(EXECUTE_TASK.length(), cmd.indexOf(TASK_ARGS));
+                    String taskArgs = cmd.substring(cmd.indexOf(TASK_ARGS) + TASK_ARGS.length());
+    
+                    X.println(">>>>> Task=" + taskClsName + ", args=" + taskArgs);
+    
+                    Task task = (Task)Class.forName(taskClsName).newInstance();
+                    
+                    task.execute(ignite, taskArgs.split(" "));
+    
+                    X.println(TASK_EXECUTED);
+                }
+                else if (cmd.startsWith(STOP)) {
+                    Ignition.stopAll(false);
+    
+                    running = false;
+                }
+            }
+        }
+        catch (Throwable e) {
+            e.printStackTrace();
+            
+            System.exit(1);
+        }
+    }
+    
+    public static interface Task {
+        boolean execute(Ignite ignite, String... args);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6ea7f3df/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 8e9f455..f64f731 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
@@ -21,6 +21,7 @@ import org.apache.ignite.internal.util.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.testframework.junits.common.*;
 
+import java.io.*;
 import java.util.*;
 
 /**
@@ -29,22 +30,17 @@ import java.util.*;
 public class MultiJvmTest extends GridCommonAbstractTest {
     /** Proces name to process map. */
     private final Map<String, GridJavaProcess> nodes = new HashMap<>();
-    
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest(); 
-    }
 
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
+    @Override protected void afterTestsStopped() throws Exception {
         for (GridJavaProcess process : nodes.values())
             process.kill();
-        
+
         nodes.clear();
-        
-        super.afterTest(); 
+
+        super.afterTestsStopped();
     }
 
+
     /**
      * @throws Exception If failed.
      */
@@ -54,7 +50,7 @@ public class MultiJvmTest extends GridCommonAbstractTest {
         Thread.sleep(10_000);
     }
 
-    private GridJavaProcess runIgniteProcess(final String nodeName, String cfg) throws Exception
{
+    protected GridJavaProcess runIgniteProcess(final String nodeName, String cfg) throws
Exception {
         GridJavaProcess ps = GridJavaProcess.exec(
             IgniteNodeRunner.class,
             cfg, // Params.
@@ -74,4 +70,26 @@ public class MultiJvmTest extends GridCommonAbstractTest {
         
         return ps;
     }
+
+    protected void executeTaskAndWaitForFinish(String nodeName, Class<? extends IgniteNodeRunner.Task>
taskCls,
+        Object... args) throws Exception {
+        GridJavaProcess proc = nodes.get(nodeName);
+
+        OutputStream os = proc.getProcess().getOutputStream();
+
+        String argsAsStr = "";
+
+        for (Object arg : args)
+            argsAsStr += arg.toString();
+
+        OutputStreamWriter writer = new OutputStreamWriter(os);
+        
+        writer.write(IgniteNodeRunner.EXECUTE_TASK + taskCls.getName() + IgniteNodeRunner.TASK_ARGS
+ argsAsStr + '\n');
+        
+        writer.flush();
+
+        // Wait for finish.
+        Thread.sleep(3_000);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6ea7f3df/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/PutInCache.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/PutInCache.java
b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/PutInCache.java
new file mode 100644
index 0000000..9cc9c0d
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/PutInCache.java
@@ -0,0 +1,36 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.internal.multijvm;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.util.typedef.*;
+
+/**
+ * TODO: Add class description.
+ *
+ * @author @java.author
+ * @version @java.version
+ */
+public class PutInCache implements IgniteNodeRunner.Task {
+    /** {@inheritDoc} */
+    @Override public boolean execute(Ignite ignite, String... args) {
+        int cnt = Integer.valueOf(args[0]);
+        
+        IgniteCache<Integer, String> cache = ignite.cache(null);
+
+        for (int i = 1; i <= cnt; i++) {
+            cache.put(i, "val" + i);
+
+            X.println(">>>>> Put=" + "val" + i);
+        }
+
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6ea7f3df/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml
b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml
index 98e1a71..cbc4b40 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/multijvm/example-cache.xml
@@ -37,6 +37,8 @@
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd">
     <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="localHost" value="127.0.0.1"/>
+        
         <property name="cacheConfiguration">
             <list>
                 <!-- Partitioned cache example configuration (Atomic mode). -->


Mime
View raw message