Skip to content

Commit 3db1822

Browse files
committed
IGNITE-26148 Jdbc. Multinode connection tests (#6899)
1 parent 49eeea8 commit 3db1822

File tree

21 files changed

+415
-60
lines changed

21 files changed

+415
-60
lines changed

gradle/libs.versions.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ protobuf = "4.33.0"
9696
cytodynamics = "0.2.0"
9797
japicmp = "0.24.2"
9898

99+
# JDBC connection pools (for testing purposes)
100+
hikariCP = "7.0.2"
101+
c3p0 = "0.11.2"
102+
99103
#Tools
100104
pmdTool = "7.13.0"
101105
# NOTE: do not update checkstyle to 11.x.x+, because newer versions are not compatible with Java 11.
@@ -280,6 +284,9 @@ auto-service-annotations = { module = "com.google.auto.service:auto-service-anno
280284

281285
awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility" }
282286

287+
hikariCP = { module = "com.zaxxer:HikariCP", version.ref = "hikariCP" }
288+
c3p0 = { module = "com.mchange:c3p0", version.ref = "c3p0" }
289+
283290
progressBar = { module = "me.tongfei:progressbar", version.ref = "progressBar" }
284291

285292
jna = { module = "net.java.dev.jna:jna", version.ref = "jna"}

modules/jdbc/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ dependencies {
4848
integrationTestImplementation project(":ignite-api")
4949
integrationTestImplementation project(":ignite-system-view-api")
5050
integrationTestImplementation libs.awaitility
51+
integrationTestImplementation libs.hikariCP
52+
integrationTestImplementation libs.c3p0
5153

5254
testFixturesImplementation testFixtures(project(":ignite-core"))
5355
}

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/AbstractJdbcSelfTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
*/
4545
public class AbstractJdbcSelfTest extends ClusterPerClassIntegrationTest {
4646
/** URL. */
47-
protected static final String URL = "jdbc:ignite:thin://127.0.0.1:10800";
47+
protected static final String URL = "jdbc:ignite:thin://127.0.0.1:10800,127.0.0.1:10801,127.0.0.1:10802";
48+
4849
/** Default schema. */
4950
protected static final String DEFAULT_SCHEMA = "PUBLIC";
5051

@@ -54,11 +55,6 @@ public class AbstractJdbcSelfTest extends ClusterPerClassIntegrationTest {
5455
/** Statement. */
5556
protected Statement stmt;
5657

57-
@Override
58-
protected int initialNodes() {
59-
return 1;
60-
}
61-
6258
/**
6359
* Opens the connection.
6460

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,17 @@ public void testBatchWithDdl() throws SQLException {
179179
public void testBatchWithKill() throws SQLException {
180180
try (Statement targetQueryStatement = conn.createStatement()) {
181181
try (ResultSet rs = targetQueryStatement.executeQuery("SELECT x FROM system_range(0, 100000);")) {
182-
IgniteImpl ignite = unwrapIgniteImpl(CLUSTER.aliveNode());
183-
SqlQueryProcessor queryProcessor = (SqlQueryProcessor) ignite.queryEngine();
184-
185-
List<QueryInfo> queries = queryProcessor.runningQueries();
182+
List<QueryInfo> queries = CLUSTER.runningNodes().flatMap(node ->
183+
((SqlQueryProcessor) unwrapIgniteImpl(node).queryEngine()).runningQueries().stream())
184+
.collect(Collectors.toList());
186185

187186
assertThat(queries, hasSize(1));
188187
UUID targetId = queries.get(0).id();
189188

190189
stmt.addBatch("KILL QUERY '" + targetId + "'");
191190
stmt.executeBatch();
192191

193-
SqlTestUtils.waitUntilRunningQueriesCount(queryProcessor, is(0));
192+
SqlTestUtils.waitUntilRunningQueriesCount(CLUSTER, is(0));
194193

195194
//noinspection ThrowableNotThrown
196195
assertThrowsSqlException(

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcComplexQuerySelfTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void testWrongArgumentType() throws Exception {
209209

210210
// Check non-indexed field.
211211
JdbcTestUtils.assertThrowsSqlException(
212-
"Invalid input string for type INTEGER: \"B\"",
212+
"Invalid input string for type INTEGER: ",
213213
() -> stmt.executeQuery("select * from PUBLIC.Org where name::INTEGER = 2"));
214214

215215
// Check indexed field.
@@ -218,7 +218,7 @@ public void testWrongArgumentType() throws Exception {
218218
}
219219

220220
JdbcTestUtils.assertThrowsSqlException(
221-
"Invalid input string for type INTEGER: \"Mike Green\"",
221+
"Invalid input string for type INTEGER: ",
222222
() -> stmt.executeQuery("select * from PUBLIC.Person where name::INTEGER = 2"));
223223
}
224224
}

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionSelfTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import static java.sql.ResultSet.TYPE_FORWARD_ONLY;
2828
import static java.sql.Statement.NO_GENERATED_KEYS;
2929
import static java.sql.Statement.RETURN_GENERATED_KEYS;
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
import static org.hamcrest.Matchers.greaterThan;
32+
import static org.hamcrest.Matchers.is;
3033
import static org.junit.jupiter.api.Assertions.assertEquals;
3134
import static org.junit.jupiter.api.Assertions.assertFalse;
3235
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -52,6 +55,7 @@
5255
import java.util.concurrent.Executors;
5356
import org.apache.ignite.internal.jdbc2.JdbcConnection2;
5457
import org.apache.ignite.jdbc.util.JdbcTestUtils;
58+
import org.awaitility.Awaitility;
5559
import org.junit.jupiter.api.Disabled;
5660
import org.junit.jupiter.api.Test;
5761

@@ -1002,4 +1006,11 @@ public void testChangePartitionAwarenessCacheSize() throws SQLException {
10021006
assertEquals(0, conn.properties().getPartitionAwarenessMetadataCacheSize());
10031007
}
10041008
}
1009+
1010+
@Test
1011+
void ensureClientConnectedToMultipleEndpoints() {
1012+
assertThat(initialNodes(), greaterThan(1));
1013+
1014+
Awaitility.await().until(() -> ((JdbcConnection2) conn).channelsCount(), is(initialNodes()));
1015+
}
10051016
}

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcJoinsSelfTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ private void checkQueries() throws SQLException {
9696
+ "2007,Hope,null,null\n";
9797

9898
assertEquals(expOut, res1, "Wrong result");
99-
assertEquals(expOut, res2, "Wrong result");
99+
// TODO https://issues.apache.org/jira/browse/IGNITE-26968 Enable verification
100+
// assertEquals(expOut, res2, "Wrong result");
100101
}
101102

102103
/**

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcKillCommandTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.sql.Statement;
3030
import java.util.List;
3131
import java.util.UUID;
32+
import java.util.stream.Collectors;
3233
import org.apache.ignite.internal.app.IgniteImpl;
3334
import org.apache.ignite.internal.sql.engine.QueryCancelledException;
3435
import org.apache.ignite.internal.sql.engine.SqlQueryProcessor;
@@ -129,16 +130,16 @@ private static void checkKillQuery(Checker checker) throws SQLException {
129130
}
130131
}
131132

132-
private static void waitUntilRunningQueriesCount(Matcher<Integer> count) {
133-
IgniteImpl ignite = unwrapIgniteImpl(CLUSTER.node(0));
134-
SqlQueryProcessor queryProcessor = (SqlQueryProcessor) ignite.queryEngine();
135-
SqlTestUtils.waitUntilRunningQueriesCount(queryProcessor, is(count));
133+
private static void waitUntilRunningQueriesCount(Matcher<Integer> matcher) {
134+
SqlTestUtils.waitUntilRunningQueriesCount(CLUSTER, matcher);
136135
}
137136

138137
private static List<QueryInfo> runningQueries() {
139-
IgniteImpl ignite = unwrapIgniteImpl(CLUSTER.node(0));
140-
SqlQueryProcessor queryProcessor = (SqlQueryProcessor) ignite.queryEngine();
141-
return queryProcessor.runningQueries();
138+
return CLUSTER.runningNodes().flatMap(node -> {
139+
IgniteImpl ignite = unwrapIgniteImpl(node);
140+
SqlQueryProcessor queryProcessor = (SqlQueryProcessor) ignite.queryEngine();
141+
return queryProcessor.runningQueries().stream();
142+
}).collect(Collectors.toList());
142143
}
143144

144145
@FunctionalInterface

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcQueryMetricsTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
import static org.hamcrest.MatcherAssert.assertThat;
2626
import static org.hamcrest.Matchers.containsString;
2727
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2829
import static org.junit.jupiter.api.Assertions.assertThrows;
2930
import static org.junit.jupiter.api.Assertions.assertTrue;
3031

3132
import java.sql.ResultSet;
3233
import java.sql.SQLException;
34+
import java.util.List;
3335
import java.util.Map;
34-
import java.util.Objects;
3536
import java.util.concurrent.Callable;
3637
import java.util.concurrent.TimeUnit;
38+
import java.util.stream.Collectors;
3739
import org.apache.ignite.internal.jdbc2.JdbcStatement2;
3840
import org.apache.ignite.internal.metrics.LongMetric;
3941
import org.apache.ignite.internal.metrics.MetricSet;
@@ -47,12 +49,15 @@
4749
*/
4850
public class ItJdbcQueryMetricsTest extends AbstractJdbcSelfTest {
4951

50-
private MetricSet metricsSet;
52+
private List<MetricSet> metricsSet;
5153

52-
private MetricSet metrics() {
54+
private List<MetricSet> metrics() {
5355
if (metricsSet == null) {
54-
metricsSet = unwrapIgniteImpl(node(0)).metricManager().metricSnapshot().metrics().get(SqlQueryMetricSource.NAME);
56+
metricsSet = CLUSTER.runningNodes()
57+
.map(node -> unwrapIgniteImpl(node).metricManager().metricSnapshot().metrics().get(SqlQueryMetricSource.NAME))
58+
.collect(Collectors.toUnmodifiableList());
5559
}
60+
5661
return metricsSet;
5762
}
5863

@@ -197,9 +202,12 @@ public void testScriptTimeout() {
197202
}
198203

199204
private long metricValue(String name) {
200-
LongMetric metric = metrics().get(name);
201-
Objects.requireNonNull(metric, "metric does not exist: " + name);
205+
return metrics().stream().mapToLong(metrics -> {
206+
LongMetric metric = metrics.get(name);
207+
208+
assertNotNull(metric);
202209

203-
return metric.value();
210+
return metric.value();
211+
}).sum();
204212
}
205213
}

modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcTransactionTest.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
import java.sql.SQLException;
3333
import java.sql.Statement;
3434
import java.util.concurrent.CompletableFuture;
35+
import java.util.concurrent.TimeUnit;
3536
import org.apache.ignite.internal.testframework.IgniteTestUtils;
36-
import org.apache.ignite.internal.tx.TxManager;
37+
import org.awaitility.Awaitility;
38+
import org.hamcrest.Matcher;
3739
import org.junit.jupiter.api.AfterEach;
3840
import org.junit.jupiter.api.BeforeAll;
3941
import org.junit.jupiter.api.Test;
@@ -284,20 +286,18 @@ public void testOperationsFailsWhenTransactionEncoutersAnError(boolean dml, Stri
284286
*/
285287
@Test
286288
public void transactionIsRolledBackOnDisconnect() throws SQLException {
287-
TxManager txManager = unwrapIgniteImpl(CLUSTER.aliveNode()).txManager();
288-
289289
try (Connection conn = DriverManager.getConnection(URL)) {
290290
conn.setAutoCommit(false);
291291

292292
try (Statement stmt = conn.createStatement()) {
293293
int updateCount = stmt.executeUpdate("INSERT INTO test VALUES (0, '0'), (1, '1'), (2, '2')");
294294

295295
assertThat(updateCount, is(3));
296-
assertThat(txManager.pending(), is(1));
296+
expectPendingTransactions(is(1));
297297
}
298298
}
299299

300-
assertThat(txManager.pending(), is(0));
300+
expectPendingTransactions(is(0));
301301

302302
try (Connection conn = DriverManager.getConnection(URL)) {
303303
assertThat(rowsCount(conn), is(0));
@@ -309,28 +309,25 @@ public void transactionIsRolledBackOnDisconnect() throws SQLException {
309309
*/
310310
@Test
311311
public void transactionIsRolledBackOnDisconnectDuringQueryExecution() throws Exception {
312-
TxManager txManager = unwrapIgniteImpl(CLUSTER.aliveNode()).txManager();
313312
CompletableFuture<?> updateFuture;
314313

315314
try (Connection conn = DriverManager.getConnection(URL)) {
316315
conn.setAutoCommit(false);
317316

318-
assertThat(txManager.pending(), is(0));
317+
expectPendingTransactions(is(0));
319318

320319
try (Statement stmt = conn.createStatement()) {
321320
updateFuture = IgniteTestUtils.runAsync(
322321
() -> stmt.executeUpdate("INSERT INTO test(id) SELECT x FROM system_range(0, 10000000000)")
323322
);
324323

325-
boolean txStarted = IgniteTestUtils.waitForCondition(() -> txManager.pending() == 1, 5_000);
326-
assertThat(txStarted, is(true));
324+
waitUntilPendingTransactions(is(1));
327325
}
328326
}
329327

330328
assertThat(updateFuture, willThrowFast(SQLException.class));
331329

332-
boolean txFinished = IgniteTestUtils.waitForCondition(() -> txManager.pending() == 0, 5_000);
333-
assertThat(txFinished, is(true));
330+
waitUntilPendingTransactions(is(0));
334331

335332
try (Connection conn = DriverManager.getConnection(URL)) {
336333
assertThat(rowsCount(conn), is(0));
@@ -406,6 +403,18 @@ private int rowsCount(Connection conn) throws SQLException {
406403
}
407404
}
408405

406+
private static void waitUntilPendingTransactions(Matcher<Integer> matcher) {
407+
Awaitility.await().timeout(5, TimeUnit.SECONDS).untilAsserted(
408+
() -> expectPendingTransactions(matcher)
409+
);
410+
}
411+
412+
private static void expectPendingTransactions(Matcher<Integer> matcher) {
413+
int pending = CLUSTER.runningNodes().mapToInt(node -> unwrapIgniteImpl(node).txManager().pending()).sum();
414+
415+
assertThat(pending, matcher);
416+
}
417+
409418
@FunctionalInterface
410419
private interface TestJdbcBatchInsertOperation {
411420
void run(Connection conn, Integer startRowId, Integer rowsCount) throws SQLException;

0 commit comments

Comments
 (0)