You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/12/17 15:00:02 UTC
[03/15] ignite git commit: IGNITE-2178 - Fixed primary key set for
scan query.
IGNITE-2178 - Fixed primary key set for scan query.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/916f59aa
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/916f59aa
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/916f59aa
Branch: refs/heads/ignite-843-rc2
Commit: 916f59aa1504a02288b965c50b9acffa29a2a464
Parents: 5f26538
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Thu Dec 17 12:01:42 2015 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Thu Dec 17 12:02:27 2015 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheUtils.java | 18 +------
.../IgniteBinaryObjectFieldsQuerySelfTest.java | 53 ++++++++++++++++++--
2 files changed, 50 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/916f59aa/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index f118003..51f6dcd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -1578,23 +1578,7 @@ public class GridCacheUtils {
) {
return new CacheEntryPredicateAdapter() {
@Override public boolean apply(GridCacheEntryEx e) {
- return aff.isPrimary(n, e.key().value(e.context().cacheObjectContext(), false));
- }
- };
- }
-
- /**
- * @param aff Affinity.
- * @param n Node.
- * @return Predicate that evaulates to {@code true} if entry is primary for node.
- */
- public static <K, V> IgnitePredicate<Cache.Entry<K, V>> cachePrimary0(
- final Affinity<K> aff,
- final ClusterNode n
- ) {
- return new IgnitePredicate<Cache.Entry<K, V>>() {
- @Override public boolean apply(Cache.Entry<K, V> e) {
- return aff.isPrimary(n, e.getKey());
+ return aff.isPrimary(n, e.key());
}
};
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/916f59aa/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
index 091c633..5c1e578 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
@@ -19,16 +19,19 @@ package org.apache.ignite.internal.processors.cache;
import java.util.List;
import javax.cache.Cache;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CacheRebalanceMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
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;
@@ -48,6 +51,9 @@ public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTes
/** IP finder. */
private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+ /** Grid count. */
+ public static final int GRID_CNT = 4;
+
/** */
private static ClassLoader extClassLoader;
@@ -94,8 +100,7 @@ public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTes
@Override protected void beforeTestsStarted() throws Exception {
extClassLoader = getExternalClassLoader();
- startGrids(4);
-
+ startGrids(GRID_CNT);
}
/** {@inheritDoc} */
@@ -165,7 +170,7 @@ public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTes
* @throws Exception If failed.
*/
private void checkFieldsQuery(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
- IgniteCache<Object, Object>cache = grid(3).getOrCreateCache(cache(cacheMode, atomicity));
+ IgniteCache<Object, Object>cache = grid(GRID_CNT - 1).getOrCreateCache(cache(cacheMode, atomicity));
try {
populate(cache);
@@ -195,7 +200,7 @@ public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTes
* @throws Exception If failed.
*/
private void checkQuery(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
- IgniteCache<Object, Object> cache = grid(3).getOrCreateCache(cache(cacheMode, atomicity));
+ IgniteCache<Object, Object> cache = grid(GRID_CNT - 1).getOrCreateCache(cache(cacheMode, atomicity));
try {
populate(cache);
@@ -215,6 +220,26 @@ public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTes
assertEquals("person-last-" + i, U.field(person, "lastName"));
assertEquals((double)(i * 25), U.field(person, "salary"));
}
+
+ int max = 49;
+
+ // Check local scan query with keepBinary flag set.
+ ScanQuery<BinaryObject, BinaryObject> scanQry = new ScanQuery<>(new PersonKeyFilter(max));
+
+ QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> curs = grid(GRID_CNT - 1)
+ .cache(null).withKeepBinary().query(scanQry);
+
+ List<Cache.Entry<BinaryObject, BinaryObject>> records = curs.getAll();
+
+ assertEquals(50, records.size());
+
+ for (Cache.Entry<BinaryObject, BinaryObject> entry : records) {
+ BinaryObject key = entry.getKey();
+
+ assertTrue(key.<Integer>field("id") <= max);
+
+ assertEquals(PERSON_KEY_CLS_NAME, key.deserialize().getClass().getName());
+ }
}
finally {
grid(3).destroyCache(null);
@@ -243,4 +268,24 @@ public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTes
cache.put(key, person);
}
}
+
+ /**
+ *
+ */
+ private static class PersonKeyFilter implements IgniteBiPredicate<BinaryObject, BinaryObject> {
+ /** Max ID allowed. */
+ private int maxId;
+
+ /**
+ * @param maxId Max ID allowed.
+ */
+ public PersonKeyFilter(int maxId) {
+ this.maxId = maxId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean apply(BinaryObject key, BinaryObject val) {
+ return key.<Integer>field("id") <= maxId;
+ }
+ }
}