trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arvi...@apache.org
Subject [1/5] incubator-trafodion git commit: Add new jdbc rowsets test cases to dcs/src/test/jdbc_test folder.
Date Thu, 07 Jan 2016 07:35:28 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 7e1dfcabf -> e5aeb0a82


Add new jdbc rowsets test cases to dcs/src/test/jdbc_test folder.

New test cases added:
1. Batch insert with string overflow.
2. Batch update with string overflow.
3. Batch update with ID duplication.
4. Order the result set for test result assertion.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/88d8484d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/88d8484d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/88d8484d

Branch: refs/heads/master
Commit: 88d8484d0fd2559a3c1d9a65f4e9fed5135a8070
Parents: fb36e27
Author: ryzuo <joshuamurdoc@gmail.com>
Authored: Mon Dec 21 11:55:47 2015 +0000
Committer: ryzuo <joshuamurdoc@gmail.com>
Committed: Mon Dec 21 11:55:47 2015 +0000

----------------------------------------------------------------------
 .../java/org/trafodion/jdbc_test/BatchTest.java | 582 +++++++++++++++++++
 .../org/trafodion/jdbc_test/JdbcCommon.java     | 224 +++++++
 .../trafodion/phoenix/end2end/BatchTest.java    |   2 +-
 3 files changed, 807 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/88d8484d/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/BatchTest.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/BatchTest.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/BatchTest.java
