1 24 25 package org.objectweb.cjdbc.scenario.raidb1.recovery; 26 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 import java.sql.Statement ; 30 31 import org.objectweb.cjdbc.controller.core.Controller; 32 import org.objectweb.cjdbc.controller.recoverylog.RecoveryLog; 33 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate; 34 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 35 36 45 public class Raidb1RecoveryTransactionIdScenario extends Raidb1RecoveryTemplate 46 { 47 53 public void testRecoveryLogTransactionID() throws Exception 54 { 55 RecoveryLog log = mainVdb.getRequestManager().getRecoveryLog(); 57 58 long idZero = log.getLastTransactionId(); 60 61 Connection con = getCJDBCConnection(); 63 con.setAutoCommit(false); 64 Statement statement = con.createStatement(); 65 statement.executeUpdate("INSERT INTO PRODUCT VALUES(50,'myproduct',5.5)"); 66 con.commit(); 67 statement.close(); 68 69 cm.stop("25322"); 71 controller = (Controller) cm.start("25322").getProcess(); 72 cm.loadVirtualDatabases(controller, "myDB", "hsqldb-raidb1-recovery.xml"); 73 mainVdb = controller.getVirtualDatabase("myDB"); 74 mainVdb.enableAllBackends(); 75 log = mainVdb.getRequestManager().getRecoveryLog(); 77 long firstId = log.getLastTransactionId(); 78 79 con = getCJDBCConnection(); 81 con.setAutoCommit(false); 82 Statement statement2 = con.createStatement(); 83 statement2.executeUpdate("INSERT INTO DOCUMENT VALUES(50,32,5000.60)"); 84 con.rollback(); 85 statement2.close(); 86 87 Statement statement3 = con.createStatement(); 88 con.setAutoCommit(true); 89 ResultSet rs = statement3 90 .executeQuery("Select name from product where id=50"); 91 assertNotNull("Result set should not be null after restarting controller", 92 rs); 93 String myproduct = null; 94 if (rs.next()) 95 myproduct = rs.getString("name"); 96 97 if (myproduct == null || myproduct.equalsIgnoreCase("myproduct") == false) 98 fail("Could not get rigth value for product"); 99 long lastId = log.getLastTransactionId(); 100 101 System.out.println("firstId:" + firstId + ":lastId:" + lastId + "idZero:" 102 + idZero); 103 104 Connection hsqlcon = getHypersonicConnection(9003); 105 ScenarioUtility.displaySingleQueryResult("Select * from RECOVERY", hsqlcon); 106 assertTrue("RecoveryLog firstId should be greater than idZero.", 107 firstId > idZero); 108 assertTrue("RecoveryLog lastId is not properly set with firstId.[" + lastId 109 + "==" + firstId + "]", lastId > firstId + 2); 110 111 statement3.close(); 112 con.close(); 113 } 114 } | Popular Tags |