User: juhalindfors
  Date: 02/03/12 07:04:24

  Modified:    src/main/test/compliance/server MBeanServerTEST.java
                        ServerSUITE.java
  Added:       src/main/test/compliance/server MBeanDelegateTEST.java
  Log:
  merge testsuite from 1.1 branch up to RelMXTest_1_0_0_1
  
  Revision  Changes    Path
  1.7       +265 -5    jmx/src/main/test/compliance/server/MBeanServerTEST.java
  
  Index: MBeanServerTEST.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/test/compliance/server/MBeanServerTEST.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MBeanServerTEST.java      28 Feb 2002 20:08:51 -0000      1.6
  +++ MBeanServerTEST.java      12 Mar 2002 15:04:24 -0000      1.7
  @@ -22,9 +22,22 @@
   import javax.management.RuntimeOperationsException;
   import javax.management.ReflectionException;
   import javax.management.InvalidAttributeValueException;
  +import javax.management.NotificationListener;
  +import javax.management.NotificationFilter;
  +import javax.management.NotificationFilterSupport;
  +import javax.management.MBeanServerNotification;
  +import javax.management.MBeanRegistrationException;
  +import javax.management.Notification;
  +import javax.management.ObjectInstance;
   
   import test.compliance.server.support.Test;
   import test.compliance.server.support.TestMBean;
  +import test.compliance.server.support.LockedTest;
  +import test.compliance.server.support.LockedTestMBean;
  +import test.compliance.server.support.LockedTest2;
  +import test.compliance.server.support.LockedTest2MBean;
  +import test.compliance.server.support.LockedTest3;
  +import test.compliance.server.support.LockedTest3MBean;
   import test.compliance.server.support.MyScreamingException;
   import test.compliance.server.support.ExceptionOnTheRun;
   import test.compliance.server.support.BabarError;
  @@ -48,7 +61,9 @@
      // MBeanServer invoke --------------------------------------------
      
      /**
  -    * Tests invoke with primitive boolean return type
  +    * Tests invoke with primitive boolean return type. <p>
  +    *
  +    * This test includes both non-optimized and optimized dispatcher invocations.
       */
      public void testInvokeWithPrimitiveBooleanReturn()
      {
  @@ -62,6 +77,9 @@
            
            assertTrue(bool.booleanValue() == true);
            
  +         //
  +         // same test with optimized dispatcher (only affects JBossMX)
  +         //
            System.setProperty("jbossmx.optimized.dispatcher", "true");
   
            server = MBeanServerFactory.createMBeanServer();
  @@ -89,7 +107,9 @@
      }
   
      /**
  -    * Tests invoke with primitive long return type
  +    * Tests invoke with primitive long return type. <p>
  +    *
  +    * This test includes both non-optimized and optimized dispatcher invocations.
       */
      public void testInvokeWithPrimitiveLongReturn()
      {
  @@ -103,6 +123,9 @@
            
            assertTrue(l.longValue() == 1234567890123l);
            
  +         //
  +         // same test with optimized dispatcher (only affects JBossMX)
  +         //
            System.setProperty("jbossmx.optimized.dispatcher", "true");
   
            server = MBeanServerFactory.createMBeanServer();
  @@ -130,7 +153,9 @@
      }
   
      /**
  -    * Tests invoke with primitive double return type
  +    * Tests invoke with primitive double return type. <p>
  +    *
  +    * Tis test includes both non-optimized and optimized dispatcher invocations.
       */
      public void testInvokeWithPrimitiveDoubleReturn()
      {
  @@ -144,6 +169,9 @@
            
            assertTrue(d.doubleValue() == 0.1234567890123d);
            
  +         //
  +         // same test with optimized dispatcher (only affects JBossMX)
  +         //
            System.setProperty("jbossmx.optimized.dispatcher", "true");
   
            server = MBeanServerFactory.createMBeanServer();
  @@ -171,7 +199,9 @@
      }
      
      /**
  -    * Tests invoke with long signature
  +    * Tests invoke with long signature. <p>
  +    *
  +    * This test includes both non-optimized and optimized dispatcher invocations.
       */
      public void testInvokeWithLongSignature()
      {
  @@ -190,6 +220,9 @@
                           "int", "int", "int", "int", "int", "int", "int", "int", 
"int", "int" }
            );
            
  +         //
  +         // same test with optimized dispatcher (only affects JBossMX)
  +         //
            System.setProperty("jbossmx.optimized.dispatcher", "true");
   
            server = MBeanServerFactory.createMBeanServer();
  @@ -834,6 +867,9 @@
          }
       }
       
  +    
  +    // MBeanServer registerMBean ------------------------------------
  +    
       /**
        * Tests registering with null object name.
        */
  @@ -938,6 +974,8 @@
             fail("Allowed to register into JMImplementation");
       }
       
  +    // MBeanServer unregisterMBean ----------------------------------
  +    
       /**
        * Tests unregister the delegate.
        */
  @@ -951,6 +989,7 @@
          }
          // REVIEW: This exception type isn't specified, but it is logical
          //         and agrees with the RI.
  +       // JPL: agreed
          catch (RuntimeOperationsException e)
          {
             caught = true;
  @@ -962,4 +1001,225 @@
          if (caught == false)
             fail("Allowed to unregister the delegate");
       }
  +    
  +    /**
  +     * Tests basic register/unregister
  +     */
  +    public void testBasicUnregister() throws Exception
  +    {
  +       MBeanServer server = MBeanServerFactory.createMBeanServer();
  +       ObjectName name = new ObjectName("test:foo=bar");
  +       
  +       server.registerMBean(new Test(), name);
  +       server.unregisterMBean(name);
  +    }
  +    
  +    /**
  +     * Tests unregister with default domain name
  +     */
  +    public void testUnregisterWithDefaultDomainName() throws Exception
  +    {
  +       try
  +       {
  +          MBeanServer server = MBeanServerFactory.createMBeanServer();
  +          ObjectName name = new ObjectName(":foo=bar");
  +          
  +          server.registerMBean(new Test(), name);
  +          server.unregisterMBean(name);
  +       
  +       }
  +       catch (InstanceNotFoundException e)
  +       {
  +          // FAILS IN RI: RI throws InstanceNotFoundException if you try to
  +          // unregister with implicit default domain name
  +          fail("FAILS IN RI: RI throws InstanceNotFoundException when an existing 
MBean is unregistered with an implicit default domain name.");
  +       }
  +    }
  +    
  +    /**
  +     * Tests unregister with default domain name gotten from ObjectInstance at 
registration time.
  +     */
  +     public void testUnregisterWithObjectNameFromRegistration() throws Exception
  +     {
  +        try
  +        {
  +           MBeanServer server = MBeanServerFactory.createMBeanServer();
  +           ObjectName name = new ObjectName(":foo=bar");
  +           
  +           ObjectInstance oi = server.registerMBean(new Test(), name);
  +           name = oi.getObjectName();
  +           
  +           server.unregisterMBean(name);
  +        
  +        }
  +        catch (InstanceNotFoundException e)
  +        {
  +           // FAILS IN RI: RI throws InstanceNotFoundExceptin if you try yo
  +           // unregister with implicit default domain name
  +           fail("FAILS IN RI: RI throws InstanceNotFoundException when an existing 
MBean is unregistered with an implicit default domain name retrieved from the 
ObjectInstance returned at registration time.");
  +        }
  +     }
  +    
  +   /**
  +    * Tests unregister for an MBean that prevents unregistration by throwing an
  +    * unchecked exception from its preDeregister() method.
  +    */
  +   public void testUnregisterMBeanOnExceptionFromPreDeregister() throws Exception
  +   {
  +      MBeanServer server = MBeanServerFactory.createMBeanServer();
  +      ObjectName name = new ObjectName("test:foo=bar");
  +    
  +      server.registerMBean(new LockedTest(), name);
  +
  +      try
  +      {
  +         server.unregisterMBean(name);
  +         
  +         // should not reach here
  +         fail("LockedTest unregistered despite of throwing an exception from the 
preDeregister() method.");
  +      }
  +      catch (MBeanRegistrationException e)
  +      {
  +         // expected, LockedTest should prevent unregistration
  +         assertTrue(server.isRegistered(name));
  +         assertTrue(e.getTargetException() instanceof java.lang.RuntimeException);
  +      }
  +      catch (RuntimeMBeanException e)
  +      {
  +         // FAILS IN RI: according to spec (v1.0, p. 117) any exception thrown from 
the
  +         // preDeregister() method is wrapped in MBeanRegistrationException by the 
agent.
  +         fail("FAILS IN RI: spec v1.0: any exception thrown from MBean's 
preDeregister() method should be wrapped in an MBeanRegistrationException by the 
agent.");
  +      }
  +    }
  +    
  +    /**
  +     * Tests unregister for an MBean that prevents unregistration by throwing a
  +     * checked exception from its preDeregister() method.
  +     */
  +    public void testUnregisterMBeanOnExceptionFromPreDeregister2() throws Exception
  +    {
  +      MBeanServer server = MBeanServerFactory.createMBeanServer();
  +      ObjectName name = new ObjectName("test:foo=bar");
  +      
  +      server.registerMBean(new LockedTest2(), name);
  +      
  +      try
  +      {
  +         
  +         server.unregisterMBean(name);
  +       
  +         // should not reach here
  +         fail("LockedTest2 unregistered despite of throwin an exception from the 
preDeregister() method");
  +      }
  +      catch (MBeanRegistrationException e)
  +      {
  +         // expected
  +         assertTrue(server.isRegistered(name));
  +         assertTrue(e.getTargetException() instanceof MyScreamingException);
  +      }
  +    }
  +    
  +    /**
  +     * Tests unregister for an MBean that prevents unregistration by throwing a
  +     * MBeanRegistrationException from its preDeregister() method. This should
  +     * be rethrown by the agent as-is, and not wrapped into another 
MBeanRegistrationException.
  +     */
  +    public void testUnregisterMBeanOnExceptionFromPreDeregister3() throws Exception
  +    {
  +       MBeanServer server = MBeanServerFactory.createMBeanServer();
  +       ObjectName name = new ObjectName("test:foo=bar");
  +       
  +       server.registerMBean(new LockedTest3(), name);
  +       
  +       try
  +       {
  +          server.unregisterMBean(name);
  +          
  +          // should not reach here
  +          fail("LockedTest3 unregistered despite of throwing an exception from the 
preDeregister() method.");
  +       }
  +       catch (MBeanRegistrationException e)
  +       {
  +          // expected
  +          assertTrue(server.isRegistered(name));
  +          assertTrue(e.getTargetException() instanceof MyScreamingException);
  +       }
  +    }
  +    
  +    // MBeanServer addNotificationListener --------------------------
  +    
  +   /**
  +    * Tests basic listener registration to server delegate
  +    */
  +   public synchronized void testAddNotificationListenerToDelegate() throws Exception
  +   {
  +      MBeanServer server = MBeanServerFactory.createMBeanServer();
  +      
  +      class MyNotificationListener implements NotificationListener {
  +
  +         int notificationCount = 0;
  +         
  +         public void handleNotification(Notification notification, Object handback)
  +         {
  +            try
  +            {
  +               notificationCount++;
  +
  +               assertTrue(handback instanceof String);
  +               assertTrue(handback.equals("MyHandback"));
  +      
  +               try
  +               {
  +                  assertTrue(notification.getSource().equals(new 
ObjectName("JMImplementation:type=MBeanServerDelegate")));
  +               }
  +               catch (AssertionFailedError e)
  +               {
  +                  fail("FAILS IN JBOSSMX: notification source for listeners 
registered through the agent should be an object name of the source; JBossMX returns " 
+ notification.getSource());
  +               }
  +            }
  +            catch (Exception e)
  +            {
  +               fail("Unexpected error: " + e.toString());
  +            }
  +         }
  +      }
  +      
  +      MyNotificationListener listener = new MyNotificationListener();
  +      
  +      NotificationFilterSupport filter = new NotificationFilterSupport();
  +      filter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
  +      
  +      server.addNotificationListener(
  +            new ObjectName("JMImplementation:type=MBeanServerDelegate"),
  +            listener, filter, "MyHandback"
  +      );       
  +    
  +      // force notification
  +      server.registerMBean(new Test(), new ObjectName(":foo=bar"));
  +    
  +      // wait for notif to arrive max 5 secs
  +      for (int i = 0; i < 10; ++i)
  +      {
  +         wait(500);
  +         
  +         if (listener.notificationCount > 0)
  +            break;
  +      }
  +      
  +      try
  +      {
  +         assertTrue(listener.notificationCount == 1);
  +      }
  +      catch (AssertionFailedError e)
  +      {
  +         // FAILS IN RI: if a notification filter with REGISTRATION_NOTIFICATION
  +         // type enabled is used with RI (via 
NotificationFilterSupport.enableType())
  +         // then the registration notification is never received. Using a null 
filter
  +         // will however deliver the message. Seems like a bug in the RI 
notification
  +         // handling
  +         fail("FAILS IN RI: when notification filter is used with listener for 
registration notification, the event is never received.");
  +      }
  +   }
   }
  +
  +
  
  
  
  1.4       +1 -0      jmx/src/main/test/compliance/server/ServerSUITE.java
  
  Index: ServerSUITE.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/test/compliance/server/ServerSUITE.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServerSUITE.java  22 Feb 2002 16:44:33 -0000      1.3
  +++ ServerSUITE.java  12 Mar 2002 15:04:24 -0000      1.4
  @@ -23,6 +23,7 @@
   
         suite.addTest(new TestSuite(MBeanServerFactoryTEST.class));
         suite.addTest(new TestSuite(MBeanServerTEST.class));
  +      suite.addTest(new TestSuite(MBeanDelegateTEST.class));
         suite.addTest(new TestSuite(DefaultDomainTestCase.class));
         
         return suite;
  
  
  
  1.2       +81 -0     jmx/src/main/test/compliance/server/MBeanDelegateTEST.java
  
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to