# ignite-sprint-4 Added test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bc025d98 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bc025d98 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bc025d98 Branch: refs/heads/ignite-646 Commit: bc025d986723729034f7433fdec5ed968f8baeac Parents: fddf2a3 Author: sboikov <sboi...@gridgain.com> Authored: Tue Apr 21 10:57:44 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Tue Apr 21 10:58:40 2015 +0300 ---------------------------------------------------------------------- .../IgniteCachePutGetRestartAbstractTest.java | 219 +++++++++++++++++++ ...iteCacheTxNearDisabledPutGetRestartTest.java | 30 +++ .../IgniteCacheFailoverTestSuite.java | 2 + 3 files changed, 251 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bc025d98/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePutGetRestartAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePutGetRestartAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePutGetRestartAbstractTest.java new file mode 100644 index 0000000..d2066ed --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePutGetRestartAbstractTest.java @@ -0,0 +1,219 @@ +/* + * 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.processors.cache.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.transactions.*; + +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; +import static org.apache.ignite.cache.CacheRebalanceMode.*; +import static org.apache.ignite.transactions.TransactionConcurrency.*; +import static org.apache.ignite.transactions.TransactionIsolation.*; + +/** + * Test for specific user scenario. + */ +public abstract class IgniteCachePutGetRestartAbstractTest extends IgniteCacheAbstractTest { + /** */ + private static final int ENTRY_CNT = 1000; + + /** */ + private Integer expVal = 0; + + /** */ + private final Object mux = new Object(); + + /** */ + private CountDownLatch latch = new CountDownLatch(1); + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 4; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + if (gridName.equals(getTestGridName(0))) + cfg.setClientMode(true); + + cfg.setPeerClassLoadingEnabled(false); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { + CacheConfiguration cfg = super.cacheConfiguration(gridName); + + cfg.setRebalanceMode(SYNC); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 5 * 60_000; + } + + /** + * @throws Exception If failed. + */ + public void testTxPutGetRestart() throws Exception { + final IgniteTransactions txs = ignite(0).transactions(); + + final IgniteCache<Integer, Integer> cache = jcache(0); + + updateCache(cache, txs); + + final AtomicBoolean stop = new AtomicBoolean(); + + IgniteInternalFuture<?> updateFut = GridTestUtils.runAsync(new Callable<Void>() { + @Override public Void call() throws Exception { + assertTrue(latch.await(30_000, TimeUnit.MILLISECONDS)); + + int iter = 0; + + while (!stop.get()) { + log.info("Start update: " + iter); + + synchronized (mux) { + updateCache(cache, txs); + } + + log.info("End update: " + iter++); + } + + log.info("Update iterations: " + iter); + + return null; + } + }); + + IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Void>() { + @Override public Void call() throws Exception { + assertTrue(latch.await(30_000, TimeUnit.MILLISECONDS)); + + while (!stop.get()) { + log.info("Stop node."); + + stopGrid(1); + + U.sleep(100); + + log.info("Start node."); + + startGrid(1); + + U.sleep(100); + } + + return null; + } + }); + + long endTime = System.currentTimeMillis() + 2 * 60_000; + + try { + int iter = 0; + + while (System.currentTimeMillis() < endTime) { + try { + log.info("Start get: " + iter); + + synchronized (mux) { + readCache(cache, txs); + } + + log.info("End get: " + iter++); + } + finally { + if (latch.getCount() > 0) + latch.countDown(); + } + } + + log.info("Get iterations: " + iter); + } + finally { + stop.set(true); + } + + updateFut.get(); + + restartFut.get(); + + readCache(cache, txs); + } + + /** + * @param cache Cache. + * @param txs Transactions. + */ + private void readCache(IgniteCache<Integer, Integer> cache, IgniteTransactions txs) { + try (Transaction tx = txs.txStart(OPTIMISTIC, REPEATABLE_READ)) { + for (int i = 0; i < ENTRY_CNT; i++) + assertEquals(expVal, cache.get(i)); + } + } + + /** + * @param cache Cache. + * @param txs Transactions. + */ + private void updateCache(IgniteCache<Integer, Integer> cache, IgniteTransactions txs) { + int val = expVal + 1; + + try { + try (Transaction tx = txs.txStart(OPTIMISTIC, REPEATABLE_READ)) { + for (int i = 0; i < ENTRY_CNT; i++) + cache.put(i, val); + + tx.commit(); + + expVal = val; + + log.info("Updated cache, new value: " + val); + } + } + catch (IgniteException e) { + log.error("Update failed: " + e, e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bc025d98/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheTxNearDisabledPutGetRestartTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheTxNearDisabledPutGetRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheTxNearDisabledPutGetRestartTest.java new file mode 100644 index 0000000..dd5fdca --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheTxNearDisabledPutGetRestartTest.java @@ -0,0 +1,30 @@ +/* + * 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.configuration.*; + +/** + * + */ +public class IgniteCacheTxNearDisabledPutGetRestartTest extends IgniteCachePutGetRestartAbstractTest { + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bc025d98/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java index bd33fd8..9c1c57c 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java @@ -60,6 +60,8 @@ public class IgniteCacheFailoverTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheAtomicNodeJoinTest.class); suite.addTestSuite(IgniteCacheTxNodeJoinTest.class); + suite.addTestSuite(IgniteCacheTxNearDisabledPutGetRestartTest.class); + return suite; } }