1 24 25 package org.objectweb.cjdbc.scenario.raidb1.recoverylog; 26 27 import java.sql.Connection ; 28 import java.util.ArrayList ; 29 30 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate; 31 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 32 import org.objectweb.cjdbc.scenario.tools.util.RequestSender; 33 34 40 public class TransactionReplayScenario extends Raidb1RecoveryTemplate 41 { 42 43 static final int LOOPS = 500; 44 45 50 public void testReplayMissingRequestsNoTransactionNoConcurrentRequest() 51 throws Exception 52 { 53 executeTestReplay(false, false, LOOPS, 1); 54 } 55 56 61 public void testReplayMissingRequestsTransactionAndConcurrentRequests() 62 throws Exception 63 { 64 executeTestReplay(true, true, LOOPS, 1); 65 } 66 67 75 private void executeTestReplay(boolean concurrent, boolean transaction, 76 int loops, int clients) throws Exception 77 { 78 Connection con = getCJDBCConnection(); 80 String sql = "select * from document"; 81 ArrayList list = ScenarioUtility.getSingleQueryResult(sql, con); 82 ArrayList emptyList = new ArrayList (); 83 assertNotSame("Empty list after requests", list, emptyList); 84 85 String backend = "localhost2"; 87 String checkpoint = "check" + System.currentTimeMillis(); 88 mainVdb.disableBackendWithCheckpoint(backend); 89 90 ArrayList threads = new ArrayList (); 92 for (int i = 0; i < clients; i++) 93 { 94 RequestSender rs = new RequestSender(con); 95 rs.setUseTransactions(transaction); 96 rs.setDoWriteEvery(1); rs.setLoopInThread(loops); 98 Thread t = new Thread (rs); 99 threads.add(t); 100 t.start(); 101 rs.setQuit(true); 102 } 103 104 if (!concurrent) 105 joinThreads(threads); 106 107 ArrayList listaafter = ScenarioUtility.getSingleQueryResult(sql, con); 109 assertNotSame("No Updates after requests", list, listaafter); 110 111 Connection h3 = getHypersonicConnection(9003); 113 ArrayList recovery = ScenarioUtility.getSingleQueryResult( 114 "select * from recovery", h3); 115 ScenarioUtility.displayResultOnScreen(recovery); 116 117 mainVdb.enableBackendFromCheckpoint(backend, checkpoint); 119 120 if (!concurrent) 121 joinThreads(threads); 122 123 Connection h1 = getHypersonicConnection(9001); 125 ArrayList hl1 = ScenarioUtility.getSingleQueryResult(sql, h1); 126 Connection h2 = getHypersonicConnection(9002); 127 ArrayList hl2 = ScenarioUtility.getSingleQueryResult(sql, h2); 128 129 assertEquals("Backend is missing some updates", hl1, hl2); 131 } 132 133 139 private void joinThreads(ArrayList threads) throws Exception 140 { 141 for (int i = 0; i < threads.size(); i++) 142 ((Thread ) threads.get(i)).join(); 143 } 144 145 146 } 147 | Popular Tags |