trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xwq <...@git.apache.org>
Subject [GitHub] incubator-trafodion pull request #1207: [TRAFODION-2704]close unused statmen...
Date Wed, 16 Aug 2017 06:22:36 GMT
Github user xwq commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/1207#discussion_r133366599
  
    --- Diff: dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/BatchTest.java
---
    @@ -158,38 +182,51 @@ public void testBatchInsertPkDuplicate() throws Exception {
                 }
             }
             int expectedRowCount = 8;
    +        PreparedStatement insertStmt = null;
    +        Statement selectStmt = null;
     
    -        // Start to prepare and execute the batch upsert
    -        PreparedStatement insertStmt = _conn.prepareStatement(strInsert);
    -        for(int i=0; i < 10; ++i) {
    -            insertStmt.setInt(1, idArray[i]);
    -            insertStmt.setString(2, nameArray[i]);
    -            insertStmt.addBatch();
    -        }
    -        
             try {
    -            statusArray = insertStmt.executeBatch();
    -        } catch(SQLException sqle) {
    -            assertTrue(sqle.getMessage().toUpperCase().contains("BATCH UPDATE FAILED"));

    -            SQLException e = null;
    -            e = sqle.getNextException();
    -            do {
    -                assertTrue(e.getMessage().contains("ERROR[8102] The operation is prevented
by a unique constraint"));
    -            } while((e = e.getNextException()) != null);
    +            // Start to prepare and execute the batch upsert
    +            insertStmt = _conn.prepareStatement(strInsert);
    +            for(int i=0; i < 10; ++i) {
    +                insertStmt.setInt(1, idArray[i]);
    +                insertStmt.setString(2, nameArray[i]);
    +                insertStmt.addBatch();
    +            }
    +            
    +            try {
    +                statusArray = insertStmt.executeBatch();
    +            } catch(SQLException sqle) {
    +                assertTrue(sqle.getMessage().toUpperCase().contains("BATCH UPDATE FAILED"));

    +                SQLException e = null;
    +                e = sqle.getNextException();
    +                do {
    +                    assertTrue(e.getMessage().contains("ERROR[8102] The operation is
prevented by a unique constraint"));
    +                } while((e = e.getNextException()) != null);
    +            }
    +            
    +            //assertArrayEquals(expectedStatusArray, statusArray);
    +
    +            int rowCount = 0;
    +            selectStmt = _conn.createStatement();
    +            ResultSet rs = selectStmt.executeQuery(strSelect);
    +            while(rs.next()) {
    +                System.out.println("ID = " + rs.getString(1) + ", Name = " + rs.getString(2));
    +                assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
    +                assertEquals(expectedNameArray[rs.getRow()-1], rs.getString(2));
    +                rowCount++;
    +            }
    +            rs.close();
             }
    -        
    -        //assertArrayEquals(expectedStatusArray, statusArray);
    +        finally {
    +            if (selectStmt != null) {
    +                selectStmt.close();
    +            }
     
    -        int rowCount = 0;
    -        ResultSet rs = _conn.createStatement().executeQuery(strSelect);
    -        while(rs.next()) {
    -            System.out.println("ID = " + rs.getString(1) + ", Name = " + rs.getString(2));
    -            assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
    -            assertEquals(expectedNameArray[rs.getRow()-1], rs.getString(2));
    -            rowCount++;
    -        }
    -        rs.close();
    -        insertStmt.close();
    +            if (insertStmt != null) {
    --- End diff --
    
    you are right. 
    
    For now, many of the test cases have the same issues. And the mechanism for handling the
exceptions also has big problems. I planed to improve them, but it need some time to finish
it. 
    I think we can merge this to improve the jenkins test first. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message