1 24 25 package org.objectweb.cjdbc.scenario.raidb1; 26 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 import java.sql.SQLException ; 30 import java.sql.Statement ; 31 32 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb1Template; 33 34 41 public class Raidb1BasicFailoverScenario extends SimpleRaidb1Template 42 { 43 46 public void testFailOverWithVariablePool() 47 { 48 try 49 { 50 cm.loadVirtualDatabases(controller, "myDB", 52 "hsqldb-raidb1-variablepool.xml"); 53 mainVdb = controller.getVirtualDatabase("myDB"); 54 mainVdb.enableAllBackends(); 55 execute(); 56 } 57 catch (Exception e) 58 { 59 e.printStackTrace(); 60 fail("failed to test c-jdbc failover in variable pool"); 61 } 62 } 63 64 67 public void testFailOverWithRandomWaitPool() 68 { 69 try 70 { 71 cm.loadVirtualDatabases(controller, "myDB", 73 "hsqldb-raidb1-randomwaitpool.xml"); 74 mainVdb = controller.getVirtualDatabase("myDB"); 75 mainVdb.enableAllBackends(); 76 execute(); 77 } 78 catch (Exception e) 79 { 80 e.printStackTrace(); 81 fail("failed to test c-jdbc failover in random wait pool"); 82 } 83 } 84 85 88 public void testFailOverWithFailFastPool() 89 { 90 try 91 { 92 cm.loadVirtualDatabases(controller, "myDB", 94 "hsqldb-raidb1-failfastpool.xml"); 95 mainVdb = controller.getVirtualDatabase("myDB"); 96 mainVdb.enableAllBackends(); 97 execute(); 98 } 99 catch (Exception e) 100 { 101 e.printStackTrace(); 102 fail("failed to test c-jdbc failover in fail fast wait pool"); 103 } 104 } 105 106 109 public void testFailOverWithNoPool() 110 { 111 try 112 { 113 cm.loadVirtualDatabases(controller, "myDB", "hsqldb-raidb1-nopool.xml"); 115 mainVdb = controller.getVirtualDatabase("myDB"); 116 mainVdb.enableAllBackends(); 117 execute(); 118 } 119 catch (Exception e) 120 { 121 e.printStackTrace(); 122 fail("failed to test c-jdbc failover in simple connection manager"); 123 } 124 } 125 126 129 private void execute() throws Exception 130 { 131 Connection con = getCJDBCConnection(); 133 assertNotNull("Connection is null", con); 134 Statement statement = con.createStatement(); 135 ResultSet rs1 = statement.executeQuery("Select * from document"); 136 assertNotNull("ResultSet is null", rs1); 137 138 hm.stop(hm1); 140 141 synchronized (this) 143 { 144 wait(1000); 145 } 146 147 Statement statement2 = con.createStatement(); 149 ResultSet rs2 = statement2.executeQuery("Select * from document"); 150 assertNotNull("ResultSet after failover is null", rs2); 151 rs1.last(); 152 rs2.last(); 153 assertTrue("Row numbers are different", rs1.getRow() == rs2.getRow()); 154 rs1.first(); 155 rs2.first(); 156 while (rs1.next() & rs2.next()) 157 { 158 assertTrue("Some result differs from expect result set", rs1.getString( 159 "id").equals(rs2.getString("id"))); 160 } 161 162 hm.stop(hm2); 164 165 synchronized (this) 167 { 168 wait(1000); 169 } 170 Statement statement3 = con.createStatement(); 172 ResultSet rs3 = null; 173 try 174 { 175 rs3 = statement3.executeQuery("Select * from document"); 176 } 177 catch (SQLException expected) 178 { 179 } 181 assertNull("Should not be able to get a result set anymore", rs3); 182 } 183 } 184 | Popular Tags |