1 21 22 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 23 24 import java.sql.Connection ; 25 import java.sql.Statement ; 26 import java.sql.PreparedStatement ; 27 import java.sql.ResultSet ; 28 import java.sql.SQLException ; 29 30 import org.apache.derby.tools.ij; 31 import org.apache.derbyTesting.functionTests.util.TestUtil; 32 33 public class derbyStress { 34 35 private static String [] testObjects = {"table t1"}; 36 37 private static int numConn = 1; 38 private static int numRows = 100; 39 private static int numPreparedStmts = 2000; 40 41 public static void main(String [] args) { 42 try { 43 System.out.println("Test derbyStress starting"); 44 45 ij.getPropertyArg(args); 48 Connection conn = null; 49 50 for (int i = 0; i < numConn; i++) { 51 conn = ij.startJBMS(); 52 System.out.println("Testing with " + numPreparedStmts + " prepared statements"); 53 prepStmtTest(conn, numRows, numPreparedStmts); 54 System.out.println("PASS -- Prepared statement test"); 55 conn.close(); 56 } 57 58 reExecuteStatementTest(); 59 60 System.out.println("Test derbyStress finished."); 61 } catch (SQLException se) { 62 TestUtil.dumpSQLExceptions(se); 63 } catch (Throwable e) { 64 System.out.println("FAIL -- unexpected exception caught in main():\n"); 65 System.out.println(e.getMessage()); 66 e.printStackTrace(); 67 } 68 } 69 70 private static void createTables(Connection conn, int numRows) throws SQLException { 71 Statement stmt = conn.createStatement(); 72 73 TestUtil.cleanUpTest(stmt, testObjects); 74 75 stmt.execute("create table t1 (lvc LONG VARCHAR)"); 76 stmt.close(); 77 78 String insertTabSql = "insert into t1 values(?)"; 79 PreparedStatement ps = conn.prepareStatement(insertTabSql); 80 for (int i = 0; i < numRows; i++) 81 { 82 ps.setString(1,"Hello" + i); 83 ps.executeUpdate(); 84 } 85 ps.close(); 86 } 87 88 private static void prepStmtTest(Connection conn, int numRows, int numPreparedStmts) throws Exception 91 { 92 PreparedStatement ps = null; 93 ResultSet rs = null; 94 conn.setAutoCommit(false); 95 96 try { 97 98 createTables(conn, numRows); 99 100 String selTabSql = "select * from t1"; 101 102 for (int i = 0 ; i < numPreparedStmts; i++) 103 { 104 ps = conn.prepareStatement(selTabSql); 105 rs = ps.executeQuery(); 106 107 while (rs.next()) 108 { 109 rs.getString(1); 110 } 111 112 rs.close(); 113 114 } 117 conn.commit(); 118 } 119 catch (SQLException e) { 120 TestUtil.dumpSQLExceptions(e); 121 conn.rollback(); 122 } 123 } 124 125 private static void reExecuteStatementTest() throws Exception { 128 System.out.print("DERBY-557: reExecuteStatementTest() "); 129 Connection conn = ij.startJBMS(); 130 Statement stmt = conn.createStatement(); 131 for (int i = 0; i < 50000; i++) { 132 ResultSet rs = stmt.executeQuery("values(1)"); 133 } 135 TestUtil.cleanUpTest(stmt, testObjects); 136 conn.commit(); 137 stmt.close(); 138 conn.close(); 139 System.out.println("PASSED"); 140 } 141 } 142 | Popular Tags |