NSAmelchev commented on code in PR #12459:
URL: https://github.com/apache/ignite/pull/12459#discussion_r2469741518


##########
modules/core/src/test/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilterSelfTest.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.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.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * 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 = 8;
+
+    /** */
+    private int backups;
+
+    /** */
+    private String[] dcIds;
+
+    /** {@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(new 
MdcAffinityBackupFilter(dcIds.length, backups))));
+
+        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() {
+        dcIds = new String[] {"DC_0"};
+        System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, 
dcIds[0]);
+
+        backups = 1;
+        verifyGridFailsToStartWithMessage("Number of datacenters must be at 
least 2.");
+    }
+
+    /**
+     * Verifies that {@link MdcAffinityBackupFilter} enforces even number of 
partition copies per datacenter.
+     */
+    @Test
+    public void testEvenNumberOfPartitionCopiesPerDcIsEnforced() {
+        dcIds = new String[] {"DC_0", "DC_1", "DC_2"};
+        System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, 
dcIds[0]);
+
+        backups = 1;
+        verifyGridFailsToStartWithMessage("recommended value is 2");
+
+        backups = 7;
+        verifyGridFailsToStartWithMessage("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;
+
+        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);
+
+        awaitPartitionMapExchange();
+
+        verifyDistributionProperties(srv, dcIds, nodesPerDc, backups);
+    }
+
+    /**
+     * Verifies that partition copies are assigned evenly across a cluster in 
three data centers.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test3DcDistribution() throws Exception {
+        dcIds = new String[] {"DC_0", "DC_1", "DC_2"};
+        int nodesPerDc = 2;
+        backups = 5;
+
+        IgniteEx srv = startClusterAcrossDataCenters(dcIds, 2);
+
+        verifyDistributionProperties(srv, dcIds, nodesPerDc, backups);
+    }
+
+    /** */
+    private void verifyGridFailsToStartWithMessage(String msg) {
+        try {
+            startGrid(0);
+        } catch (IllegalArgumentException argEx) {

Review Comment:
   `assertThrowsWithCause/assertThrows` can be used.



-- 
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