This is an automated email from the ASF dual-hosted git repository. ptupitsyn pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push: new 9d3f085606 IGNITE-19601 Remove port range from client configuration (#2195) 9d3f085606 is described below commit 9d3f085606dbbf3676ce6c0393048afb43a3a24b Author: Pavel Tupitsyn <ptupit...@apache.org> AuthorDate: Thu Jun 15 17:03:16 2023 +0300 IGNITE-19601 Remove port range from client configuration (#2195) Remove port range from: * Server-side `ClientHandlerModule` configuration * Java client configuration * .NET client configuration --- .../testframework/IntegrationTestBase.java | 11 +- .../org/apache/ignite/internal/NodeConfig.java | 2 + .../internal/cli/CliIntegrationTestBase.java | 3 +- .../cli/commands/ItClusterCommandTest.java | 1 + .../internal/rest/ItGeneratedRestClientTest.java | 5 +- .../resources/hardcoded-ports-config.json | 3 + .../apache/ignite/client/handler/TestServer.java | 1 - .../ignite/client/handler/ClientHandlerModule.java | 31 +++-- .../ClientConnectorConfigurationSchema.java | 5 - .../org/apache/ignite/client/IgniteClient.java | 3 +- .../ignite/client/IgniteClientConfiguration.java | 16 +-- .../{HostAndPortRange.java => HostAndPort.java} | 125 ++++----------------- .../ignite/internal/client/ReliableChannel.java | 15 +-- .../apache/ignite/client/AbstractClientTest.java | 14 +-- .../ignite/client/ClientAuthenticationTest.java | 5 +- .../apache/ignite/client/ClientComputeTest.java | 6 +- .../apache/ignite/client/ClientLoggingTest.java | 42 ++++--- .../apache/ignite/client/ClientMetricsTest.java | 16 +-- .../ignite/client/ClientPutGetBenchmark.java | 2 +- .../apache/ignite/client/ConfigurationTest.java | 4 +- .../org/apache/ignite/client/ConnectionTest.java | 12 +- .../org/apache/ignite/client/DataStreamerTest.java | 2 +- .../org/apache/ignite/client/HeartbeatTest.java | 8 +- .../org/apache/ignite/client/MultiClusterTest.java | 13 +-- .../ignite/client/PartitionAwarenessTest.java | 8 +- .../org/apache/ignite/client/ReconnectTest.java | 52 +++------ .../apache/ignite/client/RequestBalancingTest.java | 6 +- .../org/apache/ignite/client/RetryPolicyTest.java | 2 +- .../org/apache/ignite/client/SchemaUpdateTest.java | 4 +- .../ignite/client/TestClientHandlerModule.java | 24 ++-- .../java/org/apache/ignite/client/TestServer.java | 27 +++-- ...tAndPortRangeTest.java => HostAndPortTest.java} | 63 ++--------- .../java/org/apache/ignite/lang/ErrorGroups.java | 3 + .../apache/ignite/jdbc/ItJdbcErrorsSelfTest.java | 2 +- .../ignite/internal/jdbc/ConnectionProperties.java | 6 +- .../internal/jdbc/ConnectionPropertiesImpl.java | 18 +-- .../ignite/internal/jdbc/JdbcConnection.java | 9 +- .../dotnet/Apache.Ignite.Tests/EndpointTests.cs | 27 +---- .../Apache.Ignite/Internal/ClientFailoverSocket.cs | 9 +- .../dotnet/Apache.Ignite/Internal/Endpoint.cs | 40 +------ .../java/org/apache/ignite/internal/Cluster.java | 11 +- .../internal/ClusterPerTestIntegrationTest.java | 9 +- .../cluster/management/ItClusterInitTest.java | 1 + .../internal/compute/ItLogicalTopologyTest.java | 3 +- .../zones/ItDistributionZonesFilterTest.java | 1 + .../raftsnapshot/ItTableRaftSnapshotsTest.java | 3 +- .../ignite/internal/rest/AbstractRestTestBase.java | 9 +- .../org/apache/ignite/internal/rest/RestNode.java | 1 + .../runner/app/AbstractSchemaChangeTest.java | 9 +- .../internal/runner/app/ItDataSchemaSyncTest.java | 6 +- .../app/ItIgniteInMemoryNodeRestartTest.java | 9 +- .../runner/app/ItIgniteNodeRestartTest.java | 10 +- .../ignite/internal/runner/app/ItIgnitionTest.java | 9 +- .../internal/runner/app/ItTablesApiTest.java | 6 +- .../runner/app/PlatformTestNodeRunner.java | 6 +- .../app/client/ItAbstractThinClientTest.java | 2 + .../sql/engine/ClusterPerClassIntegrationTest.java | 8 +- .../ignite/internal/sqllogic/ItSqlLogicTest.java | 7 +- .../org/apache/ignite/internal/ssl/ItSslTest.java | 24 ++-- 59 files changed, 308 insertions(+), 471 deletions(-) diff --git a/modules/api/src/testFixtures/java/org/apache/ignite/internal/testframework/IntegrationTestBase.java b/modules/api/src/testFixtures/java/org/apache/ignite/internal/testframework/IntegrationTestBase.java index c0f66e1ba0..860e07b637 100644 --- a/modules/api/src/testFixtures/java/org/apache/ignite/internal/testframework/IntegrationTestBase.java +++ b/modules/api/src/testFixtures/java/org/apache/ignite/internal/testframework/IntegrationTestBase.java @@ -70,6 +70,8 @@ public class IntegrationTestBase extends BaseIgniteAbstractTest { private static final int BASE_PORT = 3344; + private static final int BASE_CLIENT_PORT = 10800; + /** Nodes bootstrap configuration pattern. */ private static final String NODE_BOOTSTRAP_CFG = "{\n" + " network: {\n" @@ -78,7 +80,8 @@ public class IntegrationTestBase extends BaseIgniteAbstractTest { + " nodeFinder:{\n" + " netClusterNodes: [ {} ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; /** Futures that are going to be completed when all nodes are started and the cluster is initialized. */ @@ -101,7 +104,11 @@ public class IntegrationTestBase extends BaseIgniteAbstractTest { String nodeName = testNodeName(testInfo, i); CLUSTER_NODE_NAMES.add(nodeName); - String config = IgniteStringFormatter.format(nodeBootstrapConfigTemplate(), BASE_PORT + i, connectNodeAddr); + String config = IgniteStringFormatter.format( + nodeBootstrapConfigTemplate(), + BASE_PORT + i, + connectNodeAddr, + BASE_CLIENT_PORT + i); NODE_CONFIGS.put(nodeName, config); diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/NodeConfig.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/NodeConfig.java index 2329721cd6..cd533dd407 100644 --- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/NodeConfig.java +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/NodeConfig.java @@ -39,6 +39,7 @@ public class NodeConfig { + " netClusterNodes: [ {} ]\n" + " },\n" + " },\n" + + " clientConnector.port: {} ,\n" + " rest: {" + " ssl: {\n" + " enabled: true,\n" @@ -62,6 +63,7 @@ public class NodeConfig { + " },\n" + " },\n" + " clientConnector: {" + + " port: {},\n" + " ssl: {\n" + " enabled: true,\n" + " clientAuth: require,\n" diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/CliIntegrationTestBase.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/CliIntegrationTestBase.java index df3508ef39..becb71c8cd 100644 --- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/CliIntegrationTestBase.java +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/CliIntegrationTestBase.java @@ -62,7 +62,8 @@ public abstract class CliIntegrationTestBase extends IntegrationTestBase { + " gossipInterval: 10\n" + " },\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItClusterCommandTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItClusterCommandTest.java index 19c31e7303..24a5c5f998 100644 --- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItClusterCommandTest.java +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItClusterCommandTest.java @@ -138,6 +138,7 @@ class ItClusterCommandTest extends AbstractCliTest { 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("<CLIENT_PORT>", String.valueOf(node.restPort + 7000)); config = config.replaceAll("<NET_CLUSTER_NODES>", netClusterNodes()); return config; diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/rest/ItGeneratedRestClientTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/rest/ItGeneratedRestClientTest.java index ce0a0cb267..e10b3471c7 100644 --- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/rest/ItGeneratedRestClientTest.java +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/rest/ItGeneratedRestClientTest.java @@ -96,6 +96,8 @@ public class ItGeneratedRestClientTest { /** Start rest server port. */ private static final int BASE_REST_PORT = 10300; + private static final int BASE_CLIENT_PORT = 10800; + @WorkDirectory private static Path WORK_DIR; @@ -134,7 +136,8 @@ public class ItGeneratedRestClientTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ] \n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: " + (BASE_CLIENT_PORT + nodeIdx) + "\n" + "}"; } diff --git a/modules/cli/src/integrationTest/resources/hardcoded-ports-config.json b/modules/cli/src/integrationTest/resources/hardcoded-ports-config.json index 3873c574fb..c2d5d7c48f 100644 --- a/modules/cli/src/integrationTest/resources/hardcoded-ports-config.json +++ b/modules/cli/src/integrationTest/resources/hardcoded-ports-config.json @@ -9,5 +9,8 @@ "rest": { "port": <REST_PORT>, "portRange": 0 + }, + "clientConnector": { + "port": <CLIENT_PORT> } } diff --git a/modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java b/modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java index 053f34c20a..552806934a 100644 --- a/modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java +++ b/modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java @@ -97,7 +97,6 @@ public class TestServer { clientConnectorConfig().change( local -> local .changePort(10800) - .changePortRange(10) .changeIdleTimeout(idleTimeout) ).join(); diff --git a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java index bb91de61d2..a8fe8e1f79 100644 --- a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java +++ b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java @@ -44,6 +44,7 @@ import org.apache.ignite.internal.network.ssl.SslContextProvider; import org.apache.ignite.internal.security.authentication.AuthenticationManager; import org.apache.ignite.internal.sql.engine.QueryProcessor; import org.apache.ignite.internal.table.IgniteTablesInternal; +import org.apache.ignite.lang.ErrorGroups; import org.apache.ignite.lang.IgniteException; import org.apache.ignite.lang.IgniteInternalException; import org.apache.ignite.network.ClusterService; @@ -217,12 +218,6 @@ public class ClientHandlerModule implements IgniteComponent { * @throws IgniteException When startup has failed. */ private ChannelFuture startEndpoint(ClientConnectorView configuration) throws InterruptedException { - int desiredPort = configuration.port(); - int portRange = configuration.portRange(); - - int port = 0; - Channel ch = null; - ServerBootstrap bootstrap = bootstrapFactory.createServerBootstrap(); // Initialize SslContext once on startup to avoid initialization on each connection, and to fail in case of incorrect config. @@ -256,26 +251,26 @@ public class ClientHandlerModule implements IgniteComponent { }) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.connectTimeout()); - for (int portCandidate = desiredPort; portCandidate <= desiredPort + portRange; portCandidate++) { - ChannelFuture bindRes = bootstrap.bind(portCandidate).await(); + int port = configuration.port(); + Channel ch = null; - if (bindRes.isSuccess()) { - ch = bindRes.channel(); + ChannelFuture bindRes = bootstrap.bind(port).await(); - port = portCandidate; - break; - } else if (!(bindRes.cause() instanceof BindException)) { - throw new IgniteException(bindRes.cause()); - } + if (bindRes.isSuccess()) { + ch = bindRes.channel(); + } else if (!(bindRes.cause() instanceof BindException)) { + throw new IgniteException( + ErrorGroups.Common.INTERNAL_ERR, + "Failed to start thin client connector endpoint: " + bindRes.cause().getMessage(), + bindRes.cause()); } if (ch == null) { - String msg = "Cannot start thin client connector endpoint. " - + "All ports are in use [ports=[" + desiredPort + ", " + (desiredPort + portRange) + "]]"; + String msg = "Cannot start thin client connector endpoint. Port " + port + " is in use."; LOG.debug(msg); - throw new IgniteException(msg); + throw new IgniteException(ErrorGroups.Network.PORT_IN_USE_ERR, msg); } if (LOG.isInfoEnabled()) { diff --git a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientConnectorConfigurationSchema.java b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientConnectorConfigurationSchema.java index 889a2cba31..80bf5ee5e4 100644 --- a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientConnectorConfigurationSchema.java +++ b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientConnectorConfigurationSchema.java @@ -36,11 +36,6 @@ public class ClientConnectorConfigurationSchema { @Value(hasDefault = true) public final int port = 10800; - /** TCP port range. */ - @Range(min = 0) - @Value(hasDefault = true) - public final int portRange = 100; - /** Connect timeout. */ @Range(min = 0) @Value(hasDefault = true) diff --git a/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java b/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java index f108e2165c..53ce6488f1 100644 --- a/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java +++ b/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java @@ -112,8 +112,7 @@ public interface IgniteClient extends Ignite { /** * Sets the addresses of Ignite server nodes within a cluster. An address can be an IP address or a hostname, with or without port. - * If port is not set then Ignite will generate multiple addresses for default port range. See {@link - * IgniteClientConfiguration#DFLT_PORT}, {@link IgniteClientConfiguration#DFLT_PORT_RANGE}. + * If port is not set then Ignite will use the default one - see {@link IgniteClientConfiguration#DFLT_PORT}. * * @param addrs Addresses. * @return This instance. diff --git a/modules/client/src/main/java/org/apache/ignite/client/IgniteClientConfiguration.java b/modules/client/src/main/java/org/apache/ignite/client/IgniteClientConfiguration.java index 4f93eb6625..a5f1f242dd 100644 --- a/modules/client/src/main/java/org/apache/ignite/client/IgniteClientConfiguration.java +++ b/modules/client/src/main/java/org/apache/ignite/client/IgniteClientConfiguration.java @@ -30,9 +30,6 @@ public interface IgniteClientConfiguration { /** Default port. */ int DFLT_PORT = 10800; - /** Default port range. */ - int DFLT_PORT_RANGE = 100; - /** Default socket connect timeout, in milliseconds. */ int DFLT_CONNECT_TIMEOUT = 5000; @@ -60,8 +57,7 @@ public interface IgniteClientConfiguration { /** * Gets the addresses of Ignite server nodes within a cluster. An address can be an IP address or a hostname, with or without port. If - * port is not set then Ignite will generate multiple addresses for default port range. See {@link IgniteClientConfiguration#DFLT_PORT}, - * {@link IgniteClientConfiguration#DFLT_PORT_RANGE}. + * port is not set then Ignite will use {@link IgniteClientConfiguration#DFLT_PORT}. * * <p>Providing addresses of multiple nodes in the cluster will improve performance: Ignite will balance requests across all * connections, and use partition awareness to send key-based requests directly to the primary node. @@ -128,20 +124,20 @@ public interface IgniteClientConfiguration { @Nullable Executor asyncContinuationExecutor(); /** - * Gets the heartbeat message interval, in milliseconds. Default is <code>30_000</code>. + * Gets the heartbeat message interval, in milliseconds. Default is {@code 30_000}. * * <p>When server-side idle timeout is not zero, effective heartbeat - * interval is set to <code>min(heartbeatInterval, idleTimeout / 3)</code>. + * interval is set to {@code min(heartbeatInterval, idleTimeout / 3)}. * * <p>When thin client connection is idle (no operations are performed), heartbeat messages are sent periodically * to keep the connection alive and detect potential half-open state. * * @return Heartbeat interval. */ - public long heartbeatInterval(); + long heartbeatInterval(); /** - * Gets the heartbeat message timeout, in milliseconds. Default is <code>5000</code>. + * Gets the heartbeat message timeout, in milliseconds. Default is {@code 5000}. * * <p>When a server does not respond to a heartbeat within the specified timeout, client will close the connection. * @@ -150,7 +146,7 @@ public interface IgniteClientConfiguration { * * @return Heartbeat interval. */ - public long heartbeatTimeout(); + long heartbeatTimeout(); /** * Returns the logger factory. This factory will be used to create a logger instance when needed. diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/HostAndPortRange.java b/modules/client/src/main/java/org/apache/ignite/internal/client/HostAndPort.java similarity index 59% rename from modules/client/src/main/java/org/apache/ignite/internal/client/HostAndPortRange.java rename to modules/client/src/main/java/org/apache/ignite/internal/client/HostAndPort.java index cd42f26d0c..fb2691b766 100644 --- a/modules/client/src/main/java/org/apache/ignite/internal/client/HostAndPortRange.java +++ b/modules/client/src/main/java/org/apache/ignite/internal/client/HostAndPort.java @@ -23,9 +23,9 @@ import java.net.UnknownHostException; import org.apache.ignite.lang.IgniteException; /** - * Represents address along with port range. + * Represents address along with port. */ -public class HostAndPortRange implements Serializable { +public class HostAndPort implements Serializable { /** Serial version uid. */ private static final long serialVersionUID = 0L; @@ -33,30 +33,22 @@ public class HostAndPortRange implements Serializable { private final String host; /** Port from. */ - private final int portFrom; - - /** Port to. */ - private final int portTo; + private final int port; /** * Parse string into host and port pair. * * @param addrStr String. - * @param dfltPortFrom Default port from. - * @param dfltPortTo Default port to. + * @param dfltPort Default port. * @param errMsgPrefix Error message prefix. * @return Result. * @throws IgniteException If failed. */ - public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltPortTo, String errMsgPrefix) + public static HostAndPort parse(String addrStr, int dfltPort, String errMsgPrefix) throws IgniteException { - assert dfltPortFrom <= dfltPortTo; - String host; - String portStr; - int portFrom; - int portTo; + int port; if (addrStr == null || addrStr.isEmpty()) { throw createParseError(addrStr, errMsgPrefix, "Address is empty"); @@ -72,14 +64,10 @@ public class HostAndPortRange implements Serializable { host = addrStr.substring(1, hostEndIdx); if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default - portFrom = dfltPortFrom; - portTo = dfltPortTo; + port = dfltPort; } else { // port specified portStr = addrStr.substring(hostEndIdx + 2); - - int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr); - portFrom = ports[0]; - portTo = ports[1]; + port = parsePort(portStr, addrStr, errMsgPrefix); } } else { // IPv4 || IPv6 without port || empty host final int colIdx = addrStr.lastIndexOf(':'); @@ -89,69 +77,25 @@ public class HostAndPortRange implements Serializable { try { Inet6Address.getByName(addrStr); host = addrStr; - portFrom = dfltPortFrom; - portTo = dfltPortTo; + port = dfltPort; } catch (UnknownHostException e) { throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect", e); } } else { host = addrStr.substring(0, colIdx); portStr = addrStr.substring(colIdx + 1); - int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr); - portFrom = ports[0]; - portTo = ports[1]; + port = parsePort(portStr, addrStr, errMsgPrefix); } } else if (colIdx == 0) { throw createParseError(addrStr, errMsgPrefix, "Host name is empty"); } else { // Port is not specified, use defaults. host = addrStr; - portFrom = dfltPortFrom; - portTo = dfltPortTo; + port = dfltPort; } } - return new HostAndPortRange(host, portFrom, portTo); - } - - /** - * Verifies string containing single port or ports range. - * - * @param addrStr Address String. - * @param errMsgPrefix Error message prefix. - * @param portStr Port or port range string. - * @return Array of int[portFrom, portTo]. - * @throws IgniteException If failed. - */ - private static int[] verifyPortStr(String addrStr, String errMsgPrefix, String portStr) - throws IgniteException { - String portFromStr; - String portToStr; - - if (portStr == null || portStr.isEmpty()) { - throw createParseError(addrStr, errMsgPrefix, "port range is not specified"); - } - - int portRangeIdx = portStr.indexOf(".."); - - if (portRangeIdx >= 0) { - // Port range is specified. - portFromStr = portStr.substring(0, portRangeIdx); - portToStr = portStr.substring(portRangeIdx + 2); - } else { - // Single port is specified. - portFromStr = portStr; - portToStr = portStr; - } - - int portFrom = parsePort(portFromStr, addrStr, errMsgPrefix); - int portTo = parsePort(portToStr, addrStr, errMsgPrefix); - - if (portFrom > portTo) { - throw createParseError(addrStr, errMsgPrefix, "start port cannot be less than end port"); - } - - return new int[]{portFrom, portTo}; + return new HostAndPort(host, port); } /** @@ -168,12 +112,12 @@ public class HostAndPortRange implements Serializable { int port = Integer.parseInt(portStr); if (port <= 0 || port > 65535) { - throw createParseError(addrStr, errMsgPrefix, "port range contains invalid port " + portStr); + throw createParseError(addrStr, errMsgPrefix, "invalid port " + portStr); } return port; } catch (NumberFormatException ignored) { - throw createParseError(addrStr, errMsgPrefix, "port range contains invalid port " + portStr); + throw createParseError(addrStr, errMsgPrefix, "invalid port " + portStr); } } @@ -208,24 +152,11 @@ public class HostAndPortRange implements Serializable { * @param host Host. * @param port Port. */ - public HostAndPortRange(String host, int port) { - this(host, port, port); - } - - /** - * Constructor. - * - * @param host Host. - * @param portFrom Port from. - * @param portTo Port to. - */ - public HostAndPortRange(String host, int portFrom, int portTo) { + public HostAndPort(String host, int port) { assert host != null && !host.isEmpty(); - assert portFrom <= portTo && portFrom > 0 && portTo < 65535; this.host = host; - this.portFrom = portFrom; - this.portTo = portTo; + this.port = port; } /** @@ -242,26 +173,17 @@ public class HostAndPortRange implements Serializable { * * @return Port from. */ - public int portFrom() { - return portFrom; - } - - /** - * Returns port to. - * - * @return Port to. - */ - public int portTo() { - return portTo; + public int port() { + return port; } /** {@inheritDoc} */ @Override public boolean equals(Object o) { - if (o instanceof HostAndPortRange) { - HostAndPortRange other = (HostAndPortRange) o; + if (o instanceof HostAndPort) { + HostAndPort other = (HostAndPort) o; - return host.equals(other.host) && portFrom == other.portFrom && portTo == other.portTo; + return host.equals(other.host) && port == other.port; } else { return false; } @@ -272,8 +194,7 @@ public class HostAndPortRange implements Serializable { public int hashCode() { int res = host.hashCode(); - res = 31 * res + portFrom; - res = 31 * res + portTo; + res = 31 * res + port; return res; } @@ -281,6 +202,6 @@ public class HostAndPortRange implements Serializable { /** {@inheritDoc} */ @Override public String toString() { - return host + ":" + (portFrom == portTo ? portFrom : portFrom + ".." + portTo); + return host + ":" + port; } } diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java b/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java index 1ae7b118ab..7513ecdfcb 100644 --- a/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java +++ b/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java @@ -44,7 +44,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.stream.Collectors; -import java.util.stream.IntStream; import org.apache.ignite.client.ClientOperationType; import org.apache.ignite.client.IgniteClientConfiguration; import org.apache.ignite.client.IgniteClientConnectionException; @@ -288,22 +287,14 @@ public final class ReliableChannel implements AutoCloseable { throw new IgniteException(CONFIGURATION_ERR, "Empty addresses"); } - Collection<HostAndPortRange> ranges = new ArrayList<>(addrs.length); + Collection<HostAndPort> ranges = new ArrayList<>(addrs.length); for (String a : addrs) { - ranges.add(HostAndPortRange.parse( - a, - IgniteClientConfiguration.DFLT_PORT, - IgniteClientConfiguration.DFLT_PORT + IgniteClientConfiguration.DFLT_PORT_RANGE, - "Failed to parse Ignite server address" - )); + ranges.add(HostAndPort.parse(a, IgniteClientConfiguration.DFLT_PORT, "Failed to parse Ignite server address")); } return ranges.stream() - .flatMap(r -> IntStream - .rangeClosed(r.portFrom(), r.portTo()).boxed() - .map(p -> InetSocketAddress.createUnresolved(r.host(), p)) - ) + .map(p -> InetSocketAddress.createUnresolved(p.host(), p.port())) .collect(Collectors.toMap(a -> a, a -> 1, Integer::sum)); } diff --git a/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java b/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java index 681143c32a..51dc45ddc8 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java @@ -61,7 +61,7 @@ public abstract class AbstractClientTest { server = new FakeIgnite("server-1"); - testServer = startServer(10800, 10, 0, server); + testServer = startServer(0, server); serverPort = testServer.port(); @@ -112,39 +112,31 @@ public abstract class AbstractClientTest { /** * Returns server. * - * @param port Port. - * @param portRange Port range. * @param idleTimeout Idle timeout. * @param ignite Ignite. * @return Server. */ public static TestServer startServer( - int port, - int portRange, long idleTimeout, Ignite ignite ) { - return startServer(port, portRange, idleTimeout, ignite, null); + return startServer(idleTimeout, ignite, null); } /** * Returns server. * - * @param port Port. - * @param portRange Port range. * @param idleTimeout Idle timeout. * @param ignite Ignite. * @param nodeName Node name. * @return Server. */ public static TestServer startServer( - int port, - int portRange, long idleTimeout, Ignite ignite, String nodeName ) { - return new TestServer(port, portRange, idleTimeout, ignite, null, null, nodeName, clusterId, null); + return new TestServer(idleTimeout, ignite, null, null, nodeName, clusterId, null, null); } /** diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientAuthenticationTest.java b/modules/client/src/test/java/org/apache/ignite/client/ClientAuthenticationTest.java index 234276e0d7..6ce0ae99f8 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ClientAuthenticationTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ClientAuthenticationTest.java @@ -106,15 +106,14 @@ public class ClientAuthenticationTest { @NotNull private TestServer startServer(boolean basicAuthn) { var server = new TestServer( - 10800, - 10, 1000, new FakeIgnite(), null, null, null, UUID.randomUUID(), - authenticationConfiguration); + authenticationConfiguration, + null); if (basicAuthn) { authenticationConfiguration.change(change -> { diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java b/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java index d090b6e79b..3d811918cb 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java @@ -164,8 +164,8 @@ public class ClientComputeTest { var clusterId = UUID.randomUUID(); - server1 = new TestServer(10900, 10, 0, ignite, shouldDropConnection, null, "s1", clusterId, null); - server2 = new TestServer(10910, 10, 0, ignite, shouldDropConnection, null, "s2", clusterId, null); - server3 = new TestServer(10920, 10, 0, ignite, shouldDropConnection, null, "s3", clusterId, null); + server1 = new TestServer(0, ignite, shouldDropConnection, null, "s1", clusterId, null, null); + server2 = new TestServer(0, ignite, shouldDropConnection, null, "s2", clusterId, null, null); + server3 = new TestServer(0, ignite, shouldDropConnection, null, "s3", clusterId, null, null); } } diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientLoggingTest.java b/modules/client/src/test/java/org/apache/ignite/client/ClientLoggingTest.java index f24607a92e..6a2129769c 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ClientLoggingTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ClientLoggingTest.java @@ -23,10 +23,12 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.ArrayList; import org.apache.ignite.client.fakes.FakeIgnite; import org.apache.ignite.client.fakes.FakeIgniteTables; import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.lang.LoggerFactory; +import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -50,13 +52,13 @@ public class ClientLoggingTest { FakeIgnite ignite1 = new FakeIgnite(); ((FakeIgniteTables) ignite1.tables()).createTable("t"); - server = startServer(10950, ignite1); + server = startServer(ignite1, 10901); var loggerFactory1 = new TestLoggerFactory("client1"); var loggerFactory2 = new TestLoggerFactory("client2"); - var client1 = createClient(loggerFactory1); - var client2 = createClient(loggerFactory2); + var client1 = createClient(loggerFactory1, 10901, 10902); + var client2 = createClient(loggerFactory2, 10901, 10902); assertEquals("t", client1.tables().tables().get(0).name()); assertEquals("t", client2.tables().tables().get(0).name()); @@ -66,7 +68,7 @@ public class ClientLoggingTest { FakeIgnite ignite2 = new FakeIgnite(); ((FakeIgniteTables) ignite2.tables()).createTable("t2"); - server2 = startServer(10951, ignite2); + server2 = startServer(ignite2, 10902); assertEquals("t2", client1.tables().tables().get(0).name()); assertEquals("t2", client2.tables().tables().get(0).name()); @@ -83,33 +85,37 @@ public class ClientLoggingTest { FakeIgnite ignite = new FakeIgnite(); ((FakeIgniteTables) ignite.tables()).createTable("t"); - server = startServer(10950, ignite); - server2 = startServer(10955, ignite); + server = startServer(ignite, null); + server2 = startServer(ignite, null); var loggerFactory = new TestLoggerFactory("c"); - try (var client = createClient(loggerFactory)) { + try (var client = IgniteClient.builder() + .addresses("127.0.0.1:" + server.port(), "127.0.0.1:" + server2.port(), "127.0.0.1:43210") + .loggerFactory(loggerFactory) + .build()) { client.tables().tables(); client.tables().table("t"); loggerFactory.waitForLogContains("Connection established", 5000); - loggerFactory.waitForLogContains("c:Sending request [opCode=3, remoteAddress=127.0.0.1:1095", 5000); - loggerFactory.waitForLogContains("c:Failed to establish connection to 127.0.0.1:1095", 5000); + loggerFactory.waitForLogContains("c:Sending request [opCode=3, remoteAddress=127.0.0.1:", 5000); + loggerFactory.waitForLogContains("c:Failed to establish connection to 127.0.0.1:43210", 5000); } } - private static TestServer startServer(int port, FakeIgnite ignite) { - return AbstractClientTest.startServer( - port, - 10, - 0, - ignite - ); + private static TestServer startServer(FakeIgnite ignite, @Nullable Integer port) { + return new TestServer(0, ignite, null, null, null, AbstractClientTest.clusterId, null, port); } - private static IgniteClient createClient(LoggerFactory loggerFactory) { + private static IgniteClient createClient(LoggerFactory loggerFactory, int... ports) { + var addrs = new ArrayList<String>(); + + for (int port : ports) { + addrs.add("127.0.0.1:" + port); + } + return IgniteClient.builder() - .addresses("127.0.0.1:10950..10960") + .addresses(addrs.toArray(new String[0])) .loggerFactory(loggerFactory) .build(); } diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientMetricsTest.java b/modules/client/src/test/java/org/apache/ignite/client/ClientMetricsTest.java index aa285b372c..b2c7a95537 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ClientMetricsTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ClientMetricsTest.java @@ -45,7 +45,7 @@ public class ClientMetricsTest { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testConnectionMetrics(boolean gracefulDisconnect) throws Exception { - server = AbstractClientTest.startServer(10800, 10, 1000, new FakeIgnite()); + server = AbstractClientTest.startServer(1000, new FakeIgnite()); client = clientBuilder().build(); ClientMetricSource metrics = metrics(); @@ -72,14 +72,13 @@ public class ClientMetricsTest { Function<Integer, Boolean> shouldDropConnection = requestIdx -> requestIdx == 0; Function<Integer, Integer> responseDelay = idx -> idx > 1 ? 500 : 0; server = new TestServer( - 10800, - 10, 1000, new FakeIgnite(), shouldDropConnection, responseDelay, null, AbstractClientTest.clusterId, + null, null ); client = clientBuilder() @@ -98,14 +97,13 @@ public class ClientMetricsTest { AtomicInteger counter = new AtomicInteger(); Function<Integer, Boolean> shouldDropConnection = requestIdx -> counter.incrementAndGet() < 3; // Fail 2 handshakes. server = new TestServer( - 10800, - 10, 1000, new FakeIgnite(), shouldDropConnection, null, null, AbstractClientTest.clusterId, + null, null ); @@ -120,14 +118,13 @@ public class ClientMetricsTest { Function<Integer, Boolean> shouldDropConnection = requestIdx -> false; Function<Integer, Integer> responseDelay = idx -> counter.incrementAndGet() == 1 ? 500 : 0; server = new TestServer( - 10800, - 10, 1000, new FakeIgnite(), shouldDropConnection, responseDelay, null, AbstractClientTest.clusterId, + null, null ); client = clientBuilder() @@ -144,14 +141,13 @@ public class ClientMetricsTest { Function<Integer, Boolean> shouldDropConnection = requestIdx -> requestIdx == 5; Function<Integer, Integer> responseDelay = idx -> idx == 4 ? 1000 : 0; server = new TestServer( - 10800, - 10, 1000, new FakeIgnite(), shouldDropConnection, responseDelay, null, AbstractClientTest.clusterId, + null, null ); client = clientBuilder().build(); @@ -203,7 +199,7 @@ public class ClientMetricsTest { @Test public void testBytesSentReceived() { - server = AbstractClientTest.startServer(10800, 10, 1000, new FakeIgnite()); + server = AbstractClientTest.startServer(1000, new FakeIgnite()); client = clientBuilder().build(); assertEquals(15, metrics().bytesSent()); diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientPutGetBenchmark.java b/modules/client/src/test/java/org/apache/ignite/client/ClientPutGetBenchmark.java index a7e3dd42b1..d245013e67 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ClientPutGetBenchmark.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ClientPutGetBenchmark.java @@ -79,7 +79,7 @@ public class ClientPutGetBenchmark { ignite = new FakeIgnite("server-1"); ((FakeIgniteTables) ignite.tables()).createTable(DEFAULT_TABLE); - testServer = new TestServer(10800, 10, 1000, ignite); + testServer = new TestServer(1000, ignite); client = IgniteClient.builder() .addresses("127.0.0.1:" + testServer.port()) diff --git a/modules/client/src/test/java/org/apache/ignite/client/ConfigurationTest.java b/modules/client/src/test/java/org/apache/ignite/client/ConfigurationTest.java index 4a775f3512..4e5f7cc244 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ConfigurationTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ConfigurationTest.java @@ -58,7 +58,7 @@ public class ConfigurationTest extends AbstractClientTest { assertThat( ex.getMessage(), - containsString("Failed to parse Ignite server address (port range contains invalid port 70000): 127.0.0.1:70000")); + containsString("Failed to parse Ignite server address (invalid port 70000): 127.0.0.1:70000")); } @Test @@ -161,7 +161,7 @@ public class ConfigurationTest extends AbstractClientTest { public void testCustomAsyncContinuationExecutor() throws Exception { Function<Integer, Integer> responseDelay = x -> 50; - try (var testServer = new TestServer(10900, 10, 0, server, x -> false, responseDelay, "n2", clusterId, null)) { + try (var testServer = new TestServer(0, server, x -> false, responseDelay, "n2", clusterId, null, null)) { ExecutorService executor = Executors.newSingleThreadExecutor(); var builderThreadName = new AtomicReference<String>(); diff --git a/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java b/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java index de16f6a8aa..00b66af91e 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java @@ -53,6 +53,16 @@ public class ConnectionTest extends AbstractClientTest { testConnection("127.0.0.1:" + serverPort); } + @Test + public void testDefaultClientConfig() throws Exception { + try (var ignored = new TestServer(0, new FakeIgnite(), null, null, "abc", clusterId, null, 10800)) { + IgniteClient.builder() + .addresses("localhost") + .build() + .close(); + } + } + @Test public void testInvalidNodeAddresses() { var ex = assertThrows(IgniteClientConnectionException.class, @@ -81,7 +91,7 @@ public class ConnectionTest extends AbstractClientTest { public void testNoResponseFromServerWithinConnectTimeoutThrowsException() throws Exception { Function<Integer, Integer> responseDelay = x -> 500; - try (var srv = new TestServer(10800, 10, 300, new FakeIgnite(), x -> false, responseDelay, null, UUID.randomUUID(), null)) { + try (var srv = new TestServer(300, new FakeIgnite(), x -> false, responseDelay, null, UUID.randomUUID(), null, null)) { Builder builder = IgniteClient.builder() .addresses("127.0.0.1:" + srv.port()) .retryPolicy(new RetryLimitPolicy().retryLimit(1)) diff --git a/modules/client/src/test/java/org/apache/ignite/client/DataStreamerTest.java b/modules/client/src/test/java/org/apache/ignite/client/DataStreamerTest.java index 8c2564ad51..063a027e45 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/DataStreamerTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/DataStreamerTest.java @@ -290,7 +290,7 @@ public class DataStreamerTest extends AbstractClientTableTest { private FakeIgnite startTestServer2(Function<Integer, Boolean> shouldDropConnection, Function<Integer, Integer> responseDelay) { var ignite2 = new FakeIgnite("server-2"); - testServer2 = new TestServer(10900, 10, 10_000, ignite2, shouldDropConnection, responseDelay, null, UUID.randomUUID(), null); + testServer2 = new TestServer(10_000, ignite2, shouldDropConnection, responseDelay, null, UUID.randomUUID(), null, null); return ignite2; } diff --git a/modules/client/src/test/java/org/apache/ignite/client/HeartbeatTest.java b/modules/client/src/test/java/org/apache/ignite/client/HeartbeatTest.java index 40776b15be..5e3cdb8d8b 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/HeartbeatTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/HeartbeatTest.java @@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test; public class HeartbeatTest { @Test public void testHeartbeatLongerThanIdleTimeoutCausesDisconnect() throws Exception { - try (var srv = new TestServer(10800, 10, 50, new FakeIgnite())) { + try (var srv = new TestServer(50, new FakeIgnite())) { int srvPort = srv.port(); var loggerFactory = new TestLoggerFactory("client"); @@ -54,7 +54,7 @@ public class HeartbeatTest { @Test public void testHeartbeatShorterThanIdleTimeoutKeepsConnectionAlive() throws Exception { - try (var srv = new TestServer(10800, 10, 300, new FakeIgnite())) { + try (var srv = new TestServer(300, new FakeIgnite())) { int srvPort = srv.port(); Builder builder = IgniteClient.builder() @@ -72,7 +72,7 @@ public class HeartbeatTest { @SuppressWarnings("ThrowableNotThrown") @Test public void testInvalidHeartbeatIntervalThrows() throws Exception { - try (var srv = new TestServer(10800, 10, 300, new FakeIgnite())) { + try (var srv = new TestServer(300, new FakeIgnite())) { Builder builder = IgniteClient.builder() .addresses("127.0.0.1:" + srv.port()) @@ -87,7 +87,7 @@ public class HeartbeatTest { Function<Integer, Integer> responseDelayFunc = requestCount -> requestCount > 1 ? 500 : 0; var loggerFactory = new TestLoggerFactory("client"); - try (var srv = new TestServer(10800, 10, 300, new FakeIgnite(), x -> false, responseDelayFunc, null, UUID.randomUUID(), null)) { + try (var srv = new TestServer(300, new FakeIgnite(), x -> false, responseDelayFunc, null, UUID.randomUUID(), null, null)) { int srvPort = srv.port(); Builder builder = IgniteClient.builder() diff --git a/modules/client/src/test/java/org/apache/ignite/client/MultiClusterTest.java b/modules/client/src/test/java/org/apache/ignite/client/MultiClusterTest.java index 94db576399..a6d5182692 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/MultiClusterTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/MultiClusterTest.java @@ -48,8 +48,8 @@ public class MultiClusterTest { @BeforeEach void setUp() { - server1 = new TestServer(10900, 10, 0, new FakeIgnite(), null, null, "s1", clusterId1, null); - server2 = new TestServer(10900, 10, 0, new FakeIgnite(), null, null, "s2", clusterId2, null); + server1 = new TestServer(0, new FakeIgnite(), null, null, "s1", clusterId1, null, null); + server2 = new TestServer(0, new FakeIgnite(), null, null, "s2", clusterId2, null, null); } @AfterEach @@ -72,17 +72,16 @@ public class MultiClusterTest { assertEquals(1, client.connections().size()); String err = getFailedConnectionEntry(loggerFactory); - String expectedErr = "Cluster ID mismatch: expected=" + clusterId2 + ", actual=" + clusterId1; - - assertThat(err, CoreMatchers.containsString(expectedErr)); + assertThat(err, CoreMatchers.containsString("Cluster ID mismatch")); } } @Test public void testReconnectToDifferentClusterFails() throws Exception { + int port = server1.port(); Builder builder = IgniteClient.builder() - .addresses("127.0.0.1:" + server1.port()); + .addresses("127.0.0.1:" + port); server2.close(); @@ -90,7 +89,7 @@ public class MultiClusterTest { client.tables().tables(); server1.close(); - server1 = new TestServer(10900, 10, 0, new FakeIgnite(), null, null, "s1", clusterId2, null); + server1 = new TestServer(0, new FakeIgnite(), null, null, "s1", clusterId2, null, port); IgniteClientConnectionException ex = (IgniteClientConnectionException) assertThrowsWithCause( () -> client.tables().tables(), IgniteClientConnectionException.class, "Cluster ID mismatch"); diff --git a/modules/client/src/test/java/org/apache/ignite/client/PartitionAwarenessTest.java b/modules/client/src/test/java/org/apache/ignite/client/PartitionAwarenessTest.java index 44bd08aa63..8d08008a26 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/PartitionAwarenessTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/PartitionAwarenessTest.java @@ -76,7 +76,7 @@ public class PartitionAwarenessTest extends AbstractClientTest { ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); server2 = new FakeIgnite("server-2"); - testServer2 = startServer(10800, 10, 0, server2, "server-2"); + testServer2 = new TestServer(0, server2, null, null, "server-2", clusterId, null, serverPort + 1); var clientBuilder = IgniteClient.builder() .addresses("127.0.0.1:" + serverPort, "127.0.0.1:" + testServer2.port()) @@ -153,9 +153,9 @@ public class PartitionAwarenessTest extends AbstractClientTest { RecordView<Tuple> recordView = defaultTable().recordView(); var tx = client2.transactions().begin(); - assertOpOnNode("server-2", "get", x -> recordView.get(tx, Tuple.create().set("ID", 0L))); - assertOpOnNode("server-2", "get", x -> recordView.get(tx, Tuple.create().set("ID", 1L))); - assertOpOnNode("server-2", "get", x -> recordView.get(tx, Tuple.create().set("ID", 2L))); + assertOpOnNode("server-1", "get", x -> recordView.get(tx, Tuple.create().set("ID", 0L))); + assertOpOnNode("server-1", "get", x -> recordView.get(tx, Tuple.create().set("ID", 1L))); + assertOpOnNode("server-1", "get", x -> recordView.get(tx, Tuple.create().set("ID", 2L))); } @ParameterizedTest diff --git a/modules/client/src/test/java/org/apache/ignite/client/ReconnectTest.java b/modules/client/src/test/java/org/apache/ignite/client/ReconnectTest.java index d91faa53d0..348e25f04f 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ReconnectTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ReconnectTest.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.apache.ignite.Ignite; import org.apache.ignite.client.IgniteClient.Builder; import org.apache.ignite.client.fakes.FakeIgnite; import org.apache.ignite.client.fakes.FakeIgniteTables; @@ -53,14 +54,10 @@ public class ReconnectTest { FakeIgnite ignite1 = new FakeIgnite(); ((FakeIgniteTables) ignite1.tables()).createTable("t"); - server = AbstractClientTest.startServer( - 10900, - 10, - 0, - ignite1); + server = new TestServer(0, ignite1, null, null, null, AbstractClientTest.clusterId, null, 10905); var client = IgniteClient.builder() - .addresses("127.0.0.1:10900..10910", "127.0.0.1:10950..10960") + .addresses("127.0.0.1:10905", "127.0.0.1:10950", "127.0.0.1:10960") .retryPolicy(new RetryLimitPolicy().retryLimit(100)) .build(); @@ -71,11 +68,7 @@ public class ReconnectTest { FakeIgnite ignite2 = new FakeIgnite(); ((FakeIgniteTables) ignite2.tables()).createTable("t2"); - server2 = AbstractClientTest.startServer( - 10950, - 10, - 0, - ignite2); + server2 = new TestServer(0, ignite2, null, null, null, AbstractClientTest.clusterId, null, 10950); assertEquals("t2", client.tables().tables().get(0).name()); } @@ -86,14 +79,10 @@ public class ReconnectTest { FakeIgnite ignite1 = new FakeIgnite(); ((FakeIgniteTables) ignite1.tables()).createTable("t"); - server = AbstractClientTest.startServer( - 10900, - 10, - 0, - ignite1); + server = AbstractClientTest.startServer(0, ignite1); var client = IgniteClient.builder() - .addresses("127.0.0.1:10900..10910", "127.0.0.1:10950..10960") + .addresses("127.0.0.1:" + server.port(), "127.0.0.1:10960") .build(); assertEquals("t", client.tables().tables().get(0).name()); @@ -109,7 +98,7 @@ public class ReconnectTest { startTwoServers(); Builder builder = IgniteClient.builder() - .addresses("127.0.0.1:10900..10902") + .addresses("127.0.0.1:10901", "127.0.0.1:10902", "127.0.0.1:10903") .reconnectInterval(reconnectEnabled ? 50 : 0) .heartbeatInterval(50); @@ -119,12 +108,8 @@ public class ReconnectTest { server2.close(); waitForConnections(client, 1); - server2 = AbstractClientTest.startServer( - 10902, - 0, - 0, - new FakeIgnite(), - "node3"); + Ignite ignite = new FakeIgnite(); + server2 = new TestServer(0, ignite, null, null, "node3", AbstractClientTest.clusterId, null, 10903); if (reconnectEnabled) { waitForConnections(client, 2); @@ -143,7 +128,7 @@ public class ReconnectTest { startTwoServers(); Builder builder = IgniteClient.builder() - .addresses("127.0.0.1:10900..10902") + .addresses("127.0.0.1:10901", "127.0.0.1:10902") .reconnectInterval(50) .heartbeatInterval(50); @@ -159,19 +144,10 @@ public class ReconnectTest { } private void startTwoServers() { - server = AbstractClientTest.startServer( - 10900, - 0, - 0, - new FakeIgnite(), - "node1"); - - server2 = AbstractClientTest.startServer( - 10901, - 0, - 0, - new FakeIgnite(), - "node2"); + Ignite ignite = new FakeIgnite(); + server = new TestServer(0, ignite, null, null, "node1", AbstractClientTest.clusterId, null, 10901); + Ignite ignite1 = new FakeIgnite(); + server2 = new TestServer(0, ignite1, null, null, "node2", AbstractClientTest.clusterId, null, 10902); } private static void waitForConnections(IgniteClient client, int expectedConnections) throws InterruptedException { diff --git a/modules/client/src/test/java/org/apache/ignite/client/RequestBalancingTest.java b/modules/client/src/test/java/org/apache/ignite/client/RequestBalancingTest.java index b0440ab327..4af3dde8c8 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/RequestBalancingTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/RequestBalancingTest.java @@ -48,9 +48,9 @@ public class RequestBalancingTest { @BeforeEach void setUp() { FakeIgnite ignite = new FakeIgnite(); - server1 = AbstractClientTest.startServer(10900, 10, 0, ignite, "s1"); - server2 = AbstractClientTest.startServer(10900, 10, 0, ignite, "s2"); - server3 = AbstractClientTest.startServer(10900, 10, 0, ignite, "s3"); + server1 = new TestServer(0, ignite, null, null, "s1", AbstractClientTest.clusterId, null, 10991); + server2 = new TestServer(0, ignite, null, null, "s2", AbstractClientTest.clusterId, null, 10992); + server3 = new TestServer(0, ignite, null, null, "s3", AbstractClientTest.clusterId, null, 10993); } @AfterEach diff --git a/modules/client/src/test/java/org/apache/ignite/client/RetryPolicyTest.java b/modules/client/src/test/java/org/apache/ignite/client/RetryPolicyTest.java index a28c978eaf..9b21b1d2a0 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/RetryPolicyTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/RetryPolicyTest.java @@ -279,6 +279,6 @@ public class RetryPolicyTest { FakeIgnite ign = new FakeIgnite(); ((FakeIgniteTables) ign.tables()).createTable("t"); - server = new TestServer(10900, 10, 0, ign, shouldDropConnection, null, null, UUID.randomUUID(), null); + server = new TestServer(0, ign, shouldDropConnection, null, null, UUID.randomUUID(), null, null); } } diff --git a/modules/client/src/test/java/org/apache/ignite/client/SchemaUpdateTest.java b/modules/client/src/test/java/org/apache/ignite/client/SchemaUpdateTest.java index ecd86e7990..c6298799a4 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/SchemaUpdateTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/SchemaUpdateTest.java @@ -55,7 +55,7 @@ public class SchemaUpdateTest { @Test public void testMultipleParallelOperationsRequestSchemaOnce() { int responseDelay = 100; - server = new TestServer(10800, 10, 10000, ignite(), null, idx -> responseDelay, "n", UUID.randomUUID(), null); + server = new TestServer(10000, ignite(), null, idx -> responseDelay, "n", UUID.randomUUID(), null, null); client = startClient(); RecordView<Tuple> view = client.tables().table(DEFAULT_TABLE).recordView(); @@ -75,7 +75,7 @@ public class SchemaUpdateTest { AtomicBoolean shouldFail = new AtomicBoolean(true); Function<Integer, Boolean> shouldDropConnection = idx -> idx >= 3 && shouldFail.getAndSet(false); - server = new TestServer(10800, 10, 10000, ignite(), shouldDropConnection, null, "n", UUID.randomUUID(), null); + server = new TestServer(10000, ignite(), shouldDropConnection, null, "n", UUID.randomUUID(), null, null); client = startClient(); RecordView<Tuple> view = client.tables().table(DEFAULT_TABLE).recordView(); diff --git a/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java b/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java index 4d704e8e8f..c91537c005 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java +++ b/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java @@ -171,11 +171,6 @@ public class TestClientHandlerModule implements IgniteComponent { private ChannelFuture startEndpoint() throws InterruptedException { var configuration = registry.getConfiguration(ClientConnectorConfiguration.KEY).value(); - int desiredPort = configuration.port(); - int portRange = configuration.portRange(); - - Channel ch = null; - var requestCounter = new AtomicInteger(); ServerBootstrap bootstrap = bootstrapFactory.createServerBootstrap(); @@ -202,21 +197,18 @@ public class TestClientHandlerModule implements IgniteComponent { }) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.connectTimeout()); - for (int portCandidate = desiredPort; portCandidate <= desiredPort + portRange; portCandidate++) { - ChannelFuture bindRes = bootstrap.bind(portCandidate).await(); - - if (bindRes.isSuccess()) { - ch = bindRes.channel(); + int port = configuration.port(); + Channel ch = null; + ChannelFuture bindRes = bootstrap.bind(port).await(); - break; - } else if (!(bindRes.cause() instanceof BindException)) { - throw new IgniteException(bindRes.cause()); - } + if (bindRes.isSuccess()) { + ch = bindRes.channel(); + } else if (!(bindRes.cause() instanceof BindException)) { + throw new IgniteException(bindRes.cause()); } if (ch == null) { - String msg = "Cannot start thin client connector endpoint. " - + "All ports in range [" + desiredPort + ", " + (desiredPort + portRange) + "] are in use."; + String msg = "Cannot start thin client connector endpoint. Port " + port + " is in use."; throw new IgniteException(msg); } diff --git a/modules/client/src/test/java/org/apache/ignite/client/TestServer.java b/modules/client/src/test/java/org/apache/ignite/client/TestServer.java index 540f002d06..c6caa5e881 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/TestServer.java +++ b/modules/client/src/test/java/org/apache/ignite/client/TestServer.java @@ -22,7 +22,10 @@ import static org.mockito.Answers.RETURNS_DEEP_STUBS; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; +import java.io.IOError; +import java.io.IOException; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.net.SocketAddress; import java.util.List; import java.util.Objects; @@ -73,26 +76,21 @@ public class TestServer implements AutoCloseable { /** * Constructor. * - * @param port Port. - * @param portRange Port range. * @param idleTimeout Idle timeout. * @param ignite Ignite. */ public TestServer( - int port, - int portRange, long idleTimeout, Ignite ignite ) { this( - port, - portRange, idleTimeout, ignite, null, null, null, UUID.randomUUID(), + null, null ); } @@ -100,21 +98,18 @@ public class TestServer implements AutoCloseable { /** * Constructor. * - * @param port Port. - * @param portRange Port range. * @param idleTimeout Idle timeout. * @param ignite Ignite. */ public TestServer( - int port, - int portRange, long idleTimeout, Ignite ignite, @Nullable Function<Integer, Boolean> shouldDropConnection, @Nullable Function<Integer, Integer> responseDelay, @Nullable String nodeName, UUID clusterId, - @Nullable AuthenticationConfiguration authenticationConfiguration + @Nullable AuthenticationConfiguration authenticationConfiguration, + @Nullable Integer port ) { generator = new ConfigurationTreeGenerator(ClientConnectorConfiguration.KEY, NetworkConfiguration.KEY); cfg = new ConfigurationRegistry( @@ -127,7 +122,7 @@ public class TestServer implements AutoCloseable { cfg.start(); cfg.getConfiguration(ClientConnectorConfiguration.KEY).change( - local -> local.changePort(port).changePortRange(portRange).changeIdleTimeout(idleTimeout) + local -> local.changePort(port != null ? port : getFreePort()).changeIdleTimeout(idleTimeout) ).join(); bootstrapFactory = new NettyBootstrapFactory(cfg.getConfiguration(NetworkConfiguration.KEY), "TestServer-"); @@ -243,6 +238,14 @@ public class TestServer implements AutoCloseable { return name + "-id"; } + private static int getFreePort() { + try (var serverSocket = new ServerSocket(0)) { + return serverSocket.getLocalPort(); + } catch (IOException e) { + throw new IOError(e); + } + } + private AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) { AuthenticationManagerImpl authenticationManager = new AuthenticationManagerImpl(); authenticationConfiguration.listen(authenticationManager); diff --git a/modules/client/src/test/java/org/apache/ignite/internal/client/HostAndPortRangeTest.java b/modules/client/src/test/java/org/apache/ignite/internal/client/HostAndPortTest.java similarity index 59% rename from modules/client/src/test/java/org/apache/ignite/internal/client/HostAndPortRangeTest.java rename to modules/client/src/test/java/org/apache/ignite/internal/client/HostAndPortTest.java index 9d2d350610..c092341311 100644 --- a/modules/client/src/test/java/org/apache/ignite/internal/client/HostAndPortRangeTest.java +++ b/modules/client/src/test/java/org/apache/ignite/internal/client/HostAndPortTest.java @@ -27,23 +27,7 @@ import org.junit.jupiter.api.Test; /** * Tests HostAndPortRange. */ -public class HostAndPortRangeTest { - /** - * Tests correct input address with IPv4 host and port range. - */ - @Test - public void testParseIpv4WithPortRange() { - String addrStr = "127.0.0.1:8080..8090"; - String errMsgPrefix = ""; - int dfltPortFrom = 18360; - int dfltPortTo = 18362; - - HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix); - HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 8080, 8090); - - assertEquals(expected, actual); - } - +public class HostAndPortTest { /** * Tests correct input address with IPv4 host and single port. */ @@ -52,10 +36,9 @@ public class HostAndPortRangeTest { String addrStr = "127.0.0.1:8080"; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; - HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix); - HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 8080, 8080); + HostAndPort actual = HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix); + HostAndPort expected = new HostAndPort("127.0.0.1", 8080); assertEquals(expected, actual); } @@ -68,26 +51,9 @@ public class HostAndPortRangeTest { String addrStr = "127.0.0.1"; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; - - HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix); - HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 18360, 18362); - - assertEquals(expected, actual); - } - - /** - * Tests correct input address with IPv6 host and port range. - */ - @Test - public void testParseIpv6WithPortRange() { - String addrStr = "[::1]:8080..8090"; - String errMsgPrefix = ""; - int dfltPortFrom = 18360; - int dfltPortTo = 18362; - HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix); - HostAndPortRange expected = new HostAndPortRange("::1", 8080, 8090); + HostAndPort actual = HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix); + HostAndPort expected = new HostAndPort("127.0.0.1", 18360); assertEquals(expected, actual); } @@ -100,10 +66,9 @@ public class HostAndPortRangeTest { String addrStr = "[3ffe:2a00:100:7031::]:8080"; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; - HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix); - HostAndPortRange expected = new HostAndPortRange("3ffe:2a00:100:7031::", 8080, 8080); + HostAndPort actual = HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix); + HostAndPort expected = new HostAndPort("3ffe:2a00:100:7031::", 8080); assertEquals(expected, actual); } @@ -116,10 +81,9 @@ public class HostAndPortRangeTest { String addrStr = "::FFFF:129.144.52.38"; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; - HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix); - HostAndPortRange expected = new HostAndPortRange("::FFFF:129.144.52.38", 18360, 18362); + HostAndPort actual = HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix); + HostAndPort expected = new HostAndPort("::FFFF:129.144.52.38", 18360); assertEquals(expected, actual); } @@ -132,10 +96,9 @@ public class HostAndPortRangeTest { String addrStr = "3ffe:2a00:100:7031"; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; var ex = assertThrows(IgniteException.class, - () -> HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix)); + () -> HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix)); assertTrue(ex.getMessage().contains("IPv6 is incorrect"), ex.getMessage()); } @@ -148,10 +111,9 @@ public class HostAndPortRangeTest { String addrStr = ":8080"; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; var ex = assertThrows(IgniteException.class, - () -> HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix)); + () -> HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix)); assertTrue(ex.getMessage().contains("Host name is empty"), ex.getMessage()); } @@ -164,10 +126,9 @@ public class HostAndPortRangeTest { String addrStr = ""; String errMsgPrefix = ""; int dfltPortFrom = 18360; - int dfltPortTo = 18362; var ex = assertThrows(IgniteException.class, - () -> HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix)); + () -> HostAndPort.parse(addrStr, dfltPortFrom, errMsgPrefix)); assertTrue(ex.getMessage().contains("Address is empty"), ex.getMessage()); } diff --git a/modules/core/src/main/java/org/apache/ignite/lang/ErrorGroups.java b/modules/core/src/main/java/org/apache/ignite/lang/ErrorGroups.java index a36d8d09e3..daf854c454 100755 --- a/modules/core/src/main/java/org/apache/ignite/lang/ErrorGroups.java +++ b/modules/core/src/main/java/org/apache/ignite/lang/ErrorGroups.java @@ -357,6 +357,9 @@ public class ErrorGroups { /** Unresolvable consistent ID. */ public static final int UNRESOLVABLE_CONSISTENT_ID_ERR = NETWORK_ERR_GROUP.registerErrorCode(1); + + /** Port is in use. */ + public static final int PORT_IN_USE_ERR = NETWORK_ERR_GROUP.registerErrorCode(2); } /** Node configuration error group. */ diff --git a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsSelfTest.java b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsSelfTest.java index 0b46c00e59..8ceb7a50fb 100644 --- a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsSelfTest.java +++ b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsSelfTest.java @@ -100,7 +100,7 @@ public class ItJdbcErrorsSelfTest extends ItJdbcErrorsAbstractSelfTest { @Test public void testInvalidConnectionStringFormat() { checkErrorState(() -> DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:1000000"), - CLIENT_CONNECTION_FAILED, "port range contains invalid port 1000000"); + CLIENT_CONNECTION_FAILED, "invalid port 1000000"); } /** diff --git a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionProperties.java b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionProperties.java index fbc1f319f8..9c6058a11d 100644 --- a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionProperties.java +++ b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionProperties.java @@ -19,7 +19,7 @@ package org.apache.ignite.internal.jdbc; import java.sql.SQLException; import org.apache.ignite.client.ClientAuthenticationMode; -import org.apache.ignite.internal.client.HostAndPortRange; +import org.apache.ignite.internal.client.HostAndPort; /** * Provide access and manipulations with connection JDBC properties. @@ -59,14 +59,14 @@ public interface ConnectionProperties { * * @return Ignite nodes addresses. */ - HostAndPortRange[] getAddresses(); + HostAndPort[] getAddresses(); /** * Set the ignite node addresses. * * @param addrs Ignite nodes addresses. */ - void setAddresses(HostAndPortRange[] addrs); + void setAddresses(HostAndPort[] addrs); /** * Note: zero value means there is no limits. diff --git a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionPropertiesImpl.java b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionPropertiesImpl.java index 164638a482..ab475b1b13 100644 --- a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionPropertiesImpl.java +++ b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/ConnectionPropertiesImpl.java @@ -26,7 +26,7 @@ import java.util.StringTokenizer; import java.util.stream.Collectors; import org.apache.ignite.client.ClientAuthenticationMode; import org.apache.ignite.client.IgniteClientConfiguration; -import org.apache.ignite.internal.client.HostAndPortRange; +import org.apache.ignite.internal.client.HostAndPort; import org.apache.ignite.internal.jdbc.proto.SqlStateCode; import org.apache.ignite.internal.util.ArrayUtils; import org.apache.ignite.lang.IgniteException; @@ -53,7 +53,7 @@ public class ConnectionPropertiesImpl implements ConnectionProperties, Serializa private String url; /** Addresses. */ - private HostAndPortRange[] addrs; + private HostAndPort[] addrs; /** Schema name. Hidden property. Is used to set default schema name part of the URL. */ private final StringProperty schema = new StringProperty(PROP_SCHEMA, @@ -157,7 +157,7 @@ public class ConnectionPropertiesImpl implements ConnectionProperties, Serializa StringBuilder sbUrl = new StringBuilder(URL_PREFIX); - HostAndPortRange[] addrs = getAddresses(); + HostAndPort[] addrs = getAddresses(); for (int i = 0; i < addrs.length; i++) { if (i > 0) { @@ -185,13 +185,13 @@ public class ConnectionPropertiesImpl implements ConnectionProperties, Serializa /** {@inheritDoc} */ @Override - public HostAndPortRange[] getAddresses() { + public HostAndPort[] getAddresses() { return addrs; } /** {@inheritDoc} */ @Override - public void setAddresses(HostAndPortRange[] addrs) { + public void setAddresses(HostAndPort[] addrs) { this.addrs = addrs; } @@ -497,14 +497,14 @@ public class ConnectionPropertiesImpl implements ConnectionProperties, Serializa String[] endpoints = endpointStr.split(","); if (endpoints.length > 0) { - addrs = new HostAndPortRange[endpoints.length]; + addrs = new HostAndPort[endpoints.length]; } for (int i = 0; i < endpoints.length; ++i) { try { - addrs[i] = HostAndPortRange.parse(endpoints[i], - IgniteClientConfiguration.DFLT_PORT, IgniteClientConfiguration.DFLT_PORT, - "Invalid endpoint format (should be \"host[:portRangeFrom[..portRangeTo]]\")"); + addrs[i] = HostAndPort.parse(endpoints[i], + IgniteClientConfiguration.DFLT_PORT, + "Invalid endpoint format (should be \"host:port\")"); } catch (IgniteException e) { throw new SQLException(e.getMessage(), SqlStateCode.CLIENT_CONNECTION_FAILED, e); } diff --git a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcConnection.java b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcConnection.java index c6b7fed16d..9d1ef05ab1 100644 --- a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcConnection.java +++ b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcConnection.java @@ -56,7 +56,7 @@ import org.apache.ignite.client.BasicAuthenticator; import org.apache.ignite.client.IgniteClient; import org.apache.ignite.client.IgniteClientAuthenticator; import org.apache.ignite.client.SslConfiguration; -import org.apache.ignite.internal.client.HostAndPortRange; +import org.apache.ignite.internal.client.HostAndPort; import org.apache.ignite.internal.client.TcpIgniteClient; import org.apache.ignite.internal.jdbc.proto.IgniteQueryErrorCode; import org.apache.ignite.internal.jdbc.proto.JdbcQueryEventHandler; @@ -922,10 +922,9 @@ public class JdbcConnection implements Connection { * @param range HostAndPortRange. * @return Address string with host and port range. */ - private String createStrAddress(HostAndPortRange range) { + private String createStrAddress(HostAndPort range) { String host = range.host(); - int portFrom = range.portFrom(); - int portTo = range.portTo(); + int port = range.port(); boolean ipV6 = host.contains(":"); @@ -933,7 +932,7 @@ public class JdbcConnection implements Connection { host = "[" + host + "]"; } - return host + ":" + (portFrom == portTo ? portFrom : portFrom + ".." + portTo); + return host + ":" + port; } /** diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/EndpointTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/EndpointTests.cs index 51b1e86bc3..394f8a1992 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Tests/EndpointTests.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Tests/EndpointTests.cs @@ -34,22 +34,22 @@ namespace Apache.Ignite.Tests ex = AssertThrowsClientException("host:"); Assert.AreEqual( - "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: host:", + "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: 'host:'", ex.Message); ex = AssertThrowsClientException("host:port"); Assert.AreEqual( - "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: host:port", + "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: 'host:port'", ex.Message); ex = AssertThrowsClientException("host:1.."); Assert.AreEqual( - "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: host:1..", + "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: 'host:1..'", ex.Message); ex = AssertThrowsClientException("host:1..2..3"); Assert.AreEqual( - "Unrecognized format of IgniteClientConfiguration.Endpoint: host:1..2..3", + "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: 'host:1..2..3'", ex.Message); } @@ -59,45 +59,26 @@ namespace Apache.Ignite.Tests const string ip = "1.2.3.4"; const string host = "example.com"; const int port = 678; - const int port2 = 680; var ipWithDefaultPort = Endpoint.GetEndpoints(new IgniteClientConfiguration(ip)).Single(); Assert.AreEqual(ip, ipWithDefaultPort.Host); Assert.AreEqual(IgniteClientConfiguration.DefaultPort, ipWithDefaultPort.Port); - Assert.AreEqual(0, ipWithDefaultPort.PortRange); var ipWithCustomPort = Endpoint .GetEndpoints(new IgniteClientConfiguration($"{ip}:{port}")) .Single(); Assert.AreEqual(ip, ipWithCustomPort.Host); Assert.AreEqual(port, ipWithCustomPort.Port); - Assert.AreEqual(0, ipWithCustomPort.PortRange); - - var ipWithPortRange = Endpoint - .GetEndpoints(new IgniteClientConfiguration($"{ip}:{port}..{port2}")) - .Single(); - Assert.AreEqual(ip, ipWithPortRange.Host); - Assert.AreEqual(port, ipWithPortRange.Port); - Assert.AreEqual(port2 - port, ipWithPortRange.PortRange); var hostWithDefaultPort = Endpoint.GetEndpoints(new IgniteClientConfiguration(host)).Single(); Assert.AreEqual(host, hostWithDefaultPort.Host); Assert.AreEqual(IgniteClientConfiguration.DefaultPort, hostWithDefaultPort.Port); - Assert.AreEqual(0, hostWithDefaultPort.PortRange); var hostWithCustomPort = Endpoint .GetEndpoints(new IgniteClientConfiguration($"{host}:{port}")) .Single(); Assert.AreEqual(host, hostWithCustomPort.Host); Assert.AreEqual(port, hostWithCustomPort.Port); - Assert.AreEqual(0, hostWithCustomPort.PortRange); - - var hostWithPortRange = Endpoint - .GetEndpoints(new IgniteClientConfiguration($"{host}:{port}..{port2}")) - .Single(); - Assert.AreEqual(host, hostWithPortRange.Host); - Assert.AreEqual(port, hostWithPortRange.Port); - Assert.AreEqual(port2 - port, hostWithPortRange.PortRange); } private static IgniteClientException AssertThrowsClientException(string endpoint) diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs index 8140c0da54..d9d12ef13c 100644 --- a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs +++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs @@ -474,14 +474,11 @@ namespace Apache.Ignite.Internal foreach (var e in Endpoint.GetEndpoints(cfg)) { var host = e.Host; - Debug.Assert(host != null, "host != null"); // Checked by GetEndpoints. + Debug.Assert(host != null, "host != null"); // Checked by GetEndpoints. - for (var port = e.Port; port <= e.PortRange + e.Port; port++) + foreach (var ip in GetIps(host)) { - foreach (var ip in GetIps(host)) - { - yield return new SocketEndpoint(new IPEndPoint(ip, port), host); - } + yield return new SocketEndpoint(new IPEndPoint(ip, e.Port), host); } } } diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Endpoint.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Endpoint.cs index 4930c80602..d8ba7c528b 100644 --- a/modules/platforms/dotnet/Apache.Ignite/Internal/Endpoint.cs +++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Endpoint.cs @@ -17,7 +17,6 @@ namespace Apache.Ignite.Internal { - using System; using System.Collections.Generic; using System.ComponentModel; using Common; @@ -30,17 +29,13 @@ namespace Apache.Ignite.Internal /** */ private const char HostSeparator = ':'; - /** */ - private static readonly string[] PortsSeparators = {".."}; - /// <summary> /// Initializes a new instance of the <see cref="Endpoint"/> class. /// </summary> - private Endpoint(string host, int port = IgniteClientConfiguration.DefaultPort, int portRange = 0) + private Endpoint(string host, int port = IgniteClientConfiguration.DefaultPort) { Host = IgniteArgumentCheck.NotNullOrEmpty(host); Port = port; - PortRange = portRange; } /// <summary> @@ -54,11 +49,6 @@ namespace Apache.Ignite.Internal [DefaultValue(IgniteClientConfiguration.DefaultPort)] public int Port { get; } - /// <summary> - /// Gets the port range. Default is 0, meaning only one port is used, defined by <see cref="Port"/>. - /// </summary> - public int PortRange { get; } - /// <summary> /// Gets the client endpoints from given configuration. /// </summary> @@ -96,31 +86,7 @@ namespace Apache.Ignite.Internal var host = endpoint.Substring(0, idx); var port = endpoint.Substring(idx + 1); - var ports = port.Split(PortsSeparators, StringSplitOptions.None); - - if (ports.Length == 1) - { - return new Endpoint(host, ParsePort(endpoint, port)); - } - - if (ports.Length == 2) - { - var minPort = ParsePort(endpoint, ports[0]); - var maxPort = ParsePort(endpoint, ports[1]); - - if (maxPort < minPort) - { - throw new IgniteClientException( - ErrorGroups.Client.Configuration, - "Invalid format of IgniteClientConfiguration.Endpoint, port range is empty: " + endpoint); - } - - return new Endpoint(host, minPort, maxPort - minPort); - } - - throw new IgniteClientException( - ErrorGroups.Client.Configuration, - "Unrecognized format of IgniteClientConfiguration.Endpoint: " + endpoint); + return new Endpoint(host, ParsePort(endpoint, port)); } /// <summary> @@ -137,7 +103,7 @@ namespace Apache.Ignite.Internal throw new IgniteClientException( ErrorGroups.Client.Configuration, - "Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: " + endpoint); + $"Unrecognized format of IgniteClientConfiguration.Endpoint, failed to parse port: '{endpoint}'"); } } } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/Cluster.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/Cluster.java index b37a6c681c..509c95045d 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/Cluster.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/Cluster.java @@ -73,6 +73,8 @@ public class Cluster { /** Base port number. */ private static final int BASE_PORT = 3344; + private static final int BASE_CLIENT_PORT = 10800; + private static final String CONNECT_NODE_ADDR = "\"localhost:" + BASE_PORT + '\"'; /** Timeout for SQL queries (in milliseconds). */ @@ -85,7 +87,8 @@ public class Cluster { + " \"nodeFinder\":{\n" + " \"netClusterNodes\": [ {} ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; private final TestInfo testInfo; @@ -222,7 +225,11 @@ public class Cluster { public CompletableFuture<IgniteImpl> startNodeAsync(int nodeIndex, String nodeBootstrapConfigTemplate) { String nodeName = testNodeName(testInfo, nodeIndex); - String config = IgniteStringFormatter.format(nodeBootstrapConfigTemplate, BASE_PORT + nodeIndex, CONNECT_NODE_ADDR); + String config = IgniteStringFormatter.format( + nodeBootstrapConfigTemplate, + BASE_PORT + nodeIndex, + CONNECT_NODE_ADDR, + BASE_CLIENT_PORT + nodeIndex); return TestIgnitionManager.start(nodeName, config, workDir.resolve(nodeName)) .thenApply(IgniteImpl.class::cast) diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ClusterPerTestIntegrationTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ClusterPerTestIntegrationTest.java index 82cd58351f..2413724fc4 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ClusterPerTestIntegrationTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ClusterPerTestIntegrationTest.java @@ -54,7 +54,8 @@ public abstract class ClusterPerTestIntegrationTest extends IgniteIntegrationTes + " nodeFinder: {\n" + " netClusterNodes: [ {} ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; /** Template for node bootstrap config with Scalecube settings for fast failure detection. */ @@ -73,7 +74,8 @@ public abstract class ClusterPerTestIntegrationTest extends IgniteIntegrationTes + " gossipInterval: 10\n" + " },\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; /** Template for node bootstrap config with Scalecube settings for a disabled failure detection. */ @@ -86,7 +88,8 @@ public abstract class ClusterPerTestIntegrationTest extends IgniteIntegrationTes + " membership: {\n" + " failurePingInterval: 1000000000\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; protected Cluster cluster; diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterInitTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterInitTest.java index 6e17c630bf..accda25e4d 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterInitTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterInitTest.java @@ -107,6 +107,7 @@ public class ItClusterInitTest extends IgniteAbstractTest { for (int port : ports) { String config = "{" + " network.port: " + port + "," + + " clientConnector.port: " + (port + 8000) + "," + " network.nodeFinder.netClusterNodes: " + nodeFinderConfig + "}"; diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/compute/ItLogicalTopologyTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/compute/ItLogicalTopologyTest.java index c430c8e587..15079a7b2d 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/compute/ItLogicalTopologyTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/compute/ItLogicalTopologyTest.java @@ -70,7 +70,8 @@ class ItLogicalTopologyTest extends ClusterPerTestIntegrationTest { + " }," + " nodeAttributes: {\n" + " nodeAttributes: " + NODE_ATTRIBUTES - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; private final LogicalTopologyEventListener listener = new LogicalTopologyEventListener() { diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/distribution/zones/ItDistributionZonesFilterTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/distribution/zones/ItDistributionZonesFilterTest.java index 9100318391..74198469b5 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/distribution/zones/ItDistributionZonesFilterTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/distribution/zones/ItDistributionZonesFilterTest.java @@ -76,6 +76,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest + " nodeAttributes: {\n" + " nodeAttributes: " + nodeAttributes + " },\n" + + " clientConnector: { port:{} }\n" + "}"; } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java index a7b02217bb..f6d0bc3fe2 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java @@ -115,7 +115,8 @@ class ItTableRaftSnapshotsTest extends IgniteIntegrationTest { + " netClusterNodes: [ {} ]\n" + " }\n" + " },\n" - + " raft.rpcInstallSnapshotTimeout: 10000" + + " raft.rpcInstallSnapshotTimeout: 10000," + + " clientConnector.port: {}\n" + "}"; /** diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/AbstractRestTestBase.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/AbstractRestTestBase.java index 208564fe49..48c0581432 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/AbstractRestTestBase.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/AbstractRestTestBase.java @@ -113,7 +113,8 @@ abstract class AbstractRestTestBase extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: 10800" + "}" ); @@ -125,7 +126,8 @@ abstract class AbstractRestTestBase extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: 10801" + "}" ); @@ -137,7 +139,8 @@ abstract class AbstractRestTestBase extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: 10802" + "}" ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/RestNode.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/RestNode.java index 46099e83a3..7c8e379cbb 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/RestNode.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/rest/RestNode.java @@ -128,6 +128,7 @@ public class RestNode { + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" + " },\n" + + " clientConnector.port: " + (httpPort + 1000) + ",\n" + " rest: {\n" + " port: " + httpPort + ",\n" + " dualProtocol: " + dualProtocol + ",\n" diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/AbstractSchemaChangeTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/AbstractSchemaChangeTest.java index c35ce2e88c..43d1624430 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/AbstractSchemaChangeTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/AbstractSchemaChangeTest.java @@ -85,7 +85,8 @@ abstract class AbstractSchemaChangeTest extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:10901 }\n" + "}" ); @@ -97,7 +98,8 @@ abstract class AbstractSchemaChangeTest extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:10902 }\n" + "}" ); @@ -109,7 +111,8 @@ abstract class AbstractSchemaChangeTest extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:10903 }\n" + "}" ); } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItDataSchemaSyncTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItDataSchemaSyncTest.java index 1f1e1629a1..42c877fef3 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItDataSchemaSyncTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItDataSchemaSyncTest.java @@ -85,7 +85,8 @@ public class ItDataSchemaSyncTest extends IgniteAbstractTest { + " \"nodeFinder\": {\n" + " \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:10801 }\n" + "}", "node2", "{\n" @@ -94,7 +95,8 @@ public class ItDataSchemaSyncTest extends IgniteAbstractTest { + " \"nodeFinder\": {\n" + " \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:10802 }\n" + "}" ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteInMemoryNodeRestartTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteInMemoryNodeRestartTest.java index 68c5d4bd5e..a33c7f7ba4 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteInMemoryNodeRestartTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteInMemoryNodeRestartTest.java @@ -65,6 +65,9 @@ public class ItIgniteInMemoryNodeRestartTest extends IgniteAbstractTest { /** Default node port. */ private static final int DEFAULT_NODE_PORT = 3344; + /** Default client port. */ + private static final int DEFAULT_CLIENT_PORT = 10800; + /** Value producer for table data, is used to create data and check it later. */ private static final IntFunction<String> VALUE_PRODUCER = i -> "val " + i; @@ -74,7 +77,8 @@ public class ItIgniteInMemoryNodeRestartTest extends IgniteAbstractTest { /** Nodes bootstrap configuration pattern. */ private static final String NODE_BOOTSTRAP_CFG = "{\n" + " network.port: {},\n" - + " network.nodeFinder.netClusterNodes: {}\n" + + " network.nodeFinder.netClusterNodes: {},\n" + + " clientConnector.port: {}\n" + "}"; /** Cluster nodes. */ @@ -159,11 +163,12 @@ public class ItIgniteInMemoryNodeRestartTest extends IgniteAbstractTest { */ private static String configurationString(int idx) { int port = DEFAULT_NODE_PORT + idx; + int clientPort = DEFAULT_CLIENT_PORT + idx; // The address of the first node. @Language("HOCON") String connectAddr = "[localhost\":\"" + DEFAULT_NODE_PORT + "]"; - return IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, port, connectAddr); + return IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, port, connectAddr, clientPort); } /** diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java index 76d9c698dc..f8bb563339 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java @@ -152,6 +152,8 @@ public class ItIgniteNodeRestartTest extends IgniteAbstractTest { /** Default node port. */ private static final int DEFAULT_NODE_PORT = 3344; + private static final int DEFAULT_CLIENT_PORT = 10800; + /** Value producer for table data, is used to create data and check it later. */ private static final IntFunction<String> VALUE_PRODUCER = i -> "val " + i; @@ -180,7 +182,8 @@ public class ItIgniteNodeRestartTest extends IgniteAbstractTest { + " gossipInterval: 10\n" + " },\n" + " },\n" - + " raft: " + RAFT_CFG + "\n" + + " raft: " + RAFT_CFG + ",\n" + + " clientConnector.port: {}\n" + "}"; @InjectConfiguration("mock: " + RAFT_CFG) @@ -676,7 +679,7 @@ public class ItIgniteNodeRestartTest extends IgniteAbstractTest { private static String configurationString(int idx) { String connectAddr = "[\"localhost:" + DEFAULT_NODE_PORT + "\"]"; - return IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, DEFAULT_NODE_PORT + idx, connectAddr); + return IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, DEFAULT_NODE_PORT + idx, connectAddr, DEFAULT_CLIENT_PORT + idx); } /** @@ -1067,7 +1070,8 @@ public class ItIgniteNodeRestartTest extends IgniteAbstractTest { @Language("HOCON") String cfgString = IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, DEFAULT_NODE_PORT + 11, - "[\"localhost:" + DEFAULT_NODE_PORT + "\"]" + "[\"localhost:" + DEFAULT_NODE_PORT + "\"]", + DEFAULT_CLIENT_PORT + 11 ); PartialNode partialNode = startPartialNode(1, cfgString); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgnitionTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgnitionTest.java index badb20145d..77715c6f5f 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgnitionTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgnitionTest.java @@ -82,7 +82,8 @@ class ItIgnitionTest extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: 10800\n" + "}" ); @@ -94,7 +95,8 @@ class ItIgnitionTest extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: 10801\n" + "}" ); @@ -106,7 +108,8 @@ class ItIgnitionTest extends IgniteIntegrationTest { + " nodeFinder: {\n" + " netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: 10802\n" + "}" ); } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java index 98a5800e11..72bf12d6ea 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java @@ -82,17 +82,17 @@ public class ItTablesApiTest extends IgniteAbstractTest { /** Nodes bootstrap configuration. */ private final List<String> nodesBootstrapCfg = List.of( "{\n" - + " network.port :3344,\n" + + " network.port :3344, clientConnector.port: 10800,\n" + " network.nodeFinder.netClusterNodes:[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + "}", "{\n" - + " network.port :3345,\n" + + " network.port :3345, clientConnector.port: 10801,\n" + " network.nodeFinder.netClusterNodes:[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + "}", "{\n" - + " network.port :3346,\n" + + " network.port :3346, clientConnector.port: 10802,\n" + " network.nodeFinder.netClusterNodes:[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + "}" ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java index 07a8e4fad1..d238ba42c7 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java @@ -96,7 +96,7 @@ public class PlatformTestNodeRunner { /** Nodes bootstrap configuration. */ private static final Map<String, String> nodesBootstrapCfg = Map.of( NODE_NAME, "{\n" - + " \"clientConnector\":{\"port\": 10942,\"portRange\":1,\"idleTimeout\":3000,\"" + + " \"clientConnector\":{\"port\": 10942,\"idleTimeout\":3000,\"" + "sendServerExceptionStackTraceToClient\":true}," + " \"network\": {\n" + " \"port\":3344,\n" @@ -107,7 +107,7 @@ public class PlatformTestNodeRunner { + "}", NODE_NAME2, "{\n" - + " \"clientConnector\":{\"port\": 10943,\"portRange\":1,\"idleTimeout\":3000," + + " \"clientConnector\":{\"port\": 10943,\"idleTimeout\":3000," + "\"sendServerExceptionStackTraceToClient\":true}," + " \"network\": {\n" + " \"port\":3345,\n" @@ -120,7 +120,6 @@ public class PlatformTestNodeRunner { NODE_NAME3, "{\n" + " \"clientConnector\":{" + " \"port\": 10944," - + " \"portRange\":1," + " \"idleTimeout\":3000," + " \"sendServerExceptionStackTraceToClient\":true, " + " \"ssl\": {\n" @@ -142,7 +141,6 @@ public class PlatformTestNodeRunner { NODE_NAME4, "{\n" + " \"clientConnector\":{" + " \"port\": 10945," - + " \"portRange\":1," + " \"idleTimeout\":3000," + " \"sendServerExceptionStackTraceToClient\":true, " + " \"ssl\": {\n" diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItAbstractThinClientTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItAbstractThinClientTest.java index c2b61f9aae..296663e899 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItAbstractThinClientTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItAbstractThinClientTest.java @@ -81,6 +81,7 @@ public abstract class ItAbstractThinClientTest extends IgniteAbstractTest { "{\n" + " network.port: 3344,\n" + " network.nodeFinder.netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + + " clientConnector.port: 10800\n" + "}" ); @@ -91,6 +92,7 @@ public abstract class ItAbstractThinClientTest extends IgniteAbstractTest { + " network.nodeFinder.netClusterNodes: [ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n" + " clientConnector.sendServerExceptionStackTraceToClient: true\n" + " clientConnector.metricsEnabled: true\n" + + " clientConnector.port: 10801\n" + "}" ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java index 23a52a90d2..65fe5d3de5 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java @@ -98,6 +98,9 @@ public abstract class ClusterPerClassIntegrationTest extends IgniteIntegrationTe /** Base port number. */ private static final int BASE_PORT = 3344; + /** Base client port number. */ + private static final int BASE_CLIENT_PORT = 10800; + /** Nodes bootstrap configuration pattern. */ private static final String NODE_BOOTSTRAP_CFG = "{\n" + " \"network\": {\n" @@ -105,7 +108,8 @@ public abstract class ClusterPerClassIntegrationTest extends IgniteIntegrationTe + " \"nodeFinder\":{\n" + " \"netClusterNodes\": [ {} ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port:{} }\n" + "}"; /** Cluster nodes. */ @@ -145,7 +149,7 @@ public abstract class ClusterPerClassIntegrationTest extends IgniteIntegrationTe for (int i = 0; i < nodes(); i++) { String nodeName = testNodeName(testInfo, i); - String config = IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, BASE_PORT + i, connectNodeAddr); + String config = IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, BASE_PORT + i, connectNodeAddr, BASE_CLIENT_PORT + i); futures.add(TestIgnitionManager.start(nodeName, config, WORK_DIR.resolve(nodeName))); } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/ItSqlLogicTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/ItSqlLogicTest.java index 266cbc834e..97bd0673c7 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/ItSqlLogicTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/ItSqlLogicTest.java @@ -155,6 +155,8 @@ public class ItSqlLogicTest extends IgniteIntegrationTest { /** Base port number. */ private static final int BASE_PORT = 3344; + private static final int BASE_CLIENT_PORT = 10800; + /** Nodes bootstrap configuration pattern. */ private static final String NODE_BOOTSTRAP_CFG = "{\n" + " \"network\": {\n" @@ -162,7 +164,8 @@ public class ItSqlLogicTest extends IgniteIntegrationTest { + " \"nodeFinder\":{\n" + " \"netClusterNodes\": [ {} ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector.port: {}\n" + "}"; /** Cluster nodes. */ @@ -319,7 +322,7 @@ public class ItSqlLogicTest extends IgniteIntegrationTest { .mapToObj(i -> { String nodeName = NODE_NAME_PREFIX + i; - String config = IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, BASE_PORT + i, connectNodeAddr); + String config = IgniteStringFormatter.format(NODE_BOOTSTRAP_CFG, BASE_PORT + i, connectNodeAddr, BASE_CLIENT_PORT + i); return TestIgnitionManager.start(nodeName, config, WORK_DIR.resolve(nodeName)); }) diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ssl/ItSslTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ssl/ItSslTest.java index 0160271973..5ad0371190 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ssl/ItSslTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/ssl/ItSslTest.java @@ -84,12 +84,12 @@ public class ItSslTest extends IgniteIntegrationTest { String sslDisabledBoostrapConfig = "{\n" + " network: {\n" + " ssl.enabled: false,\n" - + " port: 3355,\n" - + " portRange: 2,\n" + + " port: {},\n" + " nodeFinder:{\n" - + " netClusterNodes: [ \"localhost:3355\", \"localhost:3356\" ]\n" + + " netClusterNodes: [ {}, \"localhost:3355\", \"localhost:3356\" ]\n" + " }\n" - + " }\n" + + " },\n" + + " clientConnector: { port: {} }\n" + "}"; @BeforeAll @@ -176,12 +176,12 @@ public class ItSslTest extends IgniteIntegrationTest { + " path: \"" + escapeWindowsPath(keyStorePath) + "\"" + " }\n" + " },\n" - + " port: 3345,\n" - + " portRange: 2,\n" + + " port: {},\n" + " nodeFinder:{\n" - + " netClusterNodes: [ \"localhost:3345\", \"localhost:3346\" ]\n" + + " netClusterNodes: [ {}, \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" + " },\n" + + " clientConnector: { port: {} },\n" + " clientConnector.ssl: {\n" + " enabled: true, " + " keyStore: {\n" @@ -385,12 +385,13 @@ public class ItSslTest extends IgniteIntegrationTest { + " path: \"" + escapeWindowsPath(keyStorePath) + "\"" + " }\n" + " },\n" - + " port: 3365,\n" + + " port: {},\n" + " portRange: 2,\n" + " nodeFinder:{\n" - + " netClusterNodes: [ \"localhost:3365\", \"localhost:3366\" ]\n" + + " netClusterNodes: [ {}, \"localhost:3365\", \"localhost:3366\" ]\n" + " }\n" + " },\n" + + " clientConnector: { port: {} },\n" + " clientConnector.ssl: {\n" + " enabled: true, " + " clientAuth: \"require\", " @@ -543,12 +544,13 @@ public class ItSslTest extends IgniteIntegrationTest { + " path: \"" + escapeWindowsPath(keyStorePath) + "\"" + " }\n" + " },\n" - + " port: 3345,\n" + + " port: {},\n" + " portRange: 2,\n" + " nodeFinder:{\n" - + " netClusterNodes: [ \"localhost:3345\", \"localhost:3346\" ]\n" + + " netClusterNodes: [ {}, \"localhost:3345\", \"localhost:3346\" ]\n" + " }\n" + " },\n" + + " clientConnector.port: {},\n" + " clientConnector.ssl: {\n" + " enabled: true, " + " ciphers: " + ciphers + ",\n"