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:43 UTC

[ignite] branch ignite-17154 created (now 168b2642e6c)

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

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


      at 168b2642e6c Fix.

This branch includes the following new commits:

     new c67b162c6aa Add test.
     new 168b2642e6c Fix.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[ignite] 02/02: Fix.

Posted by am...@apache.org.
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 168b2642e6cbc8bb6bd2ba0a4be404f7028c23f7
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Fri Jun 10 15:08:28 2022 +0300

    Fix.
---
 .../ignite/internal/jdbc/thin/JdbcThinConnection.java       | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
index 072858948f9..737cbebb80f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
@@ -132,6 +132,7 @@ import static java.sql.ResultSet.TYPE_FORWARD_ONLY;
 import static org.apache.ignite.internal.processors.odbc.SqlStateCode.CLIENT_CONNECTION_FAILED;
 import static org.apache.ignite.internal.processors.odbc.SqlStateCode.CONNECTION_CLOSED;
 import static org.apache.ignite.internal.processors.odbc.SqlStateCode.CONNECTION_FAILURE;
+import static org.apache.ignite.internal.processors.odbc.SqlStateCode.DATA_EXCEPTION;
 import static org.apache.ignite.internal.processors.odbc.SqlStateCode.INTERNAL_ERROR;
 import static org.apache.ignite.marshaller.MarshallerUtils.processSystemClasses;
 
@@ -1018,6 +1019,18 @@ public class JdbcThinConnection implements Connection {
 
                     throw e;
                 }
+                catch (BinaryObjectException e) {
+                    String err = "Serialization error during sending an sql request. " +
+                        "The error can be caused by the fact that the classes used on the node are missing " +
+                        "on the client. Try to use JDBC connection option 'keepBinary=true' " +
+                        "to to avoid deserialization. Also you can use system property " +
+                        "IGNITE_SENSITIVE_DATA_LOGGING=\"plain\" to readable print content of a BinaryObject";
+
+                    if (LOG.isLoggable(Level.FINE))
+                        LOG.log(Level.FINE, err, e);
+
+                    throw new SQLException(err, DATA_EXCEPTION, e);
+                }
                 catch (Exception e) {
                     if (LOG.isLoggable(Level.FINE))
                         LOG.log(Level.FINE, "Exception during sending an sql request.", e);


[ignite] 01/02: Add test.

Posted by am...@apache.org.
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;