PakhomovAlexander commented on code in PR #5315:
URL: https://github.com/apache/ignite-3/pull/5315#discussion_r1983000196


##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/cluster/init/ItClusterInitDefaultMsCmgTest.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.cli.commands.cluster.init;
+
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import 
org.apache.ignite.internal.cli.commands.CliCommandTestNotInitializedIntegrationBase;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link ClusterInitCommand}.
+ *
+ * <p>Because the {@link org.apache.ignite.internal.cli.CliIntegrationTest} 
extends
+ * {@link org.apache.ignite.internal.ClusterPerClassIntegrationTest}, each CLI 
test case for init has to be placed in a separate
+ * test class. It'd ideal to refactor the base classes to have a CLI init test 
class with multiple test cases.
+ * This may be needed if more tests are added.
+ */
+public class ItClusterInitDefaultMsCmgTest extends 
CliCommandTestNotInitializedIntegrationBase {
+    @Override
+    protected int initialNodes() {
+        // Use 6 nodes so that there is one that's not in MS and CMG by 
default.
+        return 6;
+    }
+
+    @Test
+    @DisplayName("Init cluster with default MS and CMG")
+    void initClusterWithDefaultMsAndCmg() throws InterruptedException {
+
+        // when
+        connect(NODE_URL);
+
+        execute(
+                "cluster", "init",
+                "--name", "cluster"
+        );
+
+        assertAll(
+                this::assertExitCodeIsZero,
+                this::assertErrOutputIsEmpty,
+                () -> assertOutputContains("Cluster was initialized 
successfully")
+        );
+
+        // then
+        awaitClusterInitialized();
+
+        execute("cluster", "topology", "logical");
+        assertExitCodeIsZero();
+        for (int i = 0; i < initialNodes(); i++) {
+            assertOutputContains(CLUSTER.nodeName(i));
+        }
+
+        execute("cluster", "status");
+        assertExitCodeIsZero();
+
+        String output = getOutput();
+
+        // Extract node lists using regex
+        Pattern pattern = Pattern.compile("cmgNodes: \\[(.*?)], msNodes: 
\\[(.*?)]");
+        Matcher matcher = pattern.matcher(output);
+        assertThat("Expected cmgNodes and msNodes lists in output", 
matcher.find(), is(true));
+
+        // Parse the extracted node lists
+        Pattern listPattern = Pattern.compile(", ");
+        List<String> cmgNodes = List.of(listPattern.split(matcher.group(1)));
+        List<String> msNodes = List.of(listPattern.split(matcher.group(2)));
+
+        // Compare lists with expected
+        List<String> expectedNodes = IntStream.range(0, 5)

Review Comment:
   ```suggestion
           List<String> expectedNodes = IntStream.range(0, initialNodes() - 1)
   ```



##########
DEVNOTES.md:
##########
@@ -348,7 +348,7 @@ the docker image using `cli` parameter and connect to nodes 
using their names fr
 docker compose -f packaging/docker/docker-compose.yml up -d
 docker run -it --rm --net ignite3_default apacheignite/ignite3 cli
 > connect http://node1:10300
-> cluster init --name cluster --metastorage-group=node1,node2,node3
+> cluster init --name cluster

Review Comment:
   Just thinking: What if the `name` is also optional? If I don't care about 
name - it might be autogenerated. Like docker does for containers.



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to