ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [2/2] incubator-ignite git commit: Merge branch 'ignite-112' of https://git-wip-us.apache.org/repos/asf/incubator-ignite into ignite-sql-tests
Date Thu, 05 Feb 2015 00:42:52 GMT
Merge branch 'ignite-112' of https://git-wip-us.apache.org/repos/asf/incubator-ignite into ignite-sql-tests

Conflicts:
	modules/core/src/main/java/org/apache/ignite/IgniteCache.java
	modules/core/src/main/java/org/apache/ignite/cache/query/QueryCursor.java
	modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFieldsQuerySelfTest.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridIndexingWithNoopSwapSelfTest.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedFieldsQuerySelfTest.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedQuerySelfTest.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFieldsQuerySelfTest.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheReplicatedQuerySelfTest.java
	modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/00ab7854
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/00ab7854
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/00ab7854

Branch: refs/heads/ignite-sql-tests
Commit: 00ab785408d1f70edac83c41b138c4f3d7e382bf
Parents: f3a1aef 0a800b1
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu Feb 5 03:42:38 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu Feb 5 03:42:38 2015 +0300

----------------------------------------------------------------------
 .../GridCacheFieldsQueryNoDataSelfTest.java     |   82 -
 .../cache/GridCacheQueryIndexSelfTest.java      |  125 --
 .../IgniteCacheFieldsQueryNoDataSelfTest.java   |   82 +
 .../cache/IgniteCacheQueryIndexSelfTest.java    |  128 ++
 ...hePartitionedQueryMultiThreadedSelfTest.java |  308 ---
 ...hePartitionedQueryMultiThreadedSelfTest.java |  309 +++
 .../GridCacheAbstractFieldsQuerySelfTest.java   | 1305 -----------
 .../cache/GridCacheAbstractQuerySelfTest.java   | 2093 ------------------
 ...idCacheQueryEvictsMultiThreadedSelfTest.java |   28 -
 .../cache/GridCacheQueryLoadSelfTest.java       |  458 ----
 .../GridCacheQueryMultiThreadedSelfTest.java    |  859 -------
 ...QueryOffheapEvictsMultiThreadedSelfTest.java |   28 -
 ...dCacheQueryOffheapMultiThreadedSelfTest.java |   28 -
 .../GridCacheSqlQueryMultiThreadedSelfTest.java |  141 --
 .../cache/GridIndexingWithNoopSwapSelfTest.java |    1 +
 .../IgniteCacheAbstractFieldsQuerySelfTest.java |  761 +++++++
 .../cache/IgniteCacheAbstractQuerySelfTest.java | 1780 +++++++++++++++
 ...teCacheQueryEvictsMultiThreadedSelfTest.java |   28 +
 .../cache/IgniteCacheQueryLoadSelfTest.java     |  321 +++
 .../IgniteCacheQueryMultiThreadedSelfTest.java  |  748 +++++++
 ...QueryOffheapEvictsMultiThreadedSelfTest.java |   28 +
 ...eCacheQueryOffheapMultiThreadedSelfTest.java |   28 +
 ...gniteCacheSqlQueryMultiThreadedSelfTest.java |  137 ++
 .../GridCacheAtomicFieldsQuerySelfTest.java     |   65 -
 ...cheAtomicNearEnabledFieldsQuerySelfTest.java |   32 -
 ...GridCacheAtomicNearEnabledQuerySelfTest.java |   38 -
 .../near/GridCacheAtomicQuerySelfTest.java      |   38 -
 ...rtitionedFieldsQueryP2PDisabledSelfTest.java |   34 -
 ...GridCachePartitionedFieldsQuerySelfTest.java |  109 -
 ...achePartitionedQueryP2PDisabledSelfTest.java |   34 -
 .../near/GridCachePartitionedQuerySelfTest.java |  479 ----
 .../near/GridCacheQueryNodeRestartSelfTest.java |  227 --
 .../IgniteCacheAtomicFieldsQuerySelfTest.java   |   60 +
 ...cheAtomicNearEnabledFieldsQuerySelfTest.java |   32 +
 ...niteCacheAtomicNearEnabledQuerySelfTest.java |   38 +
 .../near/IgniteCacheAtomicQuerySelfTest.java    |   38 +
 ...rtitionedFieldsQueryP2PDisabledSelfTest.java |   34 +
 ...niteCachePartitionedFieldsQuerySelfTest.java |   60 +
 ...achePartitionedQueryP2PDisabledSelfTest.java |   34 +
 .../IgniteCachePartitionedQuerySelfTest.java    |  165 ++
 .../IgniteCacheQueryNodeRestartSelfTest.java    |  226 ++
 ...eplicatedFieldsQueryP2PDisabledSelfTest.java |   34 -
 .../GridCacheReplicatedFieldsQuerySelfTest.java |  157 --
 ...CacheReplicatedQueryP2PDisabledSelfTest.java |   34 -
 .../GridCacheReplicatedQuerySelfTest.java       |  683 ------
 ...eplicatedFieldsQueryP2PDisabledSelfTest.java |   34 +
 ...gniteCacheReplicatedFieldsQuerySelfTest.java |   80 +
 ...CacheReplicatedQueryP2PDisabledSelfTest.java |   34 +
 .../IgniteCacheReplicatedQuerySelfTest.java     |  579 +++++
 .../GridCacheLocalAtomicQuerySelfTest.java      |   32 -
 .../GridCacheLocalFieldsQuerySelfTest.java      |   38 -
 .../local/GridCacheLocalQuerySelfTest.java      |  106 -
 .../IgniteCacheLocalAtomicQuerySelfTest.java    |   32 +
 .../IgniteCacheLocalFieldsQuerySelfTest.java    |   38 +
 .../local/IgniteCacheLocalQuerySelfTest.java    |   83 +
 .../IgniteCacheQuerySelfTestSuite.java          |   51 +-
 56 files changed, 5943 insertions(+), 7621 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00ab7854/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheFieldsQueryNoDataSelfTest.java
----------------------------------------------------------------------
diff --cc modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheFieldsQueryNoDataSelfTest.java
index 0000000,41d95e9..f4bcda3
mode 000000,100644..100644
--- 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
@@@ -1,0 -1,82 +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.internal.processors.cache.query.*;
+ 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/00ab7854/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java
----------------------------------------------------------------------
diff --cc modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryIndexSelfTest.java
index 0000000,4a28ace..db62e62
mode 000000,100644..100644
--- 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
@@@ -1,0 -1,127 +1,128 @@@
+ /*
+  * 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.cache.query.annotations.*;
++import org.apache.ignite.internal.processors.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
++        @QuerySqlField
+         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/00ab7854/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --cc modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
index 0000000,0053ae3..c30c4dc
mode 000000,100644..100644
--- 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
@@@ -1,0 -1,305 +1,309 @@@
+ /*
+  * 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.cache.query.annotations.*;
+ import org.apache.ignite.configuration.*;
+ import org.apache.ignite.internal.*;
++import org.apache.ignite.internal.processors.cache.query.*;
+ 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.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 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.
+         IgniteInternalFuture<?> 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.
+         IgniteInternalFuture<?> 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
++        @QuerySqlField
+         private String name;
+ 
+         /** */
 -        @CacheQuerySqlField
