ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [50/50] [abbrv] incubator-ignite git commit: ignite-688 Age related cluster group doesn't refresh dynamically
Date Thu, 09 Apr 2015 12:14:25 GMT
ignite-688 Age related cluster group doesn't refresh dynamically


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

Branch: refs/heads/ignite-688
Commit: 40f43a514b94743332b066f8179928cdd24634a1
Parents: 52b8c1c
Author: Andrey Gura <agura@gridgain.com>
Authored: Thu Apr 9 15:02:05 2015 +0300
Committer: Andrey Gura <agura@gridgain.com>
Committed: Thu Apr 9 15:03:43 2015 +0300

----------------------------------------------------------------------
 .../internal/cluster/ClusterGroupAdapter.java   | 35 ++-------
 .../ignite/internal/GridProjectionSelfTest.java | 82 ++++++++++++++++++++
 2 files changed, 89 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/40f43a51/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
index f431e76..59696a7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
@@ -63,7 +63,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
     protected UUID subjId;
 
     /** Cluster group predicate. */
-    protected volatile IgnitePredicate<ClusterNode> p;
+    protected IgnitePredicate<ClusterNode> p;
 
     /** Node IDs. */
     private Set<UUID> ids;
@@ -657,7 +657,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
             IgniteKernal g = IgnitionEx.gridx(gridName);
 
             return ids != null ? new ClusterGroupAdapter(g.context(), subjId, ids) :
-                p != null ? new ClusterGroupAdapter(g.context(), subjId, p) : g;
+                new ClusterGroupAdapter(g.context(), subjId, p);
         }
         catch (IllegalStateException e) {
             throw U.withCause(new InvalidObjectException(e.getMessage()), e);
@@ -792,7 +792,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
         private volatile ClusterNode node;
 
         /** Node predicate. */
-        private IgnitePredicate<ClusterNode> parentP;
+        private IgnitePredicate<ClusterNode> ageP;
 
         /** Last topology version. */
         private volatile long lastTopVer;
@@ -809,25 +809,8 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
          * @param isOldest Oldest flag.
          */
         private AgeClusterGroup(ClusterGroupAdapter parent, boolean isOldest) {
-            this(parent.ctx, parent.subjId, parent.p, parent.ids, isOldest);
-        }
+            super(parent.ctx, parent.subjId, parent.p, parent.ids);
 
-        /**
-         * @param ctx Context.
-         * @param subjId Subj ID.
-         * @param p Parent predicate.
-         * @param ids Ids.
-         * @param isOldest Is oldest.
-         */
-        private AgeClusterGroup(GridKernalContext ctx,
-            UUID subjId,
-            IgnitePredicate<ClusterNode> p,
-            Set<UUID> ids,
-            boolean isOldest)
-        {
-            super(ctx, subjId, p, ids);
-
-            this.parentP = p;
             this.isOldest = isOldest;
 
             reset();
@@ -842,11 +825,9 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
             try {
                 lastTopVer = ctx.discovery().topologyVersion();
 
-                this.p = parentP;
-
                 this.node = isOldest ? U.oldest(super.nodes(), null) : U.youngest(super.nodes(),
null);
 
-                this.p = F.nodeForNodes(node);
+                this.ageP = F.nodeForNodes(node);
             }
             finally {
                 unguard();
@@ -876,7 +857,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
             if (ctx.discovery().topologyVersion() != lastTopVer)
                 reset();
 
-            return super.predicate();
+            return ageP;
         }
 
         /** {@inheritDoc} */
@@ -904,7 +885,6 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
             super.writeExternal(out);
 
             out.writeBoolean(isOldest);
-            out.writeObject(parentP);
         }
 
         /** {@inheritDoc} */
@@ -912,7 +892,6 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
             super.readExternal(in);
 
             isOldest = in.readBoolean();
-            parentP = (IgnitePredicate<ClusterNode>)in.readObject();
         }
 
         /**
@@ -924,7 +903,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
         protected Object readResolve() throws ObjectStreamException {
             ClusterGroupAdapter parent = (ClusterGroupAdapter)super.readResolve();
 
-            return new AgeClusterGroup(parent.ctx, parent.subjId, parentP, parent.ids, isOldest);
+            return new AgeClusterGroup(parent, isOldest);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/40f43a51/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
index 1fc5535..9fbad80 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
@@ -20,6 +20,8 @@ package org.apache.ignite.internal;
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.marshaller.*;
 import org.apache.ignite.testframework.junits.common.*;
 
 import java.util.*;
@@ -153,6 +155,74 @@ public class GridProjectionSelfTest extends GridProjectionAbstractTest
{
     /**
      * @throws Exception If failed.
      */
+    public void testForPredicate() throws Exception {
+        IgnitePredicate<ClusterNode> evenP = new IgnitePredicate<ClusterNode>()
{
+            @Override public boolean apply(ClusterNode node) {
+                return node.order() % 2 == 0;
+            }
+        };
+
+        IgnitePredicate<ClusterNode> oddP = new IgnitePredicate<ClusterNode>()
{
+            @Override public boolean apply(ClusterNode node) {
+                return node.order() % 2 == 1;
+            }
+        };
+
+        ClusterGroup remotes = ignite.cluster().forRemotes();
+
+        ClusterGroup evenYoungest = remotes.forPredicate(evenP).forYoungest();
+        ClusterGroup evenOldest = remotes.forPredicate(evenP).forOldest();
+
+        ClusterGroup oddYoungest = remotes.forPredicate(oddP).forYoungest();
+        ClusterGroup oddOldest = remotes.forPredicate(oddP).forOldest();
+
+        int clusterSize = ignite.cluster().nodes().size();
+
+        assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id());
+        assertEquals(grid(1).localNode().id(), evenOldest.node().id());
+
+        assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id());
+        assertEquals(grid(2).localNode().id(), oddOldest.node().id());
+
+        try (Ignite g4 = startGrid(NODES_CNT);
+            Ignite g5 = startGrid(NODES_CNT + 1))
+        {
+            clusterSize = g4.cluster().nodes().size();
+
+            assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id());
+            assertEquals(grid(1).localNode().id(), evenOldest.node().id());
+
+            assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id());
+            assertEquals(grid(2).localNode().id(), oddOldest.node().id());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAgeClusterGroupSerialization() throws Exception {
+        Marshaller marshaller = getConfiguration().getMarshaller();
+
+        ClusterGroup grp = ignite.cluster().forYoungest();
+        ClusterNode node = grp.node();
+
+        byte[] arr = marshaller.marshal(grp);
+
+        ClusterGroup obj = marshaller.unmarshal(arr, null);
+
+        assertEquals(node.id(), obj.node().id());
+
+        try (Ignite ignore = startGrid()) {
+            obj = marshaller.unmarshal(arr, null);
+
+            assertEquals(grp.node().id(), obj.node().id());
+            assertFalse(node.id().equals(obj.node().id()));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testClientServer() throws Exception {
         ClusterGroup srv = ignite.cluster().forServers();
 
@@ -166,4 +236,16 @@ public class GridProjectionSelfTest extends GridProjectionAbstractTest
{
         assertTrue(cli.nodes().contains(ignite(2).cluster().localNode()));
         assertTrue(cli.nodes().contains(ignite(3).cluster().localNode()));
     }
+
+    /**
+     * @param cnt Count.
+     * @param even Even.
+     */
+    private static int gridMaxOrder(int cnt, boolean even) {
+        assert cnt > 2;
+
+        cnt = cnt - (cnt % 2);
+
+        return even ? cnt - 1 : cnt - 2;
+    }
 }


Mime
View raw message