anton-vinogradov commented on code in PR #12459:
URL: https://github.com/apache/ignite/pull/12459#discussion_r2477905470


##########
modules/core/src/test/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilterSelfTest.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity.rendezvous;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Verifies behaviour of {@link MdcAffinityBackupFilter} - guarantees that 
each DC has at least one copy of every partition.
+ * Verified distribution uniformity in each DC separately.
+ */
+public class MdcAffinityBackupFilterSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final int PARTS_CNT = 1024;
+
+    /** */
+    private int backups;
+
+    /** */
+    private String[] dcIds;
+
+    /** */
+    private IgniteBiPredicate<ClusterNode, List<ClusterNode>> filter;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setCacheConfiguration(defaultCacheConfiguration()
+            .setBackups(backups)
+            .setAffinity(
+                new RendezvousAffinityFunction(false, PARTS_CNT)
+                    .setAffinityBackupFilter(filter)));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * Verifies that {@link MdcAffinityBackupFilter} prohibits single data 
center deployment.
+     */
+    @Test
+    public void testSingleDcDeploymentIsProhibited() {
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(1, 1),
+            IllegalArgumentException.class,
+            "Number of datacenters must be at least 2.");
+    }
+
+    /**
+     * Verifies that {@link MdcAffinityBackupFilter} enforces even number of 
partition copies per datacenter.
+     */
+    @Test
+    public void testUniformNumberOfPartitionCopiesPerDcIsEnforced() {
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(3, 1),
+            IllegalArgumentException.class,
+            "recommended value is 2");
+
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(3, 7),
+            IllegalArgumentException.class,
+            "recommended values are 5 and 8");
+    }
+
+    /**
+     * Verifies that partition copies are assigned evenly across a cluster in 
two data centers.
+     * <p/>
+     * When a node from one data center is stopped, partition distribution is 
that data center should stay uniform.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test2DcDistribution() throws Exception {
+        dcIds = new String[] {"DC_0", "DC_1"};
+        int nodesPerDc = 4;
+        backups = 3;
+        filter = new MdcAffinityBackupFilter(dcIds.length, backups);
+
+        IgniteEx srv = startClusterAcrossDataCenters(dcIds, nodesPerDc);
+
+        verifyDistributionProperties(srv, dcIds, nodesPerDc, backups);
+
+        //stopping one node in DC_1 should not compromise distribution as 
there are additional nodes in the same DC
+        stopGrid(5);
+
+        awaitPartitionMapExchange();
+
+        verifyDistributionProperties(srv, dcIds, nodesPerDc, backups);
+
+        //stopping another node in DC_1 should not compromise distribution as 
well
+        stopGrid(6);

Review Comment:
   let's stop the whole DC as well and check there is no rebalance happened.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to