[jboss-cvs] JBossAS SVN: r85234 - in projects/jboss-osgi/trunk: runtime/spi/src/main/java/org/jboss/osgi/spi/management and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 4 11:04:36 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-03-04 11:04:36 -0500 (Wed, 04 Mar 2009)
New Revision: 85234

Modified:
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java
Log:
[JBOSGI-38] verify remote bundle state

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java	2009-03-04 16:03:33 UTC (rev 85233)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java	2009-03-04 16:04:36 UTC (rev 85234)
@@ -27,6 +27,10 @@
 
 import javax.management.MBeanServerConnection;
 
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.ManagedBundleMBean;
+import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
+
 /**
  * An integration test case
  * 
@@ -66,6 +70,11 @@
       getDelegate().deploy(archive);
    }
 
+   protected ManagedBundleMBean deployBundle(String bundleName) throws Exception
+   {
+      return getDelegate().deployBundle(bundleName);
+   }
+   
    protected void undeploy(String archive) throws Exception
    {
       getDelegate().undeploy(archive);

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java	2009-03-04 16:03:33 UTC (rev 85233)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java	2009-03-04 16:04:36 UTC (rev 85234)
@@ -31,6 +31,9 @@
 
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.ManagedBundleMBean;
+import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
 
 /**
  * An integration test helper that deals with test deployment/undeployment, etc.
@@ -42,6 +45,7 @@
 {
    private static MBeanServerConnection server;
    private OSGiBootstrapProvider bootProvider;
+   private ManagedFrameworkMBean managedFramework;
    private String integrationTarget;
 
    public IntegrationTestHelper(OSGiBootstrapProvider bootProvider)
@@ -133,6 +137,16 @@
       }
    }
 
+   public ManagedBundleMBean deployBundle(String bundleName) throws Exception
+   {
+      if (managedFramework == null)
+         managedFramework = MBeanProxy.get(ManagedFrameworkMBean.class, ManagedFrameworkMBean.OBJECT_NAME, getServer());
+      
+      deploy(bundleName + ".jar");
+      
+      return MBeanProxy.get(ManagedBundleMBean.class, managedFramework.getBundle(bundleName), getServer());
+   }
+   
    public static boolean isRemoteIntegration()
    {
       return System.getProperty("jboss.bind.address") != null;

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java	2009-03-04 16:03:33 UTC (rev 85233)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java	2009-03-04 16:04:36 UTC (rev 85234)
@@ -52,9 +52,9 @@
 public class MBeanProxy
 {
   @SuppressWarnings( { "unchecked" })
-  public static Object get(Class interf, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
+  public static <T> T get(Class<T> interf, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
   {
-    return get(new Class[] { interf }, name, server);
+    return (T)get(new Class[] { interf }, name, server);
   }
 
   @SuppressWarnings( { "unchecked" })
@@ -118,9 +118,12 @@
     {
       try
       {
-        if (server == null)
-          throw new MBeanProxyException("null agent reference");
+         if (server == null)
+            throw new MBeanProxyException("null agent reference");
 
+         if (name == null)
+            throw new MBeanProxyException("null object name");
+
         this.server = server;
         this.objectName = name;
 

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java	2009-03-04 16:03:33 UTC (rev 85233)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java	2009-03-04 16:04:36 UTC (rev 85234)
@@ -40,8 +40,6 @@
  */
 public class ManagedFramework implements ManagedFrameworkMBean
 {
-   private static final String OBJECT_NAME = "jboss.osgi:service=ManagedFramework";
-
    // Provide logging
    final Logger log = Logger.getLogger(ManagedFramework.class);
 
@@ -53,6 +51,21 @@
    }
 
    @SuppressWarnings("unchecked")
