sanpwc commented on code in PR #2122:
URL: https://github.com/apache/ignite-3/pull/2122#discussion_r1211132499


##########
modules/distribution-zones/src/test/java/org/apache/ignite/internal/distributionzones/DistributionZoneManagerAlterFilterTest.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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.internal.distributionzones;
+
+import static 
org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_ZONE_ID;
+import static 
org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_ZONE_NAME;
+import static 
org.apache.ignite.internal.distributionzones.DistributionZoneManager.IMMEDIATE_TIMER_VALUE;
+import static 
org.apache.ignite.internal.distributionzones.DistributionZoneManager.INFINITE_TIMER_VALUE;
+import static 
org.apache.ignite.internal.distributionzones.DistributionZonesTestUtil.assertDataNodesFromManager;
+import static 
org.apache.ignite.internal.distributionzones.DistributionZonesUtil.zoneScaleUpChangeTriggerKey;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.cluster.management.topology.api.LogicalNode;
+import org.apache.ignite.internal.metastorage.server.If;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.NetworkAddress;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test scenarios when filter of a zone is altered and immediate scale up is 
triggered.
+ */
+public class DistributionZoneManagerAlterFilterTest  extends 
BaseDistributionZoneManagerTest {
+    private static final String ZONE_NAME = "zone1";
+
+    private static final int ZONE_ID = 1;
+
+    private static final String FILTER = "$[?(@.storage == 'SSD' || @.region 
== 'US')]";
+
+    private static final LogicalNode A = new LogicalNode(
+            new ClusterNode("1", "A", new NetworkAddress("localhost", 123)),
+            Map.of("region", "US", "storage", "SSD", "dataRegionSize", "10")
+    );
+
+    private static final LogicalNode B = new LogicalNode(
+            new ClusterNode("2", "B", new NetworkAddress("localhost", 123)),
+            Map.of("region", "EU", "storage", "HHD", "dataRegionSize", "30")
+    );
+
+    private static final LogicalNode C = new LogicalNode(
+            new ClusterNode("3", "C", new NetworkAddress("localhost", 123)),
+            Map.of("region", "CN", "storage", "SSD", "dataRegionSize", "20")
+    );
+
+    private static final LogicalNode D = new LogicalNode(
+            new ClusterNode("4", "D", new NetworkAddress("localhost", 123)),
+            Map.of("region", "CN", "storage", "HDD", "dataRegionSize", "20")
+    );
+
+    /**
+     * Tests that node that was added before altering filter is taken into 
account after altering of a filter and corresponding
+     * immediate scale up.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    void testAlterFilter() throws Exception {
+        preparePrerequisites();
+
+        // Change timers to infinite, add new node, alter filter and check 
that data nodes was changed.
+        distributionZoneManager.alterZone(
+                ZONE_NAME,
+                new DistributionZoneConfigurationParameters.Builder(ZONE_NAME)
+                        .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE)
+                        .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE)
+                        .filter(FILTER)
+                        .build()
+        ).get(10_000, TimeUnit.MILLISECONDS);
+
+        topology.putNode(D);
+
+        String newFilter = "$[?(@.region == 'CN')]";
+
+        distributionZoneManager.alterZone(ZONE_NAME,
+                new DistributionZoneConfigurationParameters.Builder(ZONE_NAME)
+                        .filter(newFilter)
+                        .build()
+        ).get(10_000, TimeUnit.MILLISECONDS);
+
+        // TODO: https://issues.apache.org/jira/browse/IGNITE-19506 change 
this to the causality versioned call to dataNodes.
+        assertDataNodesFromManager(
+                distributionZoneManager,
+                ZONE_ID,
+                Set.of(C, 
D).stream().map(ClusterNode::name).collect(Collectors.toSet()),
+                10_000
+        );
+    }
+
+    /**
+     * Tests for default zone that node that was added before altering filter 
is taken into account
+     * after altering of a filter and corresponding immediate scale up.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    void testAlterFilterForDefaultZone() throws Exception {
+        topology.putNode(A);
+        topology.putNode(B);
+        topology.putNode(C);
+
+        startDistributionZoneManager();
+
+        distributionZoneManager.alterZone(
+                DEFAULT_ZONE_NAME,

Review Comment:
   I'd rather use parametrized test for default/custom zone variations.



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