[jboss-cvs] JBossAS SVN: r89678 - in trunk: cluster/src/main/org/jboss/ha/singleton and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 2 12:35:11 EDT 2009


Author: pferraro
Date: 2009-06-02 12:35:11 -0400 (Tue, 02 Jun 2009)
New Revision: 89678

Modified:
   trunk/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java
Log:
[JBAS-6792] Port new fix for infinite rpc loop rfrom Branch_5_x

Modified: trunk/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java	2009-06-02 16:10:01 UTC (rev 89677)
+++ trunk/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java	2009-06-02 16:35:11 UTC (rev 89678)
@@ -357,7 +357,7 @@
       // to ensure that it can be safely transferred over the wire
       notification.setSource(this.getServiceName());
       
-      this.handleEvent(notification);
+      this.service.handleEvent(notification);
    }
 
    protected void sendNotificationToLocalListeners(Notification notification)
@@ -378,7 +378,7 @@
     */
    public void handleEvent(Notification notification) throws Exception
    {
-      this.service.handleEvent(notification);
+      this.notifyListeners(notification);
    }
 
    /**

Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2009-06-02 16:10:01 UTC (rev 89677)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2009-06-02 16:35:11 UTC (rev 89678)
@@ -131,18 +131,7 @@
    @Override
    protected HASingleton<Notification> createHAService()
    {
-      return new HASingletonImpl<Notification>(this, this, this)
-      {
-         /**
-          * Expose HASingletonSupport subclass methods to rpc handler
-          * @see org.jboss.ha.framework.server.HASingletonImpl#getRpcHandler()
-          */
-         @Override
-         protected HAServiceRpcHandler<Notification> getRpcHandler()
-         {
-            return HASingletonSupport.this;
-         }         
-      };
+      return new HASingletonService();
    }
 
    /**
@@ -150,6 +139,34 @@
     */
    public void stopOldMaster() throws Exception
    {
-      ((HASingletonImpl<Notification>) this.getHAService()).stopOldMaster();
+      ((HASingletonService) this.getHAService()).stopIfMaster();
    }
+   
+   private class HASingletonService extends HASingletonImpl<Notification>
+   {
+      HASingletonService()
+      {
+         super(HASingletonSupport.this, HASingletonSupport.this, HASingletonSupport.this);
+      }
+      
+      /**
+       * Expose HASingletonSupport subclass methods to rpc handler
+       * @see org.jboss.ha.framework.server.HASingletonImpl#getRpcHandler()
+       */
+      @Override
+      protected HAServiceRpcHandler<Notification> getRpcHandler()
+      {
+         return HASingletonSupport.this;
+      }
+      
+      /**
+       * Expose to parent class
+       * @see org.jboss.ha.framework.server.HASingletonImpl#stopIfMaster()
+       */
+      @Override
+      protected void stopIfMaster()
+      {
+         super.stopIfMaster();
+      }
+   }
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java	2009-06-02 16:10:01 UTC (rev 89677)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java	2009-06-02 16:35:11 UTC (rev 89678)
@@ -24,6 +24,7 @@
 import java.util.List;
 
 import javax.management.MBeanServerConnection;
+import javax.management.Notification;
 import javax.management.ObjectName;
 
 import junit.framework.Test;
@@ -47,21 +48,50 @@
       return JBossClusteredTestCase.getDeploySetup(HAServiceUnitTestCase.class, "ha-service.sar");
    }
 
