sashapolo commented on code in PR #3297:
URL: https://github.com/apache/ignite-3/pull/3297#discussion_r1508643211


##########
modules/network/src/test/java/org/apache/ignite/internal/network/netty/NettyServerTest.java:
##########
@@ -140,6 +146,36 @@ public void testStartTwice() {
         assertThrows(IgniteInternalException.class, server::start);
     }
 
+    /**
+     * Tests that bootstrap tries to bind to address specified in 
configuration.
+     */
+    @Test
+    public void testBindWithAddress() {
+        String host = "localhost";
+        assertThat(serverCfg.listenAddress().update(host), 
willCompleteSuccessfully());
+
+        getServer(true);
+
+        serverCfg.listenAddress().update("");

Review Comment:
   What does this line check?



##########
modules/network/src/test/java/org/apache/ignite/internal/network/netty/NettyServerTest.java:
##########
@@ -140,6 +146,36 @@ public void testStartTwice() {
         assertThrows(IgniteInternalException.class, server::start);
     }
 
+    /**
+     * Tests that bootstrap tries to bind to address specified in 
configuration.
+     */
+    @Test
+    public void testBindWithAddress() {
+        String host = "localhost";
+        assertThat(serverCfg.listenAddress().update(host), 
willCompleteSuccessfully());
+
+        getServer(true);
+
+        serverCfg.listenAddress().update("");
+
+    }
+
+    /**
+     * Tests the case when couldn't bind to the address provided.
+     */
+    @Test
+    public void testBindUnknownAddressFailed() {
+        String address = "unknown-address";
+        assertThat(serverCfg.listenAddress().update(address), 
willCompleteSuccessfully());
+
+        AssertionFailedError e = assertThrows(AssertionFailedError.class, () 
-> getServer(true));
+
+        String expectedError = String.format("Address %s:%d is not available", 
address, serverCfg.port().value());
+        assertTrue(e.getCause().getMessage().contains(expectedError));

Review Comment:
   It would be more correct to use `assertThat(message, contains(expected))`



##########
modules/network/src/test/java/org/apache/ignite/internal/network/netty/NettyServerTest.java:
##########
@@ -140,6 +146,36 @@ public void testStartTwice() {
         assertThrows(IgniteInternalException.class, server::start);
     }
 
+    /**
+     * Tests that bootstrap tries to bind to address specified in 
configuration.
+     */
+    @Test
+    public void testBindWithAddress() {
+        String host = "localhost";
+        assertThat(serverCfg.listenAddress().update(host), 
willCompleteSuccessfully());
+
+        getServer(true);

Review Comment:
   Please add `assertDoesNotThrow` here



##########
modules/network/src/test/java/org/apache/ignite/internal/network/netty/NettyServerTest.java:
##########
@@ -140,6 +146,36 @@ public void testStartTwice() {
         assertThrows(IgniteInternalException.class, server::start);
     }
 
+    /**
+     * Tests that bootstrap tries to bind to address specified in 
configuration.
+     */
+    @Test
+    public void testBindWithAddress() {
+        String host = "localhost";
+        assertThat(serverCfg.listenAddress().update(host), 
willCompleteSuccessfully());
+
+        getServer(true);
+
+        serverCfg.listenAddress().update("");
+
+    }
+
+    /**
+     * Tests the case when couldn't bind to the address provided.
+     */
+    @Test
+    public void testBindUnknownAddressFailed() {
+        String address = "unknown-address";
+        assertThat(serverCfg.listenAddress().update(address), 
willCompleteSuccessfully());
+
+        AssertionFailedError e = assertThrows(AssertionFailedError.class, () 
-> getServer(true));
+
+        String expectedError = String.format("Address %s:%d is not available", 
address, serverCfg.port().value());
+        assertTrue(e.getCause().getMessage().contains(expectedError));
+
+        assertThat(serverCfg.listenAddress().update(""), 
willCompleteSuccessfully());

Review Comment:
   And what does this line check?



##########
modules/network/src/test/java/org/apache/ignite/internal/network/netty/NettyServerTest.java:
##########
@@ -140,6 +146,36 @@ public void testStartTwice() {
         assertThrows(IgniteInternalException.class, server::start);
     }
 
+    /**
+     * Tests that bootstrap tries to bind to address specified in 
configuration.

Review Comment:
   How do you check this condition in this test?



##########
modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/ItClientHandlerBindTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.client.handler;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.net.ConnectException;
+import java.net.Socket;
+import java.util.concurrent.CompletionException;
+import 
org.apache.ignite.client.handler.configuration.ClientConnectorConfiguration;
+import 
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import 
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.network.configuration.NetworkConfiguration;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Client connector address configuration tests.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public class ItClientHandlerBindTest extends BaseIgniteAbstractTest {
+    @InjectConfiguration
+    private NetworkConfiguration networkConfiguration;
+
+    @Test
+    void listenOnlySpecificAddress(
+            TestInfo testInfo,
+            @InjectConfiguration("mock.listenAddress=127.0.0.7") 
ClientConnectorConfiguration clientConnectorConfiguration
+    ) throws Exception {
+        TestServer server = new TestServer(null, null, 
clientConnectorConfiguration, networkConfiguration);
+
+        ClientHandlerModule serverModule = assertDoesNotThrow(() -> 
server.start(testInfo));
+
+        int port = serverModule.localAddress().getPort();
+
+        assertDoesNotThrow(
+                () -> {
+                    Socket socket = new Socket("127.0.0.7", port);
+                    socket.close();
+                });
+
+        assertThrows(
+                ConnectException.class,
+                () -> {
+                    Socket socket = new Socket("127.0.0.1", port);
+                    socket.close();
+                });
+
+        serverModule.stop();

Review Comment:
   This stuff should be placed either in an `@AfterEach` method or in a 
`finally` block



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to