AMashenkov commented on a change in pull request #284: URL: https://github.com/apache/ignite-3/pull/284#discussion_r708051194
########## File path: modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/JdbcStatementSelfTest.java ########## @@ -0,0 +1,874 @@ +/* + * 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 java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.Statement; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +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.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Statement test. + */ +@SuppressWarnings({"ThrowableNotThrown"}) +public class JdbcStatementSelfTest extends AbstractJdbcSelfTest { + /** SQL query. */ + private static final String SQL = + "select 1::INTEGER, true, 1::TINYINT, 1::SMALLINT, 1::INTEGER, 1::BIGINT, 1.0::FLOAT, 1.0::DOUBLE, 1.0::DOUBLE, '1';"; + + /** Statement. */ + private Statement stmt; + + /** Connection. */ + private Connection conn; + + /** + * Create the connection ant statement. + * + * @throws Exception if failed. + */ + @BeforeEach + protected void beforeTest() throws Exception { + conn = DriverManager.getConnection(URL); + + stmt = conn.createStatement(); + + assertNotNull(stmt); + assertFalse(stmt.isClosed()); + } + + /** + * Close the connection and statement. + * + * @throws Exception if failed. + */ + @AfterEach + protected void afterTest() throws Exception { + if (stmt != null && !stmt.isClosed()) { + stmt.close(); + + assertTrue(stmt.isClosed()); + } + + conn.close(); + + assertTrue(stmt.isClosed()); + assertTrue(conn.isClosed()); + } + + /** + * TODO IGNITE-15187 + IGNITE-15108 + * + * @throws Exception If failed. + */ + @Test + @Disabled + public void testExecuteQuery0() throws Exception { + ResultSet rs = stmt.executeQuery(SQL); + + assertNotNull(rs); + + int cnt = 0; + + while (rs.next()) { + int id = rs.getInt("id"); + + if (id == 2) { + assertEquals("Joe", rs.getString("firstName")); + assertEquals("Black", rs.getString("lastName")); + assertEquals(35, rs.getInt("age")); + } + else if (id == 3) { + assertEquals("Mike", rs.getString("firstName")); + assertEquals("Green", rs.getString("lastName")); + assertEquals(40, rs.getInt("age")); + } + else + fail("Wrong ID: " + id); + + cnt++; + } + + assertEquals(2, cnt); + } + + /** + * @throws Exception If failed. + */ + @Test + public void testExecuteQuery1() throws Exception { + final String sqlText = "select 5;"; + + try (ResultSet rs = stmt.executeQuery(sqlText)) { + assertNotNull(rs); + + assertTrue(rs.next()); + + int val = rs.getInt(1); + + assertTrue(val >= 1 && val <= 10, "Invalid val: " + val); + } + + stmt.close(); + + // Call on a closed statement + checkStatementClosed(() -> stmt.executeQuery(sqlText)); + } + + /** + * TODO IGNITE-15187 + IGNITE-15108 + * + * @throws Exception If failed. + */ + @Test + @Disabled + public void testExecute() throws Exception { + assertTrue(stmt.execute(SQL)); + + assertEquals(-1, stmt.getUpdateCount(), "Update count must be -1 for SELECT query"); + + ResultSet rs = stmt.getResultSet(); + + assertNotNull(rs); + + int cnt = 0; + + while (rs.next()) { + int id = rs.getInt("id"); + + if (id == 2) { + assertEquals("Joe", rs.getString("firstName")); + assertEquals("Black", rs.getString("lastName")); + assertEquals(35, rs.getInt("age")); + } + else if (id == 3) { + assertEquals( "Mike", rs.getString("firstName")); + assertEquals( "Green", rs.getString("lastName")); + assertEquals(40, rs.getInt("age")); + } + else + fail("Wrong ID: " + id); + + cnt++; + } + + assertEquals(2, cnt); + + assertFalse(stmt.getMoreResults(), "Statement has more results."); + } + + /** + * TODO IGNITE-15187 + IGNITE-15108 + * @throws Exception If failed. + */ + @Test + @Disabled Review comment: ```suggestion * @throws Exception If failed. */ @Test @Disabled("IGNITE-15187 + IGNITE-15108") ``` -- 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]
