korlov42 commented on a change in pull request #522:
URL: https://github.com/apache/ignite-3/pull/522#discussion_r784881109



##########
File path: 
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcErrorsAbstractSelfTest.java
##########
@@ -0,0 +1,631 @@
+/*
+ * 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.internal.runner.app.jdbc;
+
+import static 
org.apache.ignite.client.proto.query.SqlStateCode.CONNECTION_CLOSED;
+import static 
org.apache.ignite.client.proto.query.SqlStateCode.CONVERSION_FAILED;
+import static 
org.apache.ignite.client.proto.query.SqlStateCode.INVALID_CURSOR_STATE;
+import static org.apache.ignite.client.proto.query.SqlStateCode.NULL_VALUE;
+import static 
org.apache.ignite.client.proto.query.SqlStateCode.PARSING_EXCEPTION;
+import static 
org.apache.ignite.client.proto.query.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;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.List;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test SQLSTATE codes propagation with (any) Ignite JDBC driver.
+ */
+public abstract class ItJdbcErrorsAbstractSelfTest extends 
AbstractJdbcSelfTest {
+    /**
+     * Test that parsing-related error codes get propagated to Ignite SQL 
exceptions.
+     */
+    @Test
+    @Disabled("https://issues.apache.org/jira/browse/IGNITE-15247";)
+    public void testParsingErrors() {
+        checkErrorState("gibberish", PARSING_EXCEPTION,
+                "Failed to parse query. Syntax error in SQL statement 
\"GIBBERISH[*] \"");
+    }
+
+    /**
+     * Test that error codes from tables related DDL operations get propagated 
to Ignite SQL
+     * exceptions.
+     */
+    @Test
+    @Disabled("https://issues.apache.org/jira/browse/IGNITE-15247";)
+    public void testTableErrors() {
+        checkErrorState("DROP TABLE \"PUBLIC\".missing", PARSING_EXCEPTION, 
"Table doesn't exist: MISSING");
+    }
+
+    /**
+     * Test that error codes from indexes related DDL operations get 
propagated to Ignite SQL
+     * exceptions.
+     */
+    @Test
+    @Disabled("https://issues.apache.org/jira/browse/IGNITE-15247";)
+    public void testIndexErrors() {
+        checkErrorState("DROP INDEX \"PUBLIC\".missing", PARSING_EXCEPTION, 
"Index doesn't exist: MISSING");
+    }
+
+    /**
+     * Test that error codes from DML operations get propagated to Ignite SQL 
exceptions.
+     *
+     * @throws SQLException if failed.
+     */
+    @Test
+    @Disabled("https://issues.apache.org/jira/browse/IGNITE-15247";)
+    public void testDmlErrors() throws SQLException {
+        stmt.execute("CREATE TABLE INTEGER(KEY INT PRIMARY KEY, VAL INT)");
+
+        try {
+            checkErrorState("INSERT INTO INTEGER(key, val) values(1, null)", 
NULL_VALUE,
+                    "Value for INSERT, COPY, MERGE, or UPDATE must not be 
null");
+
+            checkErrorState("INSERT INTO INTEGER(key, val) values(1, 'zzz')", 
CONVERSION_FAILED,
+                    "Value conversion failed [column=_VAL, 
from=java.lang.String, to=java.lang.Integer]");
+        } finally {
+            stmt.execute("DROP TABLE INTEGER;");
+        }
+    }
+
+    /**
+     * Test error code for the case when user attempts to refer a future 
currently unsupported.
+     *
+     * @throws SQLException if failed.
+     */
+    @Test
+    @Disabled("https://issues.apache.org/jira/browse/IGNITE-15247";)
+    public void testUnsupportedSql() throws SQLException {
+        stmt.execute("CREATE TABLE INTEGER(KEY INT PRIMARY KEY, VAL INT)");
+
+        try {
+            checkErrorState("ALTER TABLE INTEGER MODIFY COLUMN KEY CHAR", 
UNSUPPORTED_OPERATION,
+                    "ALTER COLUMN is not supported");
+        } finally {
+            stmt.execute("DROP TABLE INTEGER;");
+        }
+    }
+
+    /**
+     * Test error code for the case when user attempts to use a closed 
connection.
+     *
+     * @throws SQLException if failed.
+     */
+    @Test
+    public void testConnectionClosed() throws SQLException {
+        Connection conn = getConnection();
+        DatabaseMetaData meta = conn.getMetaData();
+
+        conn.close();
+
+        checkErrorState(() -> conn.prepareStatement("SELECT 1"), 
CONNECTION_CLOSED, "Connection is closed.");
+        checkErrorState(() -> conn.createStatement(), CONNECTION_CLOSED, 
"Connection is closed.");
+        checkErrorState(() -> conn.getMetaData(), CONNECTION_CLOSED, 
"Connection is closed.");
+        checkErrorState(() -> meta.getIndexInfo(null, null, null, false, 
false), CONNECTION_CLOSED, "Connection is closed.");
+        checkErrorState(() -> meta.getColumns(null, null, null, null), 
CONNECTION_CLOSED, "Connection is closed.");
+        checkErrorState(() -> meta.getPrimaryKeys(null, null, null), 
CONNECTION_CLOSED, "Connection is closed.");
+        checkErrorState(() -> meta.getSchemas(null, null), CONNECTION_CLOSED, 
"Connection is closed.");
+        checkErrorState(() -> meta.getTables(null, null, null, null), 
CONNECTION_CLOSED, "Connection is closed.");
+    }
+
+    /**
+     * Test error code for the case when user attempts to use a closed result 
set.
+     */
+    @Test
+    public void testResultSetClosed() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 1")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.close();
+
+                rs.getInt(1);
+            }
+        }, INVALID_CURSOR_STATE, "Result set is closed");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code int} 
value from column whose
+     * value can't be converted to an {@code int}.
+     */
+    @Test
+    public void testInvalidIntFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getInt(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to int");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code long} 
value from column whose
+     * value can't be converted to an {@code long}.
+     */
+    @Test
+    public void testInvalidLongFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getLong(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to long");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code float} 
value from column whose
+     * value can't be converted to an {@code float}.
+     */
+    @Test
+    public void testInvalidFloatFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getFloat(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to float");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code double} 
value from column whose
+     * value can't be converted to an {@code double}.
+     */
+    @Test
+    public void testInvalidDoubleFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getDouble(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to double");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code byte} 
value from column whose
+     * value can't be converted to an {@code byte}.
+     */
+    @Test
+    public void testInvalidByteFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getByte(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to byte");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code short} 
value from column whose
+     * value can't be converted to an {@code short}.
+     */
+    @Test
+    public void testInvalidShortFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getShort(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to short");
+    }
+
+    /**
+     * Test error code for the case when user attempts to get {@code 
BigDecimal} value from column
+     * whose value can't be converted to an {@code BigDecimal}.
+     */
+    @Test
+    public void testInvalidBigDecimalFormat() {
+        checkErrorState(() -> {
+            try (PreparedStatement stmt = conn.prepareStatement("SELECT 
'zzz'")) {
+                ResultSet rs = stmt.executeQuery();
+
+                rs.next();
+
+                rs.getBigDecimal(1);
+            }
+        }, CONVERSION_FAILED, "Cannot convert to");

Review comment:
       fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to