[Jboss-cvs] JBossAS SVN: r56212 - in branches/Branch_4_0/testsuite/src: main/org/jboss/test/cluster main/org/jboss/test/cluster/jmx main/org/jboss/test/cluster/jmx/test main/org/jboss/test/ha/jmx/test main/org/jboss/test/jmx/ha resources/jmx/ha/META-INF

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 23 21:51:15 EDT 2006


Author: bstansberry at jboss.com
Date: 2006-08-23 21:51:12 -0400 (Wed, 23 Aug 2006)
New Revision: 56212

Added:
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java
Modified:
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/jmx/test/HAServiceMBeanSupportUnitTestCase.java
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAService.java
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceMBean.java
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceRemote.java
   branches/Branch_4_0/testsuite/src/resources/jmx/ha/META-INF/jboss-service.xml
Log:
[JBAS-3194] Add ability to suppress JMX notifications of lifecycle events

Added: branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java	2006-08-24 01:36:21 UTC (rev 56211)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java	2006-08-24 01:51:12 UTC (rev 56212)
@@ -0,0 +1,132 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.cluster.jmx.test;
+
+import org.jboss.invocation.ServiceUnavailableException;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.jmx.ha.HAServiceRemote;
+
+import junit.framework.Test;
+
+/**
+ * Tests for ha invoker.
+ *
+ * @author <a href="mailto:brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class HAInvokerUnitTestCase
+   extends JBossClusteredTestCase
+{
+   private boolean deployed0_ = true;
+   private boolean deployed1_ = true;
+   
+   public HAInvokerUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+      throws Exception
+   {
+      return JBossClusteredTestCase.getDeploySetup(HAInvokerUnitTestCase.class, "ha-invoker.sar");
+   }
+
+   public void testHAProxyFailover()
+      throws Exception
+   {
+      getLog().debug("testHAProxyFailover");
+      
+      HAServiceRemote remote = (HAServiceRemote) getInitialContext().lookup("jmx/HAService");
+      assertEquals("Hello", remote.hello());
+      String nodeA = remote.getClusterNode();
+      assertNotNull("Got clusterNode", nodeA);
+      // Invoke again to check it works with load balancing
+      assertFalse("Requests load balanced", nodeA.equals(remote.getClusterNode()));
+      
+      // Undeploy from one node
+      reconfigureCluster();
+      
+      // Check it still works
+      try
+      {
+         assertEquals("Hello", remote.hello());
+      }
+      catch (ServiceUnavailableException sue)
+      {
+         getLog().info("testHAProxyFailover failed", sue);
+         fail("Failover did not succeed: " + sue.getMessage());
+      }
+   }   
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      configureCluster();
+   }
+
+   protected String getDeploymentName()
+   {
+      return "ha-invoker.sar";
+   }
+
+   protected void configureCluster() throws Exception
+   {
+      RMIAdaptor[] adaptors = getAdaptors();
+      String warName = getDeploymentName();
+      if (!deployed0_)
+      {
+         deploy(adaptors[0], warName);
+         getLog().debug("Deployed " + warName + " on server0");
+         deployed0_ = true;
+      }
+      if (!deployed1_)
+      {
+         deploy(adaptors[1], warName);
+         getLog().debug("Deployed " + warName + " on server1");
+         deployed1_ = true;
+      }
+   
+      sleep(2000);
+   }
+   
+   protected void reconfigureCluster() throws Exception
+   {
+      RMIAdaptor[] adaptors = getAdaptors();
+      if (!deployed1_)
+      {
+         deploy(adaptors[1], getDeploymentName());
+         deployed1_ = true;
+         
+         sleep(2000);
+      }
+      
+      if (deployed0_)
+      {
+         undeploy(adaptors[0], getDeploymentName());
+         deployed0_ = false;
+         
+         sleep(2000);
+      }
+   }
+
+}

Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/jmx/test/HAServiceMBeanSupportUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/jmx/test/HAServiceMBeanSupportUnitTestCase.java	2006-08-24 01:36:21 UTC (rev 56211)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/jmx/test/HAServiceMBeanSupportUnitTestCase.java	2006-08-24 01:51:12 UTC (rev 56212)
@@ -21,6 +21,9 @@
 */
 package org.jboss.test.ha.jmx.test;
 
+import java.util.EmptyStackException;
+
+import javax.management.AttributeChangeNotification;
 import javax.management.Notification;
 
 import junit.framework.TestCase;
@@ -96,5 +99,50 @@
     assertEquals("method not invoked as expected",
       haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners");      
   }
