#IGNITE-99: Add different cache affinity functions to 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/ca530750 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ca530750 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ca530750 Branch: refs/heads/ignite-99-2 Commit: ca530750d72a840be3885f6652c54d24d9e6f1ef Parents: 16298c5 Author: ivasilinets <ivasilin...@gridgain.com> Authored: Tue Jan 27 17:16:15 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Tue Jan 27 17:16:15 2015 +0300 ---------------------------------------------------------------------- .../affinity/GridAffinityAssignment.java | 4 +- .../affinity/GridAffinityProcessor.java | 62 +++-- .../apache/ignite/internal/util/GridUtils.java | 9 + .../ignite/IgniteCacheAffinityAbstractTest.java | 238 ----------------- .../apache/ignite/IgniteCacheAffinityTest.java | 260 +++++++++++++++++++ ...ePartitionedNearPartitionedAffinityTest.java | 18 -- .../IgniteCachePartitionedOnlyAffinityTest.java | 18 -- ...heReplicatedPartitionedOnlyAffinityTest.java | 18 -- 8 files changed, 305 insertions(+), 322 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java index 1890fa4..673db6d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java @@ -103,7 +103,7 @@ class GridAffinityAssignment implements Serializable { public Set<Integer> primaryPartitions(UUID nodeId) { Set<Integer> set = primary.get(nodeId); - return set == null ? Collections.<Integer>emptySet() : Collections.unmodifiableSet(set); + return set == null ? Collections.<Integer>emptySet() : set; } /** @@ -115,7 +115,7 @@ class GridAffinityAssignment implements Serializable { public Set<Integer> backupPartitions(UUID nodeId) { Set<Integer> set = backup.get(nodeId); - return set == null ? Collections.<Integer>emptySet() : Collections.unmodifiableSet(set); + return set == null ? Collections.<Integer>emptySet() : set; } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java index f36faa2..bad1f59 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java @@ -77,7 +77,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { // Clean up affinity functions if such cache no more exists. if (evtType == EVT_NODE_FAILED || evtType == EVT_NODE_LEFT) { - Collection<String> caches = new HashSet<>(); + final Collection<String> caches = new HashSet<>(); for (ClusterNode clusterNode : ((IgniteDiscoveryEvent)evt).topologyNodes()) caches.addAll(U.cacheNames(clusterNode)); @@ -495,6 +495,20 @@ public class GridAffinityProcessor extends GridProcessorAdapter { this.portableEnabled = portableEnabled; } + /** + * @return Cache affinity function. + */ + private CacheAffinityFunction affFunc() { + return affFunc; + } + + /** + * @return Affinity assignment. + */ + private GridAffinityAssignment assignment() { + return assignment; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(AffinityInfo.class, this); @@ -567,7 +581,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - return cache().affFunc.partitions(); + return cache().affFunc().partitions(); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -582,7 +596,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - return cache().affFunc.partition(key); + return cache().affFunc().partition(key); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -597,8 +611,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - return cache() - .assignment.primaryPartitions(n.id()).contains(partition(key)); + return cache().assignment().primaryPartitions(n.id()).contains(partition(key)); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -608,17 +621,12 @@ public class GridAffinityProcessor extends GridProcessorAdapter { } } - private AffinityInfo cache() throws IgniteCheckedException { - return affinityCache(cacheName, topologyVersion()); - } - /** {@inheritDoc} */ @Override public boolean isBackup(ClusterNode n, K key) { ctx.gateway().readLock(); try { - return cache() - .assignment.backupPartitions(n.id()).contains(partition(key)); + return cache().assignment().backupPartitions(n.id()).contains(partition(key)); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -645,7 +653,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - Set<Integer> parts = cache().assignment.primaryPartitions(n.id()); + Set<Integer> parts = cache().assignment().primaryPartitions(n.id()); return U.toIntArray(parts); } @@ -662,7 +670,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - Set<Integer> parts = cache().assignment.backupPartitions(n.id()); + Set<Integer> parts = cache().assignment().backupPartitions(n.id()); return U.toIntArray(parts); } @@ -679,21 +687,12 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - Collection<Integer> parts = new HashSet<>(); - - AffinityInfo affInfo = cache(); - - for (int partsCnt = affInfo.affFunc.partitions(), part = 0; part < partsCnt; part++) { - for (ClusterNode affNode : affInfo.assignment.get(part)) { - if (n.id().equals(affNode.id())) { - parts.add(part); + GridAffinityAssignment assignment = cache().assignment(); - break; - } - } - } + int[] primary = U.toIntArray(assignment.primaryPartitions(n.id())); + int[] backup = U.toIntArray(assignment.backupPartitions(n.id())); - return U.toIntArray(parts); + return U.addAll(primary, backup); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -769,7 +768,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - return F.first(cache().assignment.get(part)); + return F.first(cache().assignment().get(part)); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -803,7 +802,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter { ctx.gateway().readLock(); try { - return cache().assignment.get(part); + return cache().assignment().get(part); } catch (IgniteCheckedException e) { throw new IgniteException(e); @@ -814,6 +813,13 @@ public class GridAffinityProcessor extends GridProcessorAdapter { } /** + * @return Affinity info for current topology version. + */ + private AffinityInfo cache() throws IgniteCheckedException { + return affinityCache(cacheName, topologyVersion()); + } + + /** * @return Topology version. */ private long topologyVersion() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java index 5279b59..6a6b82c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java @@ -6245,6 +6245,15 @@ public abstract class GridUtils { return arr; } + public static int[] addAll(int[] arr1, int[] arr2) { + int[] all = new int[arr1.length + arr2.length]; + + System.arraycopy(arr1, 0, all, 0, arr1.length); + System.arraycopy(arr2, 0, all, arr1.length, arr2.length); + + return all; + } + /** * Converts array of integers into list. * http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityAbstractTest.java deleted file mode 100644 index 562ce0b..0000000 --- a/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityAbstractTest.java +++ /dev/null @@ -1,238 +0,0 @@ -package org.apache.ignite; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.processors.cache.*; - -import javax.cache.*; -import java.util.*; - -/** - * Tests for {@link org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy}. - */ -public abstract class IgniteCacheAffinityAbstractTest extends IgniteCacheAbstractTest { - /** Initial grid count. */ - private int GRID_COUNT = 3; - - /** Cache name */ - private final String CACHE1 = "cache1"; - - /** {@inheritDoc} */ - @Override protected int gridCount() { - return GRID_COUNT; - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration cache0 = cacheConfiguration(null); - - CacheConfiguration cache1 = cacheConfiguration(null); - cache1.setName(CACHE1); - - if (gridName.contains("0")) - cfg.setCacheConfiguration(); - else if (gridName.contains("1")) - cfg.setCacheConfiguration(cache0); - else - cfg.setCacheConfiguration(cache0, cache1); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected CacheAtomicityMode atomicityMode() { - return CacheAtomicityMode.TRANSACTIONAL; - } - - /** - * Throws Exception if failed. - */ - public void testAffinity() throws Exception { - if (cacheMode().equals(CacheMode.LOCAL)) { - info("Test is not applied for local cache."); - - return; - } - - GridCache<String, Integer> cache0 = grid(1).cache(null); - GridCache<String, Integer> cache1 = grid(2).cache(CACHE1); - - for (int i = 0; i < 10; ++i) - cache0.put(Integer.toString(i), i); - - for (int i = 10; i < 20; ++i) - cache1.put(Integer.toString(i), i); - - checkAffinity(); - - startGrid(gridCount()); - startGrid(gridCount() + 1); - - GRID_COUNT += 2; - - checkAffinity(); - } - - /** - * Check CacheAffinityProxy methods. - */ - private void checkAffinity() { - for (int i = 0; i < gridCount(); ++i) { - if (grid(i).cachex(null) != null) - checkAffinity(grid(i).<String, Integer>jcache(null), grid(i).<String, Integer>cache(null)); - - if (grid(i).cachex(CACHE1) != null) - checkAffinity(grid(i).<String, Integer>jcache(CACHE1), grid(i).<String, Integer>cache(CACHE1)); - } - } - - /** - * @param jcache Jcache to iterate over. - * @param cache Cache to check. - */ - private void checkAffinity(IgniteCache<String, Integer> jcache, GridCache<String, Integer> cache) { - for (int i = 0; i < gridCount(); ++i) - checkGridAffinity(grid(i).<String>affinity(cache.name()), jcache, cache); - } - - /** - * @param testAff Cache affinity to test. - * @param jcache Ignite cache. - * @param cache Cache. - */ - private void checkGridAffinity(CacheAffinity<String> testAff, IgniteCache<String, Integer> jcache, - GridCache<String, Integer> cache) { - checkAffinityKey(testAff, jcache, cache.affinity()); - - checkPartitions(testAff, cache.affinity()); - - checkIsBackupOrPrimary(testAff, jcache, cache.affinity()); - - checkMapKeyToNode(testAff, jcache, cache.affinity()); - } - - /** - * Check mapKeyToNode, mapKeyToPrimaryAndBackups and mapPartitionToNode methods. - */ - private void checkMapKeyToNode(CacheAffinity<String> testAff, - IgniteCache<String, Integer> jcache, CacheAffinity<String> aff) { - Iterator<Cache.Entry<String, Integer>> iter = jcache.iterator(); - - while (iter.hasNext()) { - Cache.Entry<String, Integer> entry = iter.next(); - - UUID node1 = testAff.mapKeyToNode(entry.getKey()).id(); - UUID node2 = aff.mapKeyToNode(entry.getKey()).id(); - - assertEquals(node1, node2); - - Collection<ClusterNode> nodes1 = testAff.mapKeyToPrimaryAndBackups(entry.getKey()); - Collection<ClusterNode> nodes2 = aff.mapKeyToPrimaryAndBackups(entry.getKey()); - - checkEqualCollection(nodes1, nodes2); - - int part = aff.partition(entry.getKey()); - - assertEquals(testAff.mapPartitionToNode(part).id(), aff.mapPartitionToNode(part).id()); - } - } - - /** - * Check affinityKey method. - */ - private void checkAffinityKey(CacheAffinity<String> testAff, - IgniteCache<String, Integer> jcache, CacheAffinity<String> aff) { - Iterator<Cache.Entry<String, Integer>> iter = jcache.iterator(); - - while (iter.hasNext()) { - Cache.Entry<String, Integer> entry = iter.next(); - - assertEquals(testAff.affinityKey(entry.getKey()), (aff.affinityKey(entry.getKey()))); - } - } - - /** - * Check isBackup, isPrimary and isPrimaryOrBackup methods. - */ - private void checkIsBackupOrPrimary(CacheAffinity<String> testAff, IgniteCache<String, Integer> jcache, - CacheAffinity<String> aff) { - - Iterator<Cache.Entry<String, Integer>> iter = jcache.iterator(); - - while (iter.hasNext()) { - Cache.Entry<String, Integer> entry = iter.next(); - - for (ClusterNode n : nodes()) { - assertEquals(testAff.isBackup(n, entry.getKey()), aff.isBackup(n, entry.getKey())); - - assertEquals(testAff.isPrimary(n, entry.getKey()), aff.isPrimary(n, entry.getKey())); - - assertEquals(testAff.isPrimaryOrBackup(n, entry.getKey()), aff.isPrimaryOrBackup(n, entry.getKey())); - } - } - } - - /** - * Check allPartitions, backupPartitions and primaryPartitions methods. - */ - private void checkPartitions(CacheAffinity<String> testAff, CacheAffinity<String> aff) { - for (ClusterNode n : nodes()) { - checkEqualIntArray(testAff.allPartitions(n), aff.allPartitions(n)); - - checkEqualIntArray(testAff.backupPartitions(n), aff.backupPartitions(n)); - - checkEqualIntArray(testAff.primaryPartitions(n), aff.primaryPartitions(n)); - } - } - - /** - * Check equal arrays. - */ - private void checkEqualIntArray(int[] arr1, int[] arr2) { - assertEquals(arr1.length, arr2.length); - - Collection<Integer> col1 = new HashSet<>(); - - for (int i = 0; i < arr1.length; ++i) - col1.add(arr1[i]); - - for (int i = 0; i < arr2.length; ++i) { - assertTrue(col1.contains(arr2[i])); - - col1.remove(arr2[i]); - } - - assertEquals(0, col1.size()); - - } - - /** - * Check equal collections. - */ - private void checkEqualCollection(Collection<ClusterNode> col1, Collection<ClusterNode> col2) { - Collection<ClusterNode> colCopy1 = new HashSet<>(col1); - - for (ClusterNode node : col2) { - assertTrue(colCopy1.contains(node)); - colCopy1.remove(node); - } - - assertEquals(0, colCopy1.size()); - } - - /** - * @return Cluster nodes. - */ - private Collection<ClusterNode> nodes() { - Set<ClusterNode> nodes = new HashSet<>(); - - for (int i = 0; i < gridCount(); ++i) - nodes.addAll(grid(i).nodes()); - - return nodes; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityTest.java new file mode 100644 index 0000000..96e0f2a --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/IgniteCacheAffinityTest.java @@ -0,0 +1,260 @@ +package org.apache.ignite; + +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.affinity.consistenthash.*; +import org.apache.ignite.cache.affinity.fair.*; +import org.apache.ignite.cache.affinity.rendezvous.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.cache.*; + +import javax.cache.*; +import java.util.*; + +/** + * Tests for {@link org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy}. + */ +public class IgniteCacheAffinityTest extends IgniteCacheAbstractTest { + /** Initial grid count. */ + private int GRID_COUNT = 3; + + /** Cache name */ + private final String CACHE1 = "ConsistentCache"; + + /** Cache name */ + private final String CACHE2 = "PartitionFairCache"; + + /** Cache name */ + private final String CACHE3 = "RendezvousCache"; + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return GRID_COUNT; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration cache0 = cacheConfiguration(null); + + CacheConfiguration cache1 = cacheConfiguration(null); + cache1.setName(CACHE1); + cache1.setAffinity(new CacheConsistentHashAffinityFunction()); + + CacheConfiguration cache2 = cacheConfiguration(null); + cache2.setName(CACHE2); + cache2.setAffinity(new CachePartitionFairAffinity()); + + CacheConfiguration cache3 = cacheConfiguration(null); + cache3.setName(CACHE3); + cache3.setAffinity(new CacheRendezvousAffinityFunction()); + + if (gridName.contains("0")) + cfg.setCacheConfiguration(cache0); + else + cfg.setCacheConfiguration(cache0, cache1, cache2, cache3); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return CacheAtomicityMode.TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected CacheDistributionMode distributionMode() { + return CacheDistributionMode.NEAR_PARTITIONED; + } + + /** + * Throws Exception if failed. + */ + public void testAffinity() throws Exception { + if (cacheMode().equals(CacheMode.LOCAL)) { + info("Test is not applied for local cache."); + + return; + } + + GridCache<String, Integer> cache0 = grid(1).cache(null); + GridCache<String, Integer> cache1 = grid(1).cache(CACHE1); + GridCache<String, Integer> cache2 = grid(1).cache(CACHE2); + GridCache<String, Integer> cache3 = grid(1).cache(CACHE3); + + for (int i = 0; i < 10; ++i) + cache0.put(Integer.toString(i), i); + + for (int i = 10; i < 20; ++i) + cache1.put(Integer.toString(i), i); + + for (int i = 20; i < 30; ++i) + cache2.put(Integer.toString(i), i); + + for (int i = 30; i < 40; ++i) + cache3.put(Integer.toString(i), i); + + checkAffinity(); + + stopGrid(gridCount() - 1); + + startGrid(gridCount() - 1); + startGrid(gridCount()); + + GRID_COUNT += 1; + + checkAffinity(); + } + + /** + * Check CacheAffinityProxy methods. + */ + private void checkAffinity() { + checkGridAffinity(grid(0).affinity(null), grid(1).jcache(null), grid(1).cache(null)); + + checkGridAffinity(grid(0).affinity(CACHE1), grid(1).jcache(CACHE1), grid(1).cache(CACHE1)); + + checkGridAffinity(grid(0).affinity(CACHE2), grid(1).jcache(CACHE2), grid(1).cache(CACHE2)); + + checkGridAffinity(grid(0).affinity(CACHE3), grid(1).jcache(CACHE3), grid(1).cache(CACHE3)); + } + + /** + * @param testAff Cache affinity to test. + * @param jcache Ignite cache. + * @param cache Cache. + */ + private void checkGridAffinity(CacheAffinity testAff, IgniteCache jcache, GridCache cache) { + checkAffinityKey(testAff, jcache, cache.affinity()); + + checkPartitions(testAff, cache.affinity()); + + checkIsBackupOrPrimary(testAff, jcache, cache.affinity()); + + checkMapKeyToNode(testAff, jcache, cache.affinity()); + } + + /** + * Check mapKeyToNode, mapKeyToPrimaryAndBackups and mapPartitionToNode methods. + */ + private void checkMapKeyToNode(CacheAffinity testAff, IgniteCache jcache, CacheAffinity aff) { + Iterator<Cache.Entry> iter = jcache.iterator(); + + while (iter.hasNext()) { + Cache.Entry entry = iter.next(); + + UUID node1 = testAff.mapKeyToNode(entry.getKey()).id(); + UUID node2 = aff.mapKeyToNode(entry.getKey()).id(); + + assertEquals(node1, node2); + + Collection<ClusterNode> nodes1 = testAff.mapKeyToPrimaryAndBackups(entry.getKey()); + Collection<ClusterNode> nodes2 = aff.mapKeyToPrimaryAndBackups(entry.getKey()); + + checkEqualCollection(nodes1, nodes2); + + int part = aff.partition(entry.getKey()); + + assertEquals(testAff.mapPartitionToNode(part).id(), aff.mapPartitionToNode(part).id()); + } + } + + /** + * Check affinityKey method. + */ + private void checkAffinityKey(CacheAffinity testAff, IgniteCache jcache, CacheAffinity aff) { + Iterator<Cache.Entry> iter = jcache.iterator(); + + while (iter.hasNext()) { + Cache.Entry entry = iter.next(); + + assertEquals(testAff.affinityKey(entry.getKey()), (aff.affinityKey(entry.getKey()))); + } + } + + /** + * Check isBackup, isPrimary and isPrimaryOrBackup methods. + */ + private void checkIsBackupOrPrimary(CacheAffinity testAff, IgniteCache jcache, CacheAffinity aff) { + + Iterator<Cache.Entry> iter = jcache.iterator(); + + while (iter.hasNext()) { + Cache.Entry entry = iter.next(); + + for (ClusterNode n : nodes()) { + assertEquals(testAff.isBackup(n, entry.getKey()), aff.isBackup(n, entry.getKey())); + + assertEquals(testAff.isPrimary(n, entry.getKey()), aff.isPrimary(n, entry.getKey())); + + assertEquals(testAff.isPrimaryOrBackup(n, entry.getKey()), aff.isPrimaryOrBackup(n, entry.getKey())); + } + } + } + + /** + * Check allPartitions, backupPartitions and primaryPartitions methods. + */ + private void checkPartitions(CacheAffinity testAff, CacheAffinity aff) { + for (ClusterNode n : nodes()) { + checkEqualIntArray(testAff.allPartitions(n), aff.allPartitions(n)); + + checkEqualIntArray(testAff.backupPartitions(n), aff.backupPartitions(n)); + + checkEqualIntArray(testAff.primaryPartitions(n), aff.primaryPartitions(n)); + } + } + + /** + * Check equal arrays. + */ + private void checkEqualIntArray(int[] arr1, int[] arr2) { + assertEquals(arr1.length, arr2.length); + + Collection<Integer> col1 = new HashSet<>(); + + for (int i = 0; i < arr1.length; ++i) + col1.add(arr1[i]); + + for (int i = 0; i < arr2.length; ++i) { + assertTrue(col1.contains(arr2[i])); + + col1.remove(arr2[i]); + } + + assertEquals(0, col1.size()); + } + + /** + * Check equal collections. + */ + private void checkEqualCollection(Collection<ClusterNode> col1, Collection<ClusterNode> col2) { + Collection<ClusterNode> colCopy1 = new HashSet<>(col1); + + for (ClusterNode node : col2) { + assertTrue(colCopy1.contains(node)); + colCopy1.remove(node); + } + + assertEquals(0, colCopy1.size()); + } + + /** + * @return Cluster nodes. + */ + private Collection<ClusterNode> nodes() { + Set<ClusterNode> nodes = new HashSet<>(); + + for (int i = 0; i < gridCount(); ++i) + nodes.addAll(grid(i).nodes()); + + return nodes; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedNearPartitionedAffinityTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedNearPartitionedAffinityTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedNearPartitionedAffinityTest.java deleted file mode 100644 index 310eb04..0000000 --- a/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedNearPartitionedAffinityTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.apache.ignite; - -import org.apache.ignite.cache.*; - -/** - * Tests for {@link org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy}. - */ -public class IgniteCachePartitionedNearPartitionedAffinityTest extends IgniteCacheAffinityAbstractTest { - /** {@inheritDoc} */ - @Override protected CacheMode cacheMode() { - return CacheMode.PARTITIONED; - } - - /** {@inheritDoc} */ - @Override protected CacheDistributionMode distributionMode() { - return CacheDistributionMode.NEAR_PARTITIONED; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedOnlyAffinityTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedOnlyAffinityTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedOnlyAffinityTest.java deleted file mode 100644 index b9fac92..0000000 --- a/modules/core/src/test/java/org/apache/ignite/IgniteCachePartitionedOnlyAffinityTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.apache.ignite; - -import org.apache.ignite.cache.*; - -/** - * Tests for {@link org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy}. - */ -public class IgniteCachePartitionedOnlyAffinityTest extends IgniteCacheAffinityAbstractTest { - /** {@inheritDoc} */ - @Override protected CacheMode cacheMode() { - return CacheMode.PARTITIONED; - } - - /** {@inheritDoc} */ - @Override protected CacheDistributionMode distributionMode() { - return CacheDistributionMode.PARTITIONED_ONLY; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ca530750/modules/core/src/test/java/org/apache/ignite/IgniteCacheReplicatedPartitionedOnlyAffinityTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteCacheReplicatedPartitionedOnlyAffinityTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteCacheReplicatedPartitionedOnlyAffinityTest.java deleted file mode 100644 index efdb8bc..0000000 --- a/modules/core/src/test/java/org/apache/ignite/IgniteCacheReplicatedPartitionedOnlyAffinityTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.apache.ignite; - -import org.apache.ignite.cache.*; - -/** - * Tests for {@link org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy}. - */ -public class IgniteCacheReplicatedPartitionedOnlyAffinityTest extends IgniteCacheAffinityAbstractTest{ - /** {@inheritDoc} */ - @Override protected CacheMode cacheMode() { - return CacheMode.REPLICATED; - } - - /** {@inheritDoc} */ - @Override protected CacheDistributionMode distributionMode() { - return CacheDistributionMode.PARTITIONED_ONLY; - } -}