[jboss-cvs] JBossAS SVN: r76672 - in trunk/testsuite/src/main/org/jboss/test/cluster: hasingleton and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 5 12:22:40 EDT 2008


Author: pferraro
Date: 2008-08-05 12:22:40 -0400 (Tue, 05 Aug 2008)
New Revision: 76672

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonTester.java
Modified:
   trunk/testsuite/src/main/org/jboss/test/cluster/haservice/HAServiceMBeanSupportTester.java
   trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonSupportTester.java
   trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/MockHAPartition.java
Log:
Refactored HASingletonSupport into pojo + mbean wrapper.
Simplified responsibility of HASingletonElectionPolicy.

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/haservice/HAServiceMBeanSupportTester.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/haservice/HAServiceMBeanSupportTester.java	2008-08-05 16:18:21 UTC (rev 76671)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/haservice/HAServiceMBeanSupportTester.java	2008-08-05 16:22:40 UTC (rev 76672)
@@ -1,117 +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.
-  */
-
+ * 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.haservice;
 
+import java.util.List;
 import java.util.Stack;
 
 import javax.management.MalformedObjectNameException;
 import javax.management.Notification;
 import javax.management.ObjectName;
 
+import org.jboss.ha.framework.interfaces.HAService;
+import org.jboss.ha.framework.server.HAServiceImpl;
 import org.jboss.ha.jmx.HAServiceMBeanSupport;
 
 /**
  * 
- * @author  Ivelin Ivanov <ivelin at apache.org>
+ * @author   Ivelin Ivanov <ivelin at apache.org>
  *
  */
 public class HAServiceMBeanSupportTester extends HAServiceMBeanSupport
 {
-  public static final String SERVICE_NAME = "jboss.examples:name=HAServiceMBeanSupportTester";
-  
-  public Stack __invokationStack__ = new Stack();
+   public static final String SERVICE_NAME = "jboss.examples:name=HAServiceMBeanSupportTester";
+   
+   public final Stack<Object> invocationStack = new Stack<Object>();
 
-  public boolean __isDRMMasterReplica__ = false;
+   public boolean isSingletonStarted = false;
 
-  public boolean __isSingletonStarted__ = false;
+   public boolean shouldSendNotificationRemoteFail = false;
 
-  public boolean __shouldSendNotificationRemoteFail__ = false;
+   /**
+    * @see org.jboss.ha.jmx.HAServiceMBeanSupport#createHAService()
+    */
+   @Override
+   protected HAService<Notification> createHAService()
+   {
+      return new HAServiceImpl<Notification>(this, this)
+      {
+         @Override
+         protected void registerRPCHandler()
+         {
+            HAServiceMBeanSupportTester.this.invocationStack.push("registerRPCHandler");
+         }
 
-  protected void setupPartition() throws Exception
-  {
-    __invokationStack__.push("setupPartition");
-  }
+         @Override
+         protected void unregisterRPCHandler()
+         {
+            HAServiceMBeanSupportTester.this.invocationStack.push("unregisterRPCHandler");
+         }
 
-  protected void registerRPCHandler()
-  {
-    __invokationStack__.push("registerRPCHandler");
-  }
+         @Override
+         protected void registerDRMListener() throws Exception
+         {
+            HAServiceMBeanSupportTester.this.invocationStack.push("registerDRMListener");
+         }
 
-  protected void unregisterRPCHandler()
-  {
-    __invokationStack__.push("unregisterRPCHandler");
-  }
+         @Override
+         protected void unregisterDRMListener() throws Exception
+         {
+            HAServiceMBeanSupportTester.this.invocationStack.push("unregisterDRMListener");
+         }
+      };
+   }
 
-  protected void registerDRMListener() throws Exception
-  {
-    __invokationStack__.push("registerDRMListener");
-  }
+   @Override
+   protected void setupPartition() throws Exception
+   {
+      this.invocationStack.push("setupPartition");
+   }
 
-  protected void unregisterDRMListener() throws Exception
-  {
-    __invokationStack__.push("unregisterDRMListener");
-  }
+   @Override
+   protected void sendNotificationRemote(Notification notification)
+      throws Exception
+   {
+      if (this.shouldSendNotificationRemoteFail)
+      {
+         throw new Exception("simulated exception");
+      }
+      this.invocationStack.push("sendNotificationRemote");
+      this.invocationStack.push(notification);
+   }
 
-  protected boolean isDRMMasterReplica()
-  {
-    __invokationStack__.push("isDRMMasterReplica");
-    return __isDRMMasterReplica__;
-  }
+   @Override
+   protected void sendNotificationToLocalListeners(Notification notification)
+   {
+      this.invocationStack.push("sendNotificationToLocalListeners");
+      this.invocationStack.push(notification);
+   }
 
-  public void callMethodOnPartition(String methodName, Object[] args)
-    throws Exception
-  {
-    __invokationStack__.push("callMethodOnCluster:" + methodName);
-  }
+   @Override
+   @SuppressWarnings("unchecked")
+   public List callMethodOnPartition(String methodName, Object[] args, Class[] types) throws Exception
+   {
+      this.invocationStack.push("callMethodOnCluster:" + methodName);
+      return null;
+   }
 
-  protected void sendNotificationRemote(Notification notification)
-    throws Exception
-  {
-    if (__shouldSendNotificationRemoteFail__)
-      throw new Exception("simulated exception");
-    __invokationStack__.push("sendNotificationRemote");
-    __invokationStack__.push(notification);
-  }
-
-  protected void sendNotificationToLocalListeners(Notification notification)
-  {
-    __invokationStack__.push("sendNotificationToLocalListeners");
-    __invokationStack__.push(notification);
-  }
-
-  public ObjectName getServiceName()
-  {
-    ObjectName oname = null;
-    try
-    {
-      oname = new ObjectName(SERVICE_NAME);
-    }
-    catch (MalformedObjectNameException e)
-    {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
-    }
-    return oname;
-  }
-
+   @Override
+   public ObjectName getServiceName()
+   {
+      ObjectName oname = null;
+      try
+      {
+         oname = new ObjectName(SERVICE_NAME);
+      }
+      catch (MalformedObjectNameException e)
+      {
+         // TODO Auto-generated catch block
+         e.printStackTrace();
+      }
+      return oname;
+   }
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonSupportTester.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonSupportTester.java	2008-08-05 16:18:21 UTC (rev 76671)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonSupportTester.java	2008-08-05 16:22:40 UTC (rev 76672)
@@ -1,116 +1,87 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2008, Red Hat Middleware LLC, and individual contributors
-  * as indicated by the @author tags. See the copyright.txt file 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.
-  */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.hasingleton;
 
+import java.util.List;
 import java.util.Stack;
 
 import javax.management.Notification;
 
 import org.jboss.ha.singleton.HASingletonSupport;
 
-
 /**
  * 
- * @author  Ivelin Ivanov <ivelin at apache.org>
+ * @author   Ivelin Ivanov <ivelin at apache.org>
  *
  */
 public class HASingletonSupportTester extends HASingletonSupport
 {
+   public final Stack<String> invocationStack = new Stack<String>();
 
-  public Stack __invokationStack__ = new Stack();
+   public boolean isDRMMasterReplica = false;
+   public boolean isSingletonStarted = false;
 
-  public boolean __isDRMMasterReplica__ = false;
+   /**
+    * @see org.jboss.ha.singleton.HASingletonSupport#createHAService()
+    */
+   @Override
+   protected HASingletonTester createHAService()
+   {
+      return new HASingletonTester(this);
+   }
+   
+   @Override
+   protected void setupPartition() throws Exception
+   {
+      this.invocationStack.push("setupPartition");
+   }
 
-  public boolean __isSingletonStarted__ = false;
+   @Override
+   @SuppressWarnings("unchecked")
+   public List callMethodOnPartition(String methodName, Object[] args, Class[] types) throws Exception
+   {
+      this.invocationStack.push("callMethodOnCluster:" + methodName);
+      return null;
+   }
 
-  public HASingletonSupportTester()
-  {
-     setHAPartition(new MockHAPartition());
-     setServiceHAName("HASingletonSupportTester");
-  }
-  
-  protected void setupPartition() throws Exception
-  {
-    __invokationStack__.push("setupPartition");
-  }
+   @Override
+   public void startSingleton()
+   {
+      this.invocationStack.push("startSingleton");
+   }
 
-  protected void registerRPCHandler()
-  {
-    __invokationStack__.push("registerRPCHandler");
-  }
+   @Override
+   public void stopSingleton()
+   {
+      this.invocationStack.push("stopSingleton");
+   }
 
-  protected void unregisterRPCHandler()
-  {
-    __invokationStack__.push("unregisterRPCHandler");
-  }
-
-  protected void registerDRMListener() throws Exception
-  {
-    __invokationStack__.push("registerDRMListener");
-  }
-
-  protected void unregisterDRMListener() throws Exception
-  {
-    __invokationStack__.push("unregisterDRMListener");
-  }
-
-  protected boolean isDRMMasterReplica()
-  {
-    __invokationStack__.push("isDRMMasterReplica");
-    return __isDRMMasterReplica__;
-  }
-
-  public void callMethodOnPartition(String methodName, Object[] args)
-    throws Exception
-  {
-    __invokationStack__.push("callMethodOnCluster:" + methodName);
-  }
-
-  public void startSingleton()
-  {
-    __invokationStack__.push("startSingleton");
-  }
-
-  public void stopSingleton()
-  {
-    __invokationStack__.push("stopSingleton");
-  }
-
-  protected void makeThisNodeMaster()
-  {
-    __invokationStack__.push("makeThisNodeMaster");
-    super.makeThisNodeMaster();
-  }
-  
-  @Override
-  protected void restartMaster()
-  {
-     __invokationStack__.push("restartMaster");
-     super.restartMaster();
-  }
-
-  public void sendNotification(Notification notification)
-  {
-    return;
-  }
-
+   @Override
+   public void sendNotification(Notification notification)
+   {
+   }
+   
+   public HASingletonTester getDelegate()
+   {
+      return (HASingletonTester) this.getHAService();
+   }
 }

Added: trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonTester.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonTester.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/HASingletonTester.java	2008-08-05 16:22:40 UTC (rev 76672)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.hasingleton;
+
+import java.util.List;
+
+import javax.management.Notification;
+
+import org.jboss.ha.framework.server.HASingletonImpl;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class HASingletonTester extends HASingletonImpl<Notification>
+{
+   private final HASingletonSupportTester tester;
+
+   public HASingletonTester(HASingletonSupportTester tester)
+   {
+      super(tester, tester, tester);
+      
+      this.tester = tester;
+      
+      this.setHAPartition(new MockHAPartition());
+      this.setServiceHAName("HASingletonSupportTester");
+   }
+
+   @Override
+   protected void registerRPCHandler()
+   {
+      this.tester.invocationStack.push("registerRPCHandler");
+   }
+
+   @Override
+   protected void unregisterRPCHandler()
+   {
+      this.tester.invocationStack.push("unregisterRPCHandler");
+   }
+
+   @Override
+   protected void registerDRMListener() throws Exception
+   {
+      this.tester.invocationStack.push("registerDRMListener");
+   }
+
+   @Override
+   protected void unregisterDRMListener() throws Exception
+   {
+      this.tester.invocationStack.push("unregisterDRMListener");
+   }
+   
+   @Override
+   protected void makeThisNodeMaster()
+   {
+      this.tester.invocationStack.push("makeThisNodeMaster");
+      super.makeThisNodeMaster();
+   }
+   
+   @Override
+   protected void restartMaster()
+   {
+      this.tester.invocationStack.push("restartMaster");
+      super.restartMaster();
+   }
+
+   @Override
+   protected boolean isDRMMasterReplica()
+   {
+      this.tester.invocationStack.push("isDRMMasterReplica");
+      return this.tester.isDRMMasterReplica;
+   }
+   
+   @Override
+   public void stopIfMaster()
+   {
+      super.stopIfMaster();
+   }
+
+   @Override
+   public void partitionTopologyChanged(List<?> newReplicants, int newViewID, boolean merge)
+   {
+      super.partitionTopologyChanged(newReplicants, newViewID, merge);
+   }
+}
\ No newline at end of file

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/MockHAPartition.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/MockHAPartition.java	2008-08-05 16:18:21 UTC (rev 76671)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/hasingleton/MockHAPartition.java	2008-08-05 16:22:40 UTC (rev 76672)
@@ -55,7 +55,7 @@
    public void callAsynchMethodOnCluster(String serviceName, String methodName, Object[] args, Class[] types,
          boolean excludeSelf) throws Exception
    {
-      if (excludeSelf && "_stopOldMaster".equals(methodName))
+      if (excludeSelf && "stopOldMaster".equals(methodName))
       {
          // no-op -- there is no cluster
          return;




More information about the jboss-cvs-commits mailing list