ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject ignite git commit: IGNITE-3263: Affinity function must check for null keys. Reviewed and merged by Denis Magda (dmagda@gridgain.com)
Date Tue, 16 Aug 2016 23:23:37 GMT
Repository: ignite
Updated Branches:
  refs/heads/master e4eda7cf3 -> 4199ff41f


IGNITE-3263: Affinity function must check for null keys.
Reviewed and merged by Denis Magda (dmagda@gridgain.com)


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

Branch: refs/heads/master
Commit: 4199ff41f034272730029d7a1a9146a808ab7bf2
Parents: e4eda7c
Author: Saikat Maitra <saikat.maitra@gmail.com>
Authored: Tue Aug 16 16:23:32 2016 -0700
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Tue Aug 16 16:23:32 2016 -0700

----------------------------------------------------------------------
 .../cache/affinity/fair/FairAffinityFunction.java |  6 +++++-
 .../rendezvous/RendezvousAffinityFunction.java    |  4 ++++
 .../AbstractAffinityFunctionSelfTest.java         | 18 +++++++++++++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4199ff41/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
index 105efab..c624df4 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
@@ -354,6 +354,10 @@ public class FairAffinityFunction implements AffinityFunction {
 
     /** {@inheritDoc} */
     @Override public int partition(Object key) {
+        if (key == null)
+            throw new IllegalArgumentException("Null key is passed for a partition calculation.
" +
+                "Make sure that an affinity key that is used is initialized properly.");
+
         return U.safeAbs(hash(key.hashCode())) % parts;
     }
 
@@ -1137,4 +1141,4 @@ public class FairAffinityFunction implements AffinityFunction {
             return "PartSet [nodeId=" + node.id() + ", size=" + parts.size() + ", parts="
+ parts + ']';
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4199ff41/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java
index aa8680c..e876fb5 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/RendezvousAffinityFunction.java
@@ -464,6 +464,10 @@ public class RendezvousAffinityFunction implements AffinityFunction,
Externaliza
 
     /** {@inheritDoc} */
     @Override public int partition(Object key) {
+        if (key == null)
+            throw new IllegalArgumentException("Null key is passed for a partition calculation.
" +
+                "Make sure that an affinity key that is used is initialized properly.");
+
         return U.safeAbs(key.hashCode() % parts);
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4199ff41/modules/core/src/test/java/org/apache/ignite/cache/affinity/AbstractAffinityFunctionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/affinity/AbstractAffinityFunctionSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/cache/affinity/AbstractAffinityFunctionSelfTest.java
index 878d7d1..ee5b65c 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/affinity/AbstractAffinityFunctionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/affinity/AbstractAffinityFunctionSelfTest.java
@@ -106,6 +106,22 @@ public abstract class AbstractAffinityFunctionSelfTest extends GridCommonAbstrac
     /**
      * @throws Exception If failed.
      */
+    public void testNullKeyForPartitionCalculation() throws Exception {
+        AffinityFunction aff = affinityFunction();
+
+        try {
+            aff.partition(null);
+
+            fail("Should throw IllegalArgumentException due to NULL affinity key.");
+        } catch (IllegalArgumentException e) {
+            e.getMessage().contains("Null key is passed for a partition calculation. " +
+                "Make sure that an affinity key that is used is initialized properly.");
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     protected void checkNodeRemoved(int backups) throws Exception {
         checkNodeRemoved(backups, 1, 1);
     }
@@ -290,4 +306,4 @@ public abstract class AbstractAffinityFunctionSelfTest extends GridCommonAbstrac
     private static int deviation(int val, int ideal) {
         return Math.round(Math.abs(((float)val - ideal) / ideal * 100));
     }
-}
\ No newline at end of file
+}


Mime
View raw message