# sprint-2: Added tests for cache data loading during simultaneous grids start.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/ae11c586 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ae11c586 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ae11c586 Branch: refs/heads/ignite-409 Commit: ae11c586e950a76775ecc36f84ecdb44ddfe8bdf Parents: 3eca5e7 Author: Andrey Gura <ag...@gridgain.com> Authored: Wed Mar 18 16:39:32 2015 +0300 Committer: Andrey Gura <ag...@gridgain.com> Committed: Wed Mar 18 16:39:32 2015 +0300 ---------------------------------------------------------------------- ...GridCacheLoadingConcurrentGridStartTest.java | 154 +++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 1 + 2 files changed, 155 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ae11c586/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java new file mode 100644 index 0000000..ac47b88 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLoadingConcurrentGridStartTest.java @@ -0,0 +1,154 @@ +/* + * 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.cache.store.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; +import org.jetbrains.annotations.*; + +import javax.cache.*; +import javax.cache.configuration.*; +import javax.cache.integration.*; +import java.util.concurrent.*; + +import static org.apache.ignite.cache.CacheMode.*; + +/** + * Tests for cache data loading during simultaneous grids start. + */ +public class GridCacheLoadingConcurrentGridStartTest extends GridCommonAbstractTest { + /** Grids count */ + private static int GRIDS_CNT = 5; + + /** Keys count */ + private static int KEYS_CNT = 1_000_000; + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setCacheMode(PARTITIONED); + + ccfg.setBackups(1); + + CacheStore<Integer, String> store = new CacheStoreAdapter<Integer, String>() { + @Override public void loadCache(IgniteBiInClosure<Integer, String> f, Object... args) { + for (int i = 0; i < KEYS_CNT; i++) + f.apply(i, Integer.toString(i)); + } + + @Nullable @Override public String load(Integer i) throws CacheLoaderException { + return null; + } + + @Override public void write(Cache.Entry<? extends Integer, ? extends String> entry) throws CacheWriterException { + // No-op. + } + + @Override public void delete(Object o) throws CacheWriterException { + // No-op. + } + }; + + ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(store)); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * @throws Exception if failed + */ + public void testLoadCacheWithDataStreamer() throws Exception { + IgniteInClosure<Ignite> f = new IgniteInClosure<Ignite>() { + @Override public void apply(Ignite grid) { + try (IgniteDataStreamer<Integer, String> dataStreamer = grid.dataStreamer(null)) { + for (int i = 0; i < KEYS_CNT; i++) + dataStreamer.addData(i, Integer.toString(i)); + } + } + }; + + loadCache(f); + } + + /** + * @throws Exception if failed + */ + public void testLoadCacheFromStore() throws Exception { + loadCache(new IgniteInClosure<Ignite>() { + @Override public void apply(Ignite grid) { + grid.jcache(null).loadCache(null); + } + }); + } + + /** + * Loads cache using closure and asserts cache size. + * + * @param f cache loading closure + * @throws Exception if failed + */ + private void loadCache(IgniteInClosure<Ignite> f) throws Exception { + Ignite g0 = startGrid(0); + + IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Ignite>() { + @Override public Ignite call() throws Exception { + return startGridsMultiThreaded(1, GRIDS_CNT - 1); + } + }); + + try { + f.apply(g0); + } + finally { + fut.get(); + } + + assertCacheSize(); + } + + /** Asserts cache size. */ + private void assertCacheSize() { + IgniteCache<Integer, String> cache = grid(0).jcache(null); + + assertEquals(KEYS_CNT, cache.size(CachePeekMode.PRIMARY)); + + int total = 0; + + for (int i = 0; i < GRIDS_CNT; i++) + total += grid(i).jcache(null).localSize(CachePeekMode.PRIMARY); + + assertEquals(KEYS_CNT, total); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ae11c586/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index 2793550..9966c30 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -212,6 +212,7 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTest(new TestSuite(GridCacheDhtPreloadUnloadSelfTest.class)); suite.addTest(new TestSuite(GridCachePartitionedAffinityFilterSelfTest.class)); suite.addTest(new TestSuite(GridCachePartitionedPreloadLifecycleSelfTest.class)); +// suite.addTest(new TestSuite(GridCacheLoadingConcurrentGridStartTest.class)); TODO-ignite-500 suite.addTest(new TestSuite(GridCacheDhtPreloadDelayedSelfTest.class)); suite.addTest(new TestSuite(GridPartitionedBackupLoadSelfTest.class)); suite.addTest(new TestSuite(GridCachePartitionedLoadCacheSelfTest.class));