mx4j/src/test/test/javax/management/remote JMXConnectorTestCase.java,1.13,1.14

[email protected]
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/test/test/javax/management/remote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21536/test/test/javax/management/remote

Modified Files:
	JMXConnectorTestCase.java 
Log Message:
Added try/finally blocks to close the connectors

Index: JMXConnectorTestCase.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/test/test/javax/management/remote/JMXConnectorTestCase.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** JMXConnectorTestCase.java	24 Feb 2004 14:12:15 -0000	1.13
--- JMXConnectorTestCase.java	25 Feb 2004 13:42:34 -0000	1.14
***************
*** 52,55 ****
--- 52,60 ----
     }
  
+    protected void tearDown() throws Exception
+    {
+       sleep(2000);
+    }
+ 
     public abstract JMXServiceURL createJMXConnectorServerAddress() throws MalformedURLException;
  
***************
*** 180,199 ****
     public void testStopServerBeforeClosingClient() throws Exception
     {
!       JMXServiceURL url = createJMXConnectorServerAddress();
!       JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
!       cntorServer.start();
  
!       JMXConnector cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
!       MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
  
!       cntorServer.stop();
  
!       try
!       {
!          mbsc.getDefaultDomain();
!          fail();
        }
!       catch (IOException x)
        {
        }
     }
--- 185,213 ----
     public void testStopServerBeforeClosingClient() throws Exception
     {
!       JMXConnectorServer cntorServer = null;
!       JMXConnector cntor = null;
!       try
!       {
!          JMXServiceURL url = createJMXConnectorServerAddress();
!          cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
!          cntorServer.start();
  
!          cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
!          MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
  
!          cntorServer.stop();
  
!          try
!          {
!             mbsc.getDefaultDomain();
!             fail();
!          }
!          catch (IOException x)
!          {
!          }
        }
!       finally
        {
+          if (cntor != null) cntor.close();
        }
     }
***************
*** 296,331 ****
     }
  
!    public void testListenerRemovedOnClose() throws Exception
     {
!       JMXServiceURL url = createJMXConnectorServerAddress();
!       MBeanServer server = newMBeanServer();
!       JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
!       cntorServer.start();
  
!       Emitter emitter = new Emitter();
!       ObjectName emitterName = ObjectName.getInstance(":name=emitter");
!       server.registerMBean(emitter, emitterName);
  
!       JMXConnector cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
!       MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
  
!       NotificationListener listener = new NotificationListener()
!       {
!          public void handleNotification(Notification notification, Object handback)
           {
!          }
!       };
  
!       // Add the listener and be sure the mechanism of removal works fine
!       mbsc.addNotificationListener(emitterName, listener, null, null);
!       assertEquals(emitter.getSize(), 1);
!       mbsc.removeNotificationListener(emitterName, listener, null, null);
!       assertEquals(emitter.getSize(), 0);
  
!       // Add the listener and close the connector
!       mbsc.addNotificationListener(emitterName, listener, null, null);
!       assertEquals(emitter.getSize(), 1);
!       cntor.close();
!       assertEquals(emitter.getSize(), 0);
     }
  
--- 310,354 ----
     }
  
!    public void testListenersAreRemovedOnConnectorClose() throws Exception
     {
!       JMXConnectorServer cntorServer = null;
!       JMXConnector cntor = null;
!       try
!       {
!          JMXServiceURL url = createJMXConnectorServerAddress();
!          MBeanServer server = newMBeanServer();
!          cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
!          cntorServer.start();
  
!          Emitter emitter = new Emitter();
!          ObjectName emitterName = ObjectName.getInstance(":name=emitter");
!          server.registerMBean(emitter, emitterName);
  
!          cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
!          MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
  
!          NotificationListener listener = new NotificationListener()
           {
!             public void handleNotification(Notification notification, Object handback)
!             {
!             }
!          };
  
!          // Add the listener and be sure the mechanism of removal works fine
!          mbsc.addNotificationListener(emitterName, listener, null, null);
!          assertEquals(emitter.getSize(), 1);
!          mbsc.removeNotificationListener(emitterName, listener, null, null);
!          assertEquals(emitter.getSize(), 0);
  
!          // Add the listener and close the connector
!          mbsc.addNotificationListener(emitterName, listener, null, null);
!          assertEquals(emitter.getSize(), 1);
!          cntor.close();
!          assertEquals(emitter.getSize(), 0);
!       }
!       finally
!       {
!          if (cntorServer != null) cntorServer.stop();
!       }
     }
  



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.