1 24 25 package org.objectweb.cjdbc.scenario.horizontal; 26 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 import java.sql.Statement ; 30 31 import org.objectweb.cjdbc.driver.ControllerInfo; 32 import org.objectweb.cjdbc.scenario.templates.HorizontalTemplate; 33 34 40 public class BasicHorizontalScalabilityScenario extends HorizontalTemplate 41 { 42 43 48 public void testAvailability() throws Exception 49 { 50 ControllerInfo[] controllers = new ControllerInfo[]{ 51 new ControllerInfo("localhost", 25322), 52 new ControllerInfo("localhost", 25323)}; 53 Connection con = getCJDBCConnection(controllers); 54 Statement statement = con.createStatement(); 55 ResultSet rs = statement.executeQuery("Select * from document"); 56 assertNotNull("ResultSet before failure is null", rs); 57 cm.stop(controller1.getPortNumber()); 58 59 assertFalse("Controller1 should be stopped now", cm.isStarted("25322")); 60 61 Statement statement2 = con.createStatement(); 62 ResultSet rs2 = statement2 63 .executeQuery("Select * from document where id='0'"); 64 assertNotNull("ResultSet after failure is null", rs2); 65 } 66 67 72 public void testNonAvailability() throws Exception 73 { 74 ControllerInfo[] controllers = new ControllerInfo[]{new ControllerInfo( 75 "localhost", 25322)}; 76 Connection con = getCJDBCConnection(controllers); 77 Statement statement = con.createStatement(); 78 ResultSet rs = statement.executeQuery("Select * from document"); 79 assertNotNull("ResultSet before failure is null", rs); 80 cm.stop(controller1.getPortNumber()); 81 82 assertFalse("Controller1 should be stopped now", cm.isStarted("25322")); 83 84 Statement statement2 = con.createStatement(); 85 Exception notexpected = null; 86 try 87 { 88 statement2.executeQuery("Select * from document where id='0'"); 89 } 90 catch (Exception e) 91 { 92 notexpected = e; 93 } 94 assertNotNull("Should not switch to other controller [not in URL]", 95 notexpected); 96 } 97 98 } | Popular Tags |