1 22 package org.jboss.test.binding; 23 24 import java.util.ArrayList ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Properties ; 28 import java.util.Set ; 29 30 import javax.management.AttributeNotFoundException ; 31 import javax.management.ObjectName ; 32 import javax.naming.Context ; 33 import javax.naming.InitialContext ; 34 35 import org.jboss.jmx.adaptor.rmi.RMIAdaptorExt; 36 import org.jboss.management.j2ee.StateManageable; 37 import org.jboss.system.BarrierController; 38 import org.jboss.system.ServiceMBean; 39 import org.jboss.test.JBossTestCase; 40 41 48 public class BindingServiceUnitTestCase 49 extends JBossTestCase 50 { 51 static final String SERVER0_JNDI_URL = "jnp://" + System.getProperty("jbosstest.server.host", "localhost") + ":1199"; 52 static final String SERVER1_JNDI_URL = "jnp://" + System.getProperty("jbosstest.server.host", "localhost") + ":1299"; 53 static HashSet VALID_STATES = new HashSet (); 54 55 static 56 { 57 VALID_STATES.add("j2ee.state.running"); 59 VALID_STATES.add("Started"); 61 } 62 public BindingServiceUnitTestCase(String name) 63 { 64 super(name); 65 } 66 67 73 public void testAvailableServicesServer0() 74 throws Exception 75 { 76 int count = testAvailableServices(SERVER0_JNDI_URL); 77 log.info("server0 service count:"+count); 78 } 79 public void testAvailableServicesServer1() 80 throws Exception 81 { 82 int count = testAvailableServices(SERVER1_JNDI_URL); 83 log.info("server1 service count:"+count); 84 } 85 86 private int testAvailableServices(String jndiURL) 87 throws Exception 88 { 89 log.info("+++ testAvailableServices, jndiURL="+jndiURL); 90 91 Properties env = new Properties (); 92 env.setProperty(Context.PROVIDER_URL, jndiURL); 93 InitialContext ctx = new InitialContext (env); 94 RMIAdaptorExt server = (RMIAdaptorExt) ctx.lookup("jmx/invoker/RMIAdaptor"); 95 ObjectName all = new ObjectName ("*:*"); 96 Set allNames = server.queryNames(all, null); 97 ArrayList serverErrors = new ArrayList (); 98 Iterator names = allNames.iterator(); 99 int serviceCount = 0; 100 while( names.hasNext() ) 101 { 102 ObjectName name = (ObjectName ) names.next(); 103 try 104 { 105 boolean isBarrier = server.isInstanceOf(name, BarrierController.Barrier.class.getName()); 109 if( isBarrier ) 110 { 111 log.debug("Skipping BarrierController.Barrier service: '" + name 112 + "', in state: " + (String ) server.getAttribute(name, "StateString")); 113 continue; 114 } 115 118 boolean jsr77State = server.isInstanceOf(name, StateManageable.class.getName()); 119 if( jsr77State ) 120 { 121 Boolean flag = (Boolean ) server.getAttribute(name, "stateManageable"); 123 jsr77State = flag.booleanValue(); 124 } 125 boolean mbeanService = server.isInstanceOf(name, ServiceMBean.class.getName()); 126 if( jsr77State == true || mbeanService == true ) 127 { 128 serviceCount ++; 129 String state = (String ) server.getAttribute(name, "StateString"); 130 if( VALID_STATES.contains(state) == false ) 131 { 132 String msg = name+" is not Started, state="+state; 133 log.error(msg); 134 serverErrors.add(msg); 135 } 136 } 137 } 138 catch(AttributeNotFoundException e) 139 { 140 } 142 } 143 assertTrue("All services are started, errors=" 144 +serverErrors.size(), serverErrors.size() == 0); 145 return serviceCount; 146 } 147 148 151 public void testServerFound() 152 { 153 } 154 } 155 | Popular Tags |