1 21 22 package org.apache.derbyTesting.functionTests.tests.store; 23 import java.io.File ; 24 import java.io.ByteArrayInputStream ; 25 26 import java.math.BigDecimal ; 27 28 import java.sql.Connection ; 29 import java.sql.DriverManager ; 30 import java.sql.SQLException ; 31 import java.sql.PreparedStatement ; 32 import java.sql.ResultSet ; 33 import java.sql.Statement ; 34 import org.apache.derby.tools.ij; 35 import org.apache.derby.tools.JDBCDisplayUtil; 36 37 45 46 public class checkPoint 47 { 48 49 public static void main( String args[]) 50 { 51 System.out.println("Test checkpoint starting"); 52 53 try 54 { 55 ij.getPropertyArg(args); 58 Connection conn = ij.startJBMS(); 59 60 setupAllTestFiles(); 62 63 Statement stmt = conn.createStatement(); 64 stmt.executeUpdate("CREATE PROCEDURE WAIT_FOR_POST_COMMIT() DYNAMIC RESULT SETS 0 LANGUAGE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.T_Access.waitForPostCommitToFinish' PARAMETER STYLE JAVA"); 65 66 stmt.executeUpdate( "create table t1(" + 67 "c1 int not null primary key , c2 varchar(200) not null unique , c3 char(200) not null unique)"); 68 conn.setAutoCommit(true); 69 String ins_string = "insert into t1 values(?,?,?)"; 70 PreparedStatement insStmt = conn.prepareStatement(ins_string); 71 stmt.executeUpdate("CALL SYSCS_UTIL.SYSCS_CHECKPOINT_DATABASE()"); 73 stmt.executeUpdate("call WAIT_FOR_POST_COMMIT()"); 74 checkpointOccured(); 75 boolean modifiedIntervals = false; 76 for(int uniqueid =0 ; uniqueid < 3500 ; uniqueid++) 77 { 78 insStmt.setLong(1, uniqueid); 79 insStmt.setString(2, "IBM GREAT COMPANY " + uniqueid); 80 insStmt.setString(3, "IBM GREAT COMPANY " + uniqueid); 81 insStmt.executeUpdate(); 82 83 if((uniqueid % 400) == 0) 86 { 87 System.out.println("Checking logs and Checkpoint at Insert:" 88 + uniqueid); 89 stmt.executeUpdate("call WAIT_FOR_POST_COMMIT()"); 91 checkpointOccured(); 92 } 93 94 if(uniqueid > 2500 && !modifiedIntervals) 96 { 97 ResultSet rs; 98 System.out.println("Modifying the checkpoint/log intervals"); 99 String value = "150001"; 101 stmt.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY" + 102 "('derby.storage.logSwitchInterval', " + 103 "'" + value + "'"+ ")"); 104 stmt.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY" + 105 "('derby.storage.checkpointInterval', " + 106 "'" + value + "'" + ")"); 107 rs = 108 stmt.executeQuery("values SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY" + 109 "('derby.storage.checkpointInterval')"); 110 while(rs.next()){ 111 System.out.println("checkPointInterval:" + rs.getString(1)); 112 } 113 114 rs =stmt.executeQuery("values SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY" + 115 "('derby.storage.logSwitchInterval')"); 116 while(rs.next()){ 117 System.out.println("logSwitchInterval:" + rs.getString(1)); 118 } 119 120 modifiedIntervals = true; 121 } 122 } 123 124 numberOfLogFiles(); 127 conn.commit(); 128 stmt.close(); 129 insStmt.close(); 130 conn.close(); 131 } 132 catch( SQLException e) 133 { 134 dumpSQLExceptions(e); 135 } catch (Throwable e) { 136 System.out.println("FAIL -- unexpected exception:" + e.toString()); 137 } 138 139 try{ 141 Connection conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true"); 143 }catch(SQLException se){ 144 if (se.getSQLState() != null && se.getSQLState().equals("08006")) 145 System.out.println("database shutdown properly\n"); 146 else 147 dumpSQLExceptions(se); 148 } catch (Throwable e) { 149 System.out.println("FAIL -- unexpected exception:" + e.toString()); 150 } 151 152 System.out.println("Test checkpoint finished"); 153 } 154 155 156 static private void dumpSQLExceptions (SQLException se) { 157 System.out.println("FAIL -- unexpected exception: " + se.toString()); 158 while (se != null) { 159 System.out.print("SQLSTATE("+se.getSQLState()+"):"); 160 se = se.getNextException(); 161 } 162 } 163 164 165 166 private static String derbyHome; 169 private static File dbDir ; 170 private static File logDir; 171 private static File logControlFile; 172 private static long lastCheckPointTime = 0; 173 174 private static void setupAllTestFiles() 175 { 176 derbyHome = System.getProperty("derby.system.home"); 177 dbDir = new File (derbyHome, "wombat"); 178 logDir = new File (dbDir , "log"); 179 logControlFile = new File (logDir , "log.ctrl"); 180 lastCheckPointTime = logControlFile.lastModified(); 181 } 182 183 private static boolean checkpointOccured() 184 { 185 long currentModifiedTime = logControlFile.lastModified(); 186 if(currentModifiedTime > lastCheckPointTime) 187 { 188 lastCheckPointTime = currentModifiedTime ; 189 System.out.println("CHECKPOINT WAS DONE"); 190 return true; 191 } 192 193 return false; 194 } 195 196 197 private static int numberOfLogFiles() 198 { 199 File [] logFiles = logDir.listFiles(); 202 int noFiles = (logFiles == null) ? 0 : logFiles.length; 203 String lastLogFile =""; 204 for(int i = 0 ; i < noFiles ; i++) 205 { 206 String current = logFiles[i].getName() ; 207 if(current.compareTo("log.ctrl")==0 || current.compareTo("logmirror.ctrl")==0) 208 continue; 209 if(current.compareTo(lastLogFile) > 0) 210 lastLogFile = current; 211 } 212 213 if(lastLogFile.compareTo("log21.dat") > 0) 214 { 215 System.out.println("There seems to be too many log files"); 216 System.out.println(lastLogFile); 217 } 218 logFiles = null; 219 return noFiles -2 ; 220 221 222 } 223 224 } 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | Popular Tags |