1 8 package org.jboss.test.jmx.test; 9 10 import java.util.Collection ; 11 import java.util.Collections ; 12 13 import javax.management.MBeanServerConnection ; 14 import javax.management.ObjectName ; 15 16 import org.jboss.monitor.EntityLockMonitor; 17 import org.jboss.system.ServiceControllerMBean; 18 import org.jboss.system.ServiceMBean; 19 import org.jboss.test.JBossTestCase; 20 21 27 28 public class RedeployWithDependencyStressTestCase extends JBossTestCase 29 { 30 public RedeployWithDependencyStressTestCase(String name) 31 { 32 super(name); 33 } 34 35 public void testEarRedeployWithDependency() throws Exception 36 { 37 ObjectName dependent = new ObjectName ("jboss.test:test=RedeployWithDependency"); 38 ObjectName dependee = new ObjectName ("jboss.security.tests:service=WebIntegrationLoginConfig"); 39 String testUrl = "jbosstest-web.ear"; 40 41 MBeanServerConnection server = getServer(); 42 43 createMBean(server, dependent, dependee); 44 try 45 { 46 assertState(ServiceMBean.REGISTERED, dependent); 47 for (int i = 0; i < getIterationCount(); ++i) 48 { 49 try 50 { 51 deploy(testUrl); 52 assertState(ServiceMBean.STARTED, dependent); 53 } 54 finally 55 { 56 undeploy(testUrl); 57 } 58 assertState(ServiceMBean.DESTROYED, dependent); 59 } 60 } 61 finally 62 { 63 removeMBean(server, dependent); 64 } 65 } 66 67 protected void assertState(int expected, ObjectName service) throws Exception 68 { 69 MBeanServerConnection server = getServer(); 70 Integer actual = (Integer ) server.getAttribute(service, "State"); 71 assertEquals("Expected state=" + expected + " actual=" + actual, expected, actual.intValue()); 72 } 73 74 protected void createMBean(MBeanServerConnection server, ObjectName dependent, ObjectName dependee) throws Exception 75 { 76 server.createMBean(EntityLockMonitor.class.getName(), dependent); 77 try 78 { 79 server.invoke(ServiceControllerMBean.OBJECT_NAME, "create", 80 new Object [] 81 { 82 dependent, 83 Collections.singleton(dependee) 84 }, 85 new String [] 86 { 87 ObjectName .class.getName(), 88 Collection .class.getName() 89 } 90 ); 91 server.invoke(ServiceControllerMBean.OBJECT_NAME, "create", 92 new Object [] 93 { 94 dependent 95 }, 96 new String [] 97 { 98 ObjectName .class.getName() 99 } 100 ); 101 } 102 catch (Exception e) 103 { 104 server.unregisterMBean(dependent); 105 throw e; 106 } 107 } 108 109 protected void removeMBean(MBeanServerConnection server, ObjectName dependent) throws Exception 110 { 111 server.unregisterMBean(dependent); 112 } 113 } 114 | Popular Tags |