1 22 package org.jboss.test.cluster.jmx.test; 23 24 import org.jboss.invocation.ServiceUnavailableException; 25 import org.jboss.jmx.adaptor.rmi.RMIAdaptor; 26 import org.jboss.test.JBossClusteredTestCase; 27 import org.jboss.test.jmx.ha.HAServiceRemote; 28 29 import junit.framework.Test; 30 31 37 public class HAInvokerUnitTestCase 38 extends JBossClusteredTestCase 39 { 40 private boolean deployed0_ = true; 41 private boolean deployed1_ = true; 42 43 public HAInvokerUnitTestCase(String name) 44 { 45 super(name); 46 } 47 48 public static Test suite() 49 throws Exception 50 { 51 return JBossClusteredTestCase.getDeploySetup(HAInvokerUnitTestCase.class, "ha-invoker.sar"); 52 } 53 54 public void testHAProxyFailover() 55 throws Exception 56 { 57 getLog().debug("testHAProxyFailover"); 58 59 HAServiceRemote remote = (HAServiceRemote) getInitialContext().lookup("jmx/HAService"); 60 assertEquals("Hello", remote.hello()); 61 String nodeA = remote.getClusterNode(); 62 assertNotNull("Got clusterNode", nodeA); 63 assertFalse("Requests load balanced", nodeA.equals(remote.getClusterNode())); 65 66 reconfigureCluster(); 68 69 try 71 { 72 assertEquals("Hello", remote.hello()); 73 } 74 catch (ServiceUnavailableException sue) 75 { 76 fail("Known issue JBAS-3194: " + sue.getMessage()); 77 } 78 } 79 80 protected void setUp() throws Exception 81 { 82 super.setUp(); 83 configureCluster(); 84 } 85 86 protected String getDeploymentName() 87 { 88 return "ha-invoker.sar"; 89 } 90 91 protected void configureCluster() throws Exception 92 { 93 RMIAdaptor[] adaptors = getAdaptors(); 94 String warName = getDeploymentName(); 95 if (!deployed0_) 96 { 97 deploy(adaptors[0], warName); 98 getLog().debug("Deployed " + warName + " on server0"); 99 deployed0_ = true; 100 } 101 if (!deployed1_) 102 { 103 deploy(adaptors[1], warName); 104 getLog().debug("Deployed " + warName + " on server1"); 105 deployed1_ = true; 106 } 107 108 sleep(2000); 109 } 110 111 protected void reconfigureCluster() throws Exception 112 { 113 RMIAdaptor[] adaptors = getAdaptors(); 114 if (!deployed1_) 115 { 116 deploy(adaptors[1], getDeploymentName()); 117 deployed1_ = true; 118 119 sleep(2000); 120 } 121 122 if (deployed0_) 123 { 124 undeploy(adaptors[0], getDeploymentName()); 125 deployed0_ = false; 126 127 sleep(2000); 128 } 129 } 130 131 } 132 | Popular Tags |