new file mode 100755
index 0000000..f5977ae
--- /dev/null
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/BatchTest.java
@@ -0,0 +1,582 @@
+// @@@ START COPYRIGHT @@@
+//
+// 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.
+//
+// @@@ END COPYRIGHT @@@
+
+import static org.junit.Assert.*;
+import org.junit.*;
+
+import java.io.FileInputStream;
+import java.io.File;
+import java.io.IOException;
+
+import java.sql.DriverManager;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+
+import java.util.Properties;
+import java.util.Arrays;
+import java.util.ArrayList;
+
+public class BatchTest extends JdbcCommon {
+    
+    public  static final int ROW_COUNT = 10000;
+    private int[] expectedStatusArray = null;
+    private int[] statusArray = null;
+
+    private static final String strInsert = "INSERT INTO " + BATCH_TEST_TABLE + " VALUES
(?,?)";
+    private static final String strInsertFk = "INSERT INTO " + BATCH_TEST_TABLE_FK + " VALUES
(?,?,?)";
+    private static final String strUpsert = "UPSERT USING LOAD INTO " + BATCH_TEST_TABLE
+ " VALUES (?,?)";
+    private static final String strUpdate = "UPDATE " + BATCH_TEST_TABLE + " SET (DEPT_ID,DEPT_NAME)
= (?,?) WHERE DEPT_ID=?";
+    private static final String strDelete = "DELETE FROM " + BATCH_TEST_TABLE;
+    private static final String strSelect = "SELECT * FROM " + BATCH_TEST_TABLE + " ORDER
BY DEPT_ID ASCENDING";
+    private static final String strSelectFk = "SELECT * FROM " + BATCH_TEST_TABLE_FK + "
ORDER BY EID ASCENDING";
+
+    private void cleanTable() {
+        try {
+            Statement stmt = _conn.createStatement();
+            stmt.execute(strDelete);
+        } catch(Exception e) {
+            // do nothing
+        }
+    }
+
+    @BeforeClass
+    public static void doTestSuiteSetup() throws Exception {
+        /* List all of the object names being used in this entire class.
+         * The objects are dropped with errors ignored, so it is OK if the
+         * object does not exist for a particular test.
+         */
+        objDropList = new ArrayList<String>(
+            Arrays.asList("table " + BATCH_TEST_TABLE));
+        doBaseTestSuiteSetup();
+    }
+    /* @AfterClass, @Before, @After are defined in BaseTest */
+
+    @Test
+    public void testBatchInsertPositive() throws Exception {
+        printTestDescription();
+        System.out.println("Running testBatchInsertPositive......");
+
+        createTestTable(BATCH_TEST_TABLE);
+
+        // Initialize the expected status array for executeBatch() success
+        expectedStatusArray = new int[ROW_COUNT];
+        for(int i=0; i < ROW_COUNT; ++i) {
+            expectedStatusArray[i] = -2;
+        }
+
+        // Start to prepare and execute the batch insert
+        long startTime = System.currentTimeMillis();
+        PreparedStatement upsertStmt = _conn.prepareStatement(strUpsert);
+        for(int i=0; i < ROW_COUNT; ++i) {
+            upsertStmt.setInt(1, i);
+            upsertStmt.setString(2, "Traf The World " + i);
+            upsertStmt.addBatch();
+        }
+        statusArray = upsertStmt.executeBatch();
+        long endTime = System.currentTimeMillis();
+        System.out.println("Time consumption for batch inserting "
+                + ROW_COUNT + " rows is " + (endTime - startTime)  + " milli seconds");
+        assertArrayEquals(expectedStatusArray, statusArray);
+
+        // Fetch the data from the table to see if the data inserted succeeded
+        PreparedStatement selectStmt = _conn.prepareStatement(strSelect);
+        ResultSet rs = selectStmt.executeQuery();
+        int rowCount = 0;
+        while(rs.next()) {
+            assertEquals(rowCount, rs.getInt(1));
+            assertEquals("Traf The World " + String.valueOf(rowCount), rs.getString(2));
+            rowCount++;
+        }
+        assertEquals(rowCount, ROW_COUNT);
+    }
+
+    /* Currently SQL does not have the ability to dump individual row, which
+     * violates a contraint in a rowsets, and not able to return status error
+     * for the specific illegal row. The whole batch will be failed. Thus, I
+     * just comment out the expected error value in the expected status array
+     * temporarily and does not assert the status array because there is no
+     * value inserted into the table as the whole batch fails.
+     * JIRA 1701 was filed for this issue 
+     * */
+    @Test
+    public void testBatchInsertPkDuplicate() throws Exception {
+
+        printTestDescription();
+        System.out.println("Running testBatchInsertPkDuplicate......");
+
+        createTestTable(BATCH_TEST_TABLE);
+
+        // Initialize the expected status array for executeBatch() success for all rows,
+        // except for row 2 and row 6, to which we will pass duplicate ID values on
+        // purpose in actual insert later to make an unique value conflict error. The
+        // returned status value should be
+        String nameSuffix = "Traf The World ";
+        expectedStatusArray = new int[10];
+        
+        int[] expectedIdArray = new int[8];
+        String[] expectedNameArray = new String[8];
+        int[] idArray = new int[10];
+        String[] nameArray = new String[10];
+        
+        for(int i=0, j=0; i < 10; ++i) {
+            expectedStatusArray[i] = -2;
+            idArray[i] = i;
+            nameArray[i] = nameSuffix + i;
+            expectedIdArray[j] = i;
+            expectedNameArray[j] = nameArray[i];
+            switch(i) {
+                case 1:
+                case 5:
+                    idArray[i] = i-1;
+                    //expectedStatusArray[i] = -3;
+                    break;
+                default:
+                    j++;
+                    break;
+            }
+        }
+        int expectedRowCount = 8;
+
+        // 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);
+        }
+        
+        //assertArrayEquals(expectedStatusArray, statusArray);
+
+        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();
+    }
+
+    /* Currently SQL does not have the ability to dump individual row, which
+     * violates a contraint in a rowsets, and not able to return status error
+     * for the specific illegal row. The whole batch will be failed. Thus, I
+     * just comment out the expected error value in the expected status array
+     * temporarily and does not assert the status array because there is no
+     * value inserted into the table as the whole batch fails.
+     * JIRA 1716 was filed to describ this.
+     * */
+    @Test
+    public void testBatchInsertFKNotExist() throws Exception {
+        printTestDescription();
+        System.out.println("Running testBatchInsertFKNotExist......");
+
+        createTestTable(BATCH_TEST_TABLE);
+        createTestTable(BATCH_TEST_TABLE_FK);
+
+        String[] deptName = {"RD", "Marketing", "Finance"};
+        String[] employeeName = {"John", "Michael", "Paul", "Ronan", "Kate"};
+        int[] employeeDeptId = {1, 2, 2, 3, 5};
+
+        expectedStatusArray = new int[]{-2, -2, -2, -2, -2};
+
+        // Insert department records
+        PreparedStatement pstmt = _conn.prepareStatement(strInsert);
+        for(int i=0; i < deptName.length; ++i) {
+            pstmt.setInt(1, (i+1));
+            pstmt.setString(2, deptName[i]);
+            pstmt.addBatch();
+        }
+        pstmt.executeBatch();
+        pstmt.close();
+
+        // Insert employee records, which need to reference id from department
+        // as foreign key.
+        pstmt = _conn.prepareStatement(strInsertFk);
+        for(int i=0; i < employeeName.length; ++i) {
+            pstmt.setInt(1, i);
+            pstmt.setInt(2, employeeDeptId[i]);
+            pstmt.setString(3, employeeName[i]);
+            pstmt.addBatch();
+        }
+        try {
+            statusArray = pstmt.executeBatch();
+        } catch(SQLException sqle) {
+            assertTrue(sqle.getMessage().toUpperCase().contains("BATCH UPDATE FAILED"));

+            System.out.println(sqle.getMessage());
+            SQLException e = null;
+            e = sqle.getNextException();
+            do {
+                assertTrue(e.getMessage().contains("operation is prevented by referential
integrity constraint"));
+                System.out.println(e.getMessage());
+                break;
+            } while((e = e.getNextException()) != null);
+        }
+        pstmt.close();
+
+        ResultSet rs = _conn.createStatement().executeQuery(strSelectFk);
+        int rowCount = 0;
+        while(rs.next()) {
+            if(rowCount == 4)
+                break;
+            assertEquals(rowCount, rs.getInt(1));
+            assertEquals(employeeDeptId[rowCount], rs.getInt(2));
+            assertEquals(employeeName[rowCount], rs.getString(3));
+            rowCount++;
+        }
+        rs.close();
+    }
+
+    /* Normally, when there's invalid value in an individual row of a batch,
+     * the insertion of this batch shall be succeeded except the individual
+     * row with invalid value(string length larger than the collumn size in
+     * this case.), and an error code represent the specific failure will be
+     * returned in the status array for this particular row.
+     * However, SQL does not return any error code and information for this
+     * case, it just returns SQL_SUCCEED.
+     * JIRA 1717 was filed to describ this problem
+     * */
+    @Test
+    public void testBatchInsertBufferOverflow() throws Exception {
+        printTestDescription();
+        System.out.println("Running testBatchInsertBufferOverflow......");
+
+        createTestTable(BATCH_TEST_TABLE);
+
+        // Initialize the expected status array for executeBatch() success for all rows,
+        // except for row 3, to which we will pass a string buffer of which the length
+        // of the varchar column is longer than the column max length.
+        String nameSuffix = "Traf The World ";
+        expectedStatusArray = new int[10];
+        
+        int[] expectedIdArray = new int[9];
+        String[] expectedNameArray = new String[9];
+        int[] idArray = new int[10];
+        String[] nameArray = new String[10];
+        
+        for(int i=0, j=0; i < 10; ++i) {
+            expectedStatusArray[i] = -2;
+            idArray[i] = i;
+            nameArray[i] = nameSuffix + i;
+            expectedIdArray[j] = i;
+            expectedNameArray[j] = nameArray[i];
+            if(i != 2)
+                j++;
+        }
+        int expectedRowCount = 9;
+
+        // 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]);
+            if(i != 2)
+                insertStmt.setString(2, nameArray[i]);
+            else
+                insertStmt.setString(2, nameArray[i] + nameArray[i]
+                        + nameArray[i] + nameArray[i] + nameArray[i]
+                        + nameArray[i] + nameArray[i] + nameArray[i]
+                        + nameArray[i] + nameArray[i] + nameArray[i] );
+            insertStmt.addBatch();
+        }
+        
+        try {
+            statusArray = insertStmt.executeBatch();
+        } catch(SQLException sqle) {
+            assertTrue(sqle.getMessage().toUpperCase().contains("BATCH UPDATE FAILED"));

+            System.out.println(sqle.getMessage());
+            SQLException e = null;
+            e = sqle.getNextException();
+            do {
+                assertTrue(e.getMessage().contains("VARCHAR data longer than column length"));
+                System.out.println(e.getMessage());
+            } while((e = e.getNextException()) != null);
+        }
+        
+        //assertArrayEquals(expectedStatusArray, statusArray);
+
+        int rowCount = 0;
+        ResultSet rs = _conn.createStatement().executeQuery(strSelect);
+        while(rs.next()) {
+            assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
+            assertEquals(expectedNameArray[rs.getRow()-1], rs.getString(2));
+            rowCount++;
+        }
+        rs.close();
+        insertStmt.close();
+    }
+
+    @Test
+    public void testBatchUpsertDuplicate() throws Exception {
+        printTestDescription();
+        System.out.println("Running testBatchUpsertDuplicate......");
+
+        createTestTable(BATCH_TEST_TABLE);
+
+        // Initialize the expected status array for executeBatch() success for all rows,
+        // except for row 2 and row 6, to which we will pass duplicate ID values on
+        // purpose in actual insert later to make an unique value conflict error.
+        String nameSuffix = "Traf The World ";
+        expectedStatusArray = new int[10];
+        int[] expectedIdArray = new int[8];
+        String[] expectedNameArray = new String[8];
+        int[] idArray = new int[10];
+        String[] nameArray = new String[10];
+        
+        for(int i=0, j=0; i < 10; ++i) {
+            expectedStatusArray[i] = -2;
+            idArray[i] = i;
+            nameArray[i] = nameSuffix + i;
+            expectedIdArray[j] = i;
+            expectedNameArray[j] = nameArray[i];
+            switch(i) {
+                case 1:
+                case 5:
+                    idArray[i] = i-1;
+                    expectedNameArray[j-1] = nameArray[i];
+                    break;
+                default:
+                    j++;
+                    break;
+            }
+        }
+        int expectedRowCount = 8;
+
+        // Start to prepare and execute the batch upsert
+        PreparedStatement upsertStmt = _conn.prepareStatement(strUpsert);
+        for(int i=0; i < 10; ++i) {
+            upsertStmt.setInt(1, idArray[i]);
+            upsertStmt.setString(2, nameArray[i]);
+            upsertStmt.addBatch();
+        }
+        
+        statusArray = upsertStmt.executeBatch();
+        
+        assertArrayEquals(expectedStatusArray, statusArray);
+
+        int rowCount = 0;
+        ResultSet rs = _conn.createStatement().executeQuery(strSelect);
+        while(rs.next()) {
+            assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
+            assertEquals(expectedNameArray[rs.getRow()-1], rs.getString(2));
+            rowCount++;
+        }
+        assertEquals(rowCount, expectedRowCount);
+        rs.close();
+        upsertStmt.close();
+    }
+
+    @Test
+    public void testBatchUpdateOverflow() throws Exception {
+        printTestDescription();
+        System.out.println("Running testBatchUpdateOverflow......");
+
+        createTestTable(BATCH_TEST_TABLE);
+
+        String nameSuffix = "Traf The World ";
+        String uptNameSuffix = "Traf The Galaxy ";
+        expectedStatusArray = new int[10];
+        
+        int[] idArray = new int[10];
+        String[] nameArray = new String[10];
+        String[] updateNameArray = new String[5];
+        String[] expectedNameArray = new String[10];
+        
+        // Initialize the expected status array for executeBatch() success for all rows,
+        // except for 2nd row in update batch, to which we will pass a string buffer of 
+        // which the length of the varchar column is longer than the column max length.
+        for(int i=0, j=0; i < idArray.length; ++i) {
+            idArray[i] = i;
+            nameArray[i] = nameSuffix + i;
+            expectedNameArray[i] = nameArray[i];
+            expectedStatusArray[i] = -2;
+         
+            if(i > 4) {
+                updateNameArray[j] = uptNameSuffix + j;
+                expectedNameArray[i] = updateNameArray[j];
+                
+                if(i == 6) {
+                    while(updateNameArray[j].length() < 128) {
+                        updateNameArray[j] += uptNameSuffix;
+                    }
+                    //expectedStatusArray[i] = -3;
+                    expectedNameArray[i] = nameArray[i];
+                }
+                j++;
+            }
+        }
+
+        // Insert original records
+        PreparedStatement pstmt = _conn.prepareStatement(strInsert);
+        for(int i=0; i < idArray.length; ++i) {
+            pstmt.setInt(1, i);
+            pstmt.setString(2, nameArray[i]);
+            pstmt.addBatch();
+        }
+        pstmt.executeBatch();
+        pstmt.close();
+
+        // Update existing records
+        pstmt = _conn.prepareStatement(strUpdate);
+        for(int i=0; i < updateNameArray.length; ++i) {
+            pstmt.setInt(1, i+5);
+            pstmt.setString(2, updateNameArray[i]);
+            pstmt.setInt(3, i+5);
+            pstmt.addBatch();
+        }
+
+        try {
+            statusArray = pstmt.executeBatch();
+        } catch(SQLException sqle) {
+            assertTrue(sqle.getMessage().toUpperCase().contains("BATCH UPDATE FAILED"));

+            System.out.println(sqle.getMessage());
+            SQLException e = null;
+            e = sqle.getNextException();
+            do {
+                assertTrue(e.getMessage().contains("VARCHAR data longer than column length"));
+                System.out.println(e.getMessage());
+            } while((e = e.getNextException()) != null);
+        }
+        
+        //assertArrayEquals(expectedStatusArray, statusArray);
+
+        int rowCount = 0;
+        ResultSet rs = _conn.createStatement().executeQuery(strSelect);
+        while(rs.next()) {
+            assertEquals(expectedNameArray[rs.getRow()-1], rs.getString(2));
+            rowCount++;
+        }
+        rs.close();
+        pstmt.close();
+    }
+
+    /* Currently SQL does not have the ability to dump individual row, which
+     * violates a contraint in a rowsets, and not able to return status error
+     * for the specific illegal row. The whole batch will be failed. Thus, I
+     * just comment out the expected error value in the expected status array
+     * temporarily and does not assert the status array because there is no
+     * value inserted into the table as the whole batch fails.
+     * JIRA 1701 was filed for this issue 
+     * */
+    @Test
+    public void testBatchUpdatePkDuplicate() throws Exception {
+        printTestDescription();
+        System.out.println("Running testBatchUpdatePkDuplicate......");
+
+        createTestTable(BATCH_TEST_TABLE);
+
+        String nameSuffix = "Traf The World ";
+        String uptNameSuffix = "Traf The Galaxy ";
+        expectedStatusArray = new int[10];
+        
+        int[] idArray = new int[10];
+        String[] nameArray = new String[10];
+        int[] updateIdArray = new int[5];
+        String[] updateNameArray = new String[5];
+        int[] expectedIdArray = new int[10];
+        String[] expectedNameArray = new String[10];
+        
+        // Initialize the expected status array for executeBatch() success for all rows,
+        // except for 2nd row in update batch, to which we will pass a string buffer of 
+        // which the length of the varchar column is longer than the column max length.
+        for(int i=0, j=0; i < idArray.length; ++i) {
+            idArray[i] = i;
+            nameArray[i] = nameSuffix + i;
+            expectedIdArray[i] = idArray[i];
+            expectedNameArray[i] = nameArray[i];
+            expectedStatusArray[i] = -2;
+         
+            if(i > 4) {
+                updateIdArray[j] = j+15;
+                updateNameArray[j] = uptNameSuffix + j;
+                
+                if(i != 6) {
+                    expectedIdArray[i] = updateIdArray[j];
+                    expectedNameArray[i] = updateNameArray[j];
+                } else {
+                    updateIdArray[j] = 4; // Use an existing ID in the records to make unique
constraint violation.
+                    expectedStatusArray[i] = -3;
+                }
+                
+                j++;
+            }
+        }
+
+        // Insert original records
+        PreparedStatement pstmt = _conn.prepareStatement(strInsert);
+        for(int i=0; i < idArray.length; ++i) {
+            pstmt.setInt(1, i);
+            pstmt.setString(2, nameArray[i]);
+            pstmt.addBatch();
+        }
+        pstmt.executeBatch();
+        pstmt.close();
+
+        // Update existing records
+        pstmt = _conn.prepareStatement(strUpdate);
+        for(int i=0; i < updateNameArray.length; ++i) {
+            pstmt.setInt(1, updateIdArray[i]);
+            pstmt.setString(2, updateNameArray[i]);
+            pstmt.setInt(3, i+5);
+            pstmt.addBatch();
+        }
+
+        try {
+            statusArray = pstmt.executeBatch();
+        } catch(SQLException sqle) {
+            assertTrue(sqle.getMessage().toUpperCase().contains("BATCH UPDATE FAILED"));

+            System.out.println(sqle.getMessage());
+            SQLException e = null;
+            e = sqle.getNextException();
+            do {
+                assertTrue(e.getMessage().contains("The operation is prevented by a unique
constraint"));
+                System.out.println(e.getMessage());
+            } while((e = e.getNextException()) != null);
+        }
+        
+        //assertArrayEquals(expectedStatusArray, statusArray);
+
+        int rowCount = 0;
+        ResultSet rs = _conn.createStatement().executeQuery(strSelect);
+        while(rs.next()) {
+            //assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
+            //assertEquals(expectedNameArray[rs.getRow()-1], rs.getString(2));
+            rowCount++;
+        }
+        rs.close();
+        pstmt.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/88d8484d/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
new file mode 100644
index 0000000..2005ce6
--- /dev/null
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
@@ -0,0 +1,224 @@
+// @@@ START COPYRIGHT @@@
+//
+// 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.
+//
+// @@@ END COPYRIGHT @@@
+
+import static org.junit.Assert.*;
+import org.junit.*;
+
+import java.sql.DriverManager;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.Date;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Arrays;
+import java.util.ArrayList;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.lang.Thread.*;
+
+
+public class JdbcCommon {
+
+    protected static final String BATCH_TEST_TABLE = "BATCH_TEST_TABLE";
+    protected static final String BATCH_TEST_TABLE_FK = "BATCH_TEST_TABLE_FK";
+    protected static ArrayList<String> objDropList = null;
+
+    private final boolean print_testinfo = false;
+    
+    private static Map<String,String> _tableDDLMap = null;
+
+    private static String _catalog = null;
+    private static String _schema = null;
+    private static String _url = null;
+
+    protected static Connection _conn = null;
+    private static Connection commConn = null;
+    
+    protected static String getUrl() { return _url; }
+
+    private static boolean _driverRegistered = false;
+
+    static {
+        if(_tableDDLMap == null)
+            _tableDDLMap = new HashMap();
+        
+        _tableDDLMap.put(BATCH_TEST_TABLE, "CREATE TABLE BATCH_TEST_TABLE(DEPT_ID INT NOT
NULL PRIMARY KEY, DEPT_NAME VARCHAR(128))");
+        
+        _tableDDLMap.put(BATCH_TEST_TABLE_FK, "CREATE TABLE BATCH_TEST_TABLE_FK(EID INT NOT
NULL PRIMARY KEY, DEPT_ID INT, E_NAME VARCHAR(128)," +
+                " FOREIGN KEY(DEPT_ID) REFERENCES BATCH_TEST_TABLE(DEPT_ID))");
+    }
+
+    protected void printTestDescription() {
+        if (print_testinfo) {
+            System.out.println(Thread.currentThread().getStackTrace()[2]);
+        }
+    }
+
+    protected static Connection getConnection() throws Exception {
+        Connection conn = null;
+        try {
+            String propFile = System.getProperty("trafjdbc.properties");
+            assertNotNull(propFile);
+            FileInputStream fs = new FileInputStream(new File(propFile));
+            Properties props = new Properties();
+            props.load(fs);
+
+            _url = props.getProperty("url");
+            _catalog = props.getProperty("catalog");
+            _schema = props.getProperty("schema");
+           
+            // Reigser our JDBC driver if this is the first call.           
+            if (! _driverRegistered) {
+                if (_url.contains("t4jdbc"))
+                    Class.forName("org.trafodion.jdbc.t4.T4Driver");   // T4 driver
+                else
+                    Class.forName("org.trafodion.jdbc.t2.T2Driver"); // T2 driver
+                _driverRegistered = true;
+            }
+
+            conn = DriverManager.getConnection(_url, props);
+        } catch (Exception e) {
+            conn = null;
+            fail(e.getMessage());
+        }
+
+        assertNotNull(conn);
+
+        return conn;
+    }
+
+    protected void createTestTable(String tableName) {
+        assertNotNull(_conn);
+        String ddl = null;
+        ddl = _tableDDLMap.get(tableName);
+        assertNotNull(ddl);
+        StringBuilder buf = new StringBuilder(ddl);
+        ddl = buf.toString();
+
+        try {
+            _conn.createStatement().execute(ddl);
+        } catch (Exception e) { 
+            System.out.println(e.getMessage());
+            fail("Failed to create table");
+        }
+    }
+
+    protected static void doBaseTestSuiteSetup() throws Exception {
+        createSchemaIfNotExist();
+
+        String name = Thread.currentThread().getStackTrace()[2].toString();
+        name = name.substring(0, name.indexOf(".doTestSuiteSetup")); 
+        System.out.println(name);
+    }
+
+    @AfterClass
+    public static void doBaseTestSuiteCleanup() throws Exception {
+        dropSchemaIfExist();
+    }
+
+    @Before
+    public void doBaseTestSetup() throws Exception {
+        _conn = getConnection();
+    }
+
+    @After
+    public void doBaseTestCleanup() throws Exception {
+        _conn.close();
+        dropTestObjects();
+    }
+
+    // create schema if it does exist.
+    private static void createSchemaIfNotExist() throws Exception {
+        if (commConn == null)
+            commConn = getConnection();
+
+        try {
+            commConn.createStatement().execute("create schema " + _catalog + "." + _schema);
+        } catch (Exception e) {
+            // Do nothing, the schema may already exist.
+        }
+    }
+
+    private static void dropSchemaIfExist() throws Exception {
+        if (commConn == null)
+            commConn = getConnection();
+
+        try {
+            commConn.createStatement().execute("drop schema " + _catalog + "." + _schema
+ " cascade");
+        } catch (Exception e) {
+            // Do nothing, the schema may not exist.  
+        }
+    }
+
+    protected static void dropTestObjects() throws Exception {
+
+        // Use our own conn.  Who knows what the tests have been doing with
+        // auto commit of the conn that it has been using.
+        if (commConn == null)
+            commConn = getConnection();
+
+        if (objDropList == null)
+            return;
+
+        for (String objname : objDropList) {
+            for (int i = 0; i < 3; i++) {
+                try {
+                    commConn.createStatement().executeUpdate("drop " + objname + " cascade");
+                    break; // no execption, break out here
+                } catch (Exception e) {
+                    String msg = e.getMessage();
+                    if ((msg.contains("ERROR[1002]") &&
+                         msg.contains("does not exist")) ||
+                        (msg.contains("ERROR[1003]") && 
+                         msg.contains("does not exist")) ||
+                        (msg.contains("ERROR[1004]") &&
+                         msg.contains("does not exist"))) {
+                        // ERROR[1002]: catalog does not exist in SQ, 
+                        // ERROR[1003]: schema does not exist in SQ,
+                        // ERROR[1004]: schema does not exist in SQ,
+                        // we are done these cases.
+                        break;
+                    } 
+                    else if (msg.contains("ERROR[1389]") &&
+                        msg.contains("does not exist")) {
+                        // object does not exist in TRAF, we are done.
+                        break;
+                    }
+                    else if (i < 2 &&
+                        msg.contains("ERROR[1183]") &&
+                        msg.contains("Error 73")) {
+                        // error 73 should be reried up to 3 times.
+                        Thread.sleep(2000); // 2 secs
+                        System.out.println("see error 73, retrying...");
+                    } else {
+                        // all rest are bad.
+                        System.out.println(msg);
+                        fail("Failed to drop object: " + objname);
+                    }
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/88d8484d/tests/phx/src/test/java/org/trafodion/phoenix/end2end/BatchTest.java
----------------------------------------------------------------------
diff --git a/tests/phx/src/test/java/org/trafodion/phoenix/end2end/BatchTest.java b/tests/phx/src/test/java/org/trafodion/phoenix/end2end/BatchTest.java
index 3cee2b9..e924ca8 100755
--- a/tests/phx/src/test/java/org/trafodion/phoenix/end2end/BatchTest.java
+++ b/tests/phx/src/test/java/org/trafodion/phoenix/end2end/BatchTest.java
@@ -50,7 +50,7 @@ public class BatchTest extends BaseTest {
     private static final String strUpsert = "UPSERT USING LOAD INTO " + BATCH_TEST_TABLE
+ " VALUES (?,?)";
     private static final String strUpdate = "UPDATE " + BATCH_TEST_TABLE + "SET (ID, NAME)
= (?,?)";
     private static final String strDelete = "DELETE FROM " + BATCH_TEST_TABLE;
-    private static final String strSelect = "SELECT * FROM " + BATCH_TEST_TABLE;
+    private static final String strSelect = "SELECT * FROM " + BATCH_TEST_TABLE + " ORDER
BY ID ASCENDING";
 
     private void cleanTable() {
         try {


Mime
View raw message