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/09/04 12:37:09 UTC

[27/50] [abbrv] ignite git commit: Topology validator test and javadoc improvement (cherry picked from commit 2fbf328)

Topology validator test and javadoc improvement
(cherry picked from commit 2fbf328)


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

Branch: refs/heads/ignite-843
Commit: b1a9771ad992d5810fbe3de79d39ab07ddd51949
Parents: fe1caa6
Author: Anton Vinogradov <av...@apache.org>
Authored: Thu Sep 3 18:34:38 2015 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Thu Sep 3 18:41:54 2015 +0300

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       | 45 +++++++++++++++++++
 .../ignite/configuration/TopologyValidator.java |  4 +-
 ...gniteTopologyValidatorAbstractCacheTest.java | 46 ++++++++++++++++----
 3 files changed, 85 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b1a9771a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 792bb28..1bbc110 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -20,12 +20,14 @@ package org.apache.ignite.configuration;
 import java.io.Serializable;
 import java.util.Collection;
 import javax.cache.Cache;
+import javax.cache.CacheException;
 import javax.cache.configuration.CompleteConfiguration;
 import javax.cache.configuration.Factory;
 import javax.cache.configuration.MutableConfiguration;
 import javax.cache.expiry.ExpiryPolicy;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
 import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheEntryProcessor;
@@ -1788,6 +1790,27 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
 
     /**
      * Gets topology validator.
+     * <p>
+     * Topology validator checks whether the new topology is valid for specific cache at each topology change.
+     * Topology is always valid in case no topology validator used.
+     * <p>
+     * In case topology is valid for specific cache all operations on this cache are allowed.
+     * <p>
+     * In case topology is not valid for specific cache all update operations on this cache are restricted:
+     * <p>{@link CacheException} will be thrown at update operations (put, remove, etc) attempt.
+     * <p>{@link IgniteException} will be thrown at transaction commit attempt.
+     *
+     * <p>
+     * Usage example
+     * <p>
+     * Following validator allows to put data only in case topology contains exactly 2 nodes:
+     * <pre>{@code
+     * new TopologyValidator() {
+     *    @Override public boolean validate(Collection<ClusterNode> nodes) {
+     *       return nodes.size() == 2;
+     *    }
+     * }
+     * }</pre>
      * @return validator.
      */
     public TopologyValidator getTopologyValidator() {
@@ -1796,6 +1819,28 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
 
     /**
      * Sets topology validator.
+     * <p>
+     * Topology validator checks whether the new topology is valid for specific cache at each topology change.
+     * Topology is always valid in case no topology validator used.
+     * <p>
+     * In case topology is valid for specific cache all operations on this cache are allowed.
+     * <p>
+     * In case topology is not valid for specific cache all update operations on this cache are restricted:
+     * <p>{@link CacheException} will be thrown at update operations (put, remove, etc) attempt.
+     * <p>{@link IgniteException} will be thrown at transaction commit attempt.
+     *
+     * <p>
+     * Usage example
+     * <p>
+     * Following validator allows to put data only in case topology contains exactly 2 nodes:
+     * <pre>{@code
+     * new TopologyValidator() {
+     *    @Override public boolean validate(Collection<ClusterNode> nodes) {
+     *       return nodes.size() == 2;
+     *    }
+     * }
+     * }</pre>
+     *
      * @param topValidator validator.
      * @return {@code this} for chaining.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b1a9771a/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java b/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
index ef9284d..49c06a0 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
@@ -27,8 +27,8 @@ import org.apache.ignite.cluster.ClusterNode;
 public interface TopologyValidator extends Serializable {
     /**
      * Validates topology.
-     * @param nodes nodes collection to be validated.
-     * @return is topology valid or not.
+     * @param nodes Collection of nodes.
+     * @return {@code true} in case topology is valid for specific cache, otherwise {@code false}
      */
     boolean validate(Collection<ClusterNode> nodes);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/b1a9771a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java
index deb1fee..65f4694 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java
@@ -86,13 +86,11 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac
      */
     protected void putInvalid(String cacheName) {
         try {
-            assert grid(0).cache(cacheName).get(KEY_VALUE) == null;
-
             grid(0).cache(cacheName).put(KEY_VALUE, KEY_VALUE);
 
             assert false : "topology validation broken";
         }
-        catch (IgniteException | CacheException ex) {
+        catch (CacheException ex) {
             assert ex.getCause() instanceof IgniteCheckedException &&
                 ex.getCause().getMessage().contains("cache topology is not valid");
         }
@@ -105,18 +103,47 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac
      */
     protected void putValid(String cacheName) {
         try {
-            assert grid(0).cache(cacheName).get(KEY_VALUE) == null;
-
             grid(0).cache(cacheName).put(KEY_VALUE, KEY_VALUE);
 
             assert grid(0).cache(cacheName).get(KEY_VALUE).equals(KEY_VALUE);
         }
-        catch (IgniteException | CacheException ex) {
+        catch (CacheException ex) {
+            assert false : "topology validation broken";
+        }
+    }
+
+    /**
+     * Gets when topology is invalid.
+     *
+     * @param cacheName cache name.
+     */
+    protected void getInvalid(String cacheName) {
+        try {
+            assert grid(0).cache(cacheName).get(KEY_VALUE).equals(KEY_VALUE);
+        }
+        catch (CacheException ex) {
             assert false : "topology validation broken";
         }
     }
 
     /**
+     * Remove when topology is invalid.
+     *
+     * @param cacheName cache name.
+     */
+    protected void removeInvalid(String cacheName) {
+        try {
+            grid(0).cache(cacheName).remove(KEY_VALUE);
+
+            assert false : "topology validation broken";
+        }
+        catch (CacheException ex) {
+            assert ex.getCause() instanceof IgniteCheckedException &&
+                ex.getCause().getMessage().contains("cache topology is not valid");
+        }
+    }
+
+    /**
      * Commits with error.
      *
      * @param tx transaction.
@@ -125,7 +152,7 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac
         try {
             tx.commit();
         }
-        catch (IgniteException | CacheException ex) {
+        catch (IgniteException ex) {
             assert ex.getCause() instanceof IgniteCheckedException &&
                 ex.getCause().getMessage().contains("cache topology is not valid");
         }
@@ -158,8 +185,10 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac
         remove(null);
 
         putInvalid(CACHE_NAME_1);
+        removeInvalid(CACHE_NAME_1);
 
         putInvalid(CACHE_NAME_2);
+        removeInvalid(CACHE_NAME_2);
 
         startGrid(1);
 
@@ -167,7 +196,6 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac
         remove(null);
 
         putValid(CACHE_NAME_1);
-        remove(CACHE_NAME_1);
 
         putValid(CACHE_NAME_2);
         remove(CACHE_NAME_2);
@@ -177,7 +205,9 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac
         putValid(null);
         remove(null);
 
+        getInvalid(CACHE_NAME_1);
         putInvalid(CACHE_NAME_1);
+        removeInvalid(CACHE_NAME_1);
 
         putValid(CACHE_NAME_2);
         remove(CACHE_NAME_2);