IGNITE-45 - Fixing tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/61c7a493 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/61c7a493 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/61c7a493 Branch: refs/heads/ignite-45 Commit: 61c7a4939e2bc72f1d9d3709c7320ade643a43a0 Parents: 7d8c8ce Author: Alexey Goncharuk <agoncha...@gridgain.com> Authored: Mon Mar 16 19:00:30 2015 -0700 Committer: Alexey Goncharuk <agoncha...@gridgain.com> Committed: Mon Mar 16 19:00:30 2015 -0700 ---------------------------------------------------------------------- .../internal/cluster/ClusterGroupAdapter.java | 21 ++---- .../GridProjectionForCachesSelfTest.java | 73 ++++++++++++++++---- 2 files changed, 65 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/61c7a493/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 529bee2..632e441 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 @@ -18,12 +18,10 @@ package org.apache.ignite.internal.cluster; import org.apache.ignite.*; -import org.apache.ignite.cache.*; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.executor.*; import org.apache.ignite.internal.managers.discovery.*; -import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; @@ -184,7 +182,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteCompute} for this cluster group. + * @return {@link IgniteCompute} for this cluster group. */ public final IgniteCompute compute() { if (compute == null) { @@ -197,7 +195,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteMessaging} for this cluster group. + * @return {@link IgniteMessaging} for this cluster group. */ public final IgniteMessaging message() { if (messaging == null) { @@ -210,7 +208,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteEvents} for this cluster group. + * @return {@link IgniteEvents} for this cluster group. */ public final IgniteEvents events() { if (evts == null) { @@ -223,7 +221,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteServices} for this cluster group. + * @return {@link IgniteServices} for this cluster group. */ public IgniteServices services() { if (svcs == null) { @@ -665,14 +663,6 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { */ private static class CachesFilter implements IgnitePredicate<ClusterNode> { /** */ - private static final Set<CacheDistributionMode> DATA_MODES = EnumSet.of(CacheDistributionMode.NEAR_PARTITIONED, - CacheDistributionMode.PARTITIONED_ONLY); - - /** */ - private static final Set<CacheDistributionMode> CLIENT_MODES = EnumSet.of(CacheDistributionMode.CLIENT_ONLY, - CacheDistributionMode.NEAR_ONLY); - - /** */ private static final long serialVersionUID = 0L; /** Cache name. */ @@ -709,6 +699,9 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { if (affNodes && disco.cacheAffinityNode(n, cacheName)) return true; + if (!affNodes && disco.cacheAffinityNode(n, cacheName)) + return false; + if (nearNodes && disco.cacheNearNode(n, cacheName)) return true; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/61c7a493/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java index ae18a30..992aa04 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java @@ -18,10 +18,10 @@ package org.apache.ignite.internal; import org.apache.ignite.*; -import org.apache.ignite.cache.*; import org.apache.ignite.cluster.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.lang.*; import org.apache.ignite.spi.discovery.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; @@ -34,7 +34,7 @@ import java.util.*; import static org.apache.ignite.cache.CacheMode.*; /** - * Tests for {@link org.apache.ignite.cluster.ClusterGroup#forCacheNodes(String)} method. + * Tests for {@link ClusterGroup#forCacheNodes(String)} method. */ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { /** */ @@ -52,16 +52,9 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { cfg.setDiscoverySpi(discoverySpi()); - // TODO IGNITE-45. -// if (gridName.equals(getTestGridName(0))) -// cfg.setCacheConfiguration(cacheConfiguration(null, CacheDistributionMode.PARTITIONED_ONLY)); -// else if (gridName.equals(getTestGridName(1))) -// cfg.setCacheConfiguration(cacheConfiguration(CACHE_NAME, CacheDistributionMode.NEAR_ONLY)); -// else if (gridName.equals(getTestGridName(2)) || gridName.equals(getTestGridName(3))) -// cfg.setCacheConfiguration(cacheConfiguration(null, CacheDistributionMode.CLIENT_ONLY), -// cacheConfiguration(CACHE_NAME, CacheDistributionMode.NEAR_PARTITIONED)); -// else -// cfg.setCacheConfiguration(); + cfg.setCacheConfiguration( + cacheConfiguration(null, new AttributeFilter(getTestGridName(0)), false), + cacheConfiguration(CACHE_NAME, new AttributeFilter(getTestGridName(2), getTestGridName(3)), true)); return cfg; } @@ -81,12 +74,26 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { * @param cacheName Cache name. * @return Cache configuration. */ - private CacheConfiguration cacheConfiguration(@Nullable String cacheName) { + private CacheConfiguration cacheConfiguration( + @Nullable String cacheName, + IgnitePredicate<ClusterNode> nodeFilter, + boolean nearEnabled + ) { CacheConfiguration cfg = defaultCacheConfiguration(); cfg.setName(cacheName); cfg.setCacheMode(PARTITIONED); + if (nearEnabled) { + NearCacheConfiguration nearCfg = new NearCacheConfiguration(); + + nearCfg.setName(cacheName); + + cfg.setNearConfiguration(nearCfg); + } + + cfg.setNodeFilter(nodeFilter); + cfg.setBackups(1); return cfg; @@ -96,6 +103,15 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { @Override protected void beforeTestsStarted() throws Exception { for (int i = 0; i < 5; i++) startGrid(i); + + NearCacheConfiguration nearCfg = new NearCacheConfiguration(); + + nearCfg.setName(CACHE_NAME); + + grid(1).createCache(nearCfg); + + grid(2).jcache(null); + grid(3).jcache(null); } /** {@inheritDoc} */ @@ -130,7 +146,7 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { ClusterGroup prj = ignite.cluster().forCacheNodes(CACHE_NAME); assert prj != null; - assert prj.nodes().size() == 3; + assertEquals("Invalid projection: " + prj.nodes(), 3, prj.nodes().size()); assert !prj.nodes().contains(grid(0).localNode()); assert prj.nodes().contains(grid(1).localNode()); assert prj.nodes().contains(grid(2).localNode()); @@ -156,7 +172,7 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { ClusterGroup prj = ignite.cluster().forClientNodes(CACHE_NAME); assert prj != null; - assert prj.nodes().size() == 1; + assertEquals("Invalid projection: " + prj.nodes(), 1, prj.nodes().size()); assert prj.nodes().contains(grid(1).localNode()); } @@ -263,4 +279,31 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { // No-op. } } + + /** + * + */ + private static class AttributeFilter implements IgnitePredicate<ClusterNode> { + /** */ + private String[] attrs; + + /** + * @param attrs Attribute values. + */ + private AttributeFilter(String... attrs) { + this.attrs = attrs; + } + + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode node) { + String gridName = node.attribute(IgniteNodeAttributes.ATTR_GRID_NAME); + + for (String attr : attrs) { + if (F.eq(attr, gridName)) + return true; + } + + return false; + } + } }