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 A28F410B61 for ; Thu, 3 Sep 2015 09:25:00 +0000 (UTC) Received: (qmail 20611 invoked by uid 500); 3 Sep 2015 09:24:55 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 20525 invoked by uid 500); 3 Sep 2015 09:24:55 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 20175 invoked by uid 99); 3 Sep 2015 09:24:55 -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; Thu, 03 Sep 2015 09:24:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 365F2E0061; Thu, 3 Sep 2015 09:24:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 03 Sep 2015 09:25:06 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [12/24] ignite git commit: Added test. Added test. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/67699564 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/67699564 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/67699564 Branch: refs/heads/master Commit: 67699564d594647236552450d362be1e04c3d476 Parents: 3aa9ea3 Author: sboikov Authored: Wed Sep 2 15:25:15 2015 +0300 Committer: sboikov Committed: Wed Sep 2 15:34:57 2015 +0300 ---------------------------------------------------------------------- .../CachePutAllFailoverAbstractTest.java | 110 ++++++++++++++----- ...gniteCachePutRetryTransactionalSelfTest.java | 42 ------- .../junits/common/GridCommonAbstractTest.java | 41 +++++++ 3 files changed, 123 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/67699564/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CachePutAllFailoverAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CachePutAllFailoverAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CachePutAllFailoverAbstractTest.java index 62fddda..f558ba0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CachePutAllFailoverAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CachePutAllFailoverAbstractTest.java @@ -17,7 +17,15 @@ package org.apache.ignite.internal.processors.cache.distributed; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.TreeMap; +import java.util.concurrent.Callable; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; @@ -29,14 +37,6 @@ import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.testframework.GridTestUtils; import org.jetbrains.annotations.NotNull; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.TreeMap; -import java.util.concurrent.Callable; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicBoolean; - import static org.apache.ignite.cache.CacheMode.PARTITIONED; /** @@ -85,21 +85,31 @@ public abstract class CachePutAllFailoverAbstractTest extends GridCacheAbstractS * @throws Exception If failed. */ public void testPutAllFailover() throws Exception { - testPutAllFailover(false); + testPutAllFailover(Test.PUT_ALL); + } + + /** + * @throws Exception If failed. + */ + public void testPutAllFailoverPessimisticTx() throws Exception { + if (atomicityMode() == CacheAtomicityMode.ATOMIC) + return; + + testPutAllFailover(Test.PUT_ALL_PESSIMISTIC_TX); } /** * @throws Exception If failed. */ public void testPutAllFailoverAsync() throws Exception { - testPutAllFailover(true); + testPutAllFailover(Test.PUT_ALL_ASYNC); } /** - * @param async If {@code true} tests asynchronous operation. + * @param test Test type * @throws Exception If failed. */ - private void testPutAllFailover(final boolean async) throws Exception { + private void testPutAllFailover(final Test test) throws Exception { final AtomicBoolean finished = new AtomicBoolean(); final long endTime = System.currentTimeMillis() + TEST_TIME; @@ -123,7 +133,7 @@ public abstract class CachePutAllFailoverAbstractTest extends GridCacheAbstractS try { IgniteCache cache0 = ignite(0).cache(null); - final IgniteCache cache = async ? cache0.withAsync() : cache0; + final IgniteCache cache = test == Test.PUT_ALL_ASYNC ? cache0.withAsync() : cache0; GridTestUtils.runMultiThreaded(new Callable() { @Override public Object call() throws Exception { @@ -142,10 +152,8 @@ public abstract class CachePutAllFailoverAbstractTest extends GridCacheAbstractS lastInfo = time; } - if (async) { - Collection> futs = new ArrayList<>(); - - for (int i = 0 ; i < 10; i++) { + switch (test) { + case PUT_ALL: { TreeMap map = new TreeMap<>(); for (int k = 0; k < 100; k++) @@ -153,23 +161,55 @@ public abstract class CachePutAllFailoverAbstractTest extends GridCacheAbstractS cache.putAll(map); - IgniteFuture fut = cache.future(); + break; + } + + case PUT_ALL_ASYNC: { + Collection> futs = new ArrayList<>(); - assertNotNull(fut); + for (int i = 0 ; i < 10; i++) { + TreeMap map = new TreeMap<>(); - futs.add(fut); + for (int k = 0; k < 100; k++) + map.put(new TestKey(rnd.nextInt(200)), new TestValue(iter)); + + cache.putAll(map); + + IgniteFuture fut = cache.future(); + + assertNotNull(fut); + + futs.add(fut); + } + + for (IgniteFuture fut : futs) + fut.get(); + + break; } - for (IgniteFuture fut : futs) - fut.get(); - } - else { - TreeMap map = new TreeMap<>(); + case PUT_ALL_PESSIMISTIC_TX: { + final TreeMap map = new TreeMap<>(); + + for (int k = 0; k < 100; k++) + map.put(new TestKey(rnd.nextInt(200)), new TestValue(iter)); + + doInTransaction(ignite(0), new Callable() { + @Override public Object call() throws Exception { + for (TestKey key : map.keySet()) + cache.get(key); + + cache.putAll(map); - for (int k = 0; k < 100; k++) - map.put(new TestKey(rnd.nextInt(200)), new TestValue(iter)); + return null; + } + }); - cache.putAll(map); + break; + } + + default: + assert false; } iter++; @@ -277,4 +317,18 @@ public abstract class CachePutAllFailoverAbstractTest extends GridCacheAbstractS return S.toString(TestValue.class, this); } } + + /** + * + */ + private enum Test { + /** */ + PUT_ALL, + + /** */ + PUT_ALL_ASYNC, + + /** */ + PUT_ALL_PESSIMISTIC_TX + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/67699564/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePutRetryTransactionalSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePutRetryTransactionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePutRetryTransactionalSelfTest.java index 997848b..7c66efc 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePutRetryTransactionalSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePutRetryTransactionalSelfTest.java @@ -24,7 +24,6 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; -import javax.cache.CacheException; import javax.cache.processor.EntryProcessorException; import javax.cache.processor.MutableEntry; import org.apache.ignite.Ignite; @@ -32,18 +31,12 @@ import org.apache.ignite.IgniteAtomicLong; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheEntryProcessor; -import org.apache.ignite.cluster.ClusterTopologyException; import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.testframework.GridTestUtils; -import org.apache.ignite.transactions.Transaction; -import org.apache.ignite.transactions.TransactionRollbackException; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; -import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; -import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; /** * @@ -171,41 +164,6 @@ public class IgniteCachePutRetryTransactionalSelfTest extends IgniteCachePutRetr } /** - * @param ignite Ignite instance. - * @param clo Closure. - * @return Result of closure execution. - * @throws Exception If failed. - */ - private T doInTransaction(Ignite ignite, Callable clo) throws Exception { - while (true) { - try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { - T res = clo.call(); - - tx.commit(); - - return res; - } - catch (CacheException e) { - if (e.getCause() instanceof ClusterTopologyException) { - ClusterTopologyException topEx = (ClusterTopologyException)e.getCause(); - - topEx.retryReadyFuture().get(); - } - else - throw e; - } - catch (ClusterTopologyException e) { - IgniteFuture fut = e.retryReadyFuture(); - - fut.get(); - } - catch (TransactionRollbackException ignore) { - // Safe to retry right away. - } - } - } - - /** * Callable to process inside transaction. */ private static class ProcessCallable implements Callable { http://git-wip-us.apache.org/repos/asf/ignite/blob/67699564/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java index 4d7e923..13ec665 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import javax.cache.Cache; @@ -47,6 +48,7 @@ import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cluster.ClusterGroup; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.cluster.ClusterTopologyException; import org.apache.ignite.compute.ComputeTask; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.CacheConfiguration; @@ -74,12 +76,16 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.testframework.junits.GridAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionRollbackException; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.cache.CacheMode.LOCAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheRebalanceMode.NONE; import static org.apache.ignite.internal.processors.cache.GridCacheUtils.isNearEnabled; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; /** * Super class for all common tests. @@ -986,4 +992,39 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest { idx++; } } + + /** + * @param ignite Ignite instance. + * @param clo Closure. + * @return Result of closure execution. + * @throws Exception If failed. + */ + protected T doInTransaction(Ignite ignite, Callable clo) throws Exception { + while (true) { + try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + T res = clo.call(); + + tx.commit(); + + return res; + } + catch (CacheException e) { + if (e.getCause() instanceof ClusterTopologyException) { + ClusterTopologyException topEx = (ClusterTopologyException)e.getCause(); + + topEx.retryReadyFuture().get(); + } + else + throw e; + } + catch (ClusterTopologyException e) { + IgniteFuture fut = e.retryReadyFuture(); + + fut.get(); + } + catch (TransactionRollbackException ignore) { + // Safe to retry right away. + } + } + } } \ No newline at end of file