Copilot commented on code in PR #7081:
URL: https://github.com/apache/ignite-3/pull/7081#discussion_r2567715614
##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionFailoverTest.java:
##########
@@ -82,6 +123,50 @@ void testConnectionFailover() throws SQLException {
}
}
+ /**
+ * Ensures that the connection to a previously stopped node will be
restored after the specified time interval.
+ *
+ * <p>Note: this test relies on the internal implementation to ensure that
the
+ * JDBC connection property is correctly applied to the
underlying client.
+ */
+ @Test
+ @Disabled("https://issues.apache.org/jira/browse/IGNITE-27188")
+ void testConnectionRestoredAfterBackgroundReconnectInterval() throws
Exception {
+ int nodesCount = 3;
+ cluster.startAndInit(nodesCount, new int[]{2});
+ int backgroundReconnectInterval = 300;
+ int timeout = backgroundReconnectInterval * 2;
+
+ try (Connection connection = getConnection(nodesCount,
"backgroundReconnectInterval=" + backgroundReconnectInterval)) {
+ Awaitility.await().until(() -> channelsCount(connection),
is(nodesCount));
+
+ cluster.stopNode(0);
+
+ assertThat(channelsCount(connection), is(nodesCount - 1));
+
+ cluster.startNode(0);
+
+ Thread.sleep(timeout);
+
+ assertThat(channelsCount(connection), is(nodesCount));
+ }
+
+ // No background reconnection is expected.
+ try (Connection connection = getConnection(nodesCount,
"backgroundReconnectInterval=0")) {
+ Awaitility.await().until(() -> channelsCount(connection),
is(nodesCount));
+
+ cluster.stopNode(0);
+
+ assertThat(channelsCount(connection), is(nodesCount - 1));
+
+ cluster.startNode(0);
+
+ Thread.sleep(timeout);
Review Comment:
[nitpick] Consider using `Awaitility.await()` instead of `Thread.sleep()`
for more reliable testing. This would allow the test to complete faster when
the condition is met and provide better diagnostics on failure. Example:
```java
// For the negative case where no reconnection should happen
Thread.sleep(timeout);
Awaitility.await().during(Duration.ofMillis(timeout))
.atMost(Duration.ofMillis(timeout + 100))
.until(() -> channelsCount(connection), is(nodesCount - 1));
```
##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionFailoverTest.java:
##########
@@ -82,6 +123,50 @@ void testConnectionFailover() throws SQLException {
}
}
+ /**
+ * Ensures that the connection to a previously stopped node will be
restored after the specified time interval.
+ *
+ * <p>Note: this test relies on the internal implementation to ensure that
the
+ * JDBC connection property is correctly applied to the
underlying client.
+ */
+ @Test
+ @Disabled("https://issues.apache.org/jira/browse/IGNITE-27188")
+ void testConnectionRestoredAfterBackgroundReconnectInterval() throws
Exception {
+ int nodesCount = 3;
+ cluster.startAndInit(nodesCount, new int[]{2});
+ int backgroundReconnectInterval = 300;
+ int timeout = backgroundReconnectInterval * 2;
+
+ try (Connection connection = getConnection(nodesCount,
"backgroundReconnectInterval=" + backgroundReconnectInterval)) {
+ Awaitility.await().until(() -> channelsCount(connection),
is(nodesCount));
+
+ cluster.stopNode(0);
+
+ assertThat(channelsCount(connection), is(nodesCount - 1));
+
+ cluster.startNode(0);
+
+ Thread.sleep(timeout);
Review Comment:
[nitpick] Consider using `Awaitility.await()` instead of `Thread.sleep()`
for more reliable testing. This would allow the test to complete faster when
the condition is met and provide better diagnostics on failure. Example:
```java
Awaitility.await().atMost(Duration.ofMillis(timeout))
.until(() -> channelsCount(connection), is(nodesCount));
```
##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionFailoverTest.java:
##########
@@ -143,13 +250,19 @@ void testTransactionCannotBeUsedAfterNodeRestart() throws
SQLException {
}
}
- private static Connection getConnection(int nodesCount) throws
SQLException {
+ private static Connection getConnection(int nodesCount, String ... params)
throws SQLException {
String addresses = IntStream.range(0, nodesCount)
.mapToObj(i -> "127.0.0.1:" + (BASE_CLIENT_PORT + i))
.collect(Collectors.joining(","));
+ return getConnection(addresses, params);
+ }
+
+ private static Connection getConnection(String addresses, String ...
params) throws SQLException {
+ String args = String.join("&", params);
+
//noinspection CallToDriverManagerGetConnection
- return DriverManager.getConnection("jdbc:ignite:thin://" + addresses);
+ return DriverManager.getConnection("jdbc:ignite:thin://" + addresses +
"?" + args);
Review Comment:
The URL construction will produce a trailing `?` when no parameters are
provided (e.g., `jdbc:ignite:thin://127.0.0.1:10800?`). Consider handling the
empty params case:
```java
String args = params.length == 0 ? "" : "?" + String.join("&", params);
return DriverManager.getConnection("jdbc:ignite:thin://" + addresses + args);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]