+  
+  public void testSendLifecycleNotifications()
+  {
+     Notification notification = new AttributeChangeNotification(
+           haServiceMBeanSupportTester_,
+           1, System.currentTimeMillis(), "test",
+           "State", "java.lang.Integer",
+           new Integer(0), new Integer(1)
+           );
+     
+     haServiceMBeanSupportTester_.setSendRemoteLifecycleNotifications(false);
+     
+     haServiceMBeanSupportTester_.sendNotification( notification );
+     
+     assertEquals("sendNotificationToLocalListeners() was handed the original notification", 
+                 haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
 
+     assertEquals("method invoked as expected",
+       haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners");      
+
+     try
+     {
+        haServiceMBeanSupportTester_.__invokationStack__.pop();
+        fail("sendNotificationRemote() was not handed the original notification");
+     }
+     catch (EmptyStackException good) {}
+     
+     haServiceMBeanSupportTester_.setSendRemoteLifecycleNotifications(true);
+     haServiceMBeanSupportTester_.setSendLocalLifecycleNotifications(false);
+     
+     haServiceMBeanSupportTester_.sendNotification( notification );     
+
+     assertEquals("sendNotificationRemote() was handed the original notification", 
+       haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
+     
+     assertEquals("method invoked as expected",
+       haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationRemote");
+     
+     try
+     {
+        haServiceMBeanSupportTester_.__invokationStack__.pop();
+        fail("sendNotificationToLocalListeners() was not handed the original notification");
+     }
+     catch (EmptyStackException good) {}
+  }
+
 }

Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAService.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAService.java	2006-08-24 01:36:21 UTC (rev 56211)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAService.java	2006-08-24 01:51:12 UTC (rev 56212)
@@ -29,14 +29,14 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.jboss.ha.jmx.HAServiceMBeanSupport;
 import org.jboss.invocation.Invocation;
 import org.jboss.invocation.MarshalledInvocation;
 import org.jboss.security.SecurityAssociation;
 import org.jboss.system.Registry;
-import org.jboss.system.ServiceMBeanSupport;
 
 public class HAService
-   extends ServiceMBeanSupport
+   extends HAServiceMBeanSupport
    implements HAServiceRemote, HAServiceMBean
 {
    private int count = 0;
@@ -46,6 +46,8 @@
    public void startService()
       throws Exception
    {
+      super.startService();
+      
       // Calulate method hashes for remote invocation
       Method[] methods = HAServiceRemote.class.getMethods();
       HashMap tmpMap = new HashMap(methods.length);
@@ -64,6 +66,8 @@
    public void stopService()
       throws Exception
    {
+      super.stopService();
+      
       // No longer available to the invokers
       Registry.unbind(new Integer(serviceName.hashCode()));
    }
@@ -123,5 +127,10 @@
    {
       return "Hello";
    }
+   
+   public String getClusterNode()
+   {
+      return getPartition().getNodeName();
+   }
 
 }

Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceMBean.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceMBean.java	2006-08-24 01:36:21 UTC (rev 56211)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceMBean.java	2006-08-24 01:51:12 UTC (rev 56212)
@@ -24,13 +24,14 @@
 import java.util.Map;
 
 import org.jboss.invocation.Invocation;
-import org.jboss.system.ServiceMBean;
 
 public interface HAServiceMBean
-   extends ServiceMBean
+   extends org.jboss.ha.jmx.HAServiceMBean
 {
    // For remoting
    Map getMethodMap();
    Object invoke(Invocation invocation) throws Exception;
-
+   
+   boolean getSendRemoteLifecycleNotifications();
+   void setSendRemoteLifecycleNotifications(boolean send);
 }

Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceRemote.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceRemote.java	2006-08-24 01:36:21 UTC (rev 56211)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/jmx/ha/HAServiceRemote.java	2006-08-24 01:51:12 UTC (rev 56212)
@@ -26,4 +26,6 @@
 public interface HAServiceRemote
 {
    String hello() throws IOException;
+   
+   String getClusterNode();
 }

Modified: branches/Branch_4_0/testsuite/src/resources/jmx/ha/META-INF/jboss-service.xml
===================================================================
--- branches/Branch_4_0/testsuite/src/resources/jmx/ha/META-INF/jboss-service.xml	2006-08-24 01:36:21 UTC (rev 56211)
+++ branches/Branch_4_0/testsuite/src/resources/jmx/ha/META-INF/jboss-service.xml	2006-08-24 01:51:12 UTC (rev 56212)
@@ -2,7 +2,7 @@
 
 <server>
 
-   <!-- Create JRMPHA proxy for our service -->
+   <!-- Create JRMPHA proxy for the service that sends notifications -->
    <mbean code="org.jboss.proxy.generic.ProxyFactoryHA"
       name="jboss.test:service=ProxyFactory,name=HAService,protocol=jrmpha">
 
@@ -35,7 +35,8 @@
 
   <!-- Our service -->
   <mbean code="org.jboss.test.jmx.ha.HAService" 
-         name="jboss.test:service=HAService">
+         name="jboss.test:service=HAService">         
+      <attribute name="SendRemoteLifecycleNotifications">false</attribute>      
   </mbean>
    
 </server>




More information about the jboss-cvs-commits mailing list