IGNITE-112 Moving test on new query API
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/df488d08 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/df488d08 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/df488d08 Branch: refs/heads/ignite-112 Commit: df488d08f6dd4f604d2eebfa15a8e31216e00975 Parents: 1cd077d Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Wed Jan 28 19:19:33 2015 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Thu Jan 29 13:28:58 2015 +0300 ---------------------------------------------------------------------- .../GridCacheFieldsQueryNoDataSelfTest.java | 82 - .../cache/GridCacheQueryIndexSelfTest.java | 124 -- .../IgniteCacheFieldsQueryNoDataSelfTest.java | 82 + .../cache/IgniteCacheQueryIndexSelfTest.java | 127 ++ ...hePartitionedQueryMultiThreadedSelfTest.java | 304 --- ...hePartitionedQueryMultiThreadedSelfTest.java | 305 +++ .../cache/GridCacheAbstractQuerySelfTest.java | 2092 ------------------ ...idCacheQueryEvictsMultiThreadedSelfTest.java | 28 - .../cache/GridCacheQueryLoadSelfTest.java | 458 ---- .../GridCacheQueryMultiThreadedSelfTest.java | 859 ------- ...QueryOffheapEvictsMultiThreadedSelfTest.java | 28 - ...dCacheQueryOffheapMultiThreadedSelfTest.java | 28 - .../GridCacheSqlQueryMultiThreadedSelfTest.java | 140 -- .../cache/GridIndexingWithNoopSwapSelfTest.java | 2 +- .../cache/IgniteCacheAbstractQuerySelfTest.java | 1781 +++++++++++++++ ...teCacheQueryEvictsMultiThreadedSelfTest.java | 28 + .../cache/IgniteCacheQueryLoadSelfTest.java | 321 +++ .../IgniteCacheQueryMultiThreadedSelfTest.java | 748 +++++++ ...QueryOffheapEvictsMultiThreadedSelfTest.java | 28 + ...eCacheQueryOffheapMultiThreadedSelfTest.java | 28 + ...gniteCacheSqlQueryMultiThreadedSelfTest.java | 136 ++ ...GridCacheAtomicNearEnabledQuerySelfTest.java | 38 - .../near/GridCacheAtomicQuerySelfTest.java | 38 - ...achePartitionedQueryP2PDisabledSelfTest.java | 34 - .../near/GridCachePartitionedQuerySelfTest.java | 479 ---- .../near/GridCacheQueryNodeRestartSelfTest.java | 224 -- ...niteCacheAtomicNearEnabledQuerySelfTest.java | 38 + .../near/IgniteCacheAtomicQuerySelfTest.java | 38 + ...achePartitionedQueryP2PDisabledSelfTest.java | 34 + .../IgniteCachePartitionedQuerySelfTest.java | 165 ++ .../IgniteCacheQueryNodeRestartSelfTest.java | 223 ++ ...CacheReplicatedQueryP2PDisabledSelfTest.java | 34 - .../GridCacheReplicatedQuerySelfTest.java | 683 ------ ...CacheReplicatedQueryP2PDisabledSelfTest.java | 34 + .../IgniteCacheReplicatedQuerySelfTest.java | 575 +++++ .../GridCacheLocalAtomicQuerySelfTest.java | 32 - .../local/GridCacheLocalQuerySelfTest.java | 106 - .../IgniteCacheLocalAtomicQuerySelfTest.java | 32 + .../local/IgniteCacheLocalQuerySelfTest.java | 82 + .../IgniteCacheQuerySelfTestSuite.java | 37 +- 40 files changed, 4824 insertions(+), 5831 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/df488d08/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheFieldsQueryNoDataSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheFieldsQueryNoDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheFieldsQueryNoDataSelfTest.java deleted file mode 100644 index 037fcb8..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheFieldsQueryNoDataSelfTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.query.*; -import org.apache.ignite.configuration.*; -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.junits.common.*; - -import java.util.*; - -import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; - -/** - * Test for local query on partitioned cache without data. - */ -public class GridCacheFieldsQueryNoDataSelfTest extends GridCommonAbstractTest { - /** IP finder. */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration cache = defaultCacheConfiguration(); - - cache.setCacheMode(PARTITIONED); - cache.setBackups(1); - cache.setWriteSynchronizationMode(FULL_SYNC); - - cfg.setCacheConfiguration(cache); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(disco); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopGrid(); - } - - /** - * @throws Exception If failed. - */ - public void testQuery() throws Exception { - CacheQuery<List<?>> qry = grid().cache(null).queries().createSqlFieldsQuery("select _VAL from Integer"); - - Collection<List<?>> res = qry.execute().get(); - - assert res != null; - assert res.isEmpty(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/df488d08/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java deleted file mode 100644 index dcd2acf..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.query.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.util.*; - -import static org.apache.ignite.cache.CacheMode.*; - -/** - * Tests for cache query index. - */ -public class GridCacheQueryIndexSelfTest extends GridCacheAbstractSelfTest { - /** Grid count. */ - private static final int GRID_CNT = 2; - - /** Entry count. */ - private static final int ENTRY_CNT = 10; - - /** {@inheritDoc} */ - @Override protected int gridCount() { - return GRID_CNT; - } - - /** {@inheritDoc} */ - @Override protected CacheMode cacheMode() { - return PARTITIONED; - } - - /** - * @throws Exception If failed. - */ - public void testWithoutStoreLoad() throws Exception { - GridCache<Integer, CacheValue> cache = grid(0).cache(null); - - for (int i = 0; i < ENTRY_CNT; i++) - cache.put(i, new CacheValue(i)); - - checkCache(cache); - checkQuery(cache, false); - } - - /** - * @throws Exception If failed. - */ - public void testWithStoreLoad() throws Exception { - for (int i = 0; i < ENTRY_CNT; i++) - putToStore(i, new CacheValue(i)); - - GridCache<Integer, CacheValue> cache0 = grid(0).cache(null); - - cache0.loadCache(null, 0); - - checkCache(cache0); - checkQuery(cache0, true); - } - - /** - * @param cache Cache. - * @throws Exception If failed. - */ - private void checkCache(CacheProjection<Integer,CacheValue> cache) throws Exception { - assert cache.entrySet().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); - assert cache.keySet().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); - assert cache.values().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); - assert cache.size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); - } - - /** - * @param cache Cache. - * @param backups Include backups flag. - * @throws Exception If failed. - */ - private void checkQuery(CacheProjection<Integer, CacheValue> cache, boolean backups) throws Exception { - CacheQuery<Map.Entry<Integer, CacheValue>> qry = cache.queries().createSqlQuery( - CacheValue.class, "val >= 5"); - - if (backups) - qry.includeBackups(true); - - Collection<Map.Entry<Integer, CacheValue>> queried = qry.execute().get(); - - assertEquals("Unexpected query result: " + queried, 5, queried.size()); - } - - /** - * Test cache value. - */ - private static class CacheValue { - @CacheQuerySqlField - private final int val; - - CacheValue(int val) { - this.val = val; - } - - int value() { - return val; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(CacheValue.class, this); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/df488d08/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheFieldsQueryNoDataSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheFieldsQueryNoDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheFieldsQueryNoDataSelfTest.java new file mode 100644 index 0000000..41d95e9 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheFieldsQueryNoDataSelfTest.java @@ -0,0 +1,82 @@ +/* + * 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; + +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +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.junits.common.*; + +import javax.cache.*; +import java.util.*; + +import static org.apache.ignite.cache.CacheMode.*; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; + +/** + * Test for local query on partitioned cache without data. + */ +public class IgniteCacheFieldsQueryNoDataSelfTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration cache = defaultCacheConfiguration(); + + cache.setCacheMode(PARTITIONED); + cache.setBackups(1); + cache.setWriteSynchronizationMode(FULL_SYNC); + + cfg.setCacheConfiguration(cache); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopGrid(); + } + + /** + * @throws Exception If failed. + */ + public void testQuery() throws Exception { + Collection<Cache.Entry<Object, Object>> res = grid().jcache(null) + .query(new QuerySqlPredicate<>("select _VAL from Integer")).getAll(); + + assert res != null; + assert res.isEmpty(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/df488d08/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java new file mode 100644 index 0000000..4a28ace --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java @@ -0,0 +1,127 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.internal.util.typedef.internal.*; + +import javax.cache.*; +import java.util.*; + +import static org.apache.ignite.cache.CacheMode.*; + +/** + * Tests for cache query index. + */ +public class IgniteCacheQueryIndexSelfTest extends GridCacheAbstractSelfTest { + /** Grid count. */ + private static final int GRID_CNT = 2; + + /** Entry count. */ + private static final int ENTRY_CNT = 10; + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return GRID_CNT; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** + * @throws Exception If failed. + */ + public void testWithoutStoreLoad() throws Exception { + IgniteCache<Integer, CacheValue> cache = grid(0).jcache(null); + + for (int i = 0; i < ENTRY_CNT; i++) + cache.put(i, new CacheValue(i)); + + checkCache(cache); + checkQuery(cache); + } + + /** + * @throws Exception If failed. + */ + public void testWithStoreLoad() throws Exception { + for (int i = 0; i < ENTRY_CNT; i++) + putToStore(i, new CacheValue(i)); + + IgniteCache<Integer, CacheValue> cache0 = grid(0).jcache(null); + + cache0.loadCache(null, 0); + + checkCache(cache0); + checkQuery(cache0); + } + + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void checkCache(IgniteCache<Integer, CacheValue> cache) throws Exception { + Map<Integer, CacheValue> map = new HashMap<>(); + + for (Cache.Entry<Integer, CacheValue> entry : cache) + map.put(entry.getKey(), entry.getValue()); + + assert map.entrySet().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + assert map.keySet().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + assert map.values().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + assert cache.size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + } + + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void checkQuery(IgniteCache<Integer, CacheValue> cache) throws Exception { + QueryCursor<Cache.Entry<Integer, CacheValue>> qry = + cache.query(new QuerySqlPredicate<Integer, CacheValue>("val >= 5")); + + Collection<Cache.Entry<Integer, CacheValue>> queried = qry.getAll(); + + assertEquals("Unexpected query result: " + queried, 5, queried.size()); + } + + /** + * Test cache value. + */ + private static class CacheValue { + @CacheQuerySqlField + private final int val; + + CacheValue(int val) { + this.val = val; + } + + int value() { + return val; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheValue.class, this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/df488d08/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedQueryMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedQueryMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedQueryMultiThreadedSelfTest.java deleted file mode 100644 index 1ff2317..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedQueryMultiThreadedSelfTest.java +++ /dev/null @@ -1,304 +0,0 @@ -/* - * 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.near; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.query.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.lang.*; -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.internal.util.tostring.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.cache.CacheAtomicityMode.*; -import static org.apache.ignite.cache.CacheDistributionMode.*; -import static org.apache.ignite.cache.CacheMode.*; - -/** - * Tests for partitioned cache queries. - */ -public class GridCachePartitionedQueryMultiThreadedSelfTest extends GridCommonAbstractTest { - /** */ - private static final boolean TEST_INFO = true; - - /** Number of test grids (nodes). Should not be less than 2. */ - private static final int GRID_CNT = 3; - - /** */ - private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - /** Don't start grid by default. */ - public GridCachePartitionedQueryMultiThreadedSelfTest() { - super(false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration c = super.getConfiguration(gridName); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(ipFinder); - - c.setDiscoverySpi(disco); - - CacheConfiguration cc = defaultCacheConfiguration(); - - cc.setCacheMode(PARTITIONED); - - // Query should be executed without ongoing transactions. - cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); - cc.setBackups(0); - cc.setPreloadMode(CachePreloadMode.SYNC); - cc.setAtomicityMode(TRANSACTIONAL); - cc.setDistributionMode(NEAR_PARTITIONED); - - c.setCacheConfiguration(cc); - - return c; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - assert GRID_CNT >= 2 : "Constant GRID_CNT must be greater than or equal to 2."; - - startGridsMultiThreaded(GRID_CNT); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - // Clean up all caches. - for (int i = 0; i < GRID_CNT; i++) - grid(i).cache(null).removeAll(F.<CacheEntry<Object, Object>>alwaysTrue()); - } - - /** {@inheritDoc} */ - @Override protected void info(String msg) { - if (TEST_INFO) - super.info(msg); - } - - /** - * JUnit. - * - * @throws Exception If failed. - */ - @SuppressWarnings({"TooBroadScope"}) - public void testLuceneAndSqlMultithreaded() throws Exception { - // ---------- Test parameters ---------- // - int luceneThreads = 10; - int sqlThreads = 10; - long duration = 10 * 1000; - final int logMod = 100; - - final Person p1 = new Person("Jon", 1500, "Master"); - final Person p2 = new Person("Jane", 2000, "Master"); - final Person p3 = new Person("Mike", 1800, "Bachelor"); - final Person p4 = new Person("Bob", 1900, "Bachelor"); - - final GridCache<UUID, Person> cache0 = grid(0).cache(null); - - cache0.put(p1.id(), p1); - cache0.put(p2.id(), p2); - cache0.put(p3.id(), p3); - cache0.put(p4.id(), p4); - - assertEquals(4, cache0.size()); - - assert grid(0).nodes().size() == GRID_CNT; - - final AtomicBoolean done = new AtomicBoolean(); - - final AtomicLong luceneCnt = new AtomicLong(); - - // Start lucene query threads. - IgniteFuture<?> futLucene = GridTestUtils.runMultiThreadedAsync(new CAX() { - @Override public void applyx() throws IgniteCheckedException { - while (!done.get()) { - CacheQuery<Map.Entry<UUID, Person>> masters = cache0.queries().createFullTextQuery( - Person.class, "Master"); - - Collection<Map.Entry<UUID, Person>> entries = masters.execute().get(); - - checkResult(entries, p1, p2); - - long cnt = luceneCnt.incrementAndGet(); - - if (cnt % logMod == 0) - info("Executed LUCENE queries: " + cnt); - } - } - }, luceneThreads, "LUCENE-THREAD"); - - final AtomicLong sqlCnt = new AtomicLong(); - - // Start sql query threads. - IgniteFuture<?> futSql = GridTestUtils.runMultiThreadedAsync(new CAX() { - @Override public void applyx() throws IgniteCheckedException { - while (!done.get()) { - CacheQuery<Map.Entry<UUID, Person>> bachelors = - cache0.queries().createSqlQuery(Person.class, "degree = 'Bachelor'"); - - Collection<Map.Entry<UUID, Person>> entries = bachelors.execute().get(); - - checkResult(entries, p3, p4); - - long cnt = sqlCnt.incrementAndGet(); - - if (cnt % logMod == 0) - info("Executed SQL queries: " + cnt); - } - } - }, sqlThreads, "SQL-THREAD"); - - Thread.sleep(duration); - - done.set(true); - - futLucene.get(); - futSql.get(); - } - - /** - * @param entries Queried result. - * @param persons Persons that should be in the result. - */ - private void checkResult(Iterable<Map.Entry<UUID, Person>> entries, Person... persons) { - for (Map.Entry<UUID, Person> entry : entries) { - assertEquals(entry.getKey(), entry.getValue().id()); - - assert F.<Person>asList(persons).contains(entry.getValue()); - } - } - - /** Test class. */ - private static class Person implements Externalizable { - /** */ - @GridToStringExclude - private UUID id = UUID.randomUUID(); - - /** */ - @CacheQuerySqlField - private String name; - - /** */ - @CacheQuerySqlField - private int salary; - - /** */ - @CacheQuerySqlField - @CacheQueryTextField - private String degree; - - /** Required by {@link Externalizable}. */ - public Person() { - // No-op. - } - - /** - * @param name Name. - * @param salary Salary. - * @param degree Degree. - */ - Person(String name, int salary, String degree) { - assert name != null; - assert salary > 0; - assert degree != null; - - this.name = name; - this.salary = salary; - this.degree = degree; - } - - /** @return Id. */ - UUID id() { - return id; - } - - /** @return Name. */ - String name() { - return name; - } - - /** @return Salary. */ - double salary() { - return salary; - } - - /** @return Degree. */ - String degree() { - return degree; - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - U.writeUuid(out, id); - U.writeString(out, name); - out.writeInt(salary); - U.writeString(out, degree); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - id = U.readUuid(in); - name = U.readString(in); - salary = in.readInt(); - degree = U.readString(in); - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return id.hashCode() + 31 * name.hashCode() + 31 * 31 * salary; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof Person)) - return false; - - Person that = (Person)obj; - - return that.id.equals(id) && that.name.equals(name) && that.salary == salary && that.degree.equals(degree); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(Person.class, this); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/df488d08/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedQueryMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedQueryMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedQueryMultiThreadedSelfTest.java new file mode 100644 index 0000000..db807cc --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedQueryMultiThreadedSelfTest.java @@ -0,0 +1,305 @@ +/* + * 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.near; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.lang.*; +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.internal.util.tostring.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; + +import javax.cache.*; +import java.io.*; +import java.util.*; +import java.util.concurrent.atomic.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheDistributionMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * Tests for partitioned cache queries. + */ +public class IgniteCachePartitionedQueryMultiThreadedSelfTest extends GridCommonAbstractTest { + /** */ + private static final boolean TEST_INFO = true; + + /** Number of test grids (nodes). Should not be less than 2. */ + private static final int GRID_CNT = 3; + + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** Don't start grid by default. */ + public IgniteCachePartitionedQueryMultiThreadedSelfTest() { + super(false); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration c = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + c.setDiscoverySpi(disco); + + CacheConfiguration cc = defaultCacheConfiguration(); + + cc.setCacheMode(PARTITIONED); + + // Query should be executed without ongoing transactions. + cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + cc.setBackups(0); + cc.setPreloadMode(CachePreloadMode.SYNC); + cc.setAtomicityMode(TRANSACTIONAL); + cc.setDistributionMode(NEAR_PARTITIONED); + + c.setCacheConfiguration(cc); + + return c; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + assert GRID_CNT >= 2 : "Constant GRID_CNT must be greater than or equal to 2."; + + startGridsMultiThreaded(GRID_CNT); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + // Clean up all caches. + for (int i = 0; i < GRID_CNT; i++) + grid(i).cache(null).removeAll(F.<CacheEntry<Object, Object>>alwaysTrue()); + } + + /** {@inheritDoc} */ + @Override protected void info(String msg) { + if (TEST_INFO) + super.info(msg); + } + + /** + * JUnit. + * + * @throws Exception If failed. + */ + @SuppressWarnings({"TooBroadScope"}) + public void testLuceneAndSqlMultithreaded() throws Exception { + // ---------- Test parameters ---------- // + int luceneThreads = 10; + int sqlThreads = 10; + long duration = 10 * 1000; + final int logMod = 100; + + final Person p1 = new Person("Jon", 1500, "Master"); + final Person p2 = new Person("Jane", 2000, "Master"); + final Person p3 = new Person("Mike", 1800, "Bachelor"); + final Person p4 = new Person("Bob", 1900, "Bachelor"); + + final IgniteCache<UUID, Person> cache0 = grid(0).jcache(null); + + cache0.put(p1.id(), p1); + cache0.put(p2.id(), p2); + cache0.put(p3.id(), p3); + cache0.put(p4.id(), p4); + + assertEquals(4, cache0.size()); + + assert grid(0).nodes().size() == GRID_CNT; + + final AtomicBoolean done = new AtomicBoolean(); + + final AtomicLong luceneCnt = new AtomicLong(); + + // Start lucene query threads. + IgniteFuture<?> futLucene = GridTestUtils.runMultiThreadedAsync(new CAX() { + @Override public void applyx() throws IgniteCheckedException { + while (!done.get()) { + QueryCursor<Cache.Entry<UUID, Person>> master = + cache0.query(new QueryTextPredicate<UUID, Person>("Master")); + + Collection<Cache.Entry<UUID, Person>> entries = master.getAll(); + + checkResult(entries, p1, p2); + + long cnt = luceneCnt.incrementAndGet(); + + if (cnt % logMod == 0) + info("Executed LUCENE queries: " + cnt); + } + } + }, luceneThreads, "LUCENE-THREAD"); + + final AtomicLong sqlCnt = new AtomicLong(); + + // Start sql query threads. + IgniteFuture<?> futSql = GridTestUtils.runMultiThreadedAsync(new CAX() { + @Override public void applyx() throws IgniteCheckedException { + while (!done.get()) { + QueryCursor<Cache.Entry<UUID, Person>> bachelors = + cache0.query(new QuerySqlPredicate<UUID, Person>("degree = 'Bachelor'")); + + Collection<Cache.Entry<UUID, Person>> entries = bachelors.getAll(); + + checkResult(entries, p3, p4); + + long cnt = sqlCnt.incrementAndGet(); + + if (cnt % logMod == 0) + info("Executed SQL queries: " + cnt); + } + } + }, sqlThreads, "SQL-THREAD"); + + Thread.sleep(duration); + + done.set(true); + + futLucene.get(); + futSql.get(); + } + + /** + * @param entries Queried result. + * @param persons Persons that should be in the result. + */ + private void checkResult(Iterable<Cache.Entry<UUID, Person>> entries, Person... persons) { + for (Cache.Entry<UUID, Person> entry : entries) { + assertEquals(entry.getKey(), entry.getValue().id()); + + assert F.<Person>asList(persons).contains(entry.getValue()); + } + } + + /** Test class. */ + private static class Person implements Externalizable { + /** */ + @GridToStringExclude + private UUID id = UUID.randomUUID(); + + /** */ + @CacheQuerySqlField + private String name; + + /** */ + @CacheQuerySqlField + private int salary; + + /** */ + @CacheQuerySqlField + @CacheQueryTextField + private String degree; + + /** Required by {@link Externalizable}. */ + public Person() { + // No-op. + } + + /** + * @param name Name. + * @param salary Salary. + * @param degree Degree. + */ + Person(String name, int salary, String degree) { + assert name != null; + assert salary > 0; + assert degree != null; + + this.name = name; + this.salary = salary; + this.degree = degree; + } + + /** @return Id. */ + UUID id() { + return id; + } + + /** @return Name. */ + String name() { + return name; + } + + /** @return Salary. */ + double salary() { + return salary; + } + + /** @return Degree. */ + String degree() { + return degree; + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + U.writeUuid(out, id); + U.writeString(out, name); + out.writeInt(salary); + U.writeString(out, degree); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + id = U.readUuid(in); + name = U.readString(in); + salary = in.readInt(); + degree = U.readString(in); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id.hashCode() + 31 * name.hashCode() + 31 * 31 * salary; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + if (obj == this) + return true; + + if (!(obj instanceof Person)) + return false; + + Person that = (Person)obj; + + return that.id.equals(id) && that.name.equals(name) && that.salary == salary && that.degree.equals(degree); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Person.class, this); + } + } +}