1 24 25 package org.objectweb.cjdbc.scenario.tools.testlet; 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.tools.components.ComponentInterface; 33 34 40 public class FailoverOn2BackendsTestLet extends AbstractConnectionTestLet 41 { 42 43 48 public FailoverOn2BackendsTestLet(Connection con) 49 { 50 super(con); 51 } 52 53 56 public void execute() throws Exception 57 { 58 59 Object [] co = (Object [])config.get(LIST_FAILOVER_BACKENDS); 60 if(co ==null || co.length<2) 61 throw new Exception ("Failover needs at least two backends"); 62 63 ComponentInterface hm1 = (ComponentInterface)co[0]; 64 ComponentInterface hm2 = (ComponentInterface)co[1]; 65 66 Statement statement = jdbcConnection.createStatement(); 67 ResultSet rs1 = statement.executeQuery("Select * from document"); 68 assertNotNull("ResultSet is null", rs1); 69 70 hm1.release(); 72 73 Statement statement2 = jdbcConnection.createStatement(); 75 ResultSet rs2 = statement2.executeQuery("Select * from document"); 76 assertNotNull("ResultSet after failover is null", rs2); 77 rs1.last(); 78 rs2.last(); 79 assertTrue("Row numbers are different", rs1.getRow() == rs2.getRow()); 80 rs1.first(); 81 rs2.first(); 82 while (rs1.next() & rs2.next()) 83 { 84 assertTrue("Some result differs from expect result set", rs1.getString( 85 "id").equals(rs2.getString("id"))); 86 } 87 88 hm2.release(); 90 91 Statement statement3 = jdbcConnection.createStatement(); 93 ResultSet rs3 = null; 94 try 95 { 96 rs3 = statement3.executeQuery("Select * from document"); 97 } 98 catch (SQLException expected) 99 { 100 } 102 assertNull("Should not be able to get a result set anymore", rs3); 103 104 } 105 106 } 107 | Popular Tags |