Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C431C18E9B for ; Fri, 24 Jul 2015 17:32:08 +0000 (UTC) Received: (qmail 19134 invoked by uid 500); 24 Jul 2015 17:32:08 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 19104 invoked by uid 500); 24 Jul 2015 17:32:08 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 19095 invoked by uid 99); 24 Jul 2015 17:32:08 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2015 17:32:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 4407E1A76D6 for ; Fri, 24 Jul 2015 17:32:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id qqO8zreUNM8A for ; Fri, 24 Jul 2015 17:32:00 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id EC31E20C4B for ; Fri, 24 Jul 2015 17:31:58 +0000 (UTC) Received: (qmail 17119 invoked by uid 99); 24 Jul 2015 17:31:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2015 17:31:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1E2B0DFDE3; Fri, 24 Jul 2015 17:31:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Message-Id: <86e6b48164b5428695f41cb0ec19b7df@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-ignite git commit: Added test for reproducing problems during simultaneously Ignite instances stopping and cache requests executing Date: Fri, 24 Jul 2015 17:31:58 +0000 (UTC) Repository: incubator-ignite Updated Branches: refs/heads/master 58f4822b6 -> 0341759c2 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/master Commit: 0341759c2ce8bc342521e7a2a50fe333f06f5a13 Parents: 58f4822 Author: agura Authored: Fri Jul 24 20:27:03 2015 +0300 Committer: agura 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 futs; + + /** Alive grids. */ + private static Set 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(); + } + } +}