Repository: incubator-ignite Updated Branches: refs/heads/ignite-9655-merge ff2da2090 -> 908f97f16
#IGNITE-9655-merge - Added test. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/908f97f1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/908f97f1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/908f97f1 Branch: refs/heads/ignite-9655-merge Commit: 908f97f1672eafc86d1479b4369c921f1d6d5187 Parents: ff2da20 Author: Alexey Goncharuk <agoncha...@gridgain.com> Authored: Thu Feb 12 16:41:09 2015 -0800 Committer: Alexey Goncharuk <agoncha...@gridgain.com> Committed: Thu Feb 12 16:41:09 2015 -0800 ---------------------------------------------------------------------- .../IgniteClientAffinityAssignmentSelfTest.java | 156 +++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 2 + 2 files changed, 158 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/908f97f1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java new file mode 100644 index 0000000..7a7ccd1 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java @@ -0,0 +1,156 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.internal.processors.cache; + +import 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.configuration.*; +import org.apache.ignite.testframework.junits.common.*; + +import static org.apache.ignite.cache.CacheDistributionMode.*; + +/** + * Tests affinity assignment for different affinity types. + */ +public class IgniteClientAffinityAssignmentSelfTest extends GridCommonAbstractTest { + /** */ + public static final int PARTS = 256; + + /** */ + private boolean client; + + /** */ + private boolean cache; + + /** */ + private int aff; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + if (cache) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setBackups(1); + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setDistributionMode(client ? CLIENT_ONLY : PARTITIONED_ONLY); + + if (aff == 0) + ccfg.setAffinity(new CacheConsistentHashAffinityFunction(false, PARTS)); + else if (aff == 1) + ccfg.setAffinity(new CacheRendezvousAffinityFunction(false, PARTS)); + else + ccfg.setAffinity(new CachePartitionFairAffinity(PARTS)); + + cfg.setCacheConfiguration(ccfg); + } + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testConsistentHashAssignment() throws Exception { + aff = 0; + + checkAffinityFunction(); + } + + /** + * @throws Exception If failed. + */ + public void testRendezvousAssignment() throws Exception { + aff = 1; + + checkAffinityFunction(); + } + + /** + * @throws Exception If failed. + */ + public void testFairAssignment() throws Exception { + aff = 2; + + checkAffinityFunction(); + } + + /** + * @throws Exception If failed. + */ + private void checkAffinityFunction() throws Exception { + cache = true; + + startGrids(3); + + try { + checkAffinity(); + + client = true; + + startGrid(3); + + checkAffinity(); + + startGrid(4); + + checkAffinity(); + + cache = false; + + startGrid(5); + + checkAffinity(); + + stopGrid(5); + + checkAffinity(); + + stopGrid(4); + + checkAffinity(); + + stopGrid(3); + + checkAffinity(); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + private void checkAffinity() throws Exception { + CacheAffinity<Object> aff = grid(0).cache(null).affinity(); + + for (Ignite grid : Ignition.allGrids()) { + try { + if (grid.cluster().localNode().id().equals(grid(0).localNode().id())) + continue; + + CacheAffinity<Object> checkAff = grid.cache(null).affinity(); + + for (int p = 0; p < PARTS; p++) + assertEquals(aff.mapPartitionToPrimaryAndBackups(p), checkAff.mapPartitionToPrimaryAndBackups(p)); + } + catch (IllegalArgumentException ignored) { + // Skip the node without cache. + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/908f97f1/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index f040375..5674438 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -56,6 +56,8 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTest(IgniteCacheExpiryPolicyTestSuite.suite()); + suite.addTestSuite(IgniteClientAffinityAssignmentSelfTest.class); + suite.addTestSuite(IgniteCacheAtomicInvokeTest.class); suite.addTestSuite(IgniteCacheAtomicNearEnabledInvokeTest.class); suite.addTestSuite(IgniteCacheAtomicPrimaryWriteOrderInvokeTest.class);