You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2022/06/10 12:08:44 UTC

[ignite] 01/02: Add test.

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-17154
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit c67b162c6aad5a8b3c41f9f937caa9986e9d6f24
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Fri Jun 10 15:07:05 2022 +0300

    Add test.
---
 .../jdbc/thin/JdbcThinStatementSelfTest.java       | 43 ++++++++++++++++++++++
 .../internal/processors/odbc/SqlStateCode.java     |  3 ++
 .../apache/ignite/testframework/GridTestUtils.java | 10 ++---
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java
index cbc600887e1..7912dddd5b8 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java
@@ -26,11 +26,15 @@ import java.sql.SQLFeatureNotSupportedException;
 import java.sql.Statement;
 import java.util.concurrent.Callable;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.odbc.SqlStateCode;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.GridTestUtils.RunnableX;
 import org.junit.Ignore;
@@ -1096,6 +1100,45 @@ public class JdbcThinStatementSelfTest extends JdbcThinAbstractSelfTest {
             rs.getInt(1));
     }
 
+    /**
+     *
+     */
+    @org.junit.Test
+    public void testExceptionOnDeserializeResponse() throws SQLException {
+        try (Connection c = connect(grid(0), null)) {
+            execute(c, "CREATE TABLE TEST_DESERIALIZE(id int primary key, name varchar, BINFIELD OTHER) WITH " +
+                "\"cache_name=TEST_DESERIALIZE,VALUE_TYPE=TEST_TYPE\"");
+
+            IgniteCache<Object, Object> cc = grid(0).cache("TEST_DESERIALIZE");
+
+            BinaryObjectBuilder bobFld = grid(0).binary().builder("TestType");
+            bobFld.setField("fld0", 0);
+
+            BinaryObjectBuilder bob = grid(0).binary().builder("TEST_TYPE");
+            bob.setField("NAME", "name0");
+            bob.setField("BINFIELD", bobFld.build());
+
+            cc.put(0, bob.build());
+
+            try (Statement stmt = c.createStatement()) {
+                SQLException ex = GridTestUtils.assertThrows(
+                    log,
+                    () -> stmt.executeQuery("SELECT * FROM TEST_DESERIALIZE"),
+                    SQLException.class,
+                    "Serialization error during sending an sql request"
+                );
+
+                assertEquals(SqlStateCode.DATA_EXCEPTION, ex.getSQLState());
+                assertTrue(X.hasCause(ex, "TestType", BinaryInvalidTypeException.class));
+
+                ResultSet rs = stmt.executeQuery("SELECT id FROM TEST_DESERIALIZE");
+
+                rs.next();
+                assertEquals(0, rs.getInt(1));
+            }
+        }
+    }
+
     /** */
     private void fillCache() {
         IgniteCache<String, Person> cachePerson = grid(0).cache(DEFAULT_CACHE_NAME);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlStateCode.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlStateCode.java
index 2257f956d09..50a13a396fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlStateCode.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlStateCode.java
@@ -42,6 +42,9 @@ public final class SqlStateCode {
     /** IO error during communication. */
     public static final String CONNECTION_FAILURE = "08006";
 
+    /** Generic data exception. */
+    public static final String DATA_EXCEPTION = "22000";
+
     /** Null value occurred where it wasn't expected to. */
     public static final String NULL_VALUE = "22004";
 
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 19c11f3796e..173085dcff5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -477,8 +477,8 @@ public final class GridTestUtils {
      *      and this message should be equal.
      * @return Thrown throwable.
      */
-    public static Throwable assertThrows(@Nullable IgniteLogger log, Callable<?> call,
-        Class<? extends Throwable> cls, @Nullable String msg) {
+    public static <T extends Throwable> T assertThrows(@Nullable IgniteLogger log, Callable<?> call,
+        Class<? extends T> cls, @Nullable String msg) {
         return assertThrows(log, call, cls, msg, null);
     }
 
@@ -493,8 +493,8 @@ public final class GridTestUtils {
      * @param notThrowsMsg Optional exception message if expected exception wasn't thrown.
      * @return Thrown throwable.
      */
-    public static Throwable assertThrows(@Nullable IgniteLogger log, Callable<?> call,
-        Class<? extends Throwable> cls, @Nullable String msg, @Nullable String notThrowsMsg) {
+    public static <T extends Throwable> T assertThrows(@Nullable IgniteLogger log, Callable<?> call,
+        Class<? extends T> cls, @Nullable String msg, @Nullable String notThrowsMsg) {
         assert call != null;
         assert cls != null;
 
@@ -525,7 +525,7 @@ public final class GridTestUtils {
             else
                 X.println("Caught expected exception: " + e.getMessage());
 
-            return e;
+            return (T)e;
         }
 
         String asrtMsg = notThrowsMsg == null ? "Exception has not been thrown." : notThrowsMsg;