You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by zs...@apache.org on 2022/03/11 15:33:56 UTC
[ignite-3] branch main updated: IGNITE-16630 Fix JDBC tests related to MERGE statement - Fixes #710.
This is an automated email from the ASF dual-hosted git repository.
zstan 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 71ec36c IGNITE-16630 Fix JDBC tests related to MERGE statement - Fixes #710.
71ec36c is described below
commit 71ec36cbccd8c461e3c5f8294000e8a0e56c3924
Author: zstan <st...@gmail.com>
AuthorDate: Fri Mar 11 18:31:55 2022 +0300
IGNITE-16630 Fix JDBC tests related to MERGE statement - Fixes #710.
Signed-off-by: zstan <st...@gmail.com>
---
.../runner/app/jdbc/ItJdbcBatchSelfTest.java | 161 ++++-----------------
1 file changed, 25 insertions(+), 136 deletions(-)
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcBatchSelfTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcBatchSelfTest.java
index cbd117b..321e176 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcBatchSelfTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcBatchSelfTest.java
@@ -247,64 +247,46 @@ public class ItJdbcBatchSelfTest extends AbstractJdbcSelfTest {
}
}
- @Disabled("https://issues.apache.org/jira/browse/IGNITE-16489")
@Test
public void testBatchMerge() throws SQLException {
- final int batchSize = 7;
-
- for (int idx = 0, i = 0; i < batchSize; ++i, idx += i) {
- stmt.addBatch("merge into Person (id, firstName, lastName, age) values "
- + generateValues(idx, i + 1));
- }
-
- int[] updCnts = stmt.executeBatch();
+ final int batchSize = 5;
- assertEquals(batchSize, updCnts.length, "Invalid update counts size");
-
- for (int i = 0; i < batchSize; ++i) {
- assertEquals(i + 1, updCnts[i], "Invalid update count");
+ try (Statement statement = conn.createStatement()) {
+ statement.executeUpdate("CREATE TABLE Src(id INT PRIMARY KEY, firstName VARCHAR, lastName VARCHAR, age INT)");
}
- }
-
- @Disabled("https://issues.apache.org/jira/browse/IGNITE-16489")
- @Test
- public void testBatchMergeParseException() throws Exception {
- final int batchSize = 7;
- final int failedIdx = 5;
+ try {
+ for (int idx = 0, i = 0; i < batchSize; ++i, idx += i) {
+ stmt.addBatch("INSERT INTO Person (id, firstName, lastName, age) values "
+ + generateValues(idx, i + 1));
- for (int idx = 0, i = 0; i < failedIdx; ++i, idx += i) {
- stmt.addBatch("merge into Person (id, firstName, lastName, age) values "
- + generateValues(idx, i + 1));
- }
+ stmt.addBatch("INSERT INTO Src (id, firstName, lastName, age) values "
+ + generateValues(idx + 1, i + 1));
+ }
- stmt.addBatch("merge into Person (id, firstName, lastName, age) values (4444, 'FAIL', 1, 1, 1)");
+ stmt.executeBatch();
- stmt.addBatch("merge into Person (id, firstName, lastName, age) values "
- + generateValues(100, 7));
+ String sql = "MERGE INTO Person dst USING Src src ON dst.id = src.id "
+ + "WHEN MATCHED THEN UPDATE SET firstName = src.firstName "
+ + "WHEN NOT MATCHED THEN INSERT (id, firstName, lastName) VALUES (src.id, src.firstName, src.lastName)";
- try {
- stmt.executeBatch();
+ stmt.addBatch(sql);
- fail("BatchUpdateException must be thrown");
- } catch (BatchUpdateException e) {
- int[] updCnts = e.getUpdateCounts();
+ stmt.addBatch("INSERT INTO Person (id, firstName, lastName, age) values " + valuesRow(100));
- assertEquals(batchSize, updCnts.length, "Invalid update counts size");
+ stmt.addBatch(sql);
- for (int i = 0; i < batchSize; ++i) {
- assertEquals(i != failedIdx ? i + 1 : Statement.EXECUTE_FAILED, updCnts[i],
- "Invalid update count: " + i);
- }
+ int[] updCnts = stmt.executeBatch();
- if (!e.getMessage().contains("Value conversion failed")) {
- log.error("Invalid exception: ", e);
+ assertEquals(3, updCnts.length, "Invalid update counts size");
- fail();
+ // result size is equal to mathematical progression:
+ assertEquals((1 + batchSize) * batchSize / 2, updCnts[0], "Invalid update counts");
+ assertEquals((1 + batchSize) * batchSize / 2, updCnts[2], "Invalid update counts");
+ } finally {
+ try (Statement statement = conn.createStatement()) {
+ statement.executeUpdate("DROP TABLE Src;");
}
-
- assertEquals(SqlStateCode.INTERNAL_ERROR, e.getSQLState(), "Invalid SQL state.");
- assertEquals(IgniteQueryErrorCode.UNKNOWN, e.getErrorCode(), "Invalid error code.");
}
}
@@ -471,99 +453,6 @@ public class ItJdbcBatchSelfTest extends AbstractJdbcSelfTest {
}
}
- @Disabled("https://issues.apache.org/jira/browse/IGNITE-16489")
- @Test
- public void testBatchMergePrepared() throws SQLException {
- final int batchSize = 10;
-
- pstmt = conn.prepareStatement("merge into Person(_key, id, firstName, lastName, age) values "
- + "(?, ?, ?, ?, ?)");
-
- for (int i = 0; i < batchSize; ++i) {
- int paramCnt = 1;
-
- pstmt.setString(paramCnt++, "p" + i);
- pstmt.setInt(paramCnt++, i);
- pstmt.setString(paramCnt++, "Name" + i);
- pstmt.setString(paramCnt++, "Lastname" + i);
- pstmt.setInt(paramCnt++, 20 + i);
-
- pstmt.addBatch();
- }
-
- int[] updCnts = pstmt.executeBatch();
-
- assertEquals(batchSize, updCnts.length, "Invalid update counts size");
-
- for (int i = 0; i < batchSize; ++i) {
- assertEquals(1, updCnts[i], "Invalid update count");
- }
- }
-
- @Disabled("https://issues.apache.org/jira/browse/IGNITE-16489")
- @Test
- public void testBatchMergeExceptionPrepared() throws Exception {
- final int batchSize = 7;
-
- final int failedIdx = 5;
-
- pstmt = conn.prepareStatement("merge into Person(_key, id, firstName, lastName, age) values "
- + "(?, ?, ?, ?, ?)");
-
- for (int i = 0; i < failedIdx; ++i) {
- int paramCnt = 1;
-
- pstmt.setString(paramCnt++, "p" + i);
- pstmt.setInt(paramCnt++, i);
- pstmt.setString(paramCnt++, "Name" + i);
- pstmt.setString(paramCnt++, "Lastname" + i);
- pstmt.setInt(paramCnt++, 20 + i);
-
- pstmt.addBatch();
- }
-
- int paramCnt = 1;
- pstmt.setString(paramCnt++, "p" + failedIdx);
- pstmt.setString(paramCnt++, "FAIL");
- pstmt.setString(paramCnt++, "Name" + failedIdx);
- pstmt.setString(paramCnt++, "Lastname" + failedIdx);
- pstmt.setInt(paramCnt++, 20 + failedIdx);
-
- pstmt.addBatch();
-
- paramCnt = 1;
- pstmt.setString(paramCnt++, "p" + failedIdx + 1);
- pstmt.setInt(paramCnt++, failedIdx + 1);
- pstmt.setString(paramCnt++, "Name" + failedIdx + 1);
- pstmt.setString(paramCnt++, "Lastname" + failedIdx + 1);
- pstmt.setInt(paramCnt++, 20 + failedIdx + 1);
-
- pstmt.addBatch();
-
- try {
- int[] res = pstmt.executeBatch();
-
- fail("BatchUpdateException must be thrown res=" + Arrays.toString(res));
- } catch (BatchUpdateException e) {
- int[] updCnts = e.getUpdateCounts();
-
- assertEquals(batchSize, updCnts.length, "Invalid update counts size");
-
- for (int i = 0; i < batchSize; ++i) {
- assertEquals(i != failedIdx ? 1 : Statement.EXECUTE_FAILED, updCnts[i], "Invalid update count");
- }
-
- if (!e.getMessage().contains("Value conversion failed")) {
- log.error("Invalid exception: ", e);
-
- fail();
- }
-
- assertEquals(SqlStateCode.INTERNAL_ERROR, e.getSQLState(), "Invalid SQL state.");
- assertEquals(IgniteQueryErrorCode.UNKNOWN, e.getErrorCode(), "Invalid error code.");
- }
- }
-
/**
* Populates table 'Person' with entities.
*