You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/04/03 15:00:56 UTC

ignite git commit: IGNITE-8071 Failure handlers tests are added

Repository: ignite
Updated Branches:
  refs/heads/master 69da4bd3b -> a8356c25d


IGNITE-8071 Failure handlers tests are added

Signed-off-by: Andrey Gura <ag...@apache.org>


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

Branch: refs/heads/master
Commit: a8356c25d078c8d3ff4a1ff2fc8f48971bd070ab
Parents: 69da4bd
Author: Dmitriy Sorokin <sb...@gmail.com>
Authored: Tue Apr 3 17:54:21 2018 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Tue Apr 3 17:54:21 2018 +0300

----------------------------------------------------------------------
 .../failure/FailureHandlerTriggeredTest.java    | 131 +++++++++++++++++++
 .../failure/StopNodeFailureHandlerTest.java     |  74 +++++++++++
 .../StopNodeOrHaltFailureHandlerTest.java       | 100 ++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |  11 +-
 4 files changed, 314 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a8356c25/modules/core/src/test/java/org/apache/ignite/failure/FailureHandlerTriggeredTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/failure/FailureHandlerTriggeredTest.java b/modules/core/src/test/java/org/apache/ignite/failure/FailureHandlerTriggeredTest.java
new file mode 100644
index 0000000..4e4d75a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/failure/FailureHandlerTriggeredTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.failure;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
+import org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask;
+import org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager;
+import org.apache.ignite.internal.processors.query.schema.SchemaExchangeWorkerTask;
+import org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test of triggering of failure handler.
+ */
+public class FailureHandlerTriggeredTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFailureHandlerTriggeredOnExchangeWorkerTermination() throws Exception {
+        try {
+            CountDownLatch latch = new CountDownLatch(1);
+
+            TestFailureHandler hnd = new TestFailureHandler(false, latch);
+
+            IgniteEx ignite = startGrid(getConfiguration().setFailureHandler(hnd));
+
+            GridCachePartitionExchangeManager<Object, Object> exchangeMgr = ignite.context().cache().context().exchange();
+
+            GridWorker exchangeWorker =
+                GridTestUtils.getFieldValue(exchangeMgr, GridCachePartitionExchangeManager.class, "exchWorker");
+
+            assertNotNull(exchangeWorker);
+
+            GridTestUtils.invoke(exchangeWorker, "addCustomTask", new ExchangeWorkerFailureTask());
+
+            assertTrue(latch.await(2000, TimeUnit.MILLISECONDS));
+
+            assertNotNull(hnd.failureCtx);
+
+            assertEquals(hnd.failureCtx.type(), FailureType.SYSTEM_WORKER_TERMINATION);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * Test failure handler implementation
+     */
+    private class TestFailureHandler implements FailureHandler {
+        /** Invalidate. */
+        private final boolean invalidate;
+
+        /** Latch. */
+        private final CountDownLatch latch;
+
+        /** Failure context. */
+        volatile FailureContext failureCtx;
+
+        /**
+         * @param invalidate Invalidate.
+         * @param latch Latch.
+         */
+        TestFailureHandler(boolean invalidate, CountDownLatch latch) {
+            this.invalidate = invalidate;
+            this.latch = latch;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean onFailure(Ignite ignite, FailureContext failureCtx) {
+            this.failureCtx = failureCtx;
+
+            this.latch.countDown();
+
+            ignite.log().warning("Handled ignite failure: " + failureCtx);
+
+            return invalidate;
+        }
+    }
+
+    /**
+     * Custom exchange worker task implementation for delaying exchange worker processing.
+     */
+    static class ExchangeWorkerFailureTask extends SchemaExchangeWorkerTask implements CachePartitionExchangeWorkerTask {
+        /**
+         * Default constructor.
+         */
+        ExchangeWorkerFailureTask() {
+            super(new SchemaAbstractDiscoveryMessage(null) {
+                @Override public boolean exchange() {
+                    return false;
+                }
+
+                @Nullable @Override public DiscoveryCustomMessage ackMessage() {
+                    return null;
+                }
+
+                @Override public boolean isMutable() {
+                    return false;
+                }
+            });
+        }
+
+        /** {@inheritDoc} */
+        public SchemaAbstractDiscoveryMessage message() {
+            throw new Error("Exchange worker termination");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8356c25/modules/core/src/test/java/org/apache/ignite/failure/StopNodeFailureHandlerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/failure/StopNodeFailureHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/failure/StopNodeFailureHandlerTest.java
new file mode 100644
index 0000000..fb75aae
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/failure/StopNodeFailureHandlerTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.failure;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.IgniteState;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.util.typedef.PE;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * {@link StopNodeFailureHandler} tests.
+ */
+public class StopNodeFailureHandlerTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected FailureHandler getFailureHandler(String igniteInstanceName) {
+        return igniteInstanceName.endsWith("1") ?
+            new StopNodeFailureHandler() :
+            new NoOpFailureHandler();
+    }
+
+    /**
+     * Tests node is stopped after triggering StopNodeFailureHandler.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNodeStopped() throws Exception {
+        try {
+            IgniteEx ignite0 = startGrid(0);
+            IgniteEx ignite1 = startGrid(1);
+
+            final CountDownLatch latch = new CountDownLatch(1);
+
+            ignite0.events().localListen(new PE() {
+                @Override public boolean apply(Event evt) {
+                    latch.countDown();
+
+                    return true;
+                }
+            }, EventType.EVT_NODE_LEFT);
+
+            ignite1.context().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, null));
+
+            assertTrue(latch.await(2000, TimeUnit.MILLISECONDS));
+
+            Thread.sleep(1000);
+
+            assertEquals(IgnitionEx.state(ignite0.name()), IgniteState.STARTED);
+            assertEquals(IgnitionEx.state(ignite1.name()), IgniteState.STOPPED_ON_FAILURE);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8356c25/modules/core/src/test/java/org/apache/ignite/failure/StopNodeOrHaltFailureHandlerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/failure/StopNodeOrHaltFailureHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/failure/StopNodeOrHaltFailureHandlerTest.java
new file mode 100644
index 0000000..da13b06
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/failure/StopNodeOrHaltFailureHandlerTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.failure;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.CA;
+import org.apache.ignite.internal.util.typedef.PE;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy;
+
+/**
+ * {@link StopNodeOrHaltFailureHandler} tests.
+ */
+public class StopNodeOrHaltFailureHandlerTest extends GridCommonAbstractTest {
+    /** Number of grids started for tests. */
+    public static final int NODES_CNT = 3;
+
+    /** {@inheritDoc} */
+    @Override protected boolean isMultiJvm() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(NODES_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected FailureHandler getFailureHandler(String igniteInstanceName) {
+        return igniteInstanceName.endsWith("2") ?
+            new StopNodeOrHaltFailureHandler(false, 0) :
+            new NoOpFailureHandler();
+    }
+
+    /**
+     * Tests failed node's JVM is halted after triggering StopNodeOrHaltFailureHandler.
+     */
+    public void testJvmHalted() throws Exception {
+        IgniteEx g = grid(0);
+        IgniteEx rmt1 = grid(1);
+        IgniteEx rmt2 = grid(2);
+
+        assertTrue(isMultiJvmObject(rmt1));
+        assertTrue(isMultiJvmObject(rmt2));
+
+        assertTrue(g.cluster().nodes().size() == NODES_CNT);
+
+        final CountDownLatch latch = new CountDownLatch(1);
+
+        g.events().localListen(new PE() {
+            @Override public boolean apply(Event evt) {
+                latch.countDown();
+
+                return true;
+            }
+        }, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED);
+
+        g.compute().broadcast(new CA() {
+            @IgniteInstanceResource
+            private Ignite ignite;
+
+            @Override public void apply() {
+                ((IgniteEx)ignite).context().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, null));
+            }
+        });
+
+        assertTrue(latch.await(2000, TimeUnit.MILLISECONDS));
+
+        Thread.sleep(1000);
+
+        assertTrue(((IgniteProcessProxy)rmt1).getProcess().getProcess().isAlive());
+        assertFalse(((IgniteProcessProxy)rmt2).getProcess().getProcess().isAlive());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8356c25/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 4472b68..dd9cdfd 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -20,6 +20,9 @@ package org.apache.ignite.testsuites;
 import java.util.Set;
 import junit.framework.TestSuite;
 import org.apache.ignite.GridSuppressedExceptionSelfTest;
+import org.apache.ignite.failure.FailureHandlerTriggeredTest;
+import org.apache.ignite.failure.StopNodeFailureHandlerTest;
+import org.apache.ignite.failure.StopNodeOrHaltFailureHandlerTest;
 import org.apache.ignite.internal.ClassSetTest;
 import org.apache.ignite.internal.ClusterGroupHostsSelfTest;
 import org.apache.ignite.internal.ClusterGroupSelfTest;
@@ -56,8 +59,8 @@ import org.apache.ignite.internal.processors.database.BPlusTreeFakeReuseSelfTest
 import org.apache.ignite.internal.processors.database.BPlusTreeReuseSelfTest;
 import org.apache.ignite.internal.processors.database.BPlusTreeSelfTest;
 import org.apache.ignite.internal.processors.database.CacheFreeListImplSelfTest;
-import org.apache.ignite.internal.processors.database.IndexStorageSelfTest;
 import org.apache.ignite.internal.processors.database.DataRegionMetricsSelfTest;
+import org.apache.ignite.internal.processors.database.IndexStorageSelfTest;
 import org.apache.ignite.internal.processors.database.SwapPathConstructionSelfTest;
 import org.apache.ignite.internal.processors.odbc.OdbcConfigurationValidationSelfTest;
 import org.apache.ignite.internal.processors.odbc.OdbcEscapeSequenceSelfTest;
@@ -65,7 +68,6 @@ import org.apache.ignite.internal.processors.service.ClosureServiceClientsNodesT
 import org.apache.ignite.internal.product.GridProductVersionSelfTest;
 import org.apache.ignite.internal.util.GridCleanerTest;
 import org.apache.ignite.internal.util.nio.IgniteExceptionInNioWorkerSelfTest;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.DynamicProxySerializationMultiJvmSelfTest;
 import org.apache.ignite.marshaller.MarshallerContextSelfTest;
 import org.apache.ignite.messaging.GridMessagingNoPeerClassLoadingSelfTest;
@@ -191,6 +193,11 @@ public class IgniteBasicTestSuite extends TestSuite {
 
         suite.addTestSuite(ClassSetTest.class);
 
+        // Basic failure handlers.
+        suite.addTestSuite(FailureHandlerTriggeredTest.class);
+        suite.addTestSuite(StopNodeFailureHandlerTest.class);
+        suite.addTestSuite(StopNodeOrHaltFailureHandlerTest.class);
+
         return suite;
     }
 }