Repository: incubator-ignite Updated Branches: refs/heads/ignite-373 [created] 656ffc09d
#ignite-373: add 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/656ffc09 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/656ffc09 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/656ffc09 Branch: refs/heads/ignite-373 Commit: 656ffc09d99d58d2b42ec8e904659e6437fde10e Parents: 61808ed Author: ivasilinets <[email protected]> Authored: Thu May 7 18:22:25 2015 +0300 Committer: ivasilinets <[email protected]> Committed: Thu May 7 18:22:25 2015 +0300 ---------------------------------------------------------------------- .../CacheContinuousQueryRestartSelfTest.java | 145 +++++++++++++++++++ ...ridCacheContinuousQueryAbstractSelfTest.java | 35 ----- .../junits/common/GridCommonAbstractTest.java | 37 +++++ .../IgniteCacheQuerySelfTestSuite.java | 1 + 4 files changed, 183 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/656ffc09/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRestartSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRestartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRestartSelfTest.java new file mode 100644 index 0000000..039d184 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRestartSelfTest.java @@ -0,0 +1,145 @@ +/* + * 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.query.continuous; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; +import org.jsr166.*; + +import javax.cache.*; +import javax.cache.event.*; + +import java.util.*; +import java.util.concurrent.atomic.*; + +import static org.apache.ignite.cache.CacheRebalanceMode.*; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; + +/** + * Continuous queries test. + */ +public class CacheContinuousQueryRestartSelfTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** Grid count. */ + private static final int GRID_COUNT = 3; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration cacheCfg = defaultCacheConfiguration(); + + cacheCfg.setCacheMode(CacheMode.PARTITIONED); + cacheCfg.setBackups(2); + cacheCfg.setRebalanceMode(ASYNC); + cacheCfg.setWriteSynchronizationMode(FULL_SYNC); + cacheCfg.setReadThrough(true); + cacheCfg.setWriteThrough(true); + cacheCfg.setCacheStoreFactory(new StoreFactory()); + cacheCfg.setLoadPreviousValue(true); + + cfg.setCacheConfiguration(cacheCfg); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disco); + + cfg.setMarshaller(new OptimizedMarshaller(false)); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + startGrids(GRID_COUNT); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testNodeJoin() throws Exception { + final ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>(); + + final Collection<CacheEntryEvent<? extends Integer, ? extends Integer>> all = new ConcurrentLinkedDeque8<>(); + + qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() { + @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) { + for (CacheEntryEvent<? extends Integer, ? extends Integer> evt : evts) + all.add(evt); + } + }); + + final AtomicInteger id = new AtomicInteger(GRID_COUNT); + + final int keyCount = 1000; + + final Random random = new Random(keyCount); + + IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Runnable() { + @Override public void run() { + for (int i = 0; i < 2; ++i) { + IgniteCache cache = grid(0).cache(null); + + int gridId = id.getAndIncrement(); + + try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = grid(0).cache(null).query(qry)) { + cache.put(0, 0); + + startGrid(gridId); + + for (int j = 1; j < 40; j++) + cache.put(random.nextInt(), j); + } + catch (Exception e) { + throw new IgniteException(e); + } + } + } + }, 5, "QueryThread"); + + fut.get(); + + for (int i = 0; i < id.get(); i++) { + IgniteCache<Object, Object> cache = grid(i).cache(null); + + cache.removeAll(); + } + + for (int i = 0; i < GRID_COUNT; i++) + assertEquals("Cache is not empty [entrySet=" + grid(i).cache(null).localEntries() + + ", i=" + i + ']', 0, grid(i).cache(null).localSize()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/656ffc09/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java index 5a78f9f..d652cba 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java @@ -989,39 +989,4 @@ public abstract class GridCacheContinuousQueryAbstractSelfTest extends GridCommo } } } - - /** - * - */ - private static class StoreFactory implements Factory<CacheStore> { - @Override public CacheStore create() { - return new TestStore(); - } - } - - /** - * Store. - */ - private static class TestStore extends CacheStoreAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override public void loadCache(IgniteBiInClosure<Object, Object> clo, Object... args) { - for (int i = 0; i < 10; i++) - clo.apply(i, i); - } - - /** {@inheritDoc} */ - @Nullable @Override public Object load(Object key) { - return null; - } - - /** {@inheritDoc} */ - @Override public void write(javax.cache.Cache.Entry<?, ?> entry) throws CacheWriterException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void delete(Object key) throws CacheWriterException { - // No-op. - } - } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/656ffc09/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 5533897..8022a7a 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 @@ -20,6 +20,7 @@ package org.apache.ignite.testframework.junits.common; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.store.*; import org.apache.ignite.cluster.*; import org.apache.ignite.compute.*; import org.apache.ignite.configuration.*; @@ -38,6 +39,7 @@ import org.apache.ignite.testframework.junits.*; import org.jetbrains.annotations.*; import javax.cache.*; +import javax.cache.configuration.*; import javax.cache.integration.*; import javax.net.ssl.*; import java.util.*; @@ -858,4 +860,39 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest { ccfg.getAtomicWriteOrderMode() == CacheAtomicWriteOrderMode.CLOCK) U.sleep(50); } + + /** + * + */ + public static class StoreFactory implements Factory<CacheStore> { + @Override public CacheStore create() { + return new TestStore(); + } + } + + /** + * Store. + */ + public static class TestStore extends CacheStoreAdapter<Object, Object> { + /** {@inheritDoc} */ + @Override public void loadCache(IgniteBiInClosure<Object, Object> clo, Object... args) { + for (int i = 0; i < 10; i++) + clo.apply(i, i); + } + + /** {@inheritDoc} */ + @Nullable @Override public Object load(Object key) { + return null; + } + + /** {@inheritDoc} */ + @Override public void write(javax.cache.Cache.Entry<?, ?> entry) throws CacheWriterException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + // No-op. + } + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/656ffc09/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index 69d7548..da3bf5c 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -92,6 +92,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { suite.addTestSuite(GridCacheContinuousQueryAtomicSelfTest.class); suite.addTestSuite(GridCacheContinuousQueryAtomicNearEnabledSelfTest.class); suite.addTestSuite(GridCacheContinuousQueryAtomicP2PDisabledSelfTest.class); + suite.addTestSuite(CacheContinuousQueryRestartSelfTest.class); // Reduce fields queries. suite.addTestSuite(GridCacheReduceFieldsQueryLocalSelfTest.class);
