|
17 | 17 |
|
18 | 18 | package org.apache.ignite.cache.affinity.rendezvous; |
19 | 19 |
|
| 20 | +import java.util.Collection; |
| 21 | +import org.apache.ignite.IgniteCache; |
20 | 22 | import org.apache.ignite.IgniteCheckedException; |
21 | 23 | import org.apache.ignite.IgniteSystemProperties; |
| 24 | +import org.apache.ignite.cache.affinity.Affinity; |
| 25 | +import org.apache.ignite.cache.affinity.AffinityFunction; |
| 26 | +import org.apache.ignite.cluster.ClusterNode; |
22 | 27 | import org.apache.ignite.configuration.CacheConfiguration; |
23 | 28 | import org.apache.ignite.configuration.IgniteConfiguration; |
24 | 29 | import org.apache.ignite.internal.IgniteEx; |
25 | 30 | import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; |
26 | 31 | import org.junit.Test; |
27 | 32 |
|
28 | 33 | /** */ |
29 | | -public class DcAffinityBackupFilterSelfTest extends GridCommonAbstractTest { |
| 34 | +public class MdcAffinityBackupFilterSelfTest extends GridCommonAbstractTest { |
30 | 35 | /** */ |
31 | 36 | private static final String DC_0_ID = "DC_0"; |
32 | 37 |
|
33 | 38 | /** */ |
34 | 39 | private static final String DC_1_ID = "DC_1"; |
35 | 40 |
|
| 41 | + /** {@inheritDoc} */ |
36 | 42 | @Override protected IgniteConfiguration optimize(IgniteConfiguration cfg) throws IgniteCheckedException { |
37 | 43 | return super.optimize(cfg).setIncludeProperties((String[])null); |
38 | 44 | } |
39 | 45 |
|
| 46 | + /** |
| 47 | + * Verifies that partition copies are assigned evenly to all data centers. |
| 48 | + * |
| 49 | + * @throws Exception If failed. |
| 50 | + */ |
40 | 51 | @Test |
41 | | - public void test1() throws Exception { |
| 52 | + public void testBasicDistribution() throws Exception { |
42 | 53 | System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_0_ID); |
43 | | - startGrids(3); |
| 54 | + startGrids(2); |
44 | 55 |
|
45 | 56 | System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_1_ID); |
46 | | - startGrid(3); |
47 | | - startGrid(4); |
48 | | - IgniteEx srv = startGrid(5); |
| 57 | + startGrid(2); |
| 58 | + IgniteEx srv = startGrid(3); |
49 | 59 |
|
50 | | - CacheConfiguration ccfg = defaultCacheConfiguration(); |
51 | | - ccfg.setBackups(3); |
52 | | - ccfg.setAffinity(new RendezvousAffinityFunction(false, 2) |
53 | | - .setAffinityBackupFilter(new DcAffinityBackupFilter(2, 3))); |
| 60 | + CacheConfiguration ccfg = defaultCacheConfiguration() |
| 61 | + .setBackups(3) |
| 62 | + .setAffinity( |
| 63 | + new RendezvousAffinityFunction(false, 4) |
| 64 | + .setAffinityBackupFilter(new MdcAffinityBackupFilter(2, 3))); |
54 | 65 |
|
55 | | - srv.getOrCreateCache(ccfg); |
| 66 | + IgniteCache cache = srv.getOrCreateCache(ccfg); |
| 67 | + |
| 68 | + checkPartitions(srv, cache, 3); |
| 69 | + } |
| 70 | + |
| 71 | + /** */ |
| 72 | + private void checkPartitions(IgniteEx srv, IgniteCache cache, int backups) throws IgniteCheckedException {) { |
| 73 | + int partCnt = cacheConfiguration(srv.configuration(), cache.getName()).getAffinity().partitions(); |
| 74 | + Affinity aff = affinity(cache); |
| 75 | + |
| 76 | + for (int i = 0; i < partCnt; i++) { |
| 77 | + Collection<ClusterNode> nodes = aff.mapKeyToPrimaryAndBackups(i); |
| 78 | + } |
56 | 79 | } |
57 | 80 | } |
0 commit comments