This is an automated email from the ASF dual-hosted git repository.
amashenkov 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 0189bed12d IGNITE-20305 Incorrect using of Assertions.assertThrows
(#2510)
0189bed12d is described below
commit 0189bed12ddbf3134aca42b94abb78aafcfb7b8b
Author: ygerzhedovich <[email protected]>
AuthorDate: Thu Aug 31 19:02:37 2023 +0300
IGNITE-20305 Incorrect using of Assertions.assertThrows (#2510)
---
.../internal/jdbc/ItJdbcMetadataSelfTest.java | 5 +-
.../apache/ignite/jdbc/AbstractJdbcSelfTest.java | 8 +-
.../apache/ignite/jdbc/ItJdbcBatchSelfTest.java | 19 +-
.../ignite/jdbc/ItJdbcConnectionSelfTest.java | 335 ++++++++++-----------
.../ignite/jdbc/ItJdbcErrorsAbstractSelfTest.java | 13 +-
.../ignite/jdbc/ItJdbcInsertStatementSelfTest.java | 5 +-
.../ignite/jdbc/ItJdbcResultSetSelfTest.java | 36 ++-
.../ignite/jdbc/ItJdbcStatementCancelSelfTest.java | 13 +-
.../ignite/jdbc/ItJdbcStatementSelfTest.java | 66 ++--
.../org/apache/ignite/jdbc/util/JdbcTestUtils.java | 75 +++++
.../internal/marshaller/FieldAccessorTest.java | 8 +-
.../internal/sql/api/ItSqlSynchronousApiTest.java | 67 +++--
.../internal/sql/engine/ItCreateTableDdlTest.java | 108 ++++---
.../ignite/internal/sql/engine/ItDmlTest.java | 45 +--
.../sql/engine/ItDynamicParameterTest.java | 18 +-
.../internal/sql/engine/ItFunctionsTest.java | 40 ++-
.../apache/ignite/internal/sqllogic/Statement.java | 14 +-
.../schema/marshaller/KvMarshallerTest.java | 7 +-
.../RecordMarshallerValidationsTest.java | 6 +-
.../prepare/ddl/DdlSqlToCommandConverter.java | 2 +-
.../internal/sql/engine/util/SqlTestUtils.java | 11 +-
.../storage/util/MvPartitionStoragesTest.java | 112 +++----
.../table/type/NumericTypesSerializerTest.java | 30 +-
23 files changed, 559 insertions(+), 484 deletions(-)
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/internal/jdbc/ItJdbcMetadataSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/internal/jdbc/ItJdbcMetadataSelfTest.java
index 0e031f7557..1d86af8e8c 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/internal/jdbc/ItJdbcMetadataSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/internal/jdbc/ItJdbcMetadataSelfTest.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.jdbc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
@@ -47,6 +46,7 @@ import
org.apache.ignite.internal.client.proto.ProtocolVersion;
import org.apache.ignite.internal.jdbc.proto.event.JdbcColumnMeta;
import org.apache.ignite.internal.sql.engine.util.SqlTestUtils;
import org.apache.ignite.jdbc.AbstractJdbcSelfTest;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.apache.ignite.sql.ColumnType;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
@@ -626,13 +626,14 @@ public class ItJdbcMetadataSelfTest extends
AbstractJdbcSelfTest {
* Check that parameters metadata throws correct exception on non-parsable
statement.
*/
@Test
+ @Disabled("https://issues.apache.org/jira/browse/IGNITE-16203")
public void testParametersMetadataNegative() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
conn.setSchema("\"pers\"");
PreparedStatement notCorrect = conn.prepareStatement("select *
from NotExistingTable;");
- assertThrows(SQLException.class, notCorrect::getParameterMetaData,
"Table \"NOTEXISTINGTABLE\" not found");
+ JdbcTestUtils.assertThrowsSqlException("Table NOTEXISTINGTABLE not
found", notCorrect::getParameterMetaData);
}
}
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/AbstractJdbcSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/AbstractJdbcSelfTest.java
index 6b54e77f20..63190feeba 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/AbstractJdbcSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/AbstractJdbcSelfTest.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
-import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.ArrayList;
@@ -39,6 +38,7 @@ import
org.apache.ignite.internal.testframework.TestIgnitionManager;
import org.apache.ignite.internal.testframework.WorkDirectory;
import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -143,7 +143,7 @@ public class AbstractJdbcSelfTest extends
BaseIgniteAbstractTest {
* @param ex Executable function that throws an error.
*/
protected void checkResultSetClosed(Executable ex) {
- assertThrows(SQLException.class, ex, "Result set is closed");
+ JdbcTestUtils.assertThrowsSqlException("Result set is closed", ex);
}
/**
@@ -152,7 +152,7 @@ public class AbstractJdbcSelfTest extends
BaseIgniteAbstractTest {
* @param ex Executable function that throws an error.
*/
protected void checkStatementClosed(Executable ex) {
- assertThrows(SQLException.class, ex, "Statement is closed");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed", ex);
}
/**
@@ -161,7 +161,7 @@ public class AbstractJdbcSelfTest extends
BaseIgniteAbstractTest {
* @param ex Executable function that throws an error.
*/
protected void checkConnectionClosed(Executable ex) {
- assertThrows(SQLException.class, ex, "Connection is closed");
+ JdbcTestUtils.assertThrowsSqlException("Connection is closed", ex);
}
/**
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
index 883c176e41..6eaeadfdd3 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcBatchSelfTest.java
@@ -23,7 +23,6 @@ import static
org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@@ -40,6 +39,7 @@ import java.time.LocalTime;
import java.util.Arrays;
import org.apache.ignite.internal.jdbc.proto.IgniteQueryErrorCode;
import org.apache.ignite.internal.jdbc.proto.SqlStateCode;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -136,7 +136,10 @@ public class ItJdbcBatchSelfTest extends
AbstractJdbcSelfTest {
stmt.addBatch(ins1 + ";" + ins2);
- assertThrows(BatchUpdateException.class, () -> stmt.executeBatch(),
"Multiple statements are not allowed.");
+ JdbcTestUtils.assertThrowsSqlException(
+ BatchUpdateException.class,
+ "Multiple statements are not allowed.",
+ () -> stmt.executeBatch());
}
@Test
@@ -147,17 +150,17 @@ public class ItJdbcBatchSelfTest extends
AbstractJdbcSelfTest {
stmt2.close();
pstmt2.close();
- assertThrows(SQLException.class, () -> stmt2.addBatch(""), "Statement
is closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.", () ->
stmt2.addBatch(""));
- assertThrows(SQLException.class, stmt2::clearBatch, "Statement is
closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.",
stmt2::clearBatch);
- assertThrows(SQLException.class, stmt2::executeBatch, "Statement is
closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.",
stmt2::executeBatch);
- assertThrows(SQLException.class, pstmt2::addBatch, "Statement is
closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.",
pstmt2::addBatch);
- assertThrows(SQLException.class, pstmt2::clearBatch, "Statement is
closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.",
pstmt2::clearBatch);
- assertThrows(SQLException.class, pstmt2::executeBatch, "Statement is
closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.",
pstmt2::executeBatch);
}
@Test
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionSelfTest.java
index 3ba04986ba..a7f7420042 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcConnectionSelfTest.java
@@ -42,7 +42,6 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
-import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.Statement;
@@ -52,6 +51,7 @@ import java.util.ServiceLoader;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import org.apache.ignite.internal.jdbc.IgniteJdbcDriver;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -117,15 +117,15 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
assertInvalid("jdbc:ignite:thin://:10000", "Host name is empty");
assertInvalid("jdbc:ignite:thin:// :10000", "Host name is empty");
- assertInvalid("jdbc:ignite:thin://127.0.0.1:-1", "port range contains
invalid port -1");
- assertInvalid("jdbc:ignite:thin://127.0.0.1:0", "port range contains
invalid port 0");
+ assertInvalid("jdbc:ignite:thin://127.0.0.1:-1", "(invalid port -1)");
+ assertInvalid("jdbc:ignite:thin://127.0.0.1:0", "(invalid port 0)");
assertInvalid("jdbc:ignite:thin://127.0.0.1:100000",
- "port range contains invalid port 100000");
+ "(invalid port 100000)");
- assertInvalid("jdbc:ignite:thin://[::1]:-1", "port range contains
invalid port -1");
- assertInvalid("jdbc:ignite:thin://[::1]:0", "port range contains
invalid port 0");
+ assertInvalid("jdbc:ignite:thin://[::1]:-1", "(invalid port -1)");
+ assertInvalid("jdbc:ignite:thin://[::1]:0", "(invalid port 0)");
assertInvalid("jdbc:ignite:thin://[::1]:100000",
- "port range contains invalid port 100000");
+ "(invalid port 100000)");
}
/**
@@ -179,16 +179,16 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
/**
* Assert that provided URL is invalid.
*
- * @param url URL.
+ * @param url URL.
* @param errMsg Error message.
*/
- private void assertInvalid(final String url, String errMsg) {
- assertThrows(SQLException.class, () ->
DriverManager.getConnection(url), errMsg);
+ private void assertInvalid(String url, String errMsg) {
+ JdbcTestUtils.assertThrowsSqlException(errMsg, () ->
DriverManager.getConnection(url));
}
@Test
public void testClose() throws Exception {
- final Connection conn;
+ Connection conn;
try (Connection conn0 = DriverManager.getConnection(URL)) {
conn = conn0;
@@ -201,7 +201,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
assertFalse(conn.isValid(2), "Connection must be closed");
- assertThrows(SQLException.class, () -> conn.isValid(-2), "Invalid
timeout");
+ JdbcTestUtils.assertThrowsSqlException("Invalid timeout", () ->
conn.isValid(-2));
}
@Test
@@ -228,14 +228,14 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
@Test
public void testCreateStatement2() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
- int[] rsTypes = new int[]{TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE};
+ int[] rsTypes = {TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE};
- int[] rsConcurs = new int[]{ CONCUR_READ_ONLY,
ResultSet.CONCUR_UPDATABLE };
+ int[] rsConcurs = {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE};
DatabaseMetaData meta = conn.getMetaData();
- for (final int type : rsTypes) {
- for (final int concur : rsConcurs) {
+ for (int type : rsTypes) {
+ for (int concur : rsConcurs) {
if (meta.supportsResultSetConcurrency(type, concur)) {
assertEquals(TYPE_FORWARD_ONLY, type);
assertEquals(CONCUR_READ_ONLY, concur);
@@ -250,7 +250,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
continue;
}
- assertThrows(SQLFeatureNotSupportedException.class, () ->
conn.createStatement(type, concur));
+
JdbcTestUtils.assertThrowsSqlException(SQLFeatureNotSupportedException.class,
() -> conn.createStatement(type, concur));
}
}
@@ -269,17 +269,17 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
@Test
public void testCreateStatement3() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
- int[] rsTypes = new int[]{ TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE };
+ int[] rsTypes = {TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE};
- int[] rsConcurs = new int[]{ CONCUR_READ_ONLY,
ResultSet.CONCUR_UPDATABLE };
+ int[] rsConcurs = {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE};
- int[] rsHoldabilities = new int[]{ HOLD_CURSORS_OVER_COMMIT,
CLOSE_CURSORS_AT_COMMIT };
+ int[] rsHoldabilities = {HOLD_CURSORS_OVER_COMMIT,
CLOSE_CURSORS_AT_COMMIT};
DatabaseMetaData meta = conn.getMetaData();
- for (final int type : rsTypes) {
- for (final int concur : rsConcurs) {
- for (final int holdabililty : rsHoldabilities) {
+ for (int type : rsTypes) {
+ for (int concur : rsConcurs) {
+ for (int holdabililty : rsHoldabilities) {
if (meta.supportsResultSetConcurrency(type, concur)) {
assertEquals(TYPE_FORWARD_ONLY, type);
assertEquals(CONCUR_READ_ONLY, concur);
@@ -295,7 +295,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
continue;
}
- assertThrows(SQLFeatureNotSupportedException.class,
+
JdbcTestUtils.assertThrowsSqlException(SQLFeatureNotSupportedException.class,
() -> conn.createStatement(type, concur,
holdabililty));
}
}
@@ -312,10 +312,9 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testPrepareStatement() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// null query text
- assertThrows(
- SQLException.class,
- () -> conn.prepareStatement(null),
- "SQL string cannot be null"
+ JdbcTestUtils.assertThrowsSqlException(
+ "SQL string cannot be null",
+ () -> conn.prepareStatement(null)
);
final String sqlText = "select * from test where param = ?";
@@ -341,29 +340,28 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
try (Connection conn = DriverManager.getConnection(URL)) {
final String sqlText = "select * from test where param = ?";
- int[] rsTypes = new int[]{ TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE };
+ int[] rsTypes = {TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE};
- int[] rsConcurs = new int[]{ CONCUR_READ_ONLY,
ResultSet.CONCUR_UPDATABLE };
+ int[] rsConcurs = {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE};
DatabaseMetaData meta = conn.getMetaData();
- for (final int type : rsTypes) {
- for (final int concur : rsConcurs) {
+ for (int type : rsTypes) {
+ for (int concur : rsConcurs) {
if (meta.supportsResultSetConcurrency(type, concur)) {
assertEquals(TYPE_FORWARD_ONLY, type);
assertEquals(CONCUR_READ_ONLY, concur);
// null query text
- assertThrows(
- SQLException.class,
- () -> conn.prepareStatement(null, type,
concur),
- "SQL string cannot be null"
+ JdbcTestUtils.assertThrowsSqlException(
+ "SQL string cannot be null",
+ () -> conn.prepareStatement(null, type, concur)
);
continue;
}
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
() -> conn.prepareStatement(sqlText, type, concur)
);
@@ -389,11 +387,11 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
try (Connection conn = DriverManager.getConnection(URL)) {
final String sqlText = "select * from test where param = ?";
- int[] rsTypes = new int[]{ TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE };
+ int[] rsTypes = {TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE};
- int[] rsConcurs = new int[]{ CONCUR_READ_ONLY,
ResultSet.CONCUR_UPDATABLE };
+ int[] rsConcurs = {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE};
- int[] rsHoldabilities = new int[]{ HOLD_CURSORS_OVER_COMMIT,
CLOSE_CURSORS_AT_COMMIT };
+ int[] rsHoldabilities = {HOLD_CURSORS_OVER_COMMIT,
CLOSE_CURSORS_AT_COMMIT};
DatabaseMetaData meta = conn.getMetaData();
@@ -405,16 +403,15 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
assertEquals(CONCUR_READ_ONLY, concur);
// null query text
- assertThrows(
- SQLException.class,
- () -> conn.prepareStatement(null, type,
concur, holdabililty),
- "SQL string cannot be null"
+ JdbcTestUtils.assertThrowsSqlException(
+ "SQL string cannot be null",
+ () -> conn.prepareStatement(null, type,
concur, holdabililty)
);
continue;
}
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
() -> conn.prepareStatement(sqlText, type,
concur, holdabililty)
);
@@ -438,28 +435,25 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
try (Connection conn = DriverManager.getConnection(URL)) {
final String sqlText = "insert into test (val) values (?)";
- assertThrows(
- SQLFeatureNotSupportedException.class,
- () -> conn.prepareStatement(sqlText,
RETURN_GENERATED_KEYS),
- "Auto generated keys are not supported."
+ JdbcTestUtils.assertThrowsSqlException(
+ "Auto generated keys are not supported.",
+ () -> conn.prepareStatement(sqlText, RETURN_GENERATED_KEYS)
+
);
- assertThrows(
- SQLFeatureNotSupportedException.class,
- () -> conn.prepareStatement(sqlText, NO_GENERATED_KEYS),
- "Auto generated keys are not supported."
+ JdbcTestUtils.assertThrowsSqlException(
+ "Auto generated keys are not supported.",
+ () -> conn.prepareStatement(sqlText, NO_GENERATED_KEYS)
);
- assertThrows(
- SQLFeatureNotSupportedException.class,
- () -> conn.prepareStatement(sqlText, new int[]{1}),
- "Auto generated keys are not supported."
+ JdbcTestUtils.assertThrowsSqlException(
+ "Auto generated keys are not supported.",
+ () -> conn.prepareStatement(sqlText, new int[]{1})
);
- assertThrows(
- SQLFeatureNotSupportedException.class,
- () -> conn.prepareStatement(sqlText, new String[]{"ID"}),
- "Auto generated keys are not supported."
+ JdbcTestUtils.assertThrowsSqlException(
+ "Auto generated keys are not supported.",
+ () -> conn.prepareStatement(sqlText, new String[]{"ID"})
);
}
}
@@ -469,22 +463,22 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
try (Connection conn = DriverManager.getConnection(URL)) {
final String sqlText = "exec test()";
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.prepareCall(sqlText),
- "Callable functions are not supported."
+ "Callable functions are not supported.",
+ () -> conn.prepareCall(sqlText)
);
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.prepareCall(sqlText, TYPE_FORWARD_ONLY,
CONCUR_READ_ONLY),
- "Callable functions are not supported."
+ "Callable functions are not supported.",
+ () -> conn.prepareCall(sqlText, TYPE_FORWARD_ONLY,
CONCUR_READ_ONLY)
);
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.prepareCall(sqlText, TYPE_FORWARD_ONLY,
CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT),
- "Callable functions are not supported."
+ "Callable functions are not supported.",
+ () -> conn.prepareCall(sqlText, TYPE_FORWARD_ONLY,
CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT)
);
}
}
@@ -513,25 +507,23 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testCommit() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Should not be called in auto-commit mode
- assertThrows(
- SQLException.class,
- () -> conn.commit(),
- "Transaction cannot be committed explicitly in auto-commit
mode"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Transaction cannot be committed explicitly in auto-commit
mode",
+ conn::commit
);
assertTrue(conn.getAutoCommit());
// Should not be called in auto-commit mode
- assertThrows(
- SQLException.class,
- () -> conn.commit(),
- "Transaction cannot be committed explicitly in auto-commit
mode."
+ JdbcTestUtils.assertThrowsSqlException(
+ "Transaction cannot be committed explicitly in auto-commit
mode.",
+ conn::commit
);
conn.close();
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.commit());
+ checkConnectionClosed(conn::commit);
}
}
@@ -539,16 +531,15 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testRollback() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Should not be called in auto-commit mode
- assertThrows(
- SQLException.class,
- () -> conn.rollback(),
- "Transaction cannot be rolled back explicitly in
auto-commit mode."
+ JdbcTestUtils.assertThrowsSqlException(
+ "Transaction cannot be rolled back explicitly in
auto-commit mode.",
+ conn::rollback
);
conn.close();
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.rollback());
+ checkConnectionClosed(conn::rollback);
}
}
@@ -567,7 +558,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
conn.close();
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.getMetaData());
+ checkConnectionClosed(conn::getMetaData);
}
}
@@ -580,7 +571,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
checkConnectionClosed(() -> conn.setReadOnly(true));
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.isReadOnly());
+ checkConnectionClosed(conn::isReadOnly);
}
}
@@ -601,7 +592,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
checkConnectionClosed(() -> conn.setCatalog(""));
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.getCatalog());
+ checkConnectionClosed(conn::getCatalog);
}
}
@@ -609,17 +600,16 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testGetSetTransactionIsolation() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Invalid parameter value
- assertThrows(
- SQLException.class,
- () -> conn.setTransactionIsolation(-1),
- "Invalid transaction isolation level"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Invalid transaction isolation level",
+ () -> conn.setTransactionIsolation(-1)
);
// default level
assertEquals(TRANSACTION_NONE, conn.getTransactionIsolation());
- int[] levels = { TRANSACTION_READ_UNCOMMITTED,
TRANSACTION_READ_COMMITTED,
- TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE };
+ int[] levels = {TRANSACTION_READ_UNCOMMITTED,
TRANSACTION_READ_COMMITTED,
+ TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE};
for (int level : levels) {
conn.setTransactionIsolation(level);
@@ -630,7 +620,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.getTransactionIsolation());
+ checkConnectionClosed(conn::getTransactionIsolation);
// Exception when called on closed connection
checkConnectionClosed(() ->
conn.setTransactionIsolation(TRANSACTION_SERIALIZABLE));
@@ -653,42 +643,40 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
conn.close();
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.getWarnings());
+ checkConnectionClosed(conn::getWarnings);
// Exception when called on closed connection
- checkConnectionClosed(() -> conn.clearWarnings());
+ checkConnectionClosed(conn::clearWarnings);
}
}
@Test
public void testGetSetTypeMap() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.getTypeMap(),
- "Types mapping is not supported"
+ "Types mapping is not supported",
+ conn::getTypeMap
);
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.setTypeMap(new HashMap<String, Class<?>>()),
- "Types mapping is not supported"
+ "Types mapping is not supported",
+ () -> conn.setTypeMap(new HashMap<>())
);
conn.close();
// Exception when called on closed connection
- assertThrows(
- SQLException.class,
- () -> conn.getTypeMap(),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ conn::getTypeMap
);
- assertThrows(
- SQLException.class,
- () -> conn.setTypeMap(new HashMap<String, Class<?>>()),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ () -> conn.setTypeMap(new HashMap<>())
);
}
}
@@ -712,24 +700,21 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
// Invalid constant
- assertThrows(
- SQLException.class,
- () -> conn.setHoldability(-1),
- "Invalid result set holdability value"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Invalid result set holdability value",
+ () -> conn.setHoldability(-1)
);
conn.close();
- assertThrows(
- SQLException.class,
- () -> conn.getHoldability(),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ conn::getHoldability
);
- assertThrows(
- SQLException.class,
- () -> conn.setHoldability(HOLD_CURSORS_OVER_COMMIT),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ () -> conn.setHoldability(HOLD_CURSORS_OVER_COMMIT)
);
}
}
@@ -738,18 +723,17 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testCreateClob() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Unsupported
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.createClob(),
- "SQL-specific types are not supported"
+ "SQL-specific types are not supported",
+ conn::createClob
);
conn.close();
- assertThrows(
- SQLException.class,
- () -> conn.createClob(),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ conn::createClob
);
}
}
@@ -758,18 +742,17 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testCreateBlob() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Unsupported
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.createBlob(),
- "SQL-specific types are not supported"
+ "SQL-specific types are not supported",
+ conn::createBlob
);
conn.close();
- assertThrows(
- SQLException.class,
- () -> conn.createBlob(),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ conn::createBlob
);
}
}
@@ -778,18 +761,17 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testCreateNclob() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Unsupported
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.createNClob(),
- "SQL-specific types are not supported"
+ "SQL-specific types are not supported",
+ conn::createNClob
);
conn.close();
- assertThrows(
- SQLException.class,
- () -> conn.createNClob(),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ conn::createNClob
);
}
}
@@ -798,18 +780,17 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testCreateSqlXml() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Unsupported
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> conn.createSQLXML(),
- "SQL-specific types are not supported"
+ "SQL-specific types are not supported",
+ conn::createSQLXML
);
conn.close();
- assertThrows(
- SQLException.class,
- () -> conn.createSQLXML(),
- "Connection is closed"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Connection is closed",
+ conn::createSQLXML
);
}
}
@@ -830,10 +811,10 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
checkConnectionClosed(() -> conn.getClientInfo(name));
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLClientInfoException.class,
- () -> conn.setClientInfo(name, val),
- "Connection is closed"
+ "Connection is closed",
+ () -> conn.setClientInfo(name, val)
);
}
}
@@ -844,7 +825,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
final String name = "ApplicationName";
final String val = "SelfTest";
- final Properties props = new Properties();
+ Properties props = new Properties();
props.setProperty(name, val);
conn.setClientInfo(props);
@@ -857,12 +838,12 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
conn.close();
- checkConnectionClosed(() -> conn.getClientInfo());
+ checkConnectionClosed(conn::getClientInfo);
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLClientInfoException.class,
- () -> conn.setClientInfo(props),
- "Connection is closed"
+ "Connection is closed",
+ () -> conn.setClientInfo(props)
);
}
}
@@ -872,13 +853,12 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
try (Connection conn = DriverManager.getConnection(URL)) {
final String typeName = "varchar";
- final String[] elements = new String[]{"apple", "pear"};
+ String[] elements = {"apple", "pear"};
// Invalid typename
- assertThrows(
- SQLException.class,
- () -> conn.createArrayOf(null, null),
- "Type name cannot be null"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Type name cannot be null",
+ () -> conn.createArrayOf(null, null)
);
// Unsupported
@@ -895,15 +875,14 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testCreateStruct() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
// Invalid typename
- assertThrows(
- SQLException.class,
- () -> conn.createStruct(null, null),
- "Type name cannot be null"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Type name cannot be null",
+ () -> conn.createStruct(null, null)
);
final String typeName = "employee";
- final Object[] attrs = new Object[]{100, "Tom"};
+ Object[] attrs = {100, "Tom"};
checkNotSupported(() -> conn.createStruct(typeName, attrs));
@@ -932,7 +911,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
checkConnectionClosed(() -> conn.setSchema(schema));
- checkConnectionClosed(() -> conn.getSchema());
+ checkConnectionClosed(conn::getSchema);
}
}
@@ -940,13 +919,12 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
public void testAbort() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
//Invalid executor
- assertThrows(
- SQLException.class,
- () -> conn.abort(null),
- "Executor cannot be null"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Executor cannot be null",
+ () -> conn.abort(null)
);
- final Executor executor = Executors.newFixedThreadPool(1);
+ Executor executor = Executors.newFixedThreadPool(1);
conn.abort(executor);
@@ -965,10 +943,9 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
final int timeout = 1000;
//Invalid timeout
- assertThrows(
- SQLException.class,
- () -> conn.setNetworkTimeout(executor, -1),
- "Network timeout cannot be negative"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Network timeout cannot be negative",
+ () -> conn.setNetworkTimeout(executor, -1)
);
conn.setNetworkTimeout(executor, timeout);
@@ -977,7 +954,7 @@ public class ItJdbcConnectionSelfTest extends
AbstractJdbcSelfTest {
conn.close();
- checkConnectionClosed(() -> conn.getNetworkTimeout());
+ checkConnectionClosed(conn::getNetworkTimeout);
checkConnectionClosed(() -> conn.setNetworkTimeout(executor,
timeout));
}
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsAbstractSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsAbstractSelfTest.java
index 4f41367029..86378e1110 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsAbstractSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcErrorsAbstractSelfTest.java
@@ -23,10 +23,7 @@ import static
org.apache.ignite.internal.jdbc.proto.SqlStateCode.INVALID_CURSOR_
import static org.apache.ignite.internal.jdbc.proto.SqlStateCode.NULL_VALUE;
import static
org.apache.ignite.internal.jdbc.proto.SqlStateCode.PARSING_EXCEPTION;
import static
org.apache.ignite.internal.jdbc.proto.SqlStateCode.UNSUPPORTED_OPERATION;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import java.net.URL;
@@ -39,6 +36,7 @@ import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.List;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -589,11 +587,10 @@ public abstract class ItJdbcErrorsAbstractSelfTest
extends AbstractJdbcSelfTest
* @param expState Expected SQLSTATE code.
* @param expMsg Expected message.
*/
- protected void checkErrorState(final RunnableX clo, String expState,
String expMsg) {
- SQLException ex = assertThrows(SQLException.class, clo::run, expMsg);
- assertThat(ex.getMessage(), containsString(expMsg));
+ protected void checkErrorState(RunnableX clo, String expState, String
expMsg) {
+ SQLException ex = JdbcTestUtils.assertThrowsSqlException(expMsg,
clo::run);
- assertEquals(expState, ex.getSQLState(), ex.getMessage());
+ assertEquals(expState, ex.getSQLState());
}
/**
@@ -603,7 +600,7 @@ public abstract class ItJdbcErrorsAbstractSelfTest extends
AbstractJdbcSelfTest
* @param expState Error code.
* @param expMsg Error message.
*/
- private void checkSqlErrorMessage(final String sql, String expState,
String expMsg) {
+ private void checkSqlErrorMessage(String sql, String expState, String
expMsg) {
checkErrorState(() -> {
stmt.executeUpdate("DROP TABLE IF EXISTS wrong");
stmt.executeUpdate("DROP TABLE IF EXISTS test");
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcInsertStatementSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcInsertStatementSelfTest.java
index a027e4f321..035a52de00 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcInsertStatementSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcInsertStatementSelfTest.java
@@ -20,13 +20,12 @@ package org.apache.ignite.jdbc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.SQLException;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -196,7 +195,7 @@ public class ItJdbcInsertStatementSelfTest extends
ItJdbcAbstractStatementSelfTe
assertFalse(stmt.execute(sql));
- assertThrows(SQLException.class, () -> stmt.execute(SQL), "Failed to
INSERT some keys because they are already in cache.");
+ JdbcTestUtils.assertThrowsSqlException("PK unique constraint is
violated", () -> stmt.execute(SQL));
stmt.execute("select count(*) from PUBLIC.PERSON;");
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcResultSetSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcResultSetSelfTest.java
index ac3da2922a..e10ef32cf2 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcResultSetSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcResultSetSelfTest.java
@@ -21,7 +21,6 @@ import static
org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
@@ -42,6 +41,7 @@ import java.time.LocalDate;
import java.util.GregorianCalendar;
import java.util.UUID;
import org.apache.ignite.internal.tostring.S;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -151,19 +151,23 @@ public class ItJdbcResultSetSelfTest extends
AbstractJdbcSelfTest {
assertTrue(rs0.next());
assertFalse(rs0.getBoolean(1));
- assertThrows(SQLException.class, () -> {
- ResultSet badRs = stmt.executeQuery("select ''");
+ JdbcTestUtils.assertThrowsSqlException(
+ "Cannot convert to boolean: ",
+ () -> {
+ ResultSet badRs = stmt.executeQuery("select ''");
- assertTrue(badRs.next());
- assertTrue(badRs.getBoolean(1));
- }, "Cannot convert to boolean: ");
+ assertTrue(badRs.next());
+ assertTrue(badRs.getBoolean(1));
+ });
- assertThrows(SQLException.class, () -> {
- ResultSet badRs = stmt.executeQuery("select 'qwe'");
+ JdbcTestUtils.assertThrowsSqlException(
+ "Cannot convert to boolean: qwe",
+ () -> {
+ ResultSet badRs = stmt.executeQuery("select 'qwe'");
- assertTrue(badRs.next());
- assertTrue(badRs.getBoolean(1));
- }, "Cannot convert to boolean: qwe");
+ assertTrue(badRs.next());
+ assertTrue(badRs.getBoolean(1));
+ });
}
@Test
@@ -626,19 +630,19 @@ public class ItJdbcResultSetSelfTest extends
AbstractJdbcSelfTest {
@Test
public void testFindColumn() throws Exception {
- final ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
+ ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
assertNotNull(rs);
assertTrue(rs.next());
assertEquals(1, rs.findColumn("id"));
- assertThrows(SQLException.class, () -> rs.findColumn("wrong"), "Column
not found: wrong");
+ JdbcTestUtils.assertThrowsSqlException("Column not found: wrong", ()
-> rs.findColumn("wrong"));
}
@Test
public void testNotSupportedTypes() throws Exception {
- final ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
+ ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
assertTrue(rs.next());
@@ -689,7 +693,7 @@ public class ItJdbcResultSetSelfTest extends
AbstractJdbcSelfTest {
@Test
public void testUpdateNotSupported() throws Exception {
- final ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
+ ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
assertTrue(rs.next());
@@ -862,7 +866,7 @@ public class ItJdbcResultSetSelfTest extends
AbstractJdbcSelfTest {
@Test
public void testExceptionOnClosedResultSet() throws Exception {
- final ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
+ ResultSet rs = stmt.executeQuery(SQL_SINGLE_RES);
rs.close();
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementCancelSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementCancelSelfTest.java
index e8e5ad28fa..d2b8bc8bf8 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementCancelSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementCancelSelfTest.java
@@ -18,13 +18,12 @@
package org.apache.ignite.jdbc;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Statement;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -61,7 +60,7 @@ public class ItJdbcStatementCancelSelfTest extends
ItJdbcAbstractStatementSelfTe
stmt.cancel();
- assertThrows(SQLException.class, () -> stmt.getResultSet(), "The query
was cancelled while executing.");
+ JdbcTestUtils.assertThrowsSqlException("The query was cancelled while
executing.", stmt::getResultSet);
}
/**
@@ -80,7 +79,7 @@ public class ItJdbcStatementCancelSelfTest extends
ItJdbcAbstractStatementSelfTe
stmt.cancel();
- assertThrows(SQLException.class, () -> stmt.getResultSet(), "The query
was cancelled while executing.");
+ JdbcTestUtils.assertThrowsSqlException("The query was cancelled while
executing.", stmt::getResultSet);
}
/**
@@ -93,7 +92,7 @@ public class ItJdbcStatementCancelSelfTest extends
ItJdbcAbstractStatementSelfTe
public void testCancelClosedStmt() throws Exception {
stmt.close();
- assertThrows(SQLException.class, () -> stmt.cancel(), "Statement is
closed.");
+ JdbcTestUtils.assertThrowsSqlException("Statement is closed.",
stmt::cancel);
}
/**
@@ -112,7 +111,7 @@ public class ItJdbcStatementCancelSelfTest extends
ItJdbcAbstractStatementSelfTe
stmt.cancel();
- assertThrows(SQLException.class, rs::next, "The query was cancelled
while executing.");
+ JdbcTestUtils.assertThrowsSqlException("The query was cancelled while
executing.", rs::next);
}
/**
@@ -149,7 +148,7 @@ public class ItJdbcStatementCancelSelfTest extends
ItJdbcAbstractStatementSelfTe
stmt.cancel();
- assertThrows(SQLException.class, rs1::next, "The query was
cancelled while executing.");
+ JdbcTestUtils.assertThrowsSqlException("The query was cancelled
while executing.", rs1::next);
assertTrue(rs2.next(), "The other cursor mustn't be closed");
}
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementSelfTest.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementSelfTest.java
index 61dc1048ea..0cae0b498f 100644
---
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementSelfTest.java
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementSelfTest.java
@@ -32,6 +32,7 @@ import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.UUID;
+import org.apache.ignite.jdbc.util.JdbcTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -480,9 +481,9 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
public void testExecuteUpdateProducesResultSet() {
final String sqlText = "select * from TEST;";
- assertThrows(SQLException.class, () -> stmt.executeUpdate(sqlText),
- "Given statement type does not match that declared by JDBC
driver"
- );
+ JdbcTestUtils.assertThrowsSqlException(
+ "Given statement type does not match that declared by JDBC
driver",
+ () -> stmt.executeUpdate(sqlText));
}
@Test
@@ -499,7 +500,9 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
stmt.executeUpdate("DROP TABLE " + tableName);
- assertThrows(SQLException.class, () -> stmt.executeQuery("SELECT
COUNT(*) FROM " + tableName));
+ JdbcTestUtils.assertThrowsSqlException(
+ "Failed to validate query",
+ () -> stmt.executeQuery("SELECT COUNT(*) FROM " + tableName));
}
@Test
@@ -526,8 +529,10 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
public void testGetSetMaxFieldSizeUnsupported() throws Exception {
assertEquals(0, stmt.getMaxFieldSize());
- assertThrows(SQLFeatureNotSupportedException.class, () ->
stmt.setMaxFieldSize(100),
- "Field size limitation is not supported");
+ JdbcTestUtils.assertThrowsSqlException(
+ SQLFeatureNotSupportedException.class,
+ "Field size limitation is not supported",
+ () -> stmt.setMaxFieldSize(100));
assertEquals(0, stmt.getMaxFieldSize());
@@ -544,8 +549,7 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
public void testGetSetMaxRows() throws Exception {
assertEquals(0, stmt.getMaxRows());
- assertThrows(SQLException.class, () -> stmt.setMaxRows(-1),
- "Invalid max rows value");
+ JdbcTestUtils.assertThrowsSqlException("Invalid max rows value", () ->
stmt.setMaxRows(-1));
assertEquals(0, stmt.getMaxRows());
@@ -575,8 +579,7 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
public void testGetSetQueryTimeout() throws Exception {
assertEquals(0, stmt.getQueryTimeout());
- assertThrows(SQLException.class, () -> stmt.setQueryTimeout(-1),
- "Invalid timeout value");
+ JdbcTestUtils.assertThrowsSqlException("Invalid timeout value", () ->
stmt.setQueryTimeout(-1));
assertEquals(0, stmt.getQueryTimeout());
@@ -599,8 +602,7 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
public void testMaxFieldSize() throws Exception {
assertTrue(stmt.getMaxFieldSize() >= 0);
- assertThrows(SQLException.class, () -> stmt.setMaxFieldSize(-1),
- "Invalid field limit");
+ JdbcTestUtils.assertThrowsSqlException("Invalid field limit", () ->
stmt.setMaxFieldSize(-1));
checkNotSupported(() -> stmt.setMaxFieldSize(100));
}
@@ -628,9 +630,9 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
stmt.close();
- checkStatementClosed(() -> stmt.getWarnings());
+ checkStatementClosed(stmt::getWarnings);
- checkStatementClosed(() -> stmt.clearWarnings());
+ checkStatementClosed(stmt::clearWarnings);
}
@Test
@@ -708,10 +710,10 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
public void testFetchDirection() throws Exception {
assertEquals(ResultSet.FETCH_FORWARD, stmt.getFetchDirection());
- assertThrows(
+ JdbcTestUtils.assertThrowsSqlException(
SQLFeatureNotSupportedException.class,
- () -> stmt.setFetchDirection(ResultSet.FETCH_REVERSE),
- "Only forward direction is supported."
+ "Only forward direction is supported.",
+ () -> stmt.setFetchDirection(ResultSet.FETCH_REVERSE)
);
stmt.close();
@@ -722,17 +724,15 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
}
@Test
- public void testAutogenerated() throws Exception {
- assertThrows(
- SQLException.class,
- () -> stmt.executeUpdate("select 1", -1),
- "Invalid autoGeneratedKeys value"
+ public void testAutogenerated() {
+ JdbcTestUtils.assertThrowsSqlException(
+ "Invalid autoGeneratedKeys value",
+ () -> stmt.executeUpdate("select 1", -1)
);
- assertThrows(
- SQLException.class,
- () -> stmt.execute("select 1", -1),
- "Invalid autoGeneratedKeys value"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Invalid autoGeneratedKeys value",
+ () -> stmt.execute("select 1", -1)
);
// assertFalse(conn.getMetaData().supportsGetGeneratedKeys());
@@ -757,10 +757,9 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
// Put query to cache.
stmt.executeQuery("select 1;");
- assertThrows(
- SQLException.class,
- () -> stmt.executeUpdate("select 1;"),
- "Given statement type does not match that declared by JDBC
driver"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Given statement type does not match that declared by JDBC
driver",
+ () -> stmt.executeUpdate("select 1;")
);
assertNull(stmt.getResultSet(), "Not results expected. Last statement
is executed with exception");
@@ -768,10 +767,9 @@ public class ItJdbcStatementSelfTest extends
ItJdbcAbstractStatementSelfTest {
@Test
public void testStatementTypeMismatchUpdate() throws Exception {
- assertThrows(
- SQLException.class,
- () -> stmt.executeQuery("update TEST set NAME='28' where
ID=1"),
- "Given statement type does not match that declared by JDBC
driver"
+ JdbcTestUtils.assertThrowsSqlException(
+ "Given statement type does not match that declared by JDBC
driver",
+ () -> stmt.executeQuery("update TEST set NAME='28' where ID=1")
);
ResultSet rs = stmt.executeQuery("select NAME from TEST where ID=1");
diff --git
a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/util/JdbcTestUtils.java
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/util/JdbcTestUtils.java
new file mode 100644
index 0000000000..94ba7779f8
--- /dev/null
+++
b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/util/JdbcTestUtils.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.jdbc.util;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.StringContains.containsString;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.sql.SQLException;
+import org.junit.jupiter.api.function.Executable;
+
+/**
+ * Test utils for JDBC.
+ */
+public class JdbcTestUtils {
+ /**
+ * <em>Assert</em> that execution of the supplied {@code executable} throws
+ * an {@code T} and return the exception.
+ *
+ * @param expectedType Expected exception type.
+ * @param executable Supplier to execute and check thrown exception.
+ * @return Thrown the {@link SQLException}.
+ */
+ public static <T extends SQLException> T assertThrowsSqlException(Class<T>
expectedType, Executable executable) {
+ return assertThrows(expectedType, executable);
+
+ }
+
+ /**
+ * <em>Assert</em> that execution of the supplied {@code executable} throws
+ * an {@link SQLException} with expected message.
+ *
+ * @param expectedMessage Expected error message of {@link SQLException}.
+ * @param executable Supplier to execute and check thrown exception.
+ * @return Thrown the {@link SQLException}.
+ */
+ public static SQLException assertThrowsSqlException(String
expectedMessage, Executable executable) {
+ return assertThrowsSqlException(SQLException.class, expectedMessage,
executable);
+ }
+
+ /**
+ * <em>Assert</em> that execution of the supplied {@code executable} throws
+ * an {@code T} with expected error message.
+ *
+ * @param expectedType Expected exception type.
+ * @param expectedMessage Expected error message of {@link SQLException}.
+ * @param executable Supplier to execute and check thrown exception.
+ * @return Thrown the {@link SQLException}.
+ */
+ public static <T extends SQLException> T assertThrowsSqlException(
+ Class<T> expectedType,
+ String expectedMessage,
+ Executable executable) {
+ T ex = assertThrowsSqlException(expectedType, executable);
+
+ assertThat("Error message", ex.getMessage(),
containsString(expectedMessage));
+
+ return ex;
+ }
+}
diff --git
a/modules/marshaller-common/src/test/java/org/apache/ignite/internal/marshaller/FieldAccessorTest.java
b/modules/marshaller-common/src/test/java/org/apache/ignite/internal/marshaller/FieldAccessorTest.java
index 759a8ee863..3d2859e2e6 100644
---
a/modules/marshaller-common/src/test/java/org/apache/ignite/internal/marshaller/FieldAccessorTest.java
+++
b/modules/marshaller-common/src/test/java/org/apache/ignite/internal/marshaller/FieldAccessorTest.java
@@ -34,8 +34,8 @@ import static
org.apache.ignite.internal.marshaller.BinaryMode.STRING;
import static org.apache.ignite.internal.marshaller.BinaryMode.TIME;
import static org.apache.ignite.internal.marshaller.BinaryMode.TIMESTAMP;
import static org.apache.ignite.internal.marshaller.BinaryMode.UUID;
+import static
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -215,11 +215,11 @@ public class FieldAccessorTest extends
BaseIgniteAbstractTest {
assertEquals("Some string", accessor.value("Some string"));
- final Pair<MarshallerWriter, MarshallerReader> mocks = createMocks();
+ Pair<MarshallerWriter, MarshallerReader> mocks = createMocks();
- assertThrows(
- MarshallerException.class,
+ assertThrowsWithCause(
() -> accessor.write(mocks.getFirst(), "Other string"),
+ MarshallerException.class,
"Failed to write field [id=42]"
);
}
diff --git
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java
index f4a5813477..6fa1610a4c 100644
---
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java
+++
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java
@@ -18,12 +18,8 @@
package org.apache.ignite.internal.sql.api;
import static
org.apache.ignite.internal.sql.api.ItSqlAsynchronousApiTest.assertThrowsPublicException;
-import static
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
-import static org.apache.ignite.lang.ErrorGroups.Sql.CURSOR_CLOSED_ERR;
-import static org.apache.ignite.lang.ErrorGroups.Sql.QUERY_NO_RESULT_SET_ERR;
-import static org.apache.ignite.lang.ErrorGroups.Sql.RUNTIME_ERR;
-import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_PARSE_ERR;
-import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR;
+import static
org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -60,6 +56,7 @@ import org.apache.ignite.sql.SqlException;
import org.apache.ignite.sql.SqlRow;
import org.apache.ignite.table.Table;
import org.apache.ignite.tx.Transaction;
+import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
@@ -152,7 +149,7 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
checkError(
SqlException.class,
- STMT_VALIDATION_ERR,
+ Sql.STMT_VALIDATION_ERR,
"Can`t delete column(s). Column VAL1 is used by indexes
[TEST_IDX3].",
ses,
"ALTER TABLE TEST DROP COLUMN val1"
@@ -160,7 +157,7 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
SqlException ex = checkError(
SqlException.class,
- STMT_VALIDATION_ERR,
+ Sql.STMT_VALIDATION_ERR,
"Can`t delete column(s).",
ses,
"ALTER TABLE TEST DROP COLUMN (val0, val1)"
@@ -175,7 +172,7 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
checkError(
SqlException.class,
- STMT_VALIDATION_ERR,
+ Sql.STMT_VALIDATION_ERR,
"Can`t delete column, belongs to primary key: [name=ID]",
ses,
"ALTER TABLE TEST DROP COLUMN id"
@@ -281,31 +278,31 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
}
// Parse error.
- checkError(SqlException.class, STMT_PARSE_ERR, "Failed to parse
query", ses, "SELECT ID FROM");
+ checkError(SqlException.class, Sql.STMT_PARSE_ERR, "Failed to parse
query", ses, "SELECT ID FROM");
// Validation errors.
- checkError(SqlException.class, STMT_VALIDATION_ERR, "Column 'VAL0'
does not allow NULLs", ses,
+ checkError(SqlException.class, Sql.STMT_VALIDATION_ERR, "Column 'VAL0'
does not allow NULLs", ses,
"INSERT INTO TEST VALUES (2, NULL)");
- checkError(SqlException.class, STMT_VALIDATION_ERR, "Object
'NOT_EXISTING_TABLE' not found", ses,
+ checkError(SqlException.class, Sql.STMT_VALIDATION_ERR, "Object
'NOT_EXISTING_TABLE' not found", ses,
"SELECT * FROM NOT_EXISTING_TABLE");
- checkError(SqlException.class, STMT_VALIDATION_ERR, "Column
'NOT_EXISTING_COLUMN' not found", ses,
+ checkError(SqlException.class, Sql.STMT_VALIDATION_ERR, "Column
'NOT_EXISTING_COLUMN' not found", ses,
"SELECT NOT_EXISTING_COLUMN FROM TEST");
- checkError(SqlException.class, STMT_VALIDATION_ERR, "Multiple
statements are not allowed", ses, "SELECT 1; SELECT 2");
+ checkError(SqlException.class, Sql.STMT_VALIDATION_ERR, "Multiple
statements are not allowed", ses, "SELECT 1; SELECT 2");
- checkError(SqlException.class, STMT_VALIDATION_ERR, "Table without
PRIMARY KEY is not supported", ses,
+ checkError(SqlException.class, Sql.STMT_VALIDATION_ERR, "Table without
PRIMARY KEY is not supported", ses,
"CREATE TABLE TEST2 (VAL INT)");
// Execute error.
- checkError(SqlException.class, RUNTIME_ERR, "/ by zero", ses, "SELECT
1 / ?", 0);
- checkError(SqlException.class, RUNTIME_ERR, "negative substring length
not allowed", ses, "SELECT SUBSTRING('foo', 1, -3)");
+ checkError(SqlException.class, Sql.RUNTIME_ERR, "/ by zero", ses,
"SELECT 1 / ?", 0);
+ checkError(SqlException.class, Sql.RUNTIME_ERR, "negative substring
length not allowed", ses, "SELECT SUBSTRING('foo', 1, -3)");
// No result set error.
{
ResultSet rs = ses.execute(null, "CREATE TABLE TEST3 (ID INT
PRIMARY KEY)");
- assertThrowsPublicException(rs::next,
NoRowSetExpectedException.class, QUERY_NO_RESULT_SET_ERR, "Query has no result
set");
+ assertThrowsPublicException(rs::next,
NoRowSetExpectedException.class, Sql.QUERY_NO_RESULT_SET_ERR, "Query has no
result set");
}
// Cursor closed error.
@@ -314,7 +311,7 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
Thread.sleep(300); // ResultSetImpl fetches next page in
background, wait to it to complete to avoid flakiness.
rs.close();
assertThrowsPublicException(() ->
rs.forEachRemaining(Object::hashCode),
- CursorClosedException.class, CURSOR_CLOSED_ERR, null);
+ CursorClosedException.class, Sql.CURSOR_CLOSED_ERR, null);
}
}
@@ -329,9 +326,10 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
{
Transaction tx = igniteTx().begin();
try {
- assertThrowsWithCause(() -> ses.execute(tx, "CREATE TABLE
TEST2(ID INT PRIMARY KEY, VAL0 INT)"),
- SqlException.class,
- "DDL doesn't support transactions."
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "DDL doesn't support transactions.",
+ () -> ses.execute(tx, "CREATE TABLE TEST2(ID INT
PRIMARY KEY, VAL0 INT)")
);
} finally {
tx.rollback();
@@ -342,9 +340,10 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
ResultSet<SqlRow> res = ses.execute(tx, "INSERT INTO TEST VALUES
(?, ?)", -1, -1);
assertEquals(1, res.affectedRows());
- assertThrowsWithCause(() -> ses.execute(tx, "CREATE TABLE TEST2(ID
INT PRIMARY KEY, VAL0 INT)"),
- SqlException.class,
- "DDL doesn't support transactions."
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "DDL doesn't support transactions.",
+ () -> ses.execute(tx, "CREATE TABLE TEST2(ID INT PRIMARY
KEY, VAL0 INT)")
);
tx.commit();
@@ -376,17 +375,19 @@ public class ItSqlSynchronousApiTest extends
ClusterPerClassIntegrationTest {
IntStream.range(0, ROW_COUNT).forEach(i -> assertEquals(i,
res.get(i).get(0)));
// Check invalid query type
- assertThrowsWithCause(
- () -> ses.executeBatch(null, "SELECT * FROM TEST", args),
- SqlException.class,
- "Invalid SQL statement type in the batch"
+ SqlException ex = assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Invalid SQL statement type in the batch",
+ () -> ses.executeBatch(null, "SELECT * FROM TEST", args)
);
+ MatcherAssert.assertThat(ex, instanceOf(SqlBatchException.class));
- assertThrowsWithCause(
- () -> ses.executeBatch(null, "CREATE TABLE TEST1(ID INT
PRIMARY KEY, VAL0 INT)", args),
- SqlException.class,
- "Invalid SQL statement type in the batch"
+ ex = assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Invalid SQL statement type in the batch",
+ () -> ses.executeBatch(null, "CREATE TABLE TEST1(ID INT
PRIMARY KEY, VAL0 INT)", args)
);
+ MatcherAssert.assertThat(ex, instanceOf(SqlBatchException.class));
}
@Test
diff --git
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
index 6f81d7e757..6eff82fa2c 100644
---
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
+++
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java
@@ -17,12 +17,11 @@
package org.apache.ignite.internal.sql.engine;
+import static
org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
import org.apache.ignite.Ignite;
@@ -32,9 +31,10 @@ import
org.apache.ignite.internal.schema.configuration.ExtendedTableView;
import org.apache.ignite.internal.schema.configuration.TablesConfiguration;
import org.apache.ignite.internal.table.TableImpl;
import org.apache.ignite.internal.testframework.IgniteTestUtils;
-import org.apache.ignite.lang.IgniteException;
-import org.apache.ignite.sql.SqlException;
+import org.apache.ignite.lang.ErrorGroups.Sql;
+import org.apache.ignite.lang.ErrorGroups.Table;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
@@ -58,54 +58,54 @@ public class ItCreateTableDdlTest extends
ClusterPerClassIntegrationTest {
@Test
public void pkWithNullableColumns() {
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT NULL, ID1 INT NOT NULL, VAL
INT, PRIMARY KEY (ID1, ID0))"),
- "Primary key cannot contain nullable column [col=ID0]"
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Primary key cannot contain nullable column [col=ID0]",
+ () -> sql("CREATE TABLE T0(ID0 INT NULL, ID1 INT NOT NULL, VAL
INT, PRIMARY KEY (ID1, ID0))")
);
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID INT NULL PRIMARY KEY, VAL INT)"),
- "Primary key cannot contain nullable column [col=ID]"
+
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Primary key cannot contain nullable column [col=ID]",
+ () -> sql("CREATE TABLE T0(ID INT NULL PRIMARY KEY, VAL INT)")
);
}
@Test
public void pkWithInvalidColumns() {
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY
KEY (ID2, ID0))"),
- "Primary key cannot contain nullable column [col=ID0]"
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Primary key constraint contains undefined columns:
[cols=[ID2]]",
+ () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY
KEY (ID2, ID0))")
);
}
@Test
public void emptyPk() {
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY
KEY ())"),
- "Table without primary key is not supported."
+ assertThrowsSqlException(
+ Sql.STMT_PARSE_ERR,
+ "Failed to parse query: Encountered \")\"",
+ () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY
KEY ())")
);
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT)"),
- "Table without primary key is not supported."
+
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Table without PRIMARY KEY is not supported",
+ () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT)")
);
}
@Test
public void tableWithInvalidColumns() {
- assertThrows(
- IgniteException.class,
+ assertThrowsSqlException(
+ Sql.STMT_PARSE_ERR,
() -> sql("CREATE TABLE T0()")
);
- assertThat(
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT PRIMARY KEY, ID1
INT, ID0 INT)")
- ).getMessage(),
- containsString("Can't create table with duplicate columns:
ID0, ID1, ID0")
+ assertThrowsSqlException(
+ Table.TABLE_DEFINITION_ERR,
+ "Can't create table with duplicate columns: ID0, ID1, ID0",
+ () -> sql("CREATE TABLE T0(ID0 INT PRIMARY KEY, ID1 INT, ID0
INT)")
);
}
@@ -121,36 +121,29 @@ public class ItCreateTableDdlTest extends
ClusterPerClassIntegrationTest {
@Test
public void undefinedColumnsInPrimaryKey() {
- assertThat(
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID INT, VAL INT, PRIMARY
KEY (ID1, ID0, ID2))")
- ).getMessage(),
- containsString("Primary key constraint contains undefined
columns: [cols=[ID0, ID2, ID1]]")
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Primary key constraint contains undefined columns:
[cols=[ID0, ID2, ID1]]",
+ () -> sql("CREATE TABLE T0(ID INT, VAL INT, PRIMARY KEY (ID1,
ID0, ID2))")
);
}
/**
- * Check invalid colocation columns configuration:
- * - not PK columns;
- * - duplicates colocation columns.
+ * Check invalid colocation columns configuration: - not PK columns; -
duplicates colocation columns.
*/
@Test
+ @Disabled("IGNITE-20149")
public void invalidColocationColumns() {
- assertThat(
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT,
PRIMARY KEY (ID1, ID0)) COLOCATE (ID0, VAL)")
- ).getMessage(),
- containsString("Colocation columns must be subset of primary
key")
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Colocation columns must be subset of primary key",
+ () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY
KEY (ID1, ID0)) COLOCATE (ID0, VAL)")
);
- assertThat(
- assertThrows(
- IgniteException.class,
- () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT,
PRIMARY KEY (ID1, ID0)) COLOCATE (ID1, ID0, ID1)")
- ).getMessage(),
- containsString("Colocation columns contains duplicates:
[duplicates=[ID1]]]")
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Colocation columns contains duplicates: [duplicates=[ID1]]]",
+ () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY
KEY (ID1, ID0)) COLOCATE (ID1, ID0, ID1)")
);
}
@@ -253,9 +246,10 @@ public class ItCreateTableDdlTest extends
ClusterPerClassIntegrationTest {
@Test
public void doNotAllowFunctionsInNonPkColumns() {
- SqlException t = assertThrows(SqlException.class,
- () -> sql("create table t (id varchar primary key, val varchar
default gen_random_uuid)"));
-
- assertThat(t.getMessage(), containsString("Functional defaults are not
supported for non-primary key columns"));
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Functional defaults are not supported for non-primary key
columns",
+ () -> sql("create table t (id varchar primary key, val varchar
default gen_random_uuid)")
+ );
}
}
diff --git
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDmlTest.java
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDmlTest.java
index 7bac2876ed..5327aa487b 100644
---
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDmlTest.java
+++
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDmlTest.java
@@ -18,8 +18,6 @@
package org.apache.ignite.internal.sql.engine;
import static
org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
-import static org.apache.ignite.lang.ErrorGroups.Sql.CONSTRAINT_VIOLATION_ERR;
-import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -35,6 +33,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.ignite.internal.sql.engine.exec.rel.AbstractNode;
import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.lang.ErrorGroups.Sql;
import org.apache.ignite.lang.IgniteException;
import org.apache.ignite.sql.SqlException;
import org.apache.ignite.tx.Transaction;
@@ -130,7 +129,7 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
.check();
var ex = assertThrowsSqlException(
- CONSTRAINT_VIOLATION_ERR,
+ Sql.CONSTRAINT_VIOLATION_ERR,
() -> sql("INSERT INTO test VALUES (0, 0), (1, 1), (2, 2)")
);
@@ -180,7 +179,7 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
.collect(Collectors.joining("), (", "(", ")"));
SqlException ex = assertThrowsSqlException(
- CONSTRAINT_VIOLATION_ERR,
+ Sql.CONSTRAINT_VIOLATION_ERR,
() -> sql(insertStatement)
);
@@ -359,12 +358,16 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
assertQuery("SELECT * FROM test2").returns(1, 0, 0, "0").check();
// Target table alias duplicate source table name.
- assertThrows(IgniteException.class, () -> sql("MERGE INTO test2 test1
USING test1 ON c = e "
- + "WHEN MATCHED THEN UPDATE SET d = b + 1"), "Duplicate
relation name");
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Duplicate relation name",
+ () -> sql("MERGE INTO test2 test1 USING test1 ON c = e WHEN
MATCHED THEN UPDATE SET d = b + 1"));
// Source table alias duplicate target table name.
- assertThrows(IgniteException.class, () -> sql("MERGE INTO test2 USING
test1 test2 ON c = e "
- + "WHEN MATCHED THEN UPDATE SET d = b + 1"), "Duplicate
relation name");
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Duplicate relation name",
+ () -> sql("MERGE INTO test2 USING test1 test2 ON c = e WHEN
MATCHED THEN UPDATE SET d = b + 1"));
// Without aliases, reference columns by table name.
sql("MERGE INTO test2 USING test1 ON test1.a = test2.a "
@@ -373,12 +376,16 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
assertQuery("SELECT * FROM test2").returns(1, 1, 0, "0").check();
// Ambiguous column name in condition.
- assertThrows(IgniteException.class, () -> sql("MERGE INTO test2 USING
test1 ON a = test1.a "
- + "WHEN MATCHED THEN UPDATE SET a = test1.a + 1"), "Column 'A'
is ambiguous");
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Column 'A' is ambiguous",
+ () -> sql("MERGE INTO test2 USING test1 ON a = test1.a WHEN
MATCHED THEN UPDATE SET a = test1.a + 1"));
// Ambiguous column name in update statement.
- assertThrows(IgniteException.class, () -> sql("MERGE INTO test2 USING
test1 ON c = e "
- + "WHEN MATCHED THEN UPDATE SET a = a + 1"), "Column 'A' is
ambiguous");
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Column 'A' is ambiguous",
+ () -> sql("MERGE INTO test2 USING test1 ON c = e WHEN MATCHED
THEN UPDATE SET a = a + 1"));
// With aliases, reference columns by table alias.
sql("MERGE INTO test2 test1 USING test1 test2 ON test1.d = test2.b "
@@ -400,7 +407,7 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
sql("CREATE TABLE test2 (k int PRIMARY KEY, a int, b int)");
- SqlException ex = assertThrowsSqlException(CONSTRAINT_VIOLATION_ERR,
() -> sql(
+ SqlException ex =
assertThrowsSqlException(Sql.CONSTRAINT_VIOLATION_ERR, () -> sql(
"MERGE INTO test2 USING test1 ON test1.a = test2.a "
+ "WHEN MATCHED THEN UPDATE SET b = test1.b +
1 "
+ "WHEN NOT MATCHED THEN INSERT (k, a, b)
VALUES (0, a, b)"));
@@ -565,7 +572,7 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
var expectedMessage = "Failed to validate query. From line 1, column
28 to line 1, column 45: Column 'KEY' does not allow NULLs";
- assertThrowsSqlException(STMT_VALIDATION_ERR, expectedMessage, () ->
sql("INSERT INTO tbl (key, val) VALUES (NULL,'AA')"));
+ assertThrowsSqlException(Sql.STMT_VALIDATION_ERR, expectedMessage, ()
-> sql("INSERT INTO tbl (key, val) VALUES (NULL,'AA')"));
}
private void checkQueryResult(String sql, List<Object> expectedVals) {
@@ -574,10 +581,10 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
private void checkWrongDefault(String sqlType, String sqlVal) {
try {
- assertThrows(
- SqlException.class,
- () -> sql("CREATE TABLE test (val " + sqlType + " DEFAULT
" + sqlVal + ")"),
- "Cannot convert literal"
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Unable convert literal",
+ () -> sql("CREATE TABLE test (id INT PRIMARY KEY, val " +
sqlType + " DEFAULT " + sqlVal + ")")
);
} finally {
sql("DROP TABLE IF EXISTS test");
@@ -671,7 +678,7 @@ public class ItDmlTest extends
ClusterPerClassIntegrationTest {
}
private static void checkDuplicatePk(IgniteException ex) {
- assertEquals(CONSTRAINT_VIOLATION_ERR, ex.code());
+ assertEquals(Sql.CONSTRAINT_VIOLATION_ERR, ex.code());
assertThat(ex.getMessage(), containsString("PK unique constraint is
violated"));
}
}
diff --git
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDynamicParameterTest.java
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDynamicParameterTest.java
index 357120bc94..a35303bb06 100644
---
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDynamicParameterTest.java
+++
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItDynamicParameterTest.java
@@ -18,11 +18,7 @@
package org.apache.ignite.internal.sql.engine;
import static
org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
-import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR;
import static org.apache.ignite.lang.IgniteStringFormatter.format;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -37,6 +33,7 @@ import org.apache.ignite.internal.sql.engine.util.Commons;
import org.apache.ignite.internal.sql.engine.util.MetadataMatcher;
import org.apache.ignite.internal.sql.engine.util.SqlTestUtils;
import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.lang.ErrorGroups.Sql;
import org.apache.ignite.sql.ColumnType;
import org.apache.ignite.sql.SqlException;
import org.junit.jupiter.api.AfterEach;
@@ -160,8 +157,8 @@ public class ItDynamicParameterTest extends
ClusterPerClassIntegrationTest {
*/
@Test
public void testWithDifferentParametersTypesMismatch() {
- assertThrowsSqlException(STMT_VALIDATION_ERR, () ->
assertQuery("SELECT COALESCE(12.2, ?)").withParams("b").check());
- assertThrowsSqlException(STMT_VALIDATION_ERR, () ->
assertQuery("SELECT COALESCE(?, ?)").withParams(12.2, "b").check());
+ assertThrowsSqlException(Sql.STMT_VALIDATION_ERR, () ->
assertQuery("SELECT COALESCE(12.2, ?)").withParams("b").check());
+ assertThrowsSqlException(Sql.STMT_VALIDATION_ERR, () ->
assertQuery("SELECT COALESCE(?, ?)").withParams(12.2, "b").check());
}
@Test
@@ -281,10 +278,9 @@ public class ItDynamicParameterTest extends
ClusterPerClassIntegrationTest {
}
private static void assertUnexpectedNumberOfParameters(String query,
Object... params) {
- SqlException err = assertThrows(SqlException.class, () -> {
- assertQuery(query).withParams(params).check();
- }, "query: " + query);
-
- assertThat("query: " + query, err.getMessage(),
containsString("Unexpected number of query parameters"));
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ "Unexpected number of query parameters",
+ () -> assertQuery(query).withParams(params).check());
}
}
diff --git
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFunctionsTest.java
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFunctionsTest.java
index 852aa09c30..2eb7f5c9fa 100644
---
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFunctionsTest.java
+++
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFunctionsTest.java
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.sql.engine;
import static org.apache.calcite.util.Static.RESOURCE;
+import static
org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
import static
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.apache.ignite.lang.IgniteStringFormatter.format;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -32,10 +33,8 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.Temporal;
-import org.apache.calcite.runtime.Resources.ExInst;
-import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.validate.SqlValidatorException;
-import org.apache.ignite.internal.sql.engine.util.IgniteResource;
+import org.apache.ignite.lang.ErrorGroups.Sql;
import org.apache.ignite.lang.IgniteException;
import org.junit.jupiter.api.Test;
@@ -131,8 +130,10 @@ public class ItFunctionsTest extends
ClusterPerClassIntegrationTest {
assertEquals(0, sql("SELECT * FROM table(system_range(null,
1))").size());
- IgniteException ex = assertThrows(IgniteException.class,
- () -> sql("SELECT * FROM table(system_range(1, 1, 0))"),
"Increment can't be 0");
+ IgniteException ex = assertThrowsSqlException(
+ Sql.RUNTIME_ERR,
+ "Increment can't be 0",
+ () -> sql("SELECT * FROM table(system_range(1, 1, 0))"));
assertTrue(
ex.getCause() instanceof IllegalArgumentException,
@@ -273,18 +274,25 @@ public class ItFunctionsTest extends
ClusterPerClassIntegrationTest {
assertQuery("SELECT NULL::CHAR::BOOLEAN").returns(NULL_RESULT).check();
assertQuery("SELECT
?::CHAR::BOOLEAN").withParams(NULL_RESULT).returns(NULL_RESULT).check();
- ExInst<SqlValidatorException> errDynParams =
IgniteResource.INSTANCE.operationRequiresExplicitCast(SqlKind.CAST.name());
- String errStrDynParams = errDynParams.ex().getMessage();
-
- ExInst<SqlValidatorException> errWithoutDynParams =
RESOURCE.incompatibleValueType(SqlKind.CAST.name());
- String errStrWithoutDynParams = errWithoutDynParams.ex().getMessage();
+ assertThrowsSqlException(Sql.STMT_VALIDATION_ERR,
deriveCannotCastMessage("INTEGER", "BOOLEAN"), () -> sql("SELECT 1::BOOLEAN"));
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ deriveCannotCastMessage("INTEGER", "BOOLEAN"),
+ () -> sql("SELECT ?::BOOLEAN", 1));
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ deriveCannotCastMessage("DECIMAL(2, 1)", "BOOLEAN"),
+ () -> sql("SELECT 1.0::BOOLEAN"));
+ assertThrowsSqlException(
+ Sql.STMT_VALIDATION_ERR,
+ deriveCannotCastMessage("DOUBLE", "BOOLEAN"),
+ () -> sql("SELECT ?::BOOLEAN", 1.0));
+ assertThrowsSqlException(Sql.RUNTIME_ERR, "Invalid character for
cast", () -> sql("SELECT '1'::BOOLEAN"));
+ assertThrowsSqlException(Sql.RUNTIME_ERR, "Invalid character for
cast", () -> sql("SELECT ?::BOOLEAN", "1"));
+ }
- assertThrows(IgniteException.class, () -> sql("SELECT 1::BOOLEAN"),
errStrWithoutDynParams);
- assertThrows(IgniteException.class, () -> sql("SELECT ?::BOOLEAN", 1),
errStrDynParams);
- assertThrows(IgniteException.class, () -> sql("SELECT 1.0::BOOLEAN"),
errStrWithoutDynParams);
- assertThrows(IgniteException.class, () -> sql("SELECT ?::BOOLEAN",
1.0), errStrDynParams);
- assertThrows(IgniteException.class, () -> sql("SELECT '1'::BOOLEAN"),
errStrWithoutDynParams);
- assertThrows(IgniteException.class, () -> sql("SELECT ?::BOOLEAN",
"1"), errStrDynParams);
+ private String deriveCannotCastMessage(String fromType, String toType) {
+ return RESOURCE.cannotCastValue(fromType, toType).ex().getMessage();
}
@Test
diff --git
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/Statement.java
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/Statement.java
index c2e5a0e9bd..4fc3eb4f9e 100644
---
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/Statement.java
+++
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/Statement.java
@@ -51,7 +51,6 @@ import org.junit.jupiter.api.Assertions;
* </pre>
*/
final class Statement extends Command {
-
private final List<String> queries;
private final ExpectedStatementStatus expected;
@@ -113,11 +112,14 @@ final class Statement extends Command {
Assertions.fail("Not expected result at: " + posDesc + ".
Statement: " + qry, e);
}
} else {
- Throwable err = Assertions.assertThrows(Throwable.class, () ->
ctx.executeQuery(qry),
- "Not expected result at: " + posDesc + ". Statement: "
+ qry + ". Error: " + expected.errorMessage);
-
- assertThat("Not expected result at: " + posDesc + ".
Statement: " + qry
- + ". Expected: " + expected.errorMessage,
err.getMessage(), expected.errorMessage);
+ Throwable err = Assertions.assertThrows(
+ Throwable.class,
+ () -> ctx.executeQuery(qry),
+ "Not expected result at: " + posDesc + ". Statement: "
+ qry + ". No error occurred");
+
+ assertThat(
+ "Not expected result at: " + posDesc + ". Statement: "
+ qry + ". Expected: " + expected.errorMessage,
+ err.getMessage(), expected.errorMessage);
}
}
}
diff --git
a/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/KvMarshallerTest.java
b/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/KvMarshallerTest.java
index 7a8a8ba1d5..de0c685cdb 100644
---
a/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/KvMarshallerTest.java
+++
b/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/KvMarshallerTest.java
@@ -292,19 +292,18 @@ public class KvMarshallerTest {
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithoutKeyField(MarshallerFactory factory) {
- Column[] keyCols = new Column[]{
+ Column[] keyCols = {
new Column("id".toUpperCase(), INT64, false),
new Column("id2".toUpperCase(), INT64, false),
};
- Column[] valCols = new Column[]{
+ Column[] valCols = {
new Column("primitiveDoubleCol", DOUBLE, false)
};
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
- assertThrows(IllegalArgumentException.class, () ->
factory.create(schema, TestKeyObject.class, TestObjectWithAllTypes.class),
- "No field found for column id2");
+ assertThrows(IllegalArgumentException.class, () ->
factory.create(schema, TestKeyObject.class, TestObjectWithAllTypes.class));
}
@ParameterizedTest
diff --git
a/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/RecordMarshallerValidationsTest.java
b/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/RecordMarshallerValidationsTest.java
index 8d6930dc00..e2e5be6d2c 100644
---
a/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/RecordMarshallerValidationsTest.java
+++
b/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/RecordMarshallerValidationsTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.schema.marshaller;
import static
org.apache.ignite.internal.schema.DefaultValueProvider.constantProvider;
import static org.apache.ignite.internal.schema.NativeTypes.INT32;
import static org.apache.ignite.internal.schema.NativeTypes.STRING;
+import static
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -147,7 +148,10 @@ public class RecordMarshallerValidationsTest {
assertTrue(fullRec.getClass().isInstance(restoredRec));
- assertThrows(IllegalArgumentException.class, () ->
factory.create(schema, TestK2V1.class), "No field found for column k1");
+ assertThrowsWithCause(
+ () -> factory.create(schema, TestK2V1.class),
+ IllegalArgumentException.class,
+ "No field found for column K1");
}
/**
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java
index 9cc9b9aa7a..5d894ed495 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java
@@ -876,7 +876,7 @@ public class DdlSqlToCommandConverter {
}
} catch (Throwable th) {
// catch throwable here because literal throws an AssertionError
when unable to cast value to a given class
- throw new SqlException(STMT_VALIDATION_ERR, "Unable co convert
literal", th);
+ throw new SqlException(STMT_VALIDATION_ERR, "Unable convert
literal", th);
}
}
diff --git
a/modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/SqlTestUtils.java
b/modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/SqlTestUtils.java
index 36cd0e9ba0..25d538c949 100644
---
a/modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/SqlTestUtils.java
+++
b/modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/SqlTestUtils.java
@@ -17,10 +17,10 @@
package org.apache.ignite.internal.sql.engine.util;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.StringContains.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -74,10 +74,7 @@ public class SqlTestUtils {
public static SqlException assertThrowsSqlException(int expectedCode,
String expectedMessage, Executable executable) {
SqlException ex = assertThrowsSqlException(expectedCode, executable);
- String msg = ex.getMessage();
-
- assertNotNull(msg, "Error message was null, but expected '" +
expectedMessage + "'.");
- assertTrue(msg.contains(expectedMessage), "Error message '" +
ex.getMessage() + "' doesn't contain '" + expectedMessage + "'.");
+ assertThat("Error message", ex.getMessage(),
containsString(expectedMessage));
return ex;
}
@@ -133,7 +130,6 @@ public class SqlTestUtils {
* Generate random value for given SQL type.
*
* @param type SQL type to generate value related to the type.
- *
* @return Generated value for given SQL type.
*/
public static Object generateValueByType(ColumnType type) {
@@ -145,7 +141,6 @@ public class SqlTestUtils {
*
* @param base Base value to generate value.
* @param type SQL type to generate value related to the type.
- *
* @return Generated value for given SQL type.
*/
public static Object generateValueByType(int base, ColumnType type) {
diff --git
a/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/util/MvPartitionStoragesTest.java
b/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/util/MvPartitionStoragesTest.java
index d5cf178ac7..799aa58fb4 100644
---
a/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/util/MvPartitionStoragesTest.java
+++
b/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/util/MvPartitionStoragesTest.java
@@ -19,13 +19,13 @@ package org.apache.ignite.internal.storage.util;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
+import static
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static
org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
import static
org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast;
import static
org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willTimeoutFast;
import static
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
@@ -44,7 +44,6 @@ import
org.apache.ignite.internal.storage.StorageRebalanceException;
import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.function.Executable;
/**
* Class for testing {@link MvPartitionStorages}.
@@ -91,7 +90,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startCreateMvStorageFuture, willCompleteSuccessfully());
- assertThrowsWithMessage(StorageException.class, () ->
createMvStorage(1), "Storage is in process of being created");
+ assertThrowsWithCause(() -> createMvStorage(1),
StorageException.class, "Storage is in process of being created");
finishCreateMvStorageFuture.complete(null);
@@ -104,7 +103,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(createMvStorage(0), willCompleteSuccessfully());
- assertThrowsWithMessage(StorageException.class, () ->
createMvStorage(0), "Storage already exists");
+ assertThrowsWithCause(() -> createMvStorage(0),
StorageException.class, "Storage already exists");
// What if there is an error during the operation?
@@ -136,7 +135,8 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
CompletableFuture<MvPartitionStorage> reCreateMvStorageFuture =
createMvStorage(0);
- assertThrowsWithMessage(StorageException.class, () ->
createMvStorage(0),
+ assertThrowsWithCause(() -> createMvStorage(0),
+ StorageException.class,
"Creation of the storage after its destruction is already
planned"
);
@@ -206,12 +206,12 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startDestroyMvStorageFuture, willCompleteSuccessfully());
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage does not exist");
- assertThrowsWithMessage(StorageException.class, () ->
clearMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage does not exist");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage does not exist");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0), "Storage does not exist");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
abortRebalanceMvStorage(0), "Storage does not exist");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage does not exist");
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage does not exist");
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage does not exist");
finishDestroyMvStorageFuture.complete(null);
@@ -226,7 +226,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
void testDestroyError() {
assertThrows(IllegalArgumentException.class, () ->
destroyMvStorage(getPartitionIdOutOfConfig()));
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage does not exist");
assertThat(createMvStorage(0), willCompleteSuccessfully());
@@ -239,7 +239,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertNull(getMvStorage(0));
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage does not exist");
}
@Test
@@ -261,14 +261,17 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startCleanupMvStorageFuture, willCompleteSuccessfully());
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage is in process of being cleaned up");
- assertThrowsWithMessage(StorageException.class, () ->
clearMvStorage(0), "Storage is in process of being cleaned up");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage is in process of being cleaned up");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage is in process of being cleaned up");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage is in process of being cleaned up");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
abortRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage is in process of being cleaned up");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage is in process of being cleaned up");
finishCleanupMvStorageFuture.complete(null);
@@ -284,7 +287,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
void testClearError() {
assertThrows(IllegalArgumentException.class, () ->
clearMvStorage(getPartitionIdOutOfConfig()));
- assertThrowsWithMessage(StorageException.class, () ->
clearMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage does not exist");
assertThat(createMvStorage(0), willCompleteSuccessfully());
@@ -315,13 +318,15 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startStartRebalanceMvStorage, willCompleteSuccessfully());
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of starting a rebalance");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of starting a rebalance");
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage in the process of starting a rebalance");
- assertThrowsWithMessage(StorageException.class, () ->
clearMvStorage(0), "Storage in the process of starting a rebalance");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage in the process of starting a rebalance");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage in the process of starting a rebalance");
finishStartRebalanceMvStorage.complete(null);
@@ -339,7 +344,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
void testStartRebalanceError() {
assertThrows(IllegalArgumentException.class, () ->
startRebalanceMvStorage(getPartitionIdOutOfConfig()));
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage does not exist");
assertThat(createMvStorage(0), willCompleteSuccessfully());
@@ -358,7 +363,10 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startRebalanceMvStorage(0), willCompleteSuccessfully());
- assertThrows(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0), "Storage in the process of rebalance");
+ assertThrowsWithCause(
+ () -> startRebalanceMvStorage(0),
+ StorageRebalanceException.class,
+ "Storage in the process of rebalance");
}
@Test
@@ -380,15 +388,18 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startAbortRebalanceFuture, willCompleteSuccessfully());
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of aborting a rebalance");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
abortRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of aborting a rebalance");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of aborting a rebalance");
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage in the process of aborting a rebalance");
- assertThrowsWithMessage(StorageException.class, () ->
clearMvStorage(0), "Storage in the process of aborting a rebalance");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage in the process of aborting a rebalance");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage in the process of aborting a rebalance");
finishAbortRebalanceFuture.complete(null);
@@ -430,7 +441,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
void testAbortRebalanceError() {
assertThrows(IllegalArgumentException.class, () ->
abortRebalanceMvStorage(getPartitionIdOutOfConfig()));
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
abortRebalanceMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage does not exist");
assertThat(createMvStorage(0), willCompleteSuccessfully());
@@ -463,15 +474,18 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startFinishRebalanceFuture, willCompleteSuccessfully());
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
startRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of finishing a rebalance");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
abortRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of finishing a rebalance");
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0),
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
+ StorageRebalanceException.class,
"Storage in the process of finishing a rebalance");
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage in the process of finishing a rebalance");
- assertThrowsWithMessage(StorageException.class, () ->
clearMvStorage(0), "Storage in the process of finishing a rebalance");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage in the process of finishing a rebalance");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage in the process of finishing a rebalance");
finishFinishRebalanceFuture.complete(null);
@@ -484,11 +498,11 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
void testFinishRebalanceError() {
assertThrows(IllegalArgumentException.class, () ->
finishRebalanceMvStorage(getPartitionIdOutOfConfig()));
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage does not exist");
assertThat(createMvStorage(0), willCompleteSuccessfully());
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
finishRebalanceMvStorage(0), "Storage rebalancing did not start");
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
StorageRebalanceException.class, "Storage rebalancing did not start");
assertThat(startRebalanceMvStorage(0), willCompleteSuccessfully());
@@ -548,12 +562,12 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
);
// What happens if we try to perform operations on storages?
- assertThrowsWithMessage(StorageException.class, () ->
createMvStorage(6), "Storage is in the process of closing");
- assertThrowsWithMessage(StorageException.class, () ->
destroyMvStorage(0), "Storage does not exist");
- assertThrows(StorageException.class, () -> clearMvStorage(0), "Storage
does not exist");
- assertThrows(StorageException.class, () -> startRebalanceMvStorage(0),
"Storage does not exist");
- assertThrows(StorageException.class, () -> abortRebalanceMvStorage(0),
"Storage does not exist");
- assertThrows(StorageException.class, () ->
finishRebalanceMvStorage(0), "Storage does not exist");
+ assertThrowsWithCause(() -> createMvStorage(6),
StorageException.class, "Storage is in the process of closing");
+ assertThrowsWithCause(() -> destroyMvStorage(0),
StorageException.class, "Storage does not exist");
+ assertThrowsWithCause(() -> clearMvStorage(0), StorageException.class,
"Storage does not exist");
+ assertThrowsWithCause(() -> startRebalanceMvStorage(0),
StorageException.class, "Storage does not exist");
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
StorageException.class, "Storage does not exist");
+ assertThrowsWithCause(() -> finishRebalanceMvStorage(0),
StorageException.class, "Storage does not exist");
}
@Test
@@ -661,7 +675,7 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
assertThat(startAbortRebalanceFuture, willTimeoutFast());
// You can't abort rebalancing a second time.
- assertThrowsWithMessage(StorageRebalanceException.class, () ->
abortRebalanceMvStorage(0), "Rebalance abort is already planned");
+ assertThrowsWithCause(() -> abortRebalanceMvStorage(0),
StorageRebalanceException.class, "Rebalance abort is already planned");
rebalanceFuture.complete(null);
@@ -707,14 +721,4 @@ public class MvPartitionStoragesTest extends
BaseIgniteAbstractTest {
private int getPartitionIdOutOfConfig() {
return PARTITIONS;
}
-
- private static <T extends Throwable> void assertThrowsWithMessage(
- Class<T> expectedType,
- Executable executable,
- String expectedErrorMessageSubString
- ) {
- T throwable = assertThrows(expectedType, executable);
-
- assertThat(throwable.getMessage(),
containsString(expectedErrorMessageSubString));
- }
}
diff --git
a/modules/table/src/test/java/org/apache/ignite/internal/table/type/NumericTypesSerializerTest.java
b/modules/table/src/test/java/org/apache/ignite/internal/table/type/NumericTypesSerializerTest.java
index 24a4c26ba2..e1eecd0de9 100644
---
a/modules/table/src/test/java/org/apache/ignite/internal/table/type/NumericTypesSerializerTest.java
+++
b/modules/table/src/test/java/org/apache/ignite/internal/table/type/NumericTypesSerializerTest.java
@@ -17,8 +17,8 @@
package org.apache.ignite.internal.table.type;
+import static
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -139,13 +139,21 @@ public class NumericTypesSerializerTest {
final Tuple badTup = createTuple().set("key", rnd.nextLong());
- assertThrows(TupleMarshallerException.class, () ->
marshaller.marshal(badTup.set("number1", BigInteger.valueOf(999991L))),
+ assertThrowsWithCause(
+ () -> marshaller.marshal(badTup.set("number1",
BigInteger.valueOf(999991L))),
+ TupleMarshallerException.class,
"Column's type mismatch");
- assertThrows(TupleMarshallerException.class, () ->
marshaller.marshal(badTup.set("number1", new BigInteger("111111"))),
+ assertThrowsWithCause(
+ () -> marshaller.marshal(badTup.set("number1", new
BigInteger("111111"))),
+ TupleMarshallerException.class,
"Column's type mismatch");
- assertThrows(TupleMarshallerException.class, () ->
marshaller.marshal(badTup.set("number1", BigInteger.valueOf(-999991L))),
+ assertThrowsWithCause(
+ () -> marshaller.marshal(badTup.set("number1",
BigInteger.valueOf(-999991L))),
+ TupleMarshallerException.class,
"Column's type mismatch");
- assertThrows(TupleMarshallerException.class, () ->
marshaller.marshal(badTup.set("number1", new BigInteger("-111111"))),
+ assertThrowsWithCause(
+ () -> marshaller.marshal(badTup.set("number1", new
BigInteger("-111111"))),
+ TupleMarshallerException.class,
"Column's type mismatch");
}
@@ -163,20 +171,24 @@ public class NumericTypesSerializerTest {
TupleMarshaller marshaller = new TupleMarshallerImpl(new
DummySchemaManagerImpl(schema));
- assertThrows(TupleMarshallerException.class,
+ assertThrowsWithCause(
() -> marshaller.marshal(badTup.set("decimalCol", new
BigDecimal("123456789.0123"))),
+ TupleMarshallerException.class,
"Failed to set decimal value for column"
);
- assertThrows(TupleMarshallerException.class,
+ assertThrowsWithCause(
() -> marshaller.marshal(badTup.set("decimalCol", new
BigDecimal("-1234567890123"))),
+ TupleMarshallerException.class,
"Failed to set decimal value for column"
);
- assertThrows(TupleMarshallerException.class,
+ assertThrowsWithCause(
() -> marshaller.marshal(badTup.set("decimalCol", new
BigDecimal("1234567"))),
+ TupleMarshallerException.class,
"Failed to set decimal value for column"
);
- assertThrows(TupleMarshallerException.class,
+ assertThrowsWithCause(
() -> marshaller.marshal(badTup.set("decimalCol", new
BigDecimal("12345678.9"))),
+ TupleMarshallerException.class,
"Failed to set decimal value for column"
);
}