# Fix GridCachePartitionNotLoadedEventSelfTest.testPrimaryAndBackupDead()

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

Branch: refs/heads/ignite-646
Commit: 3ed184a720e14de48b5629aedcdf9db41f7e3720
Parents: 6b57db0
Author: sevdokimov <sevdoki...@gridgain.com>
Authored: Tue Apr 21 12:22:21 2015 +0300
Committer: sevdokimov <sevdoki...@gridgain.com>
Committed: Tue Apr 21 12:22:21 2015 +0300

----------------------------------------------------------------------
 ...ridCachePartitionNotLoadedEventSelfTest.java | 12 ++++-
 .../ignite/util/TestTcpCommunicationSpi.java    | 54 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3ed184a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java
index 9d16030..6da27d5 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java
@@ -27,6 +27,7 @@ import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.util.*;
 import org.eclipse.jetty.util.*;
 
 import java.util.*;
@@ -61,6 +62,8 @@ public class GridCachePartitionNotLoadedEventSelfTest extends 
GridCommonAbstract
             cfg.setNodeId(UUID.fromString(new String(chars)));
         }
 
+        cfg.setCommunicationSpi(new TestTcpCommunicationSpi());
+
         CacheConfiguration<Integer, Integer> cacheCfg = new 
CacheConfiguration<>();
 
         cacheCfg.setCacheMode(CacheMode.PARTITIONED);
@@ -105,8 +108,11 @@ public class GridCachePartitionNotLoadedEventSelfTest 
extends GridCommonAbstract
         assert jcache(0).containsKey(key);
         assert jcache(1).containsKey(key);
 
-        stopGrid(0);
-        stopGrid(1);
+        TestTcpCommunicationSpi.stop(ignite(0));
+        TestTcpCommunicationSpi.stop(ignite(1));
+
+        stopGrid(0, true);
+        stopGrid(1, true);
 
         awaitPartitionMapExchange();
 
@@ -132,6 +138,8 @@ public class GridCachePartitionNotLoadedEventSelfTest 
extends GridCommonAbstract
 
         assert jcache(0).containsKey(key);
 
+        TestTcpCommunicationSpi.stop(ignite(0));
+
         stopGrid(0, true);
 
         awaitPartitionMapExchange();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3ed184a7/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java
 
b/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java
new file mode 100644
index 0000000..ad2a262
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java
@@ -0,0 +1,54 @@
+/*
+ * 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.util;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.communication.tcp.*;
+
+/**
+ * TcpCommunicationSpi with additional features needed for tests.
+ */
+public class TestTcpCommunicationSpi extends TcpCommunicationSpi {
+    /** */
+    private volatile boolean stopped;
+
+    /** {@inheritDoc} */
+    @Override public void sendMessage(final ClusterNode node, final Message 
msg) throws IgniteSpiException {
+        if (stopped)
+            return;
+
+        super.sendMessage(node, msg);
+    }
+
+    /**
+     *
+     */
+    public void stop() {
+        stopped = true;
+    }
+
+    /**
+     * Stop SPI, messages will not send anymore.
+     */
+    public static void stop(Ignite ignite) {
+        
((TestTcpCommunicationSpi)ignite.configuration().getCommunicationSpi()).stop();
+    }
+}

Reply via email to