1 21 22 package org.apache.derbyTesting.functionTests.tests.storetests; 23 24 25 import org.apache.derby.iapi.services.sanity.SanityManager; 26 27 import org.apache.derbyTesting.functionTests.tests.store.BaseTest; 28 29 import java.sql.CallableStatement ; 30 import java.sql.Connection ; 31 import java.sql.PreparedStatement ; 32 import java.sql.ResultSet ; 33 import java.sql.SQLException ; 34 import java.sql.Statement ; 35 36 import org.apache.derby.tools.ij; 37 38 39 49 50 public class st_derby715 extends BaseTest 51 { 52 static boolean verbose = false; 53 54 public st_derby715() 55 { 56 } 57 58 59 62 private static void setup() 63 throws Exception 64 { 65 Connection conn = ij.startJBMS(); 66 Statement stmt = conn.createStatement(); 67 68 70 try 71 { 72 stmt.executeUpdate("drop table a"); 73 } 74 catch (Exception e) 75 { 76 } 78 79 try 80 { 81 stmt.executeUpdate("drop table b"); 82 } 83 catch (Exception e) 84 { 85 } 87 88 stmt.executeUpdate("create table a (a integer)"); 89 stmt.executeUpdate("create table b (b integer)"); 90 stmt.close(); 91 conn.commit(); 92 conn.close(); 93 } 94 95 public static class t1 implements Runnable 96 { 97 String [] argv; 98 99 public t1(String [] argv) 100 { 101 argv = argv; 102 } 103 public void run() 104 { 105 try 106 { 107 ij.getPropertyArg(argv); 108 Connection conn = ij.startJBMS(); 109 conn.setAutoCommit(false); 110 conn.setTransactionIsolation( 111 Connection.TRANSACTION_SERIALIZABLE); 112 113 Statement stmt = conn.createStatement(); 114 if (verbose) 115 System.out.println("Thread 1 before selecting from b"); 116 117 ResultSet rs = stmt.executeQuery("select * from b"); 119 120 if (verbose) 121 System.out.println("Thread 1 before selecting next from b"); 122 123 while (rs.next()) 124 { 125 if (verbose) 126 System.out.println("Thread t1 got " + rs.getString(1)); 127 } 128 if (verbose) 129 System.out.println("Thread 1 after all next."); 130 131 Thread.sleep(500); 133 134 if (verbose) 135 System.out.println("Thread 1 before inserting into a..."); 136 137 stmt.executeUpdate("insert into a values(1)"); 140 141 if (verbose) 142 System.out.println("Thread 1 after inserting into a..."); 143 144 conn.rollback(); 145 } 146 catch (SQLException sqle) 147 { 148 if (sqle.getSQLState().equals("40001")) 149 { 150 System.out.println("Got a Deadlock."); 155 } 156 else 157 { 158 org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException( 159 System.out, sqle); 160 sqle.printStackTrace(System.out); 161 } 162 if (verbose) 163 System.out.println("Thread 1 got exception:\n"); 164 } 165 catch (Exception ex) 166 { 167 System.out.println("got unexpected exception: " + ex); 168 } 169 } 170 } 171 172 public static class t2 implements Runnable 173 { 174 String [] argv; 175 public t2 (String [] argv) 176 { 177 argv = argv; 178 } 179 public void run() 180 { 181 try 182 { 183 ij.getPropertyArg(argv); 184 Connection conn = ij.startJBMS(); 185 conn.setAutoCommit(false); 186 conn.setTransactionIsolation( 187 Connection.TRANSACTION_SERIALIZABLE); 188 189 Statement stmt = conn.createStatement(); 190 191 if (verbose) 192 System.out.println("Thread 2 before selecting from a"); 193 194 ResultSet rs = stmt.executeQuery("select * from a"); 195 196 if (verbose) 197 System.out.println("Thread 2 before selecting next from a"); 198 199 while (rs.next()) 200 { 201 if (verbose) 202 System.out.println("Thread t2 got " + rs.getString(1)); 203 } 204 205 if (verbose) 206 System.out.println("Thread 2 after all next."); 207 208 209 Thread.sleep(500); 210 211 if (verbose) 212 System.out.println("Thread 2 before inserting into b"); 213 214 stmt.executeUpdate("insert into b values(2)"); 215 216 if (verbose) 217 System.out.println("Thread 2 after inserting into b"); 218 219 conn.rollback(); 220 } 221 catch (SQLException sqle) 222 { 223 if (verbose) 224 System.out.println("Thread 1 got exception:\n"); 225 226 if (sqle.getSQLState().equals("40001")) 227 { 228 System.out.println("Got a Deadlock."); 233 } 234 else 235 { 236 org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException( 237 System.out, sqle); 238 sqle.printStackTrace(System.out); 239 } 240 } 241 catch (Exception ex) 242 { 243 System.out.println("got unexpected exception: " + ex); 244 } 245 } 246 } 247 248 249 public void testList(Connection conn) 250 throws SQLException 251 { 252 } 253 254 public static void main(String [] argv) 255 throws Throwable 256 { 257 ij.getPropertyArg(argv); 258 259 st_derby715 setup_ddl = new st_derby715(); 260 setup_ddl.setup(); 261 setup_ddl = null; 262 263 { 264 for (int i = 0; i < 5; i++) 265 { 266 Thread test1 = new Thread (new t1(argv)); 267 Thread test2 = new Thread (new t2(argv)); 268 test1.start(); 269 test2.start(); 270 test1.join(); 271 test2.join(); 272 } 273 } 274 282 } 283 } 284 | Popular Tags |