++        @QuerySqlField
+         private int salary;
+ 
+         /** */
 -        @CacheQuerySqlField
 -        @CacheQueryTextField
++        @QuerySqlField
++        @QueryTextField
+         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/00ab7854/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridIndexingWithNoopSwapSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00ab7854/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
----------------------------------------------------------------------
diff --cc modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
index 0000000,96f903a..45cb021
mode 000000,100644..100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
@@@ -1,0 -1,1781 +1,1780 @@@
+ /*
+  * 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.GridCache;
 -import org.apache.ignite.cache.query.*;
++import org.apache.ignite.cache.query.annotations.*;
+ import org.apache.ignite.cache.store.*;
+ import org.apache.ignite.configuration.*;
+ import org.apache.ignite.events.*;
+ import org.apache.ignite.internal.*;
++import org.apache.ignite.internal.processors.cache.query.*;
++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.lang.*;
+ 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.spi.swapspace.file.*;
 -import org.apache.ignite.internal.processors.cache.query.*;
 -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 org.jdk8.backport.*;
+ import org.jetbrains.annotations.*;
+ 
+ import javax.cache.*;
+ import javax.cache.configuration.*;
+ import javax.cache.expiry.*;
+ import java.io.*;
+ import java.util.*;
+ import java.util.concurrent.*;
+ 
+ import static java.util.concurrent.TimeUnit.*;
 -import static org.apache.ignite.cache.query.CacheQueryType.*;
 -import static org.apache.ignite.events.IgniteEventType.*;
+ import static org.apache.ignite.cache.CacheAtomicityMode.*;
+ import static org.apache.ignite.cache.CacheDistributionMode.*;
+ import static org.apache.ignite.cache.CacheMode.*;
+ import static org.apache.ignite.cache.CachePreloadMode.*;
+ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
++import static org.apache.ignite.events.IgniteEventType.*;
++import static org.apache.ignite.internal.processors.cache.query.CacheQueryType.*;
+ import static org.junit.Assert.*;
+ 
+ /**
+  * Various tests for cache queries.
+  */
+ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstractTest {
+     /** Cache store. */
+     private static TestStore store = new TestStore();
+ 
+     /** */
+     private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+ 
+     /** */
+     private static final UUID subjId = UUID.fromString("8EB3B06D-0885-4B4A-9A54-02C93EF09B65");
+ 
+     /** */
+     protected Ignite ignite;
+ 
+     /**
+      * @return Grid count.
+      */
+     protected abstract int gridCount();
+ 
+     /**
+      * @return Cache mode.
+      */
+     protected abstract CacheMode cacheMode();
+ 
+     /**
+      * @return Atomicity mode.
+      */
+     protected CacheAtomicityMode atomicityMode() {
+         return TRANSACTIONAL;
+     }
+ 
+     /**
+      * @return Distribution.
+      */
+     protected CacheDistributionMode distributionMode() {
+         return NEAR_PARTITIONED;
+     }
+ 
+     /** {@inheritDoc} */
+     @SuppressWarnings("unchecked")
+     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+         IgniteConfiguration c = super.getConfiguration(gridName);
+ 
+         TcpDiscoverySpi disco = new TcpDiscoverySpi();
+ 
+         disco.setIpFinder(ipFinder);
+ 
+         c.setDiscoverySpi(disco);
+ 
 -        GridQueryConfiguration idxCfg = new GridQueryConfiguration();
++        IgniteQueryConfiguration idxCfg = new IgniteQueryConfiguration();
+ 
+         idxCfg.setIndexCustomFunctionClasses(SqlFunctions.class);
+ 
+         c.setQueryConfiguration(idxCfg);
+ 
+         // Otherwise noop swap space will be chosen on Windows.
+         c.setSwapSpaceSpi(new FileSwapSpaceSpi());
+ 
+         c.setMarshaller(new IgniteOptimizedMarshaller(false));
+ 
+         CacheConfiguration[] ccs = new CacheConfiguration[2];
+ 
+         for (int i = 0; i < ccs.length; i++) {
+             CacheConfiguration cc = defaultCacheConfiguration();
+ 
+             if (i > 0)
+                 cc.setName("c" + i);
+ 
+             cc.setCacheMode(cacheMode());
+             cc.setAtomicityMode(atomicityMode());
+             cc.setDistributionMode(gridName.startsWith("client") ? CLIENT_ONLY : distributionMode());
+             cc.setWriteSynchronizationMode(FULL_SYNC);
+             cc.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(store));
+             cc.setReadThrough(true);
+             cc.setWriteThrough(true);
+             cc.setLoadPreviousValue(true);
+             cc.setPreloadMode(SYNC);
+             cc.setSwapEnabled(true);
+             cc.setEvictNearSynchronized(false);
+ 
+             CacheQueryConfiguration qcfg = new CacheQueryConfiguration();
+ 
+             qcfg.setIndexPrimitiveKey(true);
+             qcfg.setIndexFixedTyping(true);
+ 
+             cc.setQueryConfiguration(qcfg);
+ 
+             // Explicitly set number of backups equal to number of grids.
+             if (cacheMode() == CacheMode.PARTITIONED)
+                 cc.setBackups(gridCount());
+ 
+             ccs[i] = cc;
+         }
+ 
+         c.setCacheConfiguration(ccs);
+ 
+         return c;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected void beforeTest() throws Exception {
+         ignite = startGridsMultiThreaded(gridCount());
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected void afterTest() throws Exception {
+         stopAllGrids();
+ 
+         store.reset();
+ 
+         ignite = null;
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testDifferentKeyTypes() throws Exception {
+         GridCache<Object, Object> cache = ignite.cache(null);
+ 
+         cache.putx("key", "value");
+ 
+         // Put the same value but for other key type.
+         // Operation should succeed but with warning log message.
+         cache.putx(1, "value");
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testDifferentValueTypes() throws Exception {
+         GridCache<Object, Object> cache = ignite.cache(null);
+ 
+         cache.putx("key", "value");
+ 
+         // Put value of different type but for the same key type.
+         // Operation should succeed but with warning log message.
+         cache.putx("key", 1);
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testStringType() throws Exception {
+         IgniteCache<String, String> cache = ignite.jcache(null);
+ 
+         cache.put("tst", "test");
+ 
+         QueryCursor<Cache.Entry<String, String>> qry = cache.query(new QuerySqlPredicate<String, String>("_val='test'"));
+ 
+         Cache.Entry<String, String> entry = F.first(qry.getAll());
+ 
+         assert entry != null;
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testIntegerType() throws Exception {
+         IgniteCache<String, Integer> cache = ignite.jcache(null);
+ 
+         String key = "k";
+ 
+         int val = 2;
+ 
+         cache.put(key, val);
+ 
+         QueryCursor<Cache.Entry<String, Integer>> qry =
+             cache.query(new QuerySqlPredicate<String, Integer>("select * from Integer where _key = 'k' and _val > 1"));
+ 
+         Cache.Entry<String, Integer> entry = F.first(qry.getAll());
+ 
+         assert entry != null;
+ 
+         assertEquals(Integer.valueOf(val), entry.getValue());
+     }
+ 
+     /**
+      * Tests UDFs.
+      *
+      * @throws IgniteCheckedException If failed.
+      */
+     public void testUserDefinedFunction() throws IgniteCheckedException {
+         // Without alias.
+         IgniteCache<Object, Object> cache = ignite.jcache(null);
+ 
+         QueryCursor<List<?>> qry = cache.queryFields(new QuerySqlPredicate<>("select square(1), square(2)"));
+ 
+         Collection<List<?>> res = qry.getAll();
+ 
+         assertEquals(gridCount(), res.size());
+ 
+         List<?> row = res.iterator().next();
+ 
+         assertEquals(1, row.get(0));
+         assertEquals(4, row.get(1));
+ 
+         // With alias.
+         qry = cache.queryFields(new QuerySqlPredicate<>("select _cube_(1), _cube_(2)"));
+ 
+         res = qry.getAll();
+ 
+         assertEquals(gridCount(), res.size());
+ 
+         row = res.iterator().next();
+ 
+         assertEquals(1, row.get(0));
+         assertEquals(8, row.get(1));
+ 
+         // Not registered.
+         final QueryCursor<List<?>> qry3 = cache.queryFields(new QuerySqlPredicate<>("select no()"));
+ 
+         GridTestUtils.assertThrows(
+             log,
+             new Callable<Object>() {
+                 @Override public Object call() throws Exception {
+                     qry3.getAll();
+ 
+                     return null;
+                 }
+             },
+             CacheException.class,
+             null
+         );
+     }
+ 
+     /**
+      * Expired entries are not included to result.
+      *
+      * @throws Exception If failed.
+      */
+     public void testExpiration() throws Exception {
+         ignite.jcache(null).
+             withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000))).put("key1", 1);
+ 
+         IgniteCache<String, Integer> cache = ignite.jcache(null);
+ 
+         QueryCursor<Cache.Entry<String, Integer>> qry = cache.query(new QuerySqlPredicate<String, Integer>("1=1"));
+ 
+         Cache.Entry<String, Integer> res = F.first(qry.getAll());
+ 
+         assertEquals(1, res.getValue().intValue());
+ 
+         U.sleep(1020);
+ 
+         res = F.first(qry.getAll());
+ 
+         assertNull(res);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testIllegalBounds() throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         cache.put(1, 1);
+         cache.put(2, 2);
+ 
+         QueryCursor<List<?>> qry = cache.queryFields(new QuerySqlPredicate<Integer, Integer>("_key between 2 and 1"));
+ 
+         assertTrue(qry.getAll().isEmpty());
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testComplexType() throws Exception {
+         IgniteCache<Key, GridCacheQueryTestValue> cache = ignite.jcache(null);
+ 
+         GridCacheQueryTestValue val1 = new GridCacheQueryTestValue();
+ 
+         val1.setField1("field1");
+         val1.setField2(1);
+         val1.setField3(1L);
+ 
+         GridCacheQueryTestValue val2 = new GridCacheQueryTestValue();
+ 
+         val2.setField1("field2");
+         val2.setField2(2);
+         val2.setField3(2L);
+         val2.setField6(null);
+ 
+         cache.put(new Key(100500), val1);
+         cache.put(new Key(100501), val2);
+ 
+         QueryCursor<Cache.Entry<Key, GridCacheQueryTestValue>> qry = cache
+             .query(new QuerySqlPredicate<Key, GridCacheQueryTestValue>(
+                     "fieldName='field1' and field2=1 and field3=1 and id=100500 and embeddedField2=11 and x=3"));
+ 
+         Cache.Entry<Key, GridCacheQueryTestValue> entry = F.first(qry.getAll());
+ 
+         assertNotNull(entry);
+         assertEquals(100500, entry.getKey().id);
+         assertEquals(val1, entry.getValue());
+     }
+ 
+     /**
+      * Complex key type.
+      */
+     private static class Key {
+         /** */
 -        @CacheQuerySqlField
++        @QuerySqlField
+         private final long id;
+ 
+         /**
+          * @param id Id.
+          */
+         private Key(long id) {
+             this.id = id;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public boolean equals(Object o) {
+             if (this == o)
+                 return true;
+ 
+             if (o == null || getClass() != o.getClass())
+                 return false;
+ 
+             Key key = (Key)o;
+ 
+             return id == key.id;
+ 
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public int hashCode() {
+             return (int)(id ^ (id >>> 32));
+         }
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testSelectQuery() throws Exception {
+         IgniteCache<String, String> cache = ignite.jcache(null);
+ 
+         cache.put("key", "value");
+ 
+         QueryCursor<Cache.Entry<String, String>> qry = cache.query(new QuerySqlPredicate<String, String>(
+             "select * from String"));
+ 
+         Iterator<Cache.Entry<String, String>> iter = qry.iterator();
+ 
+         assert iter != null;
+         assert iter.next() != null;
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testObjectQuery() throws Exception {
+         IgniteCache<Integer, ObjectValue> cache = ignite.jcache(null);
+ 
+         ObjectValue val = new ObjectValue("test", 0);
+ 
+         cache.put(1, val);
+ 
+         QueryCursor<Cache.Entry<Integer, ObjectValue>> qry =
+             cache.query(new QuerySqlPredicate<Integer, ObjectValue>("_val=?", val));
+ 
+         Iterator<Cache.Entry<Integer, ObjectValue>> iter = qry.iterator();
+ 
+         assert iter != null;
+ 
+         int expCnt = 1;
+ 
+         for (int i = 0; i < expCnt; i++)
+             assert iter.next() != null;
+ 
+         assert iter.next() == null;
+ 
+         qry = cache.query(new QueryTextPredicate<Integer, ObjectValue>("test"));
+ 
+         iter = qry.iterator();
+ 
+         assert iter != null;
+ 
+         for (int i = 0; i < expCnt; i++)
+             assert iter.next() != null;
+ 
+         assert iter.next() == null;
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testObjectQueryWithSwap() throws Exception {
+         IgniteCache<Integer, ObjectValue> cache = ignite.jcache(null);
+ 
+         boolean partitioned = cache.getConfiguration(CacheConfiguration.class).getCacheMode() == PARTITIONED;
+ 
+         int cnt = 10;
+ 
+         for (int i = 0; i < cnt; i++)
+             cache.put(i, new ObjectValue("test" + i, i));
+ 
+         for (Ignite g : G.allGrids()) {
+             GridCache<Integer, ObjectValue> c = g.cache(null);
+ 
+             for (int i = 0; i < cnt; i++) {
+                 if (i % 2 == 0) {
+                     assertNotNull(c.peek(i));
+ 
+                     c.evict(i); // Swap.
+ 
+                     if (!partitioned || c.affinity().mapKeyToNode(i).isLocal()) {
+                         ObjectValue peekVal = c.peek(i);
+ 
+                         assertNull("Non-null value for peek [key=" + i + ", val=" + peekVal + ']', peekVal);
+                     }
+                 }
+             }
+         }
+ 
+ 
+         QueryCursor<Cache.Entry<Integer, ObjectValue>> qry =
+             cache.query(new QuerySqlPredicate<Integer, ObjectValue>("intVal >= ? order by intVal", 0));
+ 
+         Iterator<Cache.Entry<Integer, ObjectValue>> iter = qry.iterator();
+ 
+         assert iter != null;
+ 
+         Collection<Integer> set = new HashSet<>(cnt);
+ 
+         Cache.Entry<Integer, ObjectValue> next;
+ 
+         while ((next = iter.next()) != null) {
+             ObjectValue v = next.getValue();
+ 
+             assert !set.contains(v.intValue());
+ 
+             set.add(v.intValue());
+         }
+ 
+         assert iter.next() == null;
+ 
+         assertEquals(cnt, set.size());
+ 
+         for (int i = 0; i < cnt; i++)
+             assert set.contains(i);
+ 
+         qry = cache.query(new QuerySqlPredicate<Integer, ObjectValue>("MOD(intVal, 2) = ? order by intVal", 0));
+ 
+         iter = qry.iterator();
+ 
+         assert iter != null;
+ 
+         set.clear();
+ 
+         while ((next = iter.next()) != null) {
+             ObjectValue v = next.getValue();
+ 
+             assert !set.contains(v.intValue());
+ 
+             set.add(v.intValue());
+         }
+ 
+         assert iter.next() == null;
+ 
+         assertEquals(cnt / 2, set.size());
+ 
+         for (int i = 0; i < cnt; i++)
+             if (i % 2 == 0)
+                 assert set.contains(i);
+             else
+                 assert !set.contains(i);
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testFullTextSearch() throws Exception {
+         IgniteCache<Integer, ObjectValue> cache = ignite.jcache(null);
+ 
+         // Try to execute on empty cache first.
+         QueryCursor<Cache.Entry<Integer, ObjectValue>> qry =
+             cache.query(new QuerySqlPredicate<Integer, ObjectValue>("full"));
+ 
+         assert qry.getAll().isEmpty();
+ 
+         qry = cache.query(new QuerySqlPredicate<Integer, ObjectValue>("full"));
+ 
+         assert qry.getAll().isEmpty();
+ 
+         // Now put indexed values into cache.
+         int key1 = 1;
+ 
+         ObjectValue val1 = new ObjectValue("test full text", 0);
+ 
+         cache.put(key1, val1);
+ 
+         int key2 = 2;
+ 
+         ObjectValue val2 = new ObjectValue("test full text more", 0);
+ 
+         cache.put(key2, val2);
+ 
+         qry = cache.query(new QuerySqlPredicate<Integer, ObjectValue>("full"));
+ 
+         Collection<Cache.Entry<Integer, ObjectValue>> res = qry.getAll();
+ 
+         assert res != null;
+ 
+         assert res.size() == 2;
+ 
+         qry = cache.query(new QuerySqlPredicate<Integer, ObjectValue>("full"));
+ 
+         res = qry.getAll();
+ 
+         assert res != null;
+         assert res.size() == 2;
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testRemoveIndex() throws Exception {
+         GridCache<Integer, ObjectValue> cache = ignite.cache(null);
+         GridCache<Integer, ObjectValue> cache1 = ignite.cache("c1");
+ 
+         ObjectValue val = new ObjectValue("test full text", 0);
+ 
+         int key = 1;
+ 
+         cache.putx(key, val);
+         cache1.putx(key, val);
+ 
+         GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) ignite).internalCache().context().queries();
+         GridCacheQueryManager<Object, Object> qryMgr1 = ((IgniteKernal) ignite).internalCache("c1").context().queries();
+ 
+         assert hasIndexTable(ObjectValue.class, qryMgr);
+         assert hasIndexTable(ObjectValue.class, qryMgr1);
+ 
+         assert qryMgr != null;
+ 
+         qryMgr.onUndeploy(ObjectValue.class.getClassLoader());
+ 
+         assert !hasIndexTable(ObjectValue.class, qryMgr);
+         assert hasIndexTable(ObjectValue.class, qryMgr1);
+ 
+         // Put again.
+         cache.putx(key, val);
+ 
+         assert hasIndexTable(ObjectValue.class, qryMgr);
+         assert hasIndexTable(ObjectValue.class, qryMgr1);
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testScanQuery() throws Exception {
+         IgniteCache<String, String> c1 = ignite.jcache(null);
+ 
+         c1.put("key", "value");
+ 
+         // Scan query.
+         QueryCursor<Cache.Entry<String, String>> qry = c1.query(new QueryPredicate<String, String>(){
+             @Override public boolean apply(Cache.Entry<String, String> stringStringEntry) {
+                 return true;
+             }
+         });
+ 
+         Iterator<Cache.Entry<String, String>> iter = qry.iterator();
+ 
+         assert iter != null;
+ 
+         int expCnt = 1;
+ 
+         for (int i = 0; i < expCnt; i++) {
+             Cache.Entry<String, String> e1 = iter.next();
+ 
+             assertEquals("key", e1.getKey());
+             assertEquals("value", e1.getValue());
+         }
+ 
+         assert iter.next() == null;
+     }
+ 
+     /**
+      * JUnit.
+      *
+      * @throws Exception In case of error.
+      */
+     public void testTwoObjectsTextSearch() throws Exception {
+         IgniteCache<Object, Object> c = ignite.jcache(null);
+ 
+         c.put(1, new ObjectValue("ObjectValue str", 1));
+         c.put("key", new ObjectValueOther("ObjectValueOther str"));
+ 
+         Collection<Cache.Entry<Object, Object>> res = c.query(new QueryTextPredicate<>("str")).getAll();
+ 
+         assert res != null;
+         int expCnt = 1;
+         assert res.size() == expCnt;
+         assert F.first(res).getValue().getClass() == ObjectValue.class;
+ 
+         res = c.query(new QueryTextPredicate<>("str")).getAll();
+ 
+         assert res != null;
+         assert res.size() == expCnt;
+         assert F.first(res).getValue().getClass() == ObjectValueOther.class;
+ 
+         res = c.query(new QueryTextPredicate<>("str")).getAll();
+ 
+         assert res != null;
+         assert res.size() == expCnt;
+         assert F.first(res).getValue().getClass() == ObjectValue.class;
+ 
+         res = c.query(new QueryTextPredicate<>("str")).getAll();
+ 
+         assert res != null;
+         assert res.size() == expCnt;
+         assert F.first(res).getValue().getClass() == ObjectValueOther.class;
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testEmptyObject() throws Exception {
+         IgniteCache<EmptyObject, EmptyObject> cache = ignite.jcache(null);
+ 
+         cache.put(new EmptyObject(1), new EmptyObject(2));
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             GridCacheQueryManager<Object, Object> qryMgr =
+                 ((IgniteKernal)grid(i)).internalCache().context().queries();
+ 
+             assert !hasIndexTable(EmptyObject.class, qryMgr);
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPrimitiveType() throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         cache.put(1, 1);
+         cache.put(2, 2);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new QuerySqlPredicate<Integer, Integer>("_val > 1"));
+ 
+         Collection<Cache.Entry<Integer, Integer>> res = q.getAll();
+ 
+         assertEquals(1, res.size());
+ 
+         for (Cache.Entry<Integer, Integer> e : res) {
+             assertEquals(2, (int)e.getKey());
+             assertEquals(2, (int)e.getValue());
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPaginationIteratorDefaultCache() throws Exception {
+         testPaginationIterator(null);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPaginationIteratorNamedCache() throws Exception {
+         testPaginationIterator("c1");
+     }
+ 
+     /**
+      * @param cacheName Cache name.
+      * @throws Exception If failed.
+      */
+     private void testPaginationIterator(@Nullable String cacheName) throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(cacheName);
+ 
+         for (int i = 0; i < 50; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q =
+             cache.query(new QuerySqlPredicate<Integer, Integer>("_key >= 0", 10, new Object[0]));
+ 
+         int cnt = 0;
+ 
+         for (Cache.Entry<Integer, Integer> e : q) {
+             assertTrue(e.getKey() >= 0 && e.getKey() < 50);
+             assertTrue(e.getValue() >= 0 && e.getValue() < 50);
+ 
+             cnt++;
+         }
+ 
+         assertEquals(50, cnt);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPaginationGetDefaultCache() throws Exception {
+         testPaginationGet(null);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPaginationGetNamedCache() throws Exception {
+         testPaginationGet("c1");
+     }
+ 
+     /**
+      * @param cacheName Cache name.
+      * @throws Exception If failed.
+      */
+     private void testPaginationGet(@Nullable String cacheName) throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(cacheName);
+ 
+         for (int i = 0; i < 50; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q =
+             cache.query(new QuerySqlPredicate<Integer, Integer>("_key >= 0", 10, new Object[0]));
+ 
+         List<Cache.Entry<Integer, Integer>> list = new ArrayList<>(q.getAll());
+ 
+         Collections.sort(list, new Comparator<Cache.Entry<Integer, Integer>>() {
+             @Override public int compare(Cache.Entry<Integer, Integer> e1, Cache.Entry<Integer, Integer> e2) {
+                 return e1.getKey().compareTo(e2.getKey());
+             }
+         });
+ 
+         for (int i = 0; i < 50; i++) {
+             Cache.Entry<Integer, Integer> e = list.get(i);
+ 
+             assertEquals(i, (int)e.getKey());
+             assertEquals(i, (int)e.getValue());
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testScanFilters() throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         for (int i = 0; i < 50; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new QueryPredicate<Integer, Integer>() {
+             @Override public boolean apply(Cache.Entry<Integer, Integer> e) {
+                 assertNotNull(e.getKey());
+                 assertNotNull(e.getValue());
+ 
+                 return e.getKey() >= 20 && e.getValue() < 40;
+             }
+         });
+ 
+         List<Cache.Entry<Integer, Integer>> list = new ArrayList<>(q.getAll());
+ 
+         Collections.sort(list, new Comparator<Cache.Entry<Integer, Integer>>() {
+             @Override public int compare(Cache.Entry<Integer, Integer> e1, Cache.Entry<Integer, Integer> e2) {
+                 return e1.getKey().compareTo(e2.getKey());
+             }
+         });
+ 
+         assertEquals(20, list.size());
+ 
+         for (int i = 20; i < 40; i++) {
+             Cache.Entry<Integer, Integer> e = list.get(i - 20);
+ 
+             assertEquals(i, (int)e.getKey());
+             assertEquals(i, (int)e.getValue());
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testEmptyGrid() throws Exception {
+         IgniteCache<String, Integer> cache = ignite.jcache(null);
+ 
+         String key = "k";
+ 
+         int val = 2;
+ 
+         cache.put(key, val);
+ 
+         QueryCursor<Cache.Entry<String, Integer>> qry = cache.query(new QuerySqlPredicate<String, Integer>(
+                 "select * from Integer where _key = 'k' and _val > 1"));
+ 
+         Cache.Entry<String, Integer> entry = F.first(qry.getAll());
+ 
+         assert entry != null;
+ 
+         assertEquals(Integer.valueOf(val), entry.getValue());
+     }
+ 
+     /**
+      * @throws IgniteCheckedException if failed.
+      */
+     public void testBadHashObjectKey() throws IgniteCheckedException {
+         IgniteCache<BadHashKeyObject, Integer> cache = ignite.jcache(null);
+ 
+         cache.put(new BadHashKeyObject("test_key1"), 9);
+         cache.put(new BadHashKeyObject("test_key0"), 1005001);
+         cache.put(new BadHashKeyObject("test_key1"), 7);
+ 
+         assertEquals(1005001, cache.query(new QuerySqlPredicate<BadHashKeyObject, Integer>("_key = ?",
+                 new BadHashKeyObject("test_key0"))).iterator().next().getValue().intValue());
+     }
+ 
+     /**
+      * @throws IgniteCheckedException if failed.
+      */
+     public void testTextIndexedKey() throws IgniteCheckedException {
+         IgniteCache<ObjectValue, Integer> cache = ignite.jcache(null);
+ 
+         cache.put(new ObjectValue("test_key1", 10), 19);
+         cache.put(new ObjectValue("test_key0", 11), 11005);
+         cache.put(new ObjectValue("test_key1", 12), 17);
+ 
+         assertEquals(11005,
+                 cache.query(new QueryTextPredicate<ObjectValue, Integer>("test_key0"))
+                         .iterator().next().getValue().intValue());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testAnonymousClasses() throws Exception {
+         IgniteCache<Integer, Object> cache = ignite.jcache(null);
+ 
+         Object val = new Object() {
 -            @CacheQuerySqlField
++            @QuerySqlField
+             private int field1 = 10;
+ 
+             @Override public String toString() {
+                 return "Test anonymous object.";
+             }
+         };
+ 
+         assertTrue(val.getClass().getName().endsWith("GridCacheAbstractQuerySelfTest$16"));
+ 
+         cache.put(1, val);
+ 
+         QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new QuerySqlPredicate<Integer, Object>("_key >= 0"));
+ 
+         Collection<Cache.Entry<Integer, Object>> res = q.getAll();
+ 
+         assertEquals(1, res.size());
+ 
+         QueryCursor<List<?>> fieldsRes = cache.queryFields(new QuerySqlPredicate<Integer, Object>(
+                 "select field1 from GridCacheAbstractQuerySelfTest_16"));
+ 
+         assertEquals(1, fieldsRes.getAll());
+ 
+         List<?> fields = F.first(fieldsRes.getAll());
+ 
+         assertEquals(1, fields.size());
+         assertEquals(10, fields.get(0));
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testTwoAnonymousClasses() throws Exception {
+         IgniteCache<Integer, Object> cache = ignite.jcache(null);
+ 
+         Object val1 = new Object() {
+             @Override public String toString() {
+                 return "Test anonymous object1.";
+             }
+         };
+ 
+         Object val2 = new Object() {
+             @Override public String toString() {
+                 return "Test anonymous object2.";
+             }
+         };
+ 
+         cache.put(1, val1);
+         cache.put(2, val2);
+ 
+         QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new QuerySqlPredicate<Integer, Object>("_key >= 0"));
+ 
+         Collection<Cache.Entry<Integer, Object>> res = q.getAll();
+ 
+         assertEquals(1, res.size());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOrderByOnly() throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         for (int i = 0; i < 10; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q =
+             cache.query(new QuerySqlPredicate<Integer, Integer>("_key >= 0"));
+ 
+         Collection<Cache.Entry<Integer, Integer>> res = q.getAll();
+ 
+         assertEquals(10, res.size());
+ 
+         if (cacheMode() != PARTITIONED) {
+             Iterator<Cache.Entry<Integer, Integer>> it = res.iterator();
+ 
+             for (Integer i = 0; i < 10; i++) {
+                 assertTrue(it.hasNext());
+ 
+                 Cache.Entry<Integer, Integer> e = it.next();
+ 
+                 assertEquals(i, e.getKey());
+                 assertEquals(i, e.getValue());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testLimitOnly() throws Exception {
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         for (int i = 0; i < 10; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q =
+                 cache.query(new QuerySqlPredicate<Integer, Integer>("_key >= 0"));
+ 
+         Collection<Cache.Entry<Integer, Integer>> res = q.getAll();
+ 
+         assertEquals(10, res.size());
+ 
+         if (cacheMode() != PARTITIONED) {
+             assertEquals(5, res.size());
+ 
+             Iterator<Cache.Entry<Integer, Integer>> it = res.iterator();
+ 
+             for (Integer i = 0; i < 5; i++) {
+                 assertTrue(it.hasNext());
+ 
+                 Cache.Entry<Integer, Integer> e = it.next();
+ 
+                 assertEquals(i, e.getKey());
+                 assertEquals(i, e.getValue());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testArray() throws Exception {
+         IgniteCache<Integer, ArrayObject> cache = ignite.jcache(null);
+ 
+         cache.put(1, new ArrayObject(new Long[]{1L, null, 3L}));
+         cache.put(2, new ArrayObject(new Long[] {4L, 5L, 6L}));
+ 
+         QueryCursor<Cache.Entry<Integer, ArrayObject>> q =
+             cache.query(new QuerySqlPredicate<Integer, ArrayObject>("array_contains(arr, cast(4 as long))"));
+ 
+         Collection<Cache.Entry<Integer, ArrayObject>> res = q.getAll();
+ 
+         assertEquals(1, res.size());
+ 
+         Cache.Entry<Integer, ArrayObject> e = F.first(res);
+ 
+         assertEquals(2, (int)e.getKey());
+         assertArrayEquals(new Long[]{4L, 5L, 6L}, e.getValue().arr);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testSqlQueryEvents() throws Exception {
+         testSqlQueryEvents(false);
+     }
+ 
+     /**
+      * @param customSubjId Use custom subject ID.
+      * @throws Exception If failed.
+      */
+     private void testSqlQueryEvents(final boolean customSubjId) throws Exception {
+         final Map<Integer, Integer> map = new ConcurrentHashMap8<>();
+         final CountDownLatch latch = new CountDownLatch(10);
+         final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryReadEvent;
+ 
+                     IgniteCacheQueryReadEvent<Integer, Integer> qe = (IgniteCacheQueryReadEvent<Integer, Integer>)evt;
+ 
+                     assertEquals(SQL, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertEquals("Integer", qe.className());
+                     assertEquals("_key >= ?", qe.clause());
+                     assertNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertArrayEquals(new Integer[] { 10 }, qe.arguments());
+ 
+                     map.put(qe.key(), qe.value());
+ 
+                     latch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_OBJECT_READ);
+ 
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryExecutedEvent;
+ 
+                     IgniteCacheQueryExecutedEvent qe = (IgniteCacheQueryExecutedEvent)evt;
+ 
+                     assertEquals(SQL, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertEquals("Integer", qe.className());
+                     assertEquals("_key >= ?", qe.clause());
+                     assertNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertArrayEquals(new Integer[] { 10 }, qe.arguments());
+ 
+                     execLatch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_EXECUTED);
+         }
+ 
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         for (int i = 0; i < 20; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q =
+             cache.query(new QuerySqlPredicate<Integer, Integer>("_key >= ?", 10));
+ 
+         if (customSubjId)
+             ((GridCacheQueryAdapter)q).subjectId(subjId);
+ 
+         q.getAll();
+ 
+         assert latch.await(1000, MILLISECONDS);
+         assert execLatch.await(1000, MILLISECONDS);
+ 
+         assertEquals(10, map.size());
+ 
+         for (int i = 10; i < 20; i++)
+             assertEquals(i, map.get(i).intValue());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testScanQueryEvents() throws Exception {
+         testScanQueryEvents(false);
+     }
+ 
+     /**
+      * @param customSubjId Use custom subject ID.
+      * @throws Exception If failed.
+      */
+     private void testScanQueryEvents(final boolean customSubjId) throws Exception {
+         final Map<Integer, Integer> map = new ConcurrentHashMap8<>();
+         final CountDownLatch latch = new CountDownLatch(10);
+         final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryReadEvent;
+ 
+                     IgniteCacheQueryReadEvent<Integer, Integer> qe = (IgniteCacheQueryReadEvent<Integer, Integer>)evt;
+ 
+                     assertEquals(SCAN, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertNull(qe.className());
+                     assertNull(null, qe.clause());
+                     assertNotNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertNull(qe.arguments());
+ 
+                     map.put(qe.key(), qe.value());
+ 
+                     latch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_OBJECT_READ);
+ 
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryExecutedEvent;
+ 
+                     IgniteCacheQueryExecutedEvent qe = (IgniteCacheQueryExecutedEvent)evt;
+ 
+                     assertEquals(SCAN, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertNull(qe.className());
+                     assertNull(null, qe.clause());
+                     assertNotNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertNull(qe.arguments());
+ 
+                     execLatch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_EXECUTED);
+         }
+ 
+         IgniteCache<Integer, Integer> cache = ignite.jcache(null);
+ 
+         for (int i = 0; i < 20; i++)
+             cache.put(i, i);
+ 
+         QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(
+             new QueryPredicate<Integer, Integer>() {
+                 @Override public boolean apply(Cache.Entry<Integer, Integer> e) {
+                     return e.getKey() >= 10;
+                 }
+             }
+         );
+ 
+         if (customSubjId)
+             ((GridCacheQueryAdapter)q).subjectId(subjId);
+ 
+         q.getAll();
+ 
+         assert latch.await(1000, MILLISECONDS);
+         assert execLatch.await(1000, MILLISECONDS);
+ 
+         assertEquals(10, map.size());
+ 
+         for (int i = 10; i < 20; i++)
+             assertEquals(i, map.get(i).intValue());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testTextQueryEvents() throws Exception {
+         testTextQueryEvents(false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     private void testTextQueryEvents(final boolean customSubjId) throws Exception {
+         final Map<Integer, Person> map = new ConcurrentHashMap8<>();
+         final CountDownLatch latch = new CountDownLatch(2);
+         final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryReadEvent;
+ 
+                     IgniteCacheQueryReadEvent<Integer, Person> qe = (IgniteCacheQueryReadEvent<Integer, Person>)evt;
+ 
+                     assertEquals(FULL_TEXT, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertEquals("Person", qe.className());
+                     assertEquals("White", qe.clause());
+                     assertNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertNull(qe.arguments());
+ 
+                     map.put(qe.key(), qe.value());
+ 
+                     latch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_OBJECT_READ);
+ 
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryExecutedEvent;
+ 
+                     IgniteCacheQueryExecutedEvent qe = (IgniteCacheQueryExecutedEvent)evt;
+ 
+                     assertEquals(FULL_TEXT, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertEquals("Person", qe.className());
+                     assertEquals("White", qe.clause());
+                     assertNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertNull(qe.arguments());
+ 
+                     execLatch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_EXECUTED);
+         }
+ 
+         IgniteCache<Integer, Person> cache = ignite.jcache(null);
+ 
+         cache.put(1, new Person("Bob White", 1000));
+         cache.put(2, new Person("Tom White", 1000));
+         cache.put(3, new Person("Mike Green", 1000));
+ 
+ 
+         QueryCursor<Cache.Entry<Integer, Person>> q = cache.query(new QueryTextPredicate<Integer, Person>("White"));
+ 
+         if (customSubjId)
+             ((GridCacheQueryAdapter)q).subjectId(subjId);
+ 
+         q.getAll();
+ 
+         assert latch.await(1000, MILLISECONDS);
+         assert execLatch.await(1000, MILLISECONDS);
+ 
+         assertEquals(2, map.size());
+ 
+         assertEquals("Bob White", map.get(1).name());
+         assertEquals("Tom White", map.get(2).name());
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testFieldsQueryEvents() throws Exception {
+         testFieldsQueryEvents(false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     private void testFieldsQueryEvents(final boolean customSubjId) throws Exception {
+         final Map<Integer, String> map = new ConcurrentHashMap8<>();
+         final CountDownLatch latch = new CountDownLatch(10);
+         final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryReadEvent;
+ 
+                     IgniteCacheQueryReadEvent qe = (IgniteCacheQueryReadEvent)evt;
+ 
+                     assertEquals(SQL_FIELDS, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertNull(qe.className());
+                     assertEquals("select _key, name from Person where salary > ?", qe.clause());
+                     assertNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertArrayEquals(new Integer[] { 10 }, qe.arguments());
+ 
+                     List<?> row = (List<?>)qe.row();
+ 
+                     map.put((Integer)row.get(0), (String)row.get(1));
+ 
+                     latch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_OBJECT_READ);
+ 
+             grid(i).events().localListen(new IgnitePredicate<IgniteEvent>() {
+                 @Override public boolean apply(IgniteEvent evt) {
+                     assert evt instanceof IgniteCacheQueryExecutedEvent;
+ 
+                     IgniteCacheQueryExecutedEvent qe = (IgniteCacheQueryExecutedEvent)evt;
+ 
+                     assertEquals(SQL_FIELDS, qe.queryType());
+                     assertNull(qe.cacheName());
+ 
+                     assertEquals(customSubjId ? subjId : grid(0).localNode().id(), qe.subjectId());
+ 
+                     assertNull(qe.className());
+                     assertEquals("select _key, name from Person where salary > ?", qe.clause());
+                     assertNull(qe.scanQueryFilter());
+                     assertNull(qe.continuousQueryFilter());
+                     assertArrayEquals(new Integer[] { 10 }, qe.arguments());
+ 
+                     execLatch.countDown();
+ 
+                     return true;
+                 }
+             }, EVT_CACHE_QUERY_EXECUTED);
+         }
+ 
+         IgniteCache<Integer, Person> cache = ignite.jcache(null);
+ 
+         for (int i = 1; i <= 20; i++)
+             cache.put(i, new Person("Person " + i, i));
+ 
+         QueryCursor<List<?>> q = cache
+             .queryFields(new QuerySqlPredicate<Integer, Person>("select _key, name from Person where salary > ?", 10));
+ 
+         if (customSubjId)
+             ((GridCacheQueryAdapter)q).subjectId(subjId);
+ 
+         q.getAll();
+ 
+         assert latch.await(1000, MILLISECONDS);
+         assert execLatch.await(1000, MILLISECONDS);
+ 
+         assertEquals(10, map.size());
+ 
+         for (int i = 11; i <= 20; i++)
+             assertEquals("Person " + i, map.get(i));
+     }
+ 
+     /**
+      * @param cls Class to check index table for.
+      * @param qryMgr Query manager.
+      * @return {@code true} if index has a table for given class.
+      * @throws IgniteCheckedException If failed.
+      */
+     private boolean hasIndexTable(Class<?> cls, GridCacheQueryManager<Object, Object> qryMgr) throws IgniteCheckedException {
+         return qryMgr.size(cls) != -1;
+     }
+ 
+     /**
+      *
+      */
+     private static class ArrayObject implements Serializable {
+         /** */
 -        @CacheQuerySqlField
++        @QuerySqlField
+         private Long[] arr;
+ 
+         /**
+          * @param arr Array.
+          */
+         private ArrayObject(Long[] arr) {
+             this.arr = arr;
+         }
+     }
+ 
+     /**
+      *
+      */
+     public static class Person implements Externalizable {
+         /** */
+         @GridToStringExclude
 -        @CacheQuerySqlField
++        @QuerySqlField
+         private UUID id = UUID.randomUUID();
+ 
+         /** */
 -        @CacheQuerySqlField
 -        @CacheQueryTextField
++        @QuerySqlField
++        @QueryTextField
+         private String name;
+ 
+         /** */
 -        @CacheQuerySqlField
++        @QuerySqlField
+         private int salary;
+ 
+         /** */
 -        @CacheQuerySqlField(index = true)
++        @QuerySqlField(index = true)
+         private int fake$Field;
+ 
+         /**
+          * Required by {@link Externalizable}.
+          */
+         public Person() {
+             // No-op.
+         }
+ 
+         /**
+          * @param name Name.
+          * @param salary Salary.
+          */
+         public Person(String name, int salary) {
+             assert name != null;
+             assert salary > 0;
+ 
+             this.name = name;
+             this.salary = salary;
+         }
+ 
+         /**
+          * @return Id.
+          */
+         public UUID id() {
+             return id;
+         }
+ 
+         /**
+          * @return Name.
+          */
+         public String name() {
+             return name;
+         }
+ 
+         /**
+          * @return Salary.
+          */
+         public double salary() {
+             return salary;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public void writeExternal(ObjectOutput out) throws IOException {
+             U.writeUuid(out, id);
+             U.writeString(out, name);
+             out.writeInt(salary);
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+             id = U.readUuid(in);
+             name = U.readString(in);
+             salary = in.readInt();
+         }
+ 
+         /** {@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;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public String toString() {
+             return S.toString(Person.class, this);
+         }
+     }
+ 
+     /**
+      * Test value object.
+      */
+     @SuppressWarnings("PublicInnerClass")
+     public static class ObjectValue implements Serializable {
+         /** String value. */
 -        @CacheQueryTextField
++        @QueryTextField
+         private String strVal;
+ 
+         /** Integer value. */
 -        @CacheQuerySqlField
++        @QuerySqlField
+         private int intVal;
+ 
+         /**
+          * Constructor.
+          *
+          * @param strVal String value.
+          * @param intVal Integer value.
+          */
+         ObjectValue(String strVal, int intVal) {
+             this.strVal = strVal;
+             this.intVal = intVal;
+         }
+ 
+         /**
+          * Gets value.
+          *
+          * @return Value.
+          */
+         public String getStringValue() {
+             return strVal;
+         }
+ 
+         /**
+          * @return Integer value.
+          */
+         public int intValue() {
+             return intVal;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public boolean equals(Object o) {
+             if (this == o)
+                 return true;
+ 
+             if (o == null || getClass() != o.getClass())
+                 return false;
+ 
+             ObjectValue other = (ObjectValue)o;
+ 
+             return strVal == null ? other.strVal == null : strVal.equals(other.strVal);
+ 
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public int hashCode() {
+             return strVal != null ? strVal.hashCode() : 0;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public String toString() {
+             return S.toString(ObjectValue.class, this);
+         }
+     }
+ 
+     /**
+      * Another test value object.
+      */
+     private static class ObjectValueOther {
+         /** Value. */
 -        @CacheQueryTextField
++        @QueryTextField
+         private String val;
+ 
+         /**
+          * @param val String value.
+          */
+         ObjectValueOther(String val) {
+             this.val = val;
+         }
+ 
+         /**
+          * Gets value.
+          *
+          * @return Value.
+          */
+         public String value() {
+             return val;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public boolean equals(Object o) {
+             if (this == o)
+                 return true;
+ 
+             if (o == null || getClass() != o.getClass())
+                 return false;
+ 
+             ObjectValueOther other = (ObjectValueOther)o;
+ 
+             return val == null ? other.val == null : val.equals(other.val);
+ 
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public int hashCode() {
+             return val != null ? val.hashCode() : 0;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public String toString() {
+             return S.toString(ObjectValueOther.class, this);
+         }
+     }
+ 
+     /**
+      * Empty test object.
+      */
+     @SuppressWarnings("UnusedDeclaration")
+     private static class EmptyObject {
+         /** */
+         private int val;
+ 
+         /**
+          * @param val Value.
+          */
+         private EmptyObject(int val) {
+             this.val = val;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public int hashCode() {
+             return val;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public boolean equals(Object o) {
+             if (this == o)
+                 return true;
+ 
+             if (!(o instanceof EmptyObject))
+                 return false;
+ 
+             EmptyObject that = (EmptyObject)o;
+ 
+             return val == that.val;
+         }
+     }
+ 
+     /**
+      *
+      */
+     private static class BadHashKeyObject implements Serializable {
+         /** */
 -        @CacheQuerySqlField(index = false)
++        @QuerySqlField(index = false)
+         private final String str;
+ 
+         /**
+          * @param str String.
+          */
+         private BadHashKeyObject(String str) {
+             this.str = str;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public boolean equals(Object o) {
+             if (this == o) return true;
+             if (o == null || getClass() != o.getClass()) return false;
+ 
+             BadHashKeyObject keyObj = (BadHashKeyObject) o;
+ 
+             return str.equals(keyObj.str);
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public int hashCode() {
+             return 10;
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public String toString() {
+             return S.toString(BadHashKeyObject.class, this);
+         }
+     }
+ 
+     /**
+      * Test store.
+      */
+     private static class TestStore extends CacheStoreAdapter<Object, Object> {
+         /** */
+         private Map<Object, Object> map = new ConcurrentHashMap<>();
+ 
+         /** */
+         void reset() {
+             map.clear();
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public Object load(Object key) {
+             return map.get(key);
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public void write(javax.cache.Cache.Entry<? extends Object, ? extends Object> e) {
+             map.put(e.getKey(), e.getValue());
+         }
+ 
+         /** {@inheritDoc} */
+         @Override public void delete(Object key) {
+             map.remove(key);
+         }
+     }
+ 
+     /**
+      * Functions for test.
+      */
+     @SuppressWarnings("PublicInnerClass")
+     public static class SqlFunctions {
+         /**
+          * @param x Argument.
+          * @return Square of given value.
+          */
 -        @CacheQuerySqlFunction
++        @QuerySqlFunction
+         public static int square(int x) {
+             return x * x;
+         }
+ 
+         /**
+          * @param x Argument.
+          * @return Cube of given value.
+          */
 -        @CacheQuerySqlFunction(alias = "_cube_")
++        @QuerySqlFunction(alias = "_cube_")
+         public static int cube(int x) {
+             return x * x * x;
+         }
+ 
+         /**
+          * Method which should not be registered.
+          * @return Nothing.
+          */
+         public static int no() {
+             throw new IllegalStateException();
+         }
+     }
+ }


Mime
View raw message