SF.net SVN: mx4j: [2269] trunk/mx4j

[email protected] Sat, 24 Mar 2007 14:34:27 -0700
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Revision: 2269
          http://svn.sourceforge.net/mx4j/?rev=2269&view=rev
Author:   simonebordet
Date:     2007-03-24 14:34:26 -0700 (Sat, 24 Mar 2007)

Log Message:
-----------
Fixed tests to run under Maven2.

Modified Paths:
--------------
    trunk/mx4j/jsr003/pom.xml
    trunk/mx4j/jsr003/src/main/java/mx4j/server/interceptor/NotificationListenerMBeanServerInterceptor.java
    trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerFactoryTest.java
    trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerTest.java
    trunk/mx4j/jsr003/src/test/java/test/javax/management/QueryTest.java
    trunk/mx4j/jsr003/src/test/java/test/javax/management/loading/MLetTest.java
    trunk/mx4j/pom.xml

Modified: trunk/mx4j/jsr003/pom.xml
===================================================================
--- trunk/mx4j/jsr003/pom.xml	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/jsr003/pom.xml	2007-03-24 21:34:26 UTC (rev 2269)
@@ -19,6 +19,8 @@
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
                     <testExcludes>
+                        <exclude>**/JMXSerializationTest.java</exclude>
+                        <exclude>**/JMXSignatureTest.java</exclude>
                         <exclude>**/SecurityManagerTestCase.java</exclude>
                         <exclude>**/LocalSecurityManagerTest.java</exclude>
                     </testExcludes>

