1 24 25 package org.objectweb.cjdbc.scenario.templates; 26 27 import org.objectweb.cjdbc.controller.core.Controller; 28 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase; 29 import org.objectweb.cjdbc.scenario.tools.ScenarioConstants; 30 import org.objectweb.cjdbc.scenario.tools.components.ComponentInterface; 31 import org.objectweb.cjdbc.scenario.tools.components.backend.DatabaseManager; 32 import org.objectweb.cjdbc.scenario.tools.components.controller.ControllerManager; 33 34 40 public class SimpleHorizontalTemplate extends Template 41 { 42 protected ControllerManager cm = new ControllerManager(); 43 protected DatabaseManager hm = new DatabaseManager(); 44 protected ComponentInterface hm1 = null, hm2 = null, hm3 = null, hm4 = null; 45 protected Controller controller1 = null, controller2 = null; 46 protected VirtualDatabase mainVdb1 = null, mainVdb2 = null; 47 protected String port1 = "25322"; 48 protected String port2 = "25323"; 49 50 53 protected void setUp() 54 { 55 try 56 { 57 hm1 = hm.start("9001"); 59 hm.loaddatabase("9001"); 60 hm2 = hm.start("9002"); 61 hm.loaddatabase("9002"); 62 hm3 = hm.start("9003"); 63 hm.loaddatabase("9003"); 64 hm4 = hm.start("9004"); 65 hm.loaddatabase("9004"); 66 67 controller1 = (Controller) cm.start(port1).getProcess(); 70 controller2 = (Controller) cm.start(port2).getProcess(); 72 } 73 catch (Exception e) 74 { 75 e.printStackTrace(); 76 } 77 } 78 79 protected void setDatabasesUp(String databaseFileDesc) throws Exception 80 { 81 cm.loaddatabase(port1,databaseFileDesc+"-1.xml"); 82 mainVdb1 = controller1.getVirtualDatabase("myDB"); 83 mainVdb1.enableAllBackends(); 84 85 cm.loaddatabase(port2,databaseFileDesc+"-2.xml"); 86 mainVdb2 = controller2.getVirtualDatabase("myDB"); 87 mainVdb2.enableAllBackends(); 88 } 89 90 93 protected void tearDown() 94 { 95 System.out.println("Tearing down horizontal template"); 96 cm.stopAll(); 97 hm.stopAll(); 98 99 int total = (int) ScenarioConstants.WAIT_TIME_BETWEEN_HORIZONTAL_TEST 100 / ScenarioConstants.WAIT_TIME_REFRESH_HORIZONTAL_TEST; 101 System.out.println("Waiting for jgroup to close(" + total + "):"); 102 synchronized (this) 103 { 104 for (int i = 0; i < total; i++) 105 { 106 try 107 { 108 System.out.println("*"); 109 System.out.flush(); 110 wait(ScenarioConstants.WAIT_TIME_REFRESH_HORIZONTAL_TEST); 111 } 112 catch (InterruptedException e) 113 { 114 e.printStackTrace(); 115 break; 116 } 117 } 118 } 119 System.out.println("Supposing all jgroups thread have timed out"); 120 } 121 122 } | Popular Tags |