Author: thomas.diesler(a)jboss.com
Date: 2010-04-06 07:07:48 -0400 (Tue, 06 Apr 2010)
New Revision: 103565
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/impl/src/test/java/org/jboss/test/osgi/jmx/AbstractJMXTestCase.java
Log:
Fix dependency on jboss-osg-jmx
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/impl/src/test/java/org/jboss/test/osgi/jmx/AbstractJMXTestCase.java
===================================================================
---
projects/jboss-osgi/projects/bundles/jmx/trunk/impl/src/test/java/org/jboss/test/osgi/jmx/AbstractJMXTestCase.java 2010-04-06
10:57:16 UTC (rev 103564)
+++
projects/jboss-osgi/projects/bundles/jmx/trunk/impl/src/test/java/org/jboss/test/osgi/jmx/AbstractJMXTestCase.java 2010-04-06
11:07:48 UTC (rev 103565)
@@ -31,14 +31,18 @@
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
+import org.jboss.logging.Logger;
import org.jboss.osgi.jmx.FrameworkMBeanExt;
import org.jboss.osgi.jmx.MBeanProxy;
import org.jboss.osgi.jmx.ObjectNameFactory;
import org.jboss.osgi.jmx.ServiceStateMBeanExt;
import org.jboss.osgi.testing.OSGiFrameworkTest;
-import org.jboss.osgi.testing.OSGiTestHelper;
+import org.junit.Before;
import org.junit.BeforeClass;
+import org.osgi.framework.Bundle;
import org.osgi.jmx.framework.BundleStateMBean;
+import org.osgi.jmx.framework.FrameworkMBean;
+import org.osgi.jmx.framework.ServiceStateMBean;
/**
* An abstract JMX test case.
@@ -48,16 +52,28 @@
*/
public abstract class AbstractJMXTestCase extends OSGiFrameworkTest
{
+ // Provide logging
+ private static final Logger log = Logger.getLogger(AbstractJMXTestCase.class);
+
private MBeanServer server;
@BeforeClass
public static void setUpClass() throws Exception
{
+ // Install/Start the jboss-osgi-jmx bundle
String bundleName = System.getProperty("project.build.finalName");
URL bundleURL = new File("target/" + bundleName +
".jar").toURI().toURL();
- systemContext.installBundle(bundleURL.toExternalForm());
+ Bundle bundle = systemContext.installBundle(bundleURL.toExternalForm());
+ bundle.start();
}
+ @Before
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ assertMBeanRegistration(true);
+ }
+
protected FrameworkMBeanExt getFrameworkMBean() throws Exception
{
ObjectName oname = ObjectNameFactory.create(FrameworkMBeanExt.OBJECTNAME);
@@ -92,4 +108,47 @@
}
return server;
}
+
+ private void assertMBeanRegistration(boolean state)
+ {
+ log.debug("assertMBeanRegistration: " + state);
+
+ MBeanServer server = (MBeanServer)getMBeanServer();
+ ObjectName fwkName = ObjectNameFactory.create(FrameworkMBean.OBJECTNAME);
+ ObjectName bndName = ObjectNameFactory.create(BundleStateMBean.OBJECTNAME);
+ ObjectName srvName = ObjectNameFactory.create(ServiceStateMBean.OBJECTNAME);
+
+ int timeout = 5000;
+ while (0 < (timeout -= 200))
+ {
+ boolean fwkCheck = checkMBean(server, fwkName, state);
+ boolean bndCheck = checkMBean(server, bndName, state);
+ boolean srvCheck = checkMBean(server, srvName, state);
+ if (fwkCheck == true && bndCheck == true && srvCheck == true)
+ break;
+
+ try
+ {
+ Thread.sleep(200);
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+ }
+
+ if (checkMBean(server, fwkName, state) == false)
+ log.warn("FrameworkMBean " + (state ? "not" :
"still") + " registered");
+ if (checkMBean(server, bndName, state) == false)
+ log.warn("BundleStateMBean " + (state ? "not" :
"still") + " registered");
+ if (checkMBean(server, srvName, state) == false)
+ log.warn("ServiceStateMBean " + (state ? "not" :
"still") + " registered");
+ }
+
+ private boolean checkMBean(MBeanServer server, ObjectName oname, boolean state)
+ {
+ boolean registered = server.isRegistered(oname);
+ log.debug(oname + " registered: " + registered);
+ return registered == state;
+ }
}
\ No newline at end of file
Show replies by date