-   public void testTrueEcho() throws Exception
+   public void testEcho() throws Exception
    {
+      Boolean result = this.testMethod("echo", new Object[] { false }, new Class[] { Boolean.TYPE }, Boolean.class);
+      
+      assertFalse(result.booleanValue());
+      
+      result = this.testMethod("echo", new Object[] { true }, new Class[] { Boolean.TYPE }, Boolean.class);
+      
+      assertTrue(result.booleanValue());
+   }
+
+   public void testHandleEvent() throws Exception
+   {
+      Void result = this.testMethod("handleEvent", new Object[] { new Notification("test", "source", 1) }, new Class[] { Notification.class }, Void.class);
+      
+      assertNull(result);
+   }
+   
+   private <T> T testMethod(String method, Object[] parameters, Class<?>[] types, Class<T> resultType) throws Exception
+   {
       MBeanServerConnection[] adaptors = this.getAdaptors();
-      ObjectName on = new ObjectName("jboss.ha:service=EchoHAService");
-      Object[] args = new Object[] {"echo", new Object[] {true}, new Class[] {boolean.class}};
-      String[] signature = new String[] {String.class.getName(), Object[].class.getName(), Class[].class.getName()};
-      List<?> responses = (List<?>) adaptors[0].invoke(on, "callMethodOnPartition", args, signature);
-      log.debug("Response list: " + responses);
+      ObjectName name = ObjectName.getInstance("jboss.ha:service=EchoHAService");
+      Object[] args = new Object[] { method, parameters, types };
+      String[] signature = new String[] { String.class.getName(), Object[].class.getName(), Class[].class.getName() };
+      List<?> responses = (List<?>) adaptors[0].invoke(name, "callMethodOnPartition", args, signature);
+      
+      this.log.debug("Response list: " + responses);
+      
       assertEquals(1, responses.size());
       
-      if (responses.get(0) instanceof Exception)
+      Object response = responses.get(0);
+      
+      if (response instanceof Exception)
       {
-         throw (Exception) responses.get(0);
+         throw (Exception) response;
       }
-      
-      assertTrue(((Boolean) responses.get(0)).booleanValue());
+
+      return resultType.cast(response);
    }
+   
+   public void testSendNotification() throws Exception
+   {
+      MBeanServerConnection[] adaptors = this.getAdaptors();
+      ObjectName name = new ObjectName("jboss.ha:service=EchoHAService");
+      adaptors[0].invoke(name, "sendNotification", new Object[] { new Notification("test", "source", 1) }, new String[] { Notification.class.getName() });
+   }
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java	2009-06-02 16:10:01 UTC (rev 89677)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java	2009-06-02 16:35:11 UTC (rev 89678)
@@ -24,6 +24,7 @@
 import java.util.List;
 
 import javax.management.MBeanServerConnection;
+import javax.management.Notification;
 import javax.management.ObjectName;
 
 import junit.framework.Test;
@@ -49,8 +50,12 @@
 
    public void testEcho() throws Exception
    {
-      Boolean result = this.testMethod("echo", new Object[] { true }, new Class[] { Boolean.TYPE }, Boolean.class);
+      Boolean result = this.testMethod("echo", new Object[] { false }, new Class[] { Boolean.TYPE }, Boolean.class);
       
+      assertFalse(result.booleanValue());
+      
+      result = this.testMethod("echo", new Object[] { true }, new Class[] { Boolean.TYPE }, Boolean.class);
+      
       assertTrue(result.booleanValue());
    }
 
@@ -60,24 +65,40 @@
       
       assertNull(result);
    }
+
+   public void testHandleEvent() throws Exception
+   {
+      Void result = this.testMethod("handleEvent", new Object[] { new Notification("test", "source", 1) }, new Class[] { Notification.class }, Void.class);
+      
+      assertNull(result);
+   }
    
    private <T> T testMethod(String method, Object[] parameters, Class<?>[] types, Class<T> resultType) throws Exception
    {
       MBeanServerConnection[] adaptors = this.getAdaptors();
-      ObjectName on = ObjectName.getInstance("jboss.ha:service=EchoHASingleton");
+      ObjectName name = ObjectName.getInstance("jboss.ha:service=EchoHASingleton");
       Object[] args = new Object[] { method, parameters, types };
       String[] signature = new String[] { String.class.getName(), Object[].class.getName(), Class[].class.getName() };
-      List<?> responses = (List<?>) adaptors[0].invoke(on, "callMethodOnPartition", args, signature);
+      List<?> responses = (List<?>) adaptors[0].invoke(name, "callMethodOnPartition", args, signature);
       
-      log.debug("Response list: " + responses);
+      this.log.debug("Response list: " + responses);
       
       assertEquals(1, responses.size());
       
-      if (responses.get(0) instanceof Exception)
+      Object response = responses.get(0);
+      
+      if (response instanceof Exception)
       {
-         throw (Exception) responses.get(0);
+         throw (Exception) response;
       }
 
-      return resultType.cast(responses.get(0));
+      return resultType.cast(response);
    }
+      
+   public void testSendNotification() throws Exception
+   {
+      MBeanServerConnection[] adaptors = this.getAdaptors();
+      ObjectName name = ObjectName.getInstance("jboss.ha:service=EchoHASingleton");
+      adaptors[0].invoke(name, "sendNotification", new Object[] { new Notification("test", "source", 1) }, new String[] { Notification.class.getName() });
+   }
 }




More information about the jboss-cvs-commits mailing list