ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [2/2] ignite git commit: ignite-1282 - Fixing tests.
Date Tue, 24 Nov 2015 18:39:49 GMT
ignite-1282 - Fixing tests.


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

Branch: refs/heads/ignite-1282
Commit: 8e1d6c0e8fad981fc48dd0d149fb1abf30b1a7da
Parents: 385668b
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Authored: Tue Nov 24 21:39:17 2015 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Tue Nov 24 21:39:17 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableContext.java      | 11 ++++++++++
 .../cache/affinity/GridCacheAffinityImpl.java   |  3 ++-
 .../processors/query/GridQueryProcessor.java    | 22 +++++++++++++------
 .../GridPortableAffinityKeySelfTest.java        | 12 +++++++++-
 .../IgniteCacheAbstractFieldsQuerySelfTest.java | 23 ++++++++++++++++++++
 5 files changed, 62 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8e1d6c0e/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 1ff459e..765babc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -302,6 +302,17 @@ public class PortableContext implements Externalizable {
         for (TypeDescriptor desc : descs.descriptors()) {
             registerUserType(desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName);
         }
+
+        BinaryInternalIdMapper dfltMapper = BinaryInternalIdMapper.create(globalIdMapper);
+
+        // Put affinity field names for unconfigured types.
+        for (Map.Entry<String, String> entry : affFields.entrySet()) {
+            String typeName = entry.getKey();
+
+            int typeId = dfltMapper.typeId(typeName);
+
+            affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e1d6c0e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java
index 33ab3f4..b9045e9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/affinity/GridCacheAffinityImpl.java
@@ -24,6 +24,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.affinity.Affinity;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
@@ -150,7 +151,7 @@ public class GridCacheAffinityImpl<K, V> implements Affinity<K>
{
     @Override public Object affinityKey(K key) {
         A.notNull(key, "key");
 
-        if (key instanceof CacheObject)
+        if (key instanceof CacheObject && !(key instanceof BinaryObject))
             key = ((CacheObject)key).value(cctx.cacheObjectContext(), false);
 
         return cctx.config().getAffinityMapper().affinityKey(key);

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e1d6c0e/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 d0eeeb1..c560e4e 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
@@ -1540,18 +1540,26 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String alias = aliases.get(fullName.toString());
 
-            ClassProperty tmp;
+            StringBuilder bld = new StringBuilder("get");
 
-            try {
-                StringBuilder bld = new StringBuilder("get");
+            bld.append(prop);
+
+            bld.setCharAt(3, Character.toUpperCase(bld.charAt(3)));
 
-                bld.append(prop);
+            String[] mtdNames = new String[] {bld.toString(), prop};
 
-                bld.setCharAt(3, Character.toUpperCase(bld.charAt(3)));
+            ClassProperty tmp = null;
 
-                tmp = new ClassProperty(cls.getMethod(bld.toString()), key, alias);
+            for (String mtdName : mtdNames) {
+                try {
+                    tmp = new ClassProperty(cls.getMethod(mtdName), key, alias);
+                }
+                catch (NoSuchMethodException ignore) {
+                    // No-op, will try another method or field.
+                }
             }
-            catch (NoSuchMethodException ignore) {
+
+            if (tmp == null) {
                 try {
                     tmp = new ClassProperty(cls.getDeclaredField(prop), key, alias);
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e1d6c0e/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
index 3851bbc..c243901 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.cache.CacheKeyConfiguration;
 import org.apache.ignite.cache.affinity.Affinity;
 import org.apache.ignite.configuration.BinaryConfiguration;
@@ -70,8 +71,9 @@ public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest
{
         cfg.setBinaryConfiguration(bCfg);
 
         CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject.class.getName(),
"affKey");
+        CacheKeyConfiguration keyCfg2 = new CacheKeyConfiguration("TestObject2", "affKey");
 
-        cfg.setCacheKeyCfg(keyCfg);
+        cfg.setCacheKeyCfg(keyCfg, keyCfg2);
 
         cfg.setMarshaller(new BinaryMarshaller());
 
@@ -135,6 +137,14 @@ public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest
{
 
             assertEquals(i, aff.affinityKey(new TestObject(i)));
 
+            assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
+
+            BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
+
+            bldr.setField("affKey", i);
+
+            assertEquals(i, aff.affinityKey(bldr.build()));
+
             CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i),
true);
 
             assertEquals(i, aff.affinityKey(cacheObj));

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e1d6c0e/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
index 9ccb893..1d21bdd 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
@@ -809,6 +809,21 @@ public abstract class IgniteCacheAbstractFieldsQuerySelfTest extends
GridCommonA
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testMethodAnnotationWithoutGet() throws Exception {
+        QueryCursor<List<?>> qry = grid(0).cache(null)
+            .query(new SqlFieldsQuery("select methodField from Organization where methodField='name-A'")
+            .setPageSize(10));
+
+        List<List<?>> flds = qry.getAll();
+
+        assertEquals(1, flds.size());
+
+        assertEquals("name-A", flds.get(0).get(0));
+    }
+
+    /**
      * @param cacheName Cache name.
      * @throws Exception If failed.
      */
@@ -995,6 +1010,14 @@ public abstract class IgniteCacheAbstractFieldsQuerySelfTest extends
GridCommonA
             this.name = name;
         }
 
+        /**
+         * @return Generated method value.
+         */
+        @QuerySqlField
+        public String methodField() {
+            return "name-" + name;
+        }
+
         /** {@inheritDoc} */
         @Override public boolean equals(Object o) {
             if (this == o)


Mime
View raw message