You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/05/13 15:16:34 UTC

incubator-ignite git commit: # ignite-sprint-5 added test for IGNITE-882

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-sprint-5 22341a9ad -> 82467880e


# ignite-sprint-5 added test for IGNITE-882


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

Branch: refs/heads/ignite-sprint-5
Commit: 82467880eb18bbd16a26b92300b5212f37fe3200
Parents: 22341a9
Author: sboikov <sb...@gridgain.com>
Authored: Wed May 13 16:16:12 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed May 13 16:16:12 2015 +0300

----------------------------------------------------------------------
 .../discovery/tcp/TcpDiscoveryRestartTest.java  | 199 +++++++++++++++++++
 1 file changed, 199 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/82467880/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java
new file mode 100644
index 0000000..e6bee4a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryRestartTest.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.spi.discovery.tcp;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.eclipse.jetty.util.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.events.EventType.*;
+
+/**
+ *
+ */
+public class TcpDiscoveryRestartTest extends GridCommonAbstractTest {
+    /** */
+    private TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static AtomicReference<String> err;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi spi = new TcpDiscoverySpi();
+
+        spi.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(spi);
+
+        int[] evts = {EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT};
+
+        cfg.setIncludeEventTypes(evts);
+
+        Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
+
+        lsnrs.put(new TestEventListener(), evts);
+
+        cfg.setLocalEventListeners(lsnrs);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRestart() throws Exception {
+        err = new AtomicReference<>();
+
+        final int NODE_CNT = 3;
+
+        startGrids(NODE_CNT);
+
+        final ConcurrentHashSet<UUID> nodeIds = new ConcurrentHashSet<>();
+
+        final AtomicInteger id = new AtomicInteger(NODE_CNT);
+
+        final IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                int nodeIdx = id.getAndIncrement();
+
+                for (int i = 0; i < 10 && err.get() == null; i++) {
+                    Ignite ignite = startGrid(nodeIdx);
+
+                    UUID nodeId = ignite.cluster().localNode().id();
+
+                    if (!nodeIds.add(nodeId))
+                        failed("Duplicated node ID: " + nodeId);
+
+                    stopGrid(nodeIdx);
+                }
+
+                return null;
+            }
+        }, 5, "restart-thread");
+
+        IgniteInternalFuture<?> loadFut = GridTestUtils.runMultiThreadedAsync(new Callable<Long>() {
+            @Override public Long call() throws Exception {
+                long dummyRes = 0;
+
+                List<String> list = new ArrayList<>();
+
+                while (!fut.isDone()) {
+                    for (int i = 0; i < 100; i++) {
+                        String str = new String(new byte[i]);
+
+                        list.add(str);
+
+                        dummyRes += str.hashCode();
+                    }
+
+                    if (list.size() > 1000_000) {
+                        list = new ArrayList<>();
+
+                        System.gc();
+                    }
+                }
+
+                return dummyRes;
+            }
+        }, 2, "test-load");
+
+        fut.get();
+
+        loadFut.get();
+
+        assertNull(err.get());
+
+        for (int i = 0; i < NODE_CNT; i++) {
+            Ignite ignite = ignite(i);
+
+            TestEventListener lsnr = (TestEventListener)F.firstKey(ignite.configuration().getLocalEventListeners());
+
+            assertNotNull(lsnr);
+
+            for (UUID nodeId : nodeIds)
+                lsnr.checkEvents(nodeId);
+        }
+    }
+
+
+    /**
+     * @param msg Message.
+     */
+    private void failed(String msg) {
+        info(msg);
+
+        err.compareAndSet(null, msg);
+    }
+
+    /**
+     *
+     */
+    private class TestEventListener implements IgnitePredicate<Event> {
+        /** */
+        private final ConcurrentHashSet<UUID> joinIds = new ConcurrentHashSet<>();
+
+        /** */
+        private final ConcurrentHashSet<UUID> leftIds = new ConcurrentHashSet<>();
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(Event evt) {
+            DiscoveryEvent evt0 = (DiscoveryEvent)evt;
+
+            if (evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT) {
+                if (!leftIds.add(evt0.eventNode().id()))
+                    failed("Duplicated failed node ID: " + evt0.eventNode().id());
+            }
+            else {
+                assertEquals(EVT_NODE_JOINED, evt.type());
+
+                if (!joinIds.add(evt0.eventNode().id()))
+                    failed("Duplicated joined node ID: " + evt0.eventNode().id());
+            }
+
+            return true;
+        }
+
+        /**
+         * @param nodeId Node ID.
+         */
+        void checkEvents(UUID nodeId) {
+            assertTrue("No join event: " + nodeId, joinIds.contains(nodeId));
+
+            assertTrue("No left event: " + nodeId, leftIds.contains(nodeId));
+        }
+    }
+}