+   public ObjectName getBundle(String symbolicName)
+   {
+      ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":bundle=" + symbolicName + ",*");
+      Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
+      
+      if (names.size() < 1)
+         return null;
+
+      if (names.size() > 1)
+         throw new IllegalArgumentException("Multiple bundles found: " + names);
+
+      return names.iterator().next();
+   }
+
+   @SuppressWarnings("unchecked")
    public Set<ObjectName> getBundles()
    {
       // [JBAS-6571] JMX filtering does not work with wildcards
@@ -84,11 +97,11 @@
       try
       {
          if (mbeanServer != null)
-            mbeanServer.registerMBean(this, ObjectNameFactory.create(OBJECT_NAME));
+            mbeanServer.registerMBean(this, ManagedFrameworkMBean.OBJECT_NAME);
       }
       catch (Exception ex)
       {
-         log.warn("Cannot register: " + OBJECT_NAME);
+         log.warn("Cannot register: " + ManagedFrameworkMBean.OBJECT_NAME);
       }
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java	2009-03-04 16:03:33 UTC (rev 85233)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java	2009-03-04 16:04:36 UTC (rev 85234)
@@ -35,8 +35,16 @@
  */
 public interface ManagedFrameworkMBean
 {
-  /**
-   * Get the list of all installed bundles
-   */
-  Set<ObjectName> getBundles();
+   /** The default object name: jboss.osgi:service=ManagedFramework */
+   static final ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.osgi:service=ManagedFramework");
+
+   /**
+    * Get the list of all installed bundles
+    */
+   Set<ObjectName> getBundles();
+   
+   /**
+    * Get the installed bundle 
+    */
+   ObjectName getBundle(String symbolicName);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java	2009-03-04 16:03:33 UTC (rev 85233)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi38/OSGI38DeployerTestCase.java	2009-03-04 16:04:36 UTC (rev 85234)
@@ -25,6 +25,8 @@
 
 import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 import org.jboss.osgi.spi.junit.IntegrationTest;
+import org.jboss.osgi.spi.management.ManagedBundleMBean;
+import org.osgi.framework.Bundle;
 
 /**
  * [JBOSGI-38] Investigate bundle install/start behaviour with random deployment order
@@ -54,7 +56,10 @@
     */
    public void testInstallStartX() throws Exception
    {
-      deploy("jbosgi38-bundleX.jar");
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      
       undeploy("jbosgi38-bundleX.jar");
    }
 
@@ -63,9 +68,12 @@
     */
    public void testInstallXBeforeB() throws Exception
    {
-      deploy("jbosgi38-bundleX.jar");
-      deploy("jbosgi38-bundleB.jar");
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
       
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleB.getState());
+      
       undeploy("jbosgi38-bundleB.jar");
       undeploy("jbosgi38-bundleX.jar");
    }
@@ -75,10 +83,14 @@
     */
    public void testInstallBBeforeA() throws Exception
    {
-      deploy("jbosgi38-bundleX.jar");
-      deploy("jbosgi38-bundleB.jar");
-      deploy("jbosgi38-bundleA.jar");
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
+      ManagedBundleMBean bundleA = deployBundle("jbosgi38-bundleA");
       
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleB.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleA.getState());
+      
       undeploy("jbosgi38-bundleA.jar");
       undeploy("jbosgi38-bundleB.jar");
       undeploy("jbosgi38-bundleX.jar");
@@ -89,9 +101,15 @@
     */
    public void testInstallBBeforeX() throws Exception
    {
-      deploy("jbosgi38-bundleB.jar");
-      deploy("jbosgi38-bundleX.jar");
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
       
+      assertEquals("Bundle installed", Bundle.INSTALLED, bundleB.getState());
+      
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleB.getState());
+      
       undeploy("jbosgi38-bundleX.jar");
       undeploy("jbosgi38-bundleB.jar");
    }
@@ -101,10 +119,20 @@
     */
    public void testInstallABeforeB() throws Exception
    {
-      deploy("jbosgi38-bundleA.jar");
-      deploy("jbosgi38-bundleB.jar");
-      deploy("jbosgi38-bundleX.jar");
+      ManagedBundleMBean bundleA = deployBundle("jbosgi38-bundleA");
       
+      assertEquals("Bundle installed", Bundle.INSTALLED, bundleA.getState());
+      
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
+      
+      assertEquals("Bundle installed", Bundle.INSTALLED, bundleB.getState());
+      
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleB.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleA.getState());
+      
       undeploy("jbosgi38-bundleX.jar");
       undeploy("jbosgi38-bundleB.jar");
       undeploy("jbosgi38-bundleA.jar");




More information about the jboss-cvs-commits mailing list