You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/07/30 09:26:57 UTC
[37/44] incubator-ignite git commit: Added test for reproducing
problems during simultaneously Ignite instances stopping and cache requests
executing
Added test for reproducing problems during simultaneously Ignite instances stopping and cache requests executing
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/0341759c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0341759c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0341759c
Branch: refs/heads/ignite-900
Commit: 0341759c2ce8bc342521e7a2a50fe333f06f5a13
Parents: 58f4822
Author: agura <ag...@gridgain.com>
Authored: Fri Jul 24 20:27:03 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Fri Jul 24 20:27:03 2015 +0300
----------------------------------------------------------------------
.../CacheGetFutureHangsSelfTest.java | 214 +++++++++++++++++++
1 file changed, 214 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0341759c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
new file mode 100644
index 0000000..e2acb2e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
@@ -0,0 +1,214 @@
+/*
+ * 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.internal.processors.cache.distributed;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.marshaller.optimized.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ * Test for reproducing problems during simultaneously Ignite instances stopping and cache requests executing.
+ */
+public class CacheGetFutureHangsSelfTest extends GridCommonAbstractTest {
+ /** Grid count. */
+ private static final int GRID_CNT = 8;
+
+ /** Grids. */
+ private static Ignite[] grids;
+
+ /** Ids. */
+ private static String[] ids;
+
+ /** Flags. */
+ private static AtomicBoolean[] flags;
+
+ /** Futs. */
+ private static Collection<IgniteInternalFuture> futs;
+
+ /** Alive grids. */
+ private static Set<Integer> aliveGrids;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ OptimizedMarshaller marsh = new OptimizedMarshaller();
+ marsh.setRequireSerializable(false);
+
+ cfg.setMarshaller(marsh);
+
+ CacheConfiguration ccfg = defaultCacheConfiguration();
+ ccfg.setCacheMode(CacheMode.PARTITIONED);
+ ccfg.setBackups(1);
+ ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+ ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
+ ccfg.setNearConfiguration(null);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ return cfg;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFailover() throws Exception {
+ int cnt = 10;
+
+ for (int i = 0; i < cnt; i++) {
+ try {
+ U.debug("*** Iteration " + (i + 1) + '/' + cnt);
+
+ init();
+
+ doTestFailover();
+ }
+ finally {
+ stopAllGrids();
+ }
+ }
+ }
+
+ /**
+ * Initializes test.
+ */
+ private void init() {
+ grids = new Ignite[GRID_CNT + 1];
+
+ ids = new String[GRID_CNT + 1];
+
+ aliveGrids = new HashSet<>();
+
+ flags = new AtomicBoolean[GRID_CNT + 1];
+
+ futs = new ArrayList<>();
+ }
+
+ /**
+ * Executes one test iteration.
+ */
+ private void doTestFailover() throws Exception {
+ try {
+ for (int i = 0; i < GRID_CNT + 1; i++) {
+ final IgniteEx grid = startGrid(i);
+
+ grids[i] = grid;
+
+ ids[i] = grid.localNode().id().toString();
+
+ aliveGrids.add(i);
+
+ flags[i] = new AtomicBoolean();
+ }
+
+ for (int i = 0; i < GRID_CNT + 1; i++) {
+ final int gridIdx = i;
+
+ futs.add(multithreadedAsync(new Runnable() {
+ @Override public void run() {
+ IgniteCache cache = grids[gridIdx].cache(null);
+
+ while (!flags[gridIdx].get()) {
+ int idx = ThreadLocalRandom.current().nextInt(GRID_CNT + 1);
+
+ String id = ids[idx];
+
+ if (id != null /*&& grids[gridIdx] != null*/) {
+ //U.debug("!!! Grid containsKey start " + gridIdx);
+ cache.containsKey(id);
+ //U.debug("!!! Grid containsKey finished " + gridIdx);
+ }
+
+ try {
+ Thread.sleep(ThreadLocalRandom.current().nextLong(50));
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }, 1, "containsKey-thread-" + i));
+
+ futs.add(multithreadedAsync(new Runnable() {
+ @Override public void run() {
+ IgniteCache cache = grids[gridIdx].cache(null);
+
+ while (!flags[gridIdx].get()) {
+ int idx = ThreadLocalRandom.current().nextInt(GRID_CNT + 1);
+
+ String id = ids[idx];
+
+ if (id != null /*&& grids[gridIdx] != null*/) {
+ //U.debug("!!! Grid put start " + gridIdx);
+ cache.put(id, UUID.randomUUID());
+ //U.debug("!!! Grid put finished " + gridIdx);
+ }
+
+ try {
+ Thread.sleep(ThreadLocalRandom.current().nextLong(50));
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }, 1, "put-thread-" + i));
+ }
+
+ while (aliveGrids.size() > 1) {
+ final int gridToKill = ThreadLocalRandom.current().nextInt(GRID_CNT) + 1;
+
+ if (gridToKill > 0 && grids[gridToKill] != null) {
+ U.debug("!!! Trying to kill grid " + gridToKill);
+
+ //synchronized (mons[gridToKill]) {
+ U.debug("!!! Grid stop start " + gridToKill);
+
+ grids[gridToKill].close();
+
+ aliveGrids.remove(gridToKill);
+
+ grids[gridToKill] = null;
+
+ flags[gridToKill].set(true);
+
+ U.debug("!!! Grid stop finished " + gridToKill);
+ //}
+ }
+ }
+
+ Thread.sleep(ThreadLocalRandom.current().nextLong(100));
+ }
+ finally {
+ flags[0].set(true);
+
+ for (IgniteInternalFuture fut : futs)
+ fut.get();
+ }
+ }
+}