Modified: trunk/mx4j/jsr003/src/main/java/mx4j/server/interceptor/NotificationListenerMBeanServerInterceptor.java
===================================================================
--- trunk/mx4j/jsr003/src/main/java/mx4j/server/interceptor/NotificationListenerMBeanServerInterceptor.java	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/jsr003/src/main/java/mx4j/server/interceptor/NotificationListenerMBeanServerInterceptor.java	2007-03-24 21:34:26 UTC (rev 2269)
@@ -33,6 +33,7 @@
 {
    private final Map wrappers = new HashMap();
    private final Map objectNames = new HashMap();
+   private final Object lock = new Object();
 
    public String getType()
    {
@@ -44,7 +45,7 @@
       if (isEnabled())
       {
          ListenerWrapper wrapper = null;
-         synchronized (wrappers)
+         synchronized (lock)
          {
             ListenerWrapperKey key = new ListenerWrapperKey(listener, metadata.getObjectName());
             wrapper = (ListenerWrapper)wrappers.get(key);
@@ -78,6 +79,7 @@
             }
          }
 
+         // Adding a notification listener never fails
          super.addNotificationListener(metadata, wrapper, filter, handback);
       }
       else
@@ -91,7 +93,7 @@
       if (isEnabled())
       {
          ListenerWrapper wrapper = null;
-         synchronized (wrappers)
+         synchronized (lock)
          {
             ListenerWrapperKey key = new ListenerWrapperKey(listener, metadata.getObjectName());
             wrapper = (ListenerWrapper)wrappers.remove(key);
@@ -115,11 +117,19 @@
       if (isEnabled())
       {
          ListenerWrapper wrapper = null;
-         synchronized (wrappers)
+         ListenerWrapperKey key = new ListenerWrapperKey(listener, metadata.getObjectName());
+         synchronized (lock)
          {
-            ListenerWrapperKey key = new ListenerWrapperKey(listener, metadata.getObjectName());
             wrapper = (ListenerWrapper)wrappers.get(key);
             if (wrapper == null) throw new ListenerNotFoundException("Could not find listener " + listener);
+         }
+
+         // Forward the call to the MBean, to see if the remove operation is successful
+         super.removeNotificationListener(metadata, wrapper, filter, handback);
+
+         // Removal successful, update data structures
+         synchronized (lock)
+         {
             wrapper.decreaseReferenceCount();
             if (wrapper.getReferenceCount() == 0)
             {
@@ -129,7 +139,6 @@
                if (keys.isEmpty()) objectNames.remove(metadata.getObjectName());
             }
          }
-         super.removeNotificationListener(metadata, wrapper, filter, handback);
       }
       else
       {
@@ -145,7 +154,7 @@
          {
             // We must clean up in case the MBean is unregistered
             // and the listeners are not removed
-            synchronized (wrappers)
+            synchronized (lock)
             {
                Set keys = (Set)objectNames.remove(metadata.getObjectName());
                if (keys != null)

Modified: trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerFactoryTest.java
===================================================================
--- trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerFactoryTest.java	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerFactoryTest.java	2007-03-24 21:34:26 UTC (rev 2269)
@@ -13,12 +13,12 @@
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 
-import junit.framework.TestCase;
+import test.mx4j.MX4JTestCase;
 
 /**
  * @version $Revision$
  */
-public class MBeanServerFactoryTest extends TestCase
+public class MBeanServerFactoryTest extends MX4JTestCase
 {
     public void testCreate() throws Exception
     {

Modified: trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerTest.java
===================================================================
--- trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerTest.java	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/jsr003/src/test/java/test/javax/management/MBeanServerTest.java	2007-03-24 21:34:26 UTC (rev 2269)
@@ -8,7 +8,6 @@
 
 package test.javax.management;
 
-import java.io.File;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Set;
@@ -327,9 +326,9 @@
       Object mbean1 = server.instantiate(className, null, new Object[0], new String[0]);
 
       // Register one classloader mbean
-      File file = new File("dist/test/mx4j-tests.jar");
+      URL location = getClass().getProtectionDomain().getCodeSource().getLocation();
       ClassLoader parent = getClass().getClassLoader().getParent();
-      ClassLoaderSupport loader = new ClassLoaderSupport(new URL[]{file.toURL()}, parent);
+      ClassLoaderSupport loader = new ClassLoaderSupport(new URL[]{location}, parent);
       ObjectName loaderName = new ObjectName(":type=ClassLoader");
       server.registerMBean(loader, loaderName);
 

Modified: trunk/mx4j/jsr003/src/test/java/test/javax/management/QueryTest.java
===================================================================
--- trunk/mx4j/jsr003/src/test/java/test/javax/management/QueryTest.java	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/jsr003/src/test/java/test/javax/management/QueryTest.java	2007-03-24 21:34:26 UTC (rev 2269)
@@ -226,7 +226,7 @@
       result =
       server.queryMBeans(null,
                          Query.eq(Query.classattr(),
-                                  Query.value("test.javax.management.support.QuerySupport$Test")));
+                                  Query.value("test.javax.management.support.QuerySupport$StandardTestBean")));
       assertEquals(3, result.size());
    }
 
@@ -447,13 +447,13 @@
       server.registerMBean(c, name3);
       Set result =
               server.queryMBeans(null,
-                                 Query.eq(Query.attr("test.javax.management.support.QuerySupport$Test",
+                                 Query.eq(Query.attr("test.javax.management.support.QuerySupport$StandardTestBean",
                                                      "Number"),
                                           Query.value(2)));
       assertEquals(1, result.size());
       result =
       server.queryMBeans(null,
-                         Query.eq(Query.attr("test.javax.management.support.QuerySupport.Test2",
+                         Query.eq(Query.attr("test.javax.management.support.QuerySupport$NonExistingInnerClass",
                                              "Number"),
                                   Query.value(2)));
       assertEquals(0, result.size());

Modified: trunk/mx4j/jsr003/src/test/java/test/javax/management/loading/MLetTest.java
===================================================================
--- trunk/mx4j/jsr003/src/test/java/test/javax/management/loading/MLetTest.java	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/jsr003/src/test/java/test/javax/management/loading/MLetTest.java	2007-03-24 21:34:26 UTC (rev 2269)
@@ -461,7 +461,12 @@
         MBeanServer server = newMBeanServer();
 
         ObjectName mletName = new ObjectName(":loader=mlet1");
-        MLet mlet = new MLet(new URL[0], false);
+        // The MLet loads from the jar, but also needs JMX classes,
+        // which are not in the system classpath, but in Maven Surefire classloader
+        // This of course defeats the use of the jar, since classes in the jar will
+        // not be used as the MLet parent classloader also has the same classes,
+        // but the MLet file format requires a jar.
+        MLet mlet = new MLet(new URL[0], getClass().getClassLoader());
         server.registerMBean(mlet, mletName);
 
         Set mbeans = mlet.getMBeansFromURL(mletFile.toURL());

Modified: trunk/mx4j/pom.xml
===================================================================
--- trunk/mx4j/pom.xml	2007-03-23 14:29:39 UTC (rev 2268)
+++ trunk/mx4j/pom.xml	2007-03-24 21:34:26 UTC (rev 2269)
@@ -53,6 +53,7 @@
                     <artifactId>maven-surefire-plugin</artifactId>
                     <configuration>
                         <jvm>${java.home}/bin/java</jvm>
+                        <forkMode>always</forkMode>
                     </configuration>
                 </plugin>
                 <plugin>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV