You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/04/28 14:05:52 UTC
[GitHub] [ignite-3] rpuch opened a new pull request, #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
rpuch opened a new pull request, #794:
URL: https://github.com/apache/ignite-3/pull/794
https://issues.apache.org/jira/browse/IGNITE-16513
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861717837
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
Review Comment:
It shouldn't, thanks. Removed the keyword.
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
Review Comment:
Thanks
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861718066
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Cannot parse URI", e);
+ }
+ }
+
+ @AfterEach
+ void tearDown(TestInfo testInfo) {
+ for (int i = 0; i < 3; i++) {
Review Comment:
Good catch, fixed.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
sashapolo commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861773725
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliIntegrationTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ CountDownLatch allNodesAreInPhysicalTopology = new CountDownLatch(1);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(CountDownLatch physicalTopologyIsFull) {
+ return new NoOpHandler() {
+ @Override
+ public void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.countDown();
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
Review Comment:
1. I don't think it makes much sense, all other tests start nodes sequentially
2. You can use `parallel().forEach`, it will be shorter
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
sashapolo commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861663431
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
Review Comment:
Shall we cache the client in a field? It allocates quite a lot of resources
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861695499
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
Review Comment:
To be honest, I'm a bit reluctant to use resources if a plain old file access could be employed. The code would be a bit longer (or would require a utility method to be written); also, the resource mechanism relies on classloaders which are a lot more complex and brittle than simple file access. I even bumped into bugs in IDEA a couple of times when IDE was not able to see resources even though they were in place.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861719281
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
Review Comment:
Removed waiting for REST endpoint to be available. Also, added javadocs to `IgnitionManager`, `Ignition`, `IgniteImpl` to highlight that the node is half-started when `start()` method returns.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] SammyVimes merged pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
SammyVimes merged PR #794:
URL: https://github.com/apache/ignite-3/pull/794
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
sashapolo commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861750069
##########
modules/api/src/main/java/org/apache/ignite/Ignition.java:
##########
@@ -32,6 +32,9 @@ public interface Ignition {
/**
* Starts an Ignite node with an optional bootstrap configuration from a HOCON file.
*
+ * <p>When this method returns, the node is partly started and ready to accept init command (that is, its
Review Comment:
```suggestion
* <p>When this method returns, the node is partially started and ready to accept the init command (that is, its
```
##########
modules/api/src/main/java/org/apache/ignite/Ignition.java:
##########
@@ -32,6 +32,9 @@ public interface Ignition {
/**
* Starts an Ignite node with an optional bootstrap configuration from a HOCON file.
*
+ * <p>When this method returns, the node is partly started and ready to accept init command (that is, its
Review Comment:
Same applies to all similar changes
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliIntegrationTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ CountDownLatch allNodesAreInPhysicalTopology = new CountDownLatch(1);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(CountDownLatch physicalTopologyIsFull) {
+ return new NoOpHandler() {
+ @Override
+ public void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.countDown();
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
Review Comment:
What's the point of using `runAsync` here? I think you can simply start nodes in a cycle
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
sashapolo commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861705276
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
Review Comment:
Sure, I'm ok with your current approach as well
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861718482
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
Review Comment:
This code is removed, so it's not relevant anymore
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861717307
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/HandlerAdapter.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.cli;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+/**
+ * Adapter for {@link Handler} with empty implementations of all methods but {@link Handler#publish(LogRecord)}.
+ */
+public abstract class HandlerAdapter extends Handler {
Review Comment:
The value of this class is to make the 'use site' code cleaner. Two more empty methods would distract the reader.
I understand that `HandlerAdapter` makes you think it could be an instance of Adapter design pattern and, hence, it could contain some non-trivial logic. I renamed it to `NoOpHandler` to highlight that it is just an empty implementation.
What do you think?
##########
modules/cli/src/test/java/org/apache/ignite/cli/AbstractCliTest.java:
##########
@@ -22,7 +22,7 @@
/**
* Base class for any CLI tests.
*/
-public class AbstractCliTest {
+public abstract class AbstractCliTest {
Review Comment:
Done
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
sashapolo commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861653593
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/HandlerAdapter.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.cli;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+/**
+ * Adapter for {@link Handler} with empty implementations of all methods but {@link Handler#publish(LogRecord)}.
+ */
+public abstract class HandlerAdapter extends Handler {
Review Comment:
This class is only used in one place, can we inline it?
##########
modules/cli/src/test/java/org/apache/ignite/cli/AbstractCliTest.java:
##########
@@ -22,7 +22,7 @@
/**
* Base class for any CLI tests.
*/
-public class AbstractCliTest {
+public abstract class AbstractCliTest {
Review Comment:
Can you please also remove the `private` modifier from `beforeAll` in this class?
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
Review Comment:
Why does it have to be synchronized?
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
Review Comment:
you can use `URI.create`, it will be a little shorter
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
Review Comment:
Since this file is a resource, should we use the standard resource facility instead of hardcoding the path?
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Cannot parse URI", e);
+ }
+ }
+
+ @AfterEach
+ void tearDown(TestInfo testInfo) {
+ for (int i = 0; i < 3; i++) {
Review Comment:
why 3? Shouldn't it be `NODES.size()`?
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
Review Comment:
[Optional] Some of these private methods can be 'static'
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
Review Comment:
I think we should simply use a Latch instead of an AtomicBoolean and get rid of `waitForCondition`
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
Review Comment:
I suggest using `willCompleteSuccessfully()` instead of `join`, since the future may block forever
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
Review Comment:
There's no need for this, I think. After `InitionManager.start` completes, the REST manager should already be started
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Cannot parse URI", e);
+ }
+ }
+
+ @AfterEach
+ void tearDown(TestInfo testInfo) {
+ for (int i = 0; i < 3; i++) {
+ IgnitionManager.stop(testNodeName(testInfo, i));
+ }
+
+ if (ctx != null) {
+ ctx.stop();
+ }
+ }
+
+ /**
+ * Starts a cluster of 4 nodes and executes init command on it. First node is used to issue the command via REST endpoint,
+ * second will host the meta-storage RAFT group, third will host the Cluster Management RAFT Group (CMG), fourth
+ * will be just a node.
+ *
+ * @param testInfo test info (used to derive node names)
+ */
+ @Test
+ void initClusterWithNodesOfDifferentRoles(TestInfo testInfo) {
+ int exitCode = cmd(ctx).execute(
+ "cluster", "init",
+ "--node-endpoint", FIRST_NODE.restHostPort(),
+ "--meta-storage-node", SECOND_NODE.nodeName(testInfo),
+ "--cmg-node", THIRD_NODE.nodeName(testInfo)
+ );
+
+ assertThat(
+ String.format("Wrong exit code; std is '%s', stderr is '%s'", out.toString(UTF_8), err.toString(UTF_8)),
+ exitCode, is(0)
+ );
+ assertThat(out.toString(UTF_8), is("Cluster was initialized successfully." + NL));
+
+ // TODO: when IGNITE-16526 is implemented, also check that the logical topology contains all 4 nodes
+ }
+
+ /**
+ * Creates a new command line interpreter.
+ *
+ * @param applicationCtx DI context.
+ * @return New command line instance.
+ */
+ private CommandLine cmd(ApplicationContext applicationCtx) {
Review Comment:
I think this method should be moved to `AbstractCliTest`
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Cannot parse URI", e);
+ }
+ }
+
+ @AfterEach
+ void tearDown(TestInfo testInfo) {
+ for (int i = 0; i < 3; i++) {
+ IgnitionManager.stop(testNodeName(testInfo, i));
+ }
+
+ if (ctx != null) {
+ ctx.stop();
+ }
+ }
+
+ /**
+ * Starts a cluster of 4 nodes and executes init command on it. First node is used to issue the command via REST endpoint,
+ * second will host the meta-storage RAFT group, third will host the Cluster Management RAFT Group (CMG), fourth
+ * will be just a node.
+ *
+ * @param testInfo test info (used to derive node names)
+ */
+ @Test
+ void initClusterWithNodesOfDifferentRoles(TestInfo testInfo) {
+ int exitCode = cmd(ctx).execute(
+ "cluster", "init",
+ "--node-endpoint", FIRST_NODE.restHostPort(),
+ "--meta-storage-node", SECOND_NODE.nodeName(testInfo),
+ "--cmg-node", THIRD_NODE.nodeName(testInfo)
+ );
+
+ assertThat(
+ String.format("Wrong exit code; std is '%s', stderr is '%s'", out.toString(UTF_8), err.toString(UTF_8)),
+ exitCode, is(0)
+ );
+ assertThat(out.toString(UTF_8), is("Cluster was initialized successfully." + NL));
Review Comment:
you can use `containsString` instead and get rid of the `NL` constant
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
Review Comment:
Shall we cache the client in a field? It allocated quite a lot of resources
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861708470
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Cannot parse URI", e);
+ }
+ }
+
+ @AfterEach
+ void tearDown(TestInfo testInfo) {
+ for (int i = 0; i < 3; i++) {
+ IgnitionManager.stop(testNodeName(testInfo, i));
+ }
+
+ if (ctx != null) {
+ ctx.stop();
+ }
+ }
+
+ /**
+ * Starts a cluster of 4 nodes and executes init command on it. First node is used to issue the command via REST endpoint,
+ * second will host the meta-storage RAFT group, third will host the Cluster Management RAFT Group (CMG), fourth
+ * will be just a node.
+ *
+ * @param testInfo test info (used to derive node names)
+ */
+ @Test
+ void initClusterWithNodesOfDifferentRoles(TestInfo testInfo) {
+ int exitCode = cmd(ctx).execute(
+ "cluster", "init",
+ "--node-endpoint", FIRST_NODE.restHostPort(),
+ "--meta-storage-node", SECOND_NODE.nodeName(testInfo),
+ "--cmg-node", THIRD_NODE.nodeName(testInfo)
+ );
+
+ assertThat(
+ String.format("Wrong exit code; std is '%s', stderr is '%s'", out.toString(UTF_8), err.toString(UTF_8)),
+ exitCode, is(0)
+ );
+ assertThat(out.toString(UTF_8), is("Cluster was initialized successfully." + NL));
Review Comment:
I still want to assert that a newline is emitted to make sure it does not mess with the user's terminal.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861769697
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliIntegrationTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ CountDownLatch allNodesAreInPhysicalTopology = new CountDownLatch(1);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(CountDownLatch physicalTopologyIsFull) {
+ return new NoOpHandler() {
+ @Override
+ public void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.countDown();
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
Review Comment:
I just don't want to parallelize the process of starting different nodes. Doesn't it make sense here?
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliIntegrationTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ CountDownLatch allNodesAreInPhysicalTopology = new CountDownLatch(1);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(CountDownLatch physicalTopologyIsFull) {
+ return new NoOpHandler() {
+ @Override
+ public void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.countDown();
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
Review Comment:
I just want to parallelize the process of starting different nodes. Doesn't it make sense here?
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861805952
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliIntegrationTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ CountDownLatch allNodesAreInPhysicalTopology = new CountDownLatch(1);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(CountDownLatch physicalTopologyIsFull) {
+ return new NoOpHandler() {
+ @Override
+ public void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.countDown();
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
Review Comment:
Thanks for the suggestions, I switched to parallel stream. Does it look better?
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861718223
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
Review Comment:
Switched to `CountDownLatch`
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
Review Comment:
Done
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861717668
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
Review Comment:
They could. I suggest we make them static when (and if) we need it.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861733895
##########
modules/cli/src/integrationTest/java/org/apache/ignite/cli/ItClusterCommandTest.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.cli;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.stream.Collectors.joining;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.env.Environment;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.cli.spec.IgniteCliSpec;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import picocli.CommandLine;
+
+/**
+ * Integration test for {@code ignite cluster} commands.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+class ItClusterCommandTest extends AbstractCliTest {
+ private static final Node FIRST_NODE = new Node(0, 10100, 10300);
+ private static final Node SECOND_NODE = new Node(1, 11100, 11300);
+ private static final Node THIRD_NODE = new Node(2, 12100, 12300);
+ private static final Node FOURTH_NODE = new Node(3, 13100, 13300);
+
+ private static final List<Node> NODES = List.of(FIRST_NODE, SECOND_NODE, THIRD_NODE, FOURTH_NODE);
+
+ private static final String NL = System.lineSeparator();
+
+ private static final Logger topologyLogger = Logger.getLogger("org.apache.ignite.network.scalecube.ScaleCubeTopologyService");
+
+ /** DI context. */
+ private ApplicationContext ctx;
+
+ /** stderr. */
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ /** stdout. */
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ @BeforeEach
+ void setup(@WorkDirectory Path workDir, TestInfo testInfo) throws Exception {
+ AtomicBoolean allNodesAreInPhysicalTopology = new AtomicBoolean(false);
+
+ Handler physicalTopologyWaiter = physicalTopologyWaiter(allNodesAreInPhysicalTopology);
+ topologyLogger.addHandler(physicalTopologyWaiter);
+
+ try {
+ startClusterWithoutInit(workDir, testInfo);
+
+ waitTillAllNodesJoinPhysicalTopology(allNodesAreInPhysicalTopology);
+ } finally {
+ topologyLogger.removeHandler(physicalTopologyWaiter);
+ }
+
+ ctx = ApplicationContext.run(Environment.TEST);
+ }
+
+ private Handler physicalTopologyWaiter(AtomicBoolean physicalTopologyIsFull) {
+ return new HandlerAdapter() {
+ @Override
+ public synchronized void publish(LogRecord record) {
+ if (record.getMessage().contains("Topology snapshot [nodes=" + NODES.size() + "]")) {
+ physicalTopologyIsFull.set(true);
+ }
+ }
+ };
+ }
+
+ private void startClusterWithoutInit(Path workDir, TestInfo testInfo) {
+ CompletableFuture<?>[] futures = NODES.stream()
+ .map(node -> runAsync(() -> startNodeWithoutInit(node, workDir, testInfo)))
+ .toArray(CompletableFuture[]::new);
+
+ CompletableFuture.allOf(futures).join();
+ }
+
+ private void waitTillAllNodesJoinPhysicalTopology(AtomicBoolean allNodesAreInPhysicalTopology) throws InterruptedException {
+ assertTrue(IgniteTestUtils.waitForCondition(allNodesAreInPhysicalTopology::get, 10_000));
+ }
+
+ /**
+ * Initiates node start and waits till it makes its REST endpoints available, but does NOT invoke init.
+ *
+ * @param node node
+ * @param workDir working directory
+ * @param testInfo test info
+ * @throws InterruptedException if we get interrupted
+ */
+ private void startNodeWithoutInit(Node node, Path workDir, TestInfo testInfo) throws InterruptedException, IOException {
+ String nodeName = testNodeName(testInfo, node.nodeIndex);
+
+ String config = configJsonFor(node);
+
+ IgnitionManager.start(nodeName, config, workDir.resolve(nodeName));
+
+ assertTrue(IgniteTestUtils.waitForCondition(() -> isHttpServedAt(node.restHostPort()), 10_000));
+ }
+
+ private String configJsonFor(Node node) throws IOException {
+ String config = Files.readString(Path.of("src/integrationTest/resources/hardcoded-ports-config.json"));
+ config = config.replaceAll("<NETWORK_PORT>", String.valueOf(node.networkPort));
+ config = config.replaceAll("<REST_PORT>", String.valueOf(node.restPort));
+ config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes());
+
+ return config;
+ }
+
+ private String netClusterNodes() {
+ return NODES.stream()
+ .map(Node::networkHostPort)
+ .map(s -> "\"" + s + "\"")
+ .collect(joining(", ", "[", "]"));
+ }
+
+ private boolean isHttpServedAt(String hostPort) {
+ HttpRequest request = HttpRequest.newBuilder(uriFor(hostPort))
+ .GET()
+ .build();
+
+ try {
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());
+
+ return true;
+ } catch (IOException e) {
+ return false;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private URI uriFor(String hostPort) {
+ try {
+ return new URI("http://" + hostPort + "/");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Cannot parse URI", e);
+ }
+ }
+
+ @AfterEach
+ void tearDown(TestInfo testInfo) {
+ for (int i = 0; i < 3; i++) {
+ IgnitionManager.stop(testNodeName(testInfo, i));
+ }
+
+ if (ctx != null) {
+ ctx.stop();
+ }
+ }
+
+ /**
+ * Starts a cluster of 4 nodes and executes init command on it. First node is used to issue the command via REST endpoint,
+ * second will host the meta-storage RAFT group, third will host the Cluster Management RAFT Group (CMG), fourth
+ * will be just a node.
+ *
+ * @param testInfo test info (used to derive node names)
+ */
+ @Test
+ void initClusterWithNodesOfDifferentRoles(TestInfo testInfo) {
+ int exitCode = cmd(ctx).execute(
+ "cluster", "init",
+ "--node-endpoint", FIRST_NODE.restHostPort(),
+ "--meta-storage-node", SECOND_NODE.nodeName(testInfo),
+ "--cmg-node", THIRD_NODE.nodeName(testInfo)
+ );
+
+ assertThat(
+ String.format("Wrong exit code; std is '%s', stderr is '%s'", out.toString(UTF_8), err.toString(UTF_8)),
+ exitCode, is(0)
+ );
+ assertThat(out.toString(UTF_8), is("Cluster was initialized successfully." + NL));
+
+ // TODO: when IGNITE-16526 is implemented, also check that the logical topology contains all 4 nodes
+ }
+
+ /**
+ * Creates a new command line interpreter.
+ *
+ * @param applicationCtx DI context.
+ * @return New command line instance.
+ */
+ private CommandLine cmd(ApplicationContext applicationCtx) {
Review Comment:
This also requires to move `out` and `err` (or change something else), so, to reduce invasivity, I added another abstract superclass (`AbstractCliIntegrationTest`) and moved the method and two fields there.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] rpuch commented on a diff in pull request #794: IGNITE-16513 Add an integration test for 'cluster init' CLI command
Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #794:
URL: https://github.com/apache/ignite-3/pull/794#discussion_r861772528
##########
modules/api/src/main/java/org/apache/ignite/Ignition.java:
##########
@@ -32,6 +32,9 @@ public interface Ignition {
/**
* Starts an Ignite node with an optional bootstrap configuration from a HOCON file.
*
+ * <p>When this method returns, the node is partly started and ready to accept init command (that is, its
Review Comment:
Done. I hope I did not miss anything
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org