1 21 22 package org.apache.derbyTesting.functionTests.tests.store; 23 24 import java.sql.Connection ; 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 import java.sql.Statement ; 28 import java.util.Properties ; 29 30 import javax.sql.DataSource ; 31 32 import org.apache.derby.tools.ij; 33 import org.apache.derbyTesting.functionTests.util.TestUtil; 34 35 47 public class RecoveryAfterBackup 48 { 49 50 public static void main(String [] argv) throws Throwable 51 { 52 try { 53 ij.getPropertyArg(argv); 54 Connection conn = ij.startJBMS(); 55 conn.setAutoCommit(true); 56 57 Statement s = conn.createStatement(); 60 ResultSet rs = s.executeQuery("SELECT COUNT(a), SUM(a) FROM t1"); 61 while (rs.next()) { 62 int count = rs.getInt(1); 63 int sum = rs.getInt(2); 64 if (count!=2 || sum!=1) { 65 System.out.print("Unexpected initial database state: "); 66 } 67 System.out.println("Count: " + count + " Sum: " + sum); 68 } 69 70 System.out.println("Inserting records ..."); 72 s.execute ("INSERT INTO t1 SELECT a+2 FROM t1"); 73 s.execute ("INSERT INTO t1 SELECT a+4 FROM t1"); 74 s.execute ("INSERT INTO t1 SELECT a+8 FROM t1"); 75 s.execute ("INSERT INTO t1 SELECT a+16 FROM t1"); 76 s.execute ("INSERT INTO t1 SELECT a+32 FROM t1"); 77 s.execute ("INSERT INTO t1 SELECT a+64 FROM t1"); 78 s.execute ("INSERT INTO t1 SELECT a+128 FROM t1"); 79 80 System.out.println("Shutting down database ..."); 82 try { 83 TestUtil.getConnection("", "shutdown=true"); 84 } catch(SQLException sqle) { 85 if (sqle.getSQLState() != null 86 && sqle.getSQLState().equals("XJ015")) { 87 System.out.println("Database shutdown completed"); 88 } else { 89 throw sqle; 90 } 91 } 92 93 System.out.println("Starting restore with roll-forward recovery.."); 95 String dbName = "hairynosedwombat"; 96 String connAttrs = 97 "rollForwardRecoveryFrom=extinout/mybackup/hairynosedwombat"; 98 conn = TestUtil.getConnection(dbName, connAttrs); 99 100 System.out.println("Verifying database ..."); 102 s = conn.createStatement(); 103 rs = s.executeQuery("SELECT COUNT(a), SUM(a) FROM t1"); 104 while (rs.next()) { 105 int count = rs.getInt(1); 106 int sum = rs.getInt(2); 107 if (count!=256 || sum!=256*255/2) { System.out.print("Test FAILED: "); 109 } 110 System.out.println("Count: " + count + " Sum: " + sum); 111 } 112 113 } catch (SQLException sqle) { 114 org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(System.out, 115 sqle); 116 sqle.printStackTrace(System.out); 117 } 118 } 119 } 120 | Popular Tags |