IGNITE-2190 - Fixing deserialization during scan query. - Fixes #355. Signed-off-by: Alexey Goncharuk <alexey.goncha...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/81458f51 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/81458f51 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/81458f51 Branch: refs/heads/ignite-843-rc2 Commit: 81458f51c40f58b169da178bd7a572d3c9fe01ff Parents: 2848680 Author: Alexey Goncharuk <alexey.goncha...@gmail.com> Authored: Mon Dec 21 18:54:38 2015 +0300 Committer: Alexey Goncharuk <alexey.goncha...@gmail.com> Committed: Mon Dec 21 18:54:38 2015 +0300 ---------------------------------------------------------------------- .../internal/binary/BinaryObjectImpl.java | 20 +- .../processors/cache/IgniteCacheProxy.java | 5 +- .../cache/query/GridCacheQueryManager.java | 8 +- .../processors/query/GridQueryProcessor.java | 10 +- .../IgniteCacheBinaryObjectsScanSelfTest.java | 137 +++++++++ .../cache/IgniteCacheAbstractQuerySelfTest.java | 300 +++++++++++++------ .../IgniteCacheReplicatedQuerySelfTest.java | 10 +- .../local/IgniteCacheLocalQuerySelfTest.java | 2 +- .../IgniteBinaryCacheQueryTestSuite.java | 2 + 9 files changed, 379 insertions(+), 115 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java index 2342766..d712eb8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java @@ -532,7 +532,8 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern * @return Object. */ private Object deserializeValue(@Nullable CacheObjectContext coCtx) { - BinaryReaderExImpl reader = reader(null); + BinaryReaderExImpl reader = reader(null, + coCtx != null ? coCtx.kernalContext().config().getClassLoader() : null); Object obj0 = reader.deserialize(); @@ -560,10 +561,23 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern * @param rCtx Reader context. * @return Reader. */ - private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) { + private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx, @Nullable ClassLoader ldr) { + if (ldr == null) + ldr = ctx.configuration().getClassLoader(); + return new BinaryReaderExImpl(ctx, BinaryHeapInputStream.create(arr, start), - ctx.configuration().getClassLoader(), + ldr, rCtx); } + + /** + * Create new reader for this object. + * + * @param rCtx Reader context. + * @return Reader. + */ + private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) { + return reader(rCtx, null); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 1768ecf..3dada6f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -618,7 +618,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V validate(qry); - CacheOperationContext opCtxCall = ctx.operationContextPerCall(); + final CacheOperationContext opCtxCall = ctx.operationContextPerCall(); if (qry instanceof ContinuousQuery) return (QueryCursor<R>)queryContinuous((ContinuousQuery<K, V>)qry, qry.isLocal(), @@ -630,7 +630,8 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V if (isReplicatedDataNode() || ctx.isLocal() || qry.isLocal()) return (QueryCursor<R>)new QueryCursorImpl<>(new Iterable<Cache.Entry<K, V>>() { @Override public Iterator<Cache.Entry<K, V>> iterator() { - return ctx.kernalContext().query().queryLocal(ctx, p); + return ctx.kernalContext().query().queryLocal(ctx, p, + opCtxCall != null && opCtxCall.isKeepBinary()); } }); http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java index 15502a0..8f0cab7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java @@ -807,8 +807,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte throws IgniteCheckedException { IgniteInternalCache<K, V> prj0 = cctx.cache(); - if (qry.keepBinary()) - prj0 = prj0.keepBinary(); + prj0 = prj0.keepBinary(); final IgniteInternalCache<K, V> prj = prj0; @@ -863,7 +862,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte @Override public K next() { KeyCacheObject key = iter0.next(); - return key.value(cctx.cacheObjectContext(), false); + return (K)cctx.unwrapBinaryIfNeeded(key, true); } @Override public void remove() { @@ -906,8 +905,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte CacheObject cacheVal = entry != null ? entry.peek(true, false, false, topVer, expiryPlc) : null; - // TODO 950 nocopy - val = (V)cctx.cacheObjectContext().unwrapBinaryIfNeeded(cacheVal, qry.keepBinary()); + val = (V)cctx.cacheObjectContext().unwrapBinaryIfNeeded(cacheVal, true); } catch (GridCacheEntryRemovedException e) { val = null; http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 28b854c..7d1311f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -841,7 +841,11 @@ public class GridQueryProcessor extends GridProcessorAdapter { * @param qry Query. * @return Cursor. */ - public <K, V> Iterator<Cache.Entry<K, V>> queryLocal(final GridCacheContext<?, ?> cctx, final SqlQuery qry) { + public <K, V> Iterator<Cache.Entry<K, V>> queryLocal( + final GridCacheContext<?, ?> cctx, + final SqlQuery qry, + final boolean keepBinary + ) { if (!busyLock.enterBusy()) throw new IllegalStateException("Failed to execute query (grid is stopping)."); @@ -887,8 +891,8 @@ public class GridQueryProcessor extends GridProcessorAdapter { IgniteBiTuple<K, V> t = i.next(); return new CacheEntryImpl<>( - t.getKey(), - t.getValue()); + (K)cctx.unwrapBinaryIfNeeded(t.getKey(), keepBinary, false), + (V)cctx.unwrapBinaryIfNeeded(t.getValue(), keepBinary, false)); } @Override public void remove() { http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java new file mode 100644 index 0000000..07f3833 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheBinaryObjectsScanSelfTest.java @@ -0,0 +1,137 @@ +/* + * 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 java.util.List; +import javax.cache.Cache; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteCacheBinaryObjectsScanSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String PERSON_CLS_NAME = "org.apache.ignite.tests.p2p.cache.Person"; + + /** */ + private static final String PERSON_KEY_CLS_NAME = "org.apache.ignite.tests.p2p.cache.PersonKey"; + + /** */ + private static ClassLoader ldr; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + ldr = getExternalClassLoader(); + + startGrids(3); + + startGrid("client"); + + populateCache(ldr); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + ldr = null; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(discoSpi); + cfg.setIncludeEventTypes(new int[0]); + + cfg.setMarshaller(null); + cfg.setPeerClassLoadingEnabled(false); + + if ("client".equals(gridName)) { + cfg.setClientMode(true); + + cfg.setClassLoader(ldr); + } + + return cfg; + } + + /** + * @param ldr Class loader. + * @throws Exception If failed. + */ + private void populateCache(ClassLoader ldr) throws Exception { + Class<?> keyCls = ldr.loadClass(PERSON_KEY_CLS_NAME); + Class<?> cls = ldr.loadClass(PERSON_CLS_NAME); + + Ignite client = grid("client"); + + CacheConfiguration<Object, Object> cfg = new CacheConfiguration<>("testCache"); + + IgniteCache<Object, Object> cache = client.getOrCreateCache(cfg); + + for (int i = 0; i < 100; i++) { + Object key = keyCls.newInstance(); + + GridTestUtils.setFieldValue(key, "id", i); + + cache.put(key, cls.newInstance()); + } + } + + /** + * @throws Exception If failed. + */ + public void testScanNoClasses() throws Exception { + Ignite client = grid("client"); + + IgniteCache<Object, Object> cache = client.cache("testCache"); + + List<Cache.Entry<Object, Object>> entries = cache.query(new ScanQuery<>()).getAll(); + + assertEquals(100, entries.size()); + + for (Cache.Entry<Object, Object> entry : entries) { + assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName()); + assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName()); + } + + entries = cache.query(new ScanQuery<>(1)).getAll(); + + assertFalse(entries.isEmpty()); + + for (Cache.Entry<Object, Object> entry : entries) { + assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName()); + assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName()); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java ---------------------------------------------------------------------- diff --git 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 index 79c41f8..3782596 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 @@ -44,6 +44,7 @@ import javax.cache.expiry.TouchedExpiryPolicy; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.CachePeekMode; @@ -65,6 +66,7 @@ import org.apache.ignite.events.CacheQueryExecutedEvent; import org.apache.ignite.events.CacheQueryReadEvent; import org.apache.ignite.events.Event; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.binary.BinaryMarshaller; import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; import org.apache.ignite.internal.processors.cache.query.QueryCursorEx; @@ -110,9 +112,6 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac /** */ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - /** */ - protected Ignite ignite; - /** * @return Grid count. */ @@ -207,18 +206,34 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac return false; } - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - ignite = startGridsMultiThreaded(gridCount()); + /** + * @return Ignite instance. + */ + protected Ignite ignite() { + return grid(0); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { + super.afterTest(); + + ignite().cache(null).removeAll(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGridsMultiThreaded(gridCount()); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + stopAllGrids(); store.reset(); - - ignite = null; } /** @@ -227,7 +242,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testDifferentKeyTypes() throws Exception { - final IgniteCache<Object, Object> cache = ignite.cache(null); + final IgniteCache<Object, Object> cache = ignite().cache(null); cache.put(1, "value"); @@ -247,7 +262,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testDifferentValueTypes() throws Exception { - IgniteCache<Integer, Object> cache = ignite.cache(null); + IgniteCache<Integer, Object> cache = ignite().cache(null); cache.put(7, "value"); @@ -262,7 +277,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testStringType() throws Exception { - IgniteCache<Integer, String> cache = ignite.cache(null); + IgniteCache<Integer, String> cache = ignite().cache(null); cache.put(666, "test"); @@ -281,7 +296,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testIntegerType() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); int key = 898; @@ -307,7 +322,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac */ public void testUserDefinedFunction() throws IgniteCheckedException { // Without alias. - final IgniteCache<Object, Object> cache = ignite.cache(null); + final IgniteCache<Object, Object> cache = ignite().cache(null); QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery("select square(1), square(2)")); @@ -359,10 +374,10 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testExpiration() throws Exception { - ignite.cache(null). + ignite().cache(null). withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000))).put(7, 1); - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); List<Cache.Entry<Integer, Integer>> qry = cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll(); @@ -384,7 +399,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testIllegalBounds() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); cache.put(1, 1); cache.put(2, 2); @@ -401,7 +416,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testComplexType() throws Exception { - IgniteCache<Key, GridCacheQueryTestValue> cache = ignite.cache(null); + IgniteCache<Key, GridCacheQueryTestValue> cache = ignite().cache(null); GridCacheQueryTestValue val1 = new GridCacheQueryTestValue(); @@ -431,6 +446,41 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac } /** + * @throws Exception In case of error. + */ + public void testComplexTypeKeepBinary() throws Exception { + if (ignite().configuration().getMarshaller() == null || ignite().configuration().getMarshaller() instanceof BinaryMarshaller) { + IgniteCache<Key, GridCacheQueryTestValue> cache = ignite().cache(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<BinaryObject, BinaryObject>> qry = cache.withKeepBinary() + .query(new SqlQuery<BinaryObject, BinaryObject>(GridCacheQueryTestValue.class, + "fieldName='field1' and field2=1 and field3=1 and id=100500 and embeddedField2=11 and x=3")); + + Cache.Entry<BinaryObject, BinaryObject> entry = F.first(qry.getAll()); + + assertNotNull(entry); + assertEquals(100500L, entry.getKey().field("id")); + assertEquals(val1, entry.getValue().deserialize()); + } + } + + /** * Complex key type. */ private static class Key { @@ -471,7 +521,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testSelectQuery() throws Exception { - IgniteCache<Integer, String> cache = ignite.cache(null); + IgniteCache<Integer, String> cache = ignite().cache(null); cache.put(10, "value"); @@ -490,7 +540,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testObjectQuery() throws Exception { - IgniteCache<Integer, ObjectValue> cache = ignite.cache(null); + IgniteCache<Integer, ObjectValue> cache = ignite().cache(null); ObjectValue val = new ObjectValue("test", 0); @@ -528,7 +578,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testObjectQueryWithSwap() throws Exception { - IgniteCache<Integer, ObjectValue> cache = ignite.cache(null); + IgniteCache<Integer, ObjectValue> cache = ignite().cache(null); boolean partitioned = cache.getConfiguration(CacheConfiguration.class).getCacheMode() == PARTITIONED; @@ -621,7 +671,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testFullTextSearch() throws Exception { - IgniteCache<Integer, ObjectValue> cache = ignite.cache(null); + IgniteCache<Integer, ObjectValue> cache = ignite().cache(null); // Try to execute on empty cache first. QueryCursor<Cache.Entry<Integer, ObjectValue>> qry = @@ -668,7 +718,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testScanQuery() throws Exception { - IgniteCache<Integer, String> c1 = ignite.cache(null); + IgniteCache<Integer, String> c1 = ignite().cache(null); c1.put(777, "value"); @@ -695,7 +745,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testScanPartitionQuery() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); GridCacheContext cctx = ((IgniteCacheProxy)cache).context(); @@ -739,7 +789,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testTwoObjectsTextSearch() throws Exception { - IgniteCache<Object, Object> c = ignite.cache(null); + IgniteCache<Object, Object> c = ignite().cache(null); c.put(1, new ObjectValue("ObjectValue str", 1)); c.put("key", new ObjectValueOther("ObjectValueOther str")); @@ -762,7 +812,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testEmptyObject() throws Exception { - IgniteCache<EmptyObject, EmptyObject> cache = ignite.cache(null); + IgniteCache<EmptyObject, EmptyObject> cache = ignite().cache(null); cache.put(new EmptyObject(1), new EmptyObject(2)); @@ -778,7 +828,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testPrimitiveType() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); cache.put(1, 1); cache.put(2, 2); @@ -815,7 +865,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ private void testPaginationIterator(@Nullable String cacheName) throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(cacheName); + IgniteCache<Integer, Integer> cache = ignite().cache(cacheName); for (int i = 0; i < 50; i++) cache.put(i, i); @@ -857,7 +907,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ private void testPaginationGet(@Nullable String cacheName) throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(cacheName); + IgniteCache<Integer, Integer> cache = ignite().cache(cacheName); for (int i = 0; i < 50; i++) cache.put(i, i); @@ -885,7 +935,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testScanFilters() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); for (int i = 0; i < 50; i++) cache.put(i, i); @@ -921,7 +971,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws IgniteCheckedException if failed. */ public void testBadHashObjectKey() throws IgniteCheckedException { - IgniteCache<BadHashKeyObject, Byte> cache = ignite.cache(null); + IgniteCache<BadHashKeyObject, Byte> cache = ignite().cache(null); cache.put(new BadHashKeyObject("test_key1"), (byte)1); cache.put(new BadHashKeyObject("test_key0"), (byte)10); @@ -935,7 +985,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws IgniteCheckedException if failed. */ public void testTextIndexedKey() throws IgniteCheckedException { - IgniteCache<ObjectValue, Long> cache = ignite.cache(null); + IgniteCache<ObjectValue, Long> cache = ignite().cache(null); cache.put(new ObjectValue("test_key1", 10), 19L); cache.put(new ObjectValue("test_key0", 11), 11005L); @@ -950,7 +1000,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testOrderByOnly() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); for (int i = 0; i < 10; i++) cache.put(i, i); @@ -980,7 +1030,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testLimitOnly() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); for (int i = 0; i < 10; i++) cache.put(i, i); @@ -1008,7 +1058,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testArray() throws Exception { - IgniteCache<Integer, ArrayObject> cache = ignite.cache(null); + IgniteCache<Integer, ArrayObject> cache = ignite().cache(null); cache.put(1, new ArrayObject(new Long[]{1L, null, 3L})); cache.put(2, new ArrayObject(new Long[] {4L, 5L, 6L})); @@ -1038,7 +1088,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testFieldsQueryMetadata() throws Exception { - IgniteCache<UUID, Person> cache = ignite.cache(null); + IgniteCache<UUID, Person> cache = ignite().cache(null); for (int i = 0; i < 100; i++) cache.put(UUID.randomUUID(), new Person("name-" + i, (i + 1) * 100)); @@ -1062,8 +1112,10 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac private void checkSqlQueryEvents() throws Exception { final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount()); + IgnitePredicate[] lsnrs = new IgnitePredicate[gridCount()]; + for (int i = 0; i < gridCount(); i++) { - grid(i).events().localListen(new IgnitePredicate<Event>() { + IgnitePredicate<Event> pred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryExecutedEvent; @@ -1073,26 +1125,36 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac assertNotNull(qe.clause()); assertNull(qe.scanQueryFilter()); assertNull(qe.continuousQueryFilter()); - assertArrayEquals(new Integer[] { 10 }, qe.arguments()); + assertArrayEquals(new Integer[] {10}, qe.arguments()); execLatch.countDown(); return true; } - }, EVT_CACHE_QUERY_EXECUTED); + }; + + grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED); + + lsnrs[i] = pred; } - IgniteCache<Integer, Integer> cache = ignite.cache(null); + try { + IgniteCache<Integer, Integer> cache = ignite().cache(null); - for (int i = 0; i < 20; i++) - cache.put(i, i); + for (int i = 0; i < 20; i++) + cache.put(i, i); - QueryCursor<Cache.Entry<Integer, Integer>> q = - cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= ?").setArgs(10)); + QueryCursor<Cache.Entry<Integer, Integer>> q = + cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= ?").setArgs(10)); - q.getAll(); + q.getAll(); - assert execLatch.await(1000, MILLISECONDS); + assert execLatch.await(1000, MILLISECONDS); + } + finally { + for (int i = 0; i < gridCount(); i++) + grid(i).events().stopLocalListen(lsnrs[i], EVT_CACHE_QUERY_EXECUTED); + } } /** @@ -1110,8 +1172,11 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac final CountDownLatch latch = new CountDownLatch(10); final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount()); + IgnitePredicate[] objReadLsnrs = new IgnitePredicate[gridCount()]; + IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()]; + for (int i = 0; i < gridCount(); i++) { - grid(i).events().localListen(new IgnitePredicate<Event>() { + IgnitePredicate<Event> pred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryReadEvent; @@ -1132,9 +1197,12 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac return true; } - }, EVT_CACHE_QUERY_OBJECT_READ); + }; + + grid(i).events().localListen(pred, EVT_CACHE_QUERY_OBJECT_READ); + objReadLsnrs[i] = pred; - grid(i).events().localListen(new IgnitePredicate<Event>() { + IgnitePredicate<Event> execPred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryExecutedEvent; @@ -1153,31 +1221,42 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac return true; } - }, EVT_CACHE_QUERY_EXECUTED); + }; + + grid(i).events().localListen(execPred, EVT_CACHE_QUERY_EXECUTED); + qryExecLsnrs[i] = execPred; } - IgniteCache<Integer, Integer> cache = ignite.cache(null); + try { + IgniteCache<Integer, Integer> cache = ignite().cache(null); - for (int i = 0; i < 20; i++) - cache.put(i, i); + for (int i = 0; i < 20; i++) + cache.put(i, i); - IgniteBiPredicate<Integer, Integer> filter = new IgniteBiPredicate<Integer, Integer>() { - @Override public boolean apply(Integer k, Integer v) { - return k >= 10; - } - }; + IgniteBiPredicate<Integer, Integer> filter = new IgniteBiPredicate<Integer, Integer>() { + @Override public boolean apply(Integer k, Integer v) { + return k >= 10; + } + }; - QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new ScanQuery<>(filter)); + QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new ScanQuery<>(filter)); - q.getAll(); + q.getAll(); - assert latch.await(1000, MILLISECONDS); - assert execLatch.await(1000, MILLISECONDS); + assert latch.await(1000, MILLISECONDS); + assert execLatch.await(1000, MILLISECONDS); - assertEquals(10, map.size()); + assertEquals(10, map.size()); - for (int i = 10; i < 20; i++) - assertEquals(i, map.get(i).intValue()); + for (int i = 10; i < 20; i++) + assertEquals(i, map.get(i).intValue()); + } + finally { + for (int i = 0; i < gridCount(); i++) { + grid(i).events().stopLocalListen(objReadLsnrs[i]); + grid(i).events().stopLocalListen(qryExecLsnrs[i]); + } + } } /** @@ -1188,8 +1267,11 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac final CountDownLatch latch = new CountDownLatch(2); final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount()); + IgnitePredicate[] objReadLsnrs = new IgnitePredicate[gridCount()]; + IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()]; + for (int i = 0; i < gridCount(); i++) { - grid(i).events().localListen(new IgnitePredicate<Event>() { + IgnitePredicate<Event> objReadPred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryReadEvent; @@ -1210,9 +1292,12 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac return true; } - }, EVT_CACHE_QUERY_OBJECT_READ); + }; - grid(i).events().localListen(new IgnitePredicate<Event>() { + grid(i).events().localListen(objReadPred, EVT_CACHE_QUERY_OBJECT_READ); + objReadLsnrs[i] = objReadPred; + + IgnitePredicate<Event> qryExecPred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryExecutedEvent; @@ -1231,30 +1316,41 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac return true; } - }, EVT_CACHE_QUERY_EXECUTED); + }; + + grid(i).events().localListen(qryExecPred, EVT_CACHE_QUERY_EXECUTED); + qryExecLsnrs[i] = qryExecPred; } - IgniteCache<UUID, Person> cache = ignite.cache(null); + try { + IgniteCache<UUID, Person> cache = ignite().cache(null); - UUID k1 = UUID.randomUUID(); - UUID k2 = UUID.randomUUID(); - UUID k3 = UUID.randomUUID(); + UUID k1 = UUID.randomUUID(); + UUID k2 = UUID.randomUUID(); + UUID k3 = UUID.randomUUID(); - cache.put(k1, new Person("Bob White", 1000)); - cache.put(k2, new Person("Tom White", 1000)); - cache.put(k3, new Person("Mike Green", 1000)); + cache.put(k1, new Person("Bob White", 1000)); + cache.put(k2, new Person("Tom White", 1000)); + cache.put(k3, new Person("Mike Green", 1000)); - QueryCursor<Cache.Entry<UUID, Person>> q = cache.query(new TextQuery<UUID, Person>(Person.class, "White")); + QueryCursor<Cache.Entry<UUID, Person>> q = cache.query(new TextQuery<UUID, Person>(Person.class, "White")); - q.getAll(); + q.getAll(); - assert latch.await(1000, MILLISECONDS); - assert execLatch.await(1000, MILLISECONDS); + assert latch.await(1000, MILLISECONDS); + assert execLatch.await(1000, MILLISECONDS); - assertEquals(2, map.size()); + assertEquals(2, map.size()); - assertEquals("Bob White", map.get(k1).name()); - assertEquals("Tom White", map.get(k2).name()); + assertEquals("Bob White", map.get(k1).name()); + assertEquals("Tom White", map.get(k2).name()); + } + finally { + for (int i = 0; i < gridCount(); i++) { + grid(i).events().stopLocalListen(objReadLsnrs[i]); + grid(i).events().stopLocalListen(qryExecLsnrs[i]); + } + } } /** @@ -1263,8 +1359,10 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac public void testFieldsQueryEvents() throws Exception { final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount()); + IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()]; + for (int i = 0; i < gridCount(); i++) { - grid(i).events().localListen(new IgnitePredicate<Event>() { + IgnitePredicate<Event> pred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryExecutedEvent; @@ -1274,26 +1372,35 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac assertNotNull(qe.clause()); assertNull(qe.scanQueryFilter()); assertNull(qe.continuousQueryFilter()); - assertArrayEquals(new Integer[]{10}, qe.arguments()); + assertArrayEquals(new Integer[] {10}, qe.arguments()); execLatch.countDown(); return true; } - }, EVT_CACHE_QUERY_EXECUTED); + }; + + grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED); + qryExecLsnrs[i] = pred; } - IgniteCache<UUID, Person> cache = ignite.cache(null); + try { + IgniteCache<UUID, Person> cache = ignite().cache(null); - for (int i = 1; i <= 20; i++) - cache.put(UUID.randomUUID(), new Person("Person " + i, i)); + for (int i = 1; i <= 20; i++) + cache.put(UUID.randomUUID(), new Person("Person " + i, i)); - QueryCursor<List<?>> q = cache.query(new SqlFieldsQuery("select _key, name from Person where salary > ?"). - setArgs(10)); + QueryCursor<List<?>> q = cache.query(new SqlFieldsQuery("select _key, name from Person where salary > ?"). + setArgs(10)); - q.getAll(); + q.getAll(); - assert execLatch.await(1000, MILLISECONDS); + assert execLatch.await(1000, MILLISECONDS); + } + finally { + for (int i = 0; i < gridCount(); i++) + grid(i).events().stopLocalListen(qryExecLsnrs[i]); + } } /** @@ -1574,7 +1681,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac /** * */ - private static class BadHashKeyObject implements Serializable { + private static class BadHashKeyObject implements Serializable, Comparable<BadHashKeyObject> { /** */ @QuerySqlField(index = false) private final String str; @@ -1583,7 +1690,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @param str String. */ private BadHashKeyObject(String str) { - this.str = str; + this.str = str == null ? "" : str; } /** {@inheritDoc} */ @@ -1602,6 +1709,11 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac } /** {@inheritDoc} */ + @Override public int compareTo(BadHashKeyObject o) { + return str.compareTo(o.str); + } + + /** {@inheritDoc} */ @Override public String toString() { return S.toString(BadHashKeyObject.class, this); } http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheReplicatedQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheReplicatedQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheReplicatedQuerySelfTest.java index 9c52f92..e462cce 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheReplicatedQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheReplicatedQuerySelfTest.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.lang.reflect.Field; -import java.sql.ResultSet; import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -41,7 +40,6 @@ import org.apache.ignite.cache.query.annotations.QuerySqlField; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.Event; import org.apache.ignite.events.EventType; -import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractQuerySelfTest; @@ -49,8 +47,6 @@ import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager; import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.lang.GridCloseableIterator; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; @@ -112,8 +108,8 @@ public class IgniteCacheReplicatedQuerySelfTest extends IgniteCacheAbstractQuery } /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); ignite1 = grid(0); ignite2 = grid(1); @@ -322,7 +318,7 @@ public class IgniteCacheReplicatedQuerySelfTest extends IgniteCacheAbstractQuery * @throws Exception If failed. */ public void testLostIterator() throws Exception { - IgniteCache<Integer, Integer> cache = ignite.cache(null); + IgniteCache<Integer, Integer> cache = ignite().cache(null); for (int i = 0; i < 1000; i++) cache.put(i, i); http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java index 9a4d168..64d48e3 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java @@ -47,7 +47,7 @@ public class IgniteCacheLocalQuerySelfTest extends IgniteCacheAbstractQuerySelfT * @throws Exception If test failed. */ public void testQueryLocal() throws Exception { - IgniteCache<Integer, String> cache = ignite.cache(null); + IgniteCache<Integer, String> cache = ignite().cache(null); cache.put(1, "value1"); cache.put(2, "value2"); http://git-wip-us.apache.org/repos/asf/ignite/blob/81458f51/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java index 6abc2d4..1f5d6d1 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java @@ -33,6 +33,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheQueryInternalKeysSel import org.apache.ignite.internal.processors.cache.GridCacheQuerySerializationSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest; import org.apache.ignite.internal.processors.cache.IgniteBinaryObjectFieldsQuerySelfTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheBinaryObjectsScanSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheCollocatedQuerySelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheDuplicateEntityConfigurationSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest; @@ -159,6 +160,7 @@ public class IgniteBinaryCacheQueryTestSuite extends TestSuite { suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class); suite.addTestSuite(GridCacheCrossCacheQuerySelfTest.class); suite.addTestSuite(GridCacheQuerySerializationSelfTest.class); + suite.addTestSuite(IgniteCacheBinaryObjectsScanSelfTest.class); // Scan queries. suite.addTestSuite(CacheScanPartitionQueryFallbackSelfTest.class);