[jboss-cvs] JBossAS SVN: r71093 - in branches/JBPAPP_4_2_0_GA_CP/testsuite: src/main/org/jboss/test/naming/restart and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 20 15:06:15 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-03-20 15:06:14 -0400 (Thu, 20 Mar 2008)
New Revision: 71093

Added:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBean.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBeanMBean.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/naming/restart/
Modified:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/naming.xml
Log:
[JBPAPP-653] RMI Client Doesn't Always Immediately Recover After Complete Cluster Shutdown

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/naming.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/naming.xml	2008-03-20 18:57:58 UTC (rev 71092)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/naming.xml	2008-03-20 19:06:14 UTC (rev 71093)
@@ -127,6 +127,17 @@
          <fileset dir="${build.classes}">
             <include name="org/jboss/test/naming/factory/*"/>
          </fileset>
-      </jar>     
+      </jar>    
+
+      <!-- Test of naming restart -->
+      <jar destfile="${build.lib}/naming-restart.sar">
+         <zipfileset dir="${build.resources}/naming/restart"
+            fullpath="META-INF/jboss-service.xml">
+            <include name="jboss-service.xml"/>
+         </zipfileset>
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/naming/restart/*"/>
+         </fileset>
+      </jar>
    </target>
 </project>

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.restart;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * Class that throws NoSuchObjectException in deserialization.
+ * @author bstansberry
+ */
+public class NonDeserializable implements Serializable
+{
+   private static final long serialVersionUID = 0L;
+
+   private void writeObject(java.io.ObjectOutputStream out)
+   throws IOException
+   {
+      out.defaultWriteObject();
+   }
+   
+   private void readObject(java.io.ObjectInputStream in)
+   throws IOException, ClassNotFoundException
+   {
+      throw new java.rmi.NoSuchObjectException("Let's see how this is handled");
+   }
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.restart;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.logging.Logger;
+import org.jnp.interfaces.MarshalledValuePair;
+import org.jnp.interfaces.Naming;
+import org.jnp.interfaces.NamingParser;
+
+/**
+ * Binds an object into JNDI.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class ObjectBinder implements ObjectBinderMBean
+{
+   private static Logger log = Logger.getLogger(ObjectBinder.class);
+   
+   public static final String NAME = "NamingRestartBinding";
+   public static final String BAD_BINDING = "NamingRestartBadBinding";
+   public static final String VALUE = "VALUE";
+   public static final String SUBCONTEXT_NAME = "LocalSubcontext";
+//   private String providerURL;  
+   private NamingParser parser = new NamingParser();
+   private RestartNamingServiceMBean naming;
+   
+   public void setNamingService(RestartNamingServiceMBean naming)
+   {
+//      this.providerURL = (naming == null) 
+//                              ? null 
+//                              : naming.getBindAddress() + ":" + naming.getPort();
+      this.naming = naming;
+   }
+   
+   public void start() throws Exception
+   {      
+      // Standard JNDI
+      Context ctx = new InitialContext();
+      ctx.bind(NAME, VALUE);
+      log.info("Bound " + VALUE + " to " + ctx + " under " + NAME);
+      ctx.bind(BAD_BINDING, new NonDeserializable());
+      log.info("Bound a NonDeserializable to " + ctx + " under " + BAD_BINDING);
+      
+      // For some reason creating a context for our own JNDI doesn't work
+      // inside the server, so as a hack we directly deal with the NamingServer
+      // to bind the object
+      
+//    Properties env = new Properties();
+//    env.setProperty("java.naming.provider.url", providerURL);
+//    log.info("Env = " + env);
+//    Context ctx = new InitialContext(env);
+//    ctx.bind(NAME, VALUE);
+      
+      Naming namingServer = naming.getNamingInstance();
+      namingServer.bind(parser.parse(NAME), 
+                                      new MarshalledValuePair(VALUE), 
+                                      VALUE.getClass().getName());
+      log.info("Bound " + VALUE + " to " + namingServer + " under " + NAME);
+      Context sub = namingServer.createSubcontext(parser.parse(SUBCONTEXT_NAME));
+      sub.bind(parser.parse(NAME), VALUE);
+      log.info("Bound " + VALUE + " to " + sub + " under " + NAME);
+      
+      // NOTE: we must bind the NonDeserializable directly, or else the 
+      // NamingContext will wrap it in a MarshalledValuePair, which will
+      // defeat the test by triggering deserialization too late
+      namingServer.bind(parser.parse(BAD_BINDING), new NonDeserializable(), 
+                                     NonDeserializable.class.getName());
+
+      log.info("Bound a NonDeserializable to " + namingServer + " under " + BAD_BINDING);
+   }
+   
+   /* (non-Javadoc)
+    * @see org.jboss.test.naming.restart.ObjectBinderMBean#stop()
+    */
+   public void stop() throws Exception
+   {
+      // Standard JNDI
+      Context ctx = new InitialContext();
+      ctx.unbind(NAME);
+      log.info("Unbound " + NAME + " from " + ctx);
+      ctx.unbind(BAD_BINDING);
+      log.info("Unbound " + BAD_BINDING + " from " + ctx);
+      
+      // For some reason creating a context for our own JNDI doesn't work
+      // inside the server, so as a hack we directly deal with the NamingServer
+      // to bind the object
+      
+//    Properties env = new Properties();
+//    env.setProperty("java.naming.provider.url", providerURL);
+//    
+//    Context ctx = new InitialContext(env);
+//      ctx.unbind(NAME);
+      
+      Naming namingServer = naming.getNamingInstance();
+      try
+      {
+         namingServer.unbind(parser.parse(SUBCONTEXT_NAME + "/" + NAME));
+         log.info("Unbound " + SUBCONTEXT_NAME + "/" + NAME + " from " + namingServer);
+      }
+      catch (NameNotFoundException ignored)
+      {
+         // already unbound by test
+      }
+      try
+      {
+         namingServer.unbind(parser.parse(SUBCONTEXT_NAME));
+         log.info("Unbound " + SUBCONTEXT_NAME + " from " + namingServer);
+      }
+      catch (NameNotFoundException ignored)
+      {
+         // already unbound by test
+      }
+      try
+      {
+         namingServer.unbind(parser.parse(NAME));
+         log.info("Unbound " + NAME + " from " + namingServer);
+      }
+      catch (NameNotFoundException ignored)
+      {
+         // already unbound by test
+      }
+      try
+      {
+         namingServer.unbind(parser.parse(BAD_BINDING));
+         log.info("Unbound " + BAD_BINDING + " from " + namingServer);
+      }
+      catch (NameNotFoundException ignored)
+      {
+         // already unbound by test
+      }
+      
+   }
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,24 @@
+package org.jboss.test.naming.restart;
+
+
+public interface ObjectBinderMBean
+{
+
+   void setNamingService(RestartNamingServiceMBean naming);
+
+   /**
+    * Bind an object both in standard JNDI (to expose via HA-JNDI) and in our
+    * injected NamingServer
+    * 
+    * @throws Exception
+    */
+   void start() throws Exception;
+
+   /**
+    * Undoes the bindings done in start().
+    * 
+    * @throws Exception
+    */
+   void stop() throws Exception;
+
+}
\ No newline at end of file

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.restart;
+
+import org.jboss.ha.jndi.HANamingService;
+import org.jnp.interfaces.Naming;
+import org.jnp.interfaces.NamingContext;
+
+/**
+ * Subclass of HANamingService that ensures we don't screw up
+ * the in-VM NamingContext class static haServers map.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class RestartHANamingService extends HANamingService
+{
+
+   /**
+    * Create a new RestartHANamingService.
+    * 
+    */
+   public RestartHANamingService()
+   {
+      super();
+      this.replicantName = "RestartHAJNDI";
+   }
+
+   protected void createService() throws Exception
+   {
+      Naming naming = NamingContext.getHANamingServerForPartition(clusterPartition.getPartitionName());
+      try
+      {
+         super.createService();
+      }
+      finally
+      {
+         if (naming == null)
+            NamingContext.removeHANamingServerForPartition(clusterPartition.getPartitionName());
+         else
+            NamingContext.setHANamingServerForPartition(clusterPartition.getPartitionName(), naming);
+      }
+   }
+
+   protected void stopService() throws Exception
+   {
+      Naming naming = NamingContext.getHANamingServerForPartition(clusterPartition.getPartitionName());
+      try
+      {
+         super.stopService();
+      }
+      finally
+      {
+         if (naming != null)
+            NamingContext.setHANamingServerForPartition(clusterPartition.getPartitionName(), naming);
+      }
+   }
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBean.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBean.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBean.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.restart;
+
+import org.jnp.server.NamingBeanImpl;
+
+/**
+ * Make NamingBeanImpl a StandardMBean that exposes a couple
+ * additional properties as well as the Service lifecycle.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class RestartNamingBean extends NamingBeanImpl implements RestartNamingBeanMBean
+{
+
+   public void create() throws Exception
+   {
+      // no-op      
+   }
+
+   public void destroy()
+   {
+      // no-op     
+   }
+   
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBeanMBean.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBeanMBean.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBeanMBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingBeanMBean.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.restart;
+
+import org.jboss.system.Service;
+import org.jnp.server.NamingBean;
+
+/**
+ * A RestartNamingBeanMBean.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public interface RestartNamingBeanMBean extends NamingBean, Service
+{
+   boolean getUseGlobalService();
+   void setUseGlobalService(boolean useGlobal);
+
+   boolean getInstallGlobalService();
+   void setInstallGlobalService(boolean installGlobal);
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.restart;
+
+import java.rmi.server.UnicastRemoteObject;
+
+import org.jboss.naming.NamingService;
+import org.jnp.server.Main;
+
+/**
+ * Overrides NamingService to unexport the naming stub in stopService().
+ * Used to test what happens when this is done.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class RestartNamingService extends NamingService 
+   implements RestartNamingServiceMBean
+{
+
+   protected void startService() throws Exception
+   {
+      Main main = getNamingServer();
+      main.setUseGlobalService(false);
+      main.setInstallGlobalService(false);
+      
+      super.startService();
+   }
+
+   protected void stopService() throws Exception
+   {
+      super.stopService();
+      UnicastRemoteObject.unexportObject(getNamingInstance(), true);
+   }
+   
+   
+   
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java (from rev 71092, branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,19 @@
+package org.jboss.test.naming.restart;
+
+import org.jboss.naming.NamingServiceMBean;
+import org.jnp.interfaces.Naming;
+import org.jnp.server.NamingBean;
+
+public interface RestartNamingServiceMBean extends NamingServiceMBean
+{
+   boolean getUseGlobalService();
+   void setUseGlobalService(boolean useGlobal);
+
+   boolean getInstallGlobalService();
+   void setInstallGlobalService(boolean installGlobal);
+
+   Naming getNamingInstance();
+   
+   void setNaming(NamingBean bean);
+
+}
\ No newline at end of file

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java (from rev 71079, branches/JBoss_4_0_5_GA_CP/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	2008-03-20 19:06:14 UTC (rev 71093)
@@ -0,0 +1,470 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.naming.test;
+
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.naming.restart.ObjectBinder;
+import org.jnp.interfaces.MarshalledValuePair;
+import org.jnp.interfaces.NamingContext;
+
+/**
+ * A NamingRestartUnitTestCase.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class NamingRestartUnitTestCase extends JBossTestCase
+{
+   private static final String NAMING_PORT = "19099";
+   private static final String HA_NAMING_PORT = "19100";
+   private static final String DISCOVERY_ADDRESS = "230.9.9.9";
+   private static final String DISCOVERY_PORT = "19102";
+   private static final String PARTITION_NAME = "DefaultPartition";
+ 
+   private static final String BIND_NAME = "BindName";
+   private static final String BIND_VALUE = "BindValue";
+   
+   private static final String SUBCONTEXT_NAME = "RemoteSubcontext";
+   
+   private static boolean deployed = false;
+   
+   public NamingRestartUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(NamingRestartUnitTestCase.class, null);
+   }
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      if (!deployed)
+         deploy("naming-restart.sar");
+      deployed = true;
+   }
+   
+   
+   
+   protected void tearDown() throws Exception
+   {
+      if (deployed)
+      {
+         undeploy("naming-restart.sar");
+         deployed = false;
+      }
+      
+      super.tearDown();
+   }
+
+   public void testBind() throws Exception
+   {
+      log.info("Running testBind()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         ctx2.bind(BIND_NAME, BIND_VALUE);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      assertEquals(BIND_VALUE, ctx2.lookup(BIND_NAME));
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+   
+   public void testCreateSubcontext() throws Exception
+   {
+      log.info("Running testCreateSubcontext()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         Context sub = ctx2.createSubcontext(SUBCONTEXT_NAME);
+         sub.bind(BIND_NAME, BIND_VALUE);
+         assertEquals("Proper bind to " + SUBCONTEXT_NAME, BIND_VALUE, sub.lookup(BIND_NAME));
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+   
+   public void testLookupAfterHANamingRestart() throws Exception
+   {
+      log.info("Running testLookupAfterHANamingRestart");
+      
+      lookupTest(createNamingEnvironment(HA_NAMING_PORT));
+   }
+   
+   public void testAutoDiscoveryLookupAfterHANamingRestart() throws Exception
+   {
+      log.info("Running testAutoDiscoveryLookupAfterHANamingRestart");
+      
+      lookupTest(createNamingEnvironment(DISCOVERY_ADDRESS, DISCOVERY_PORT));
+   }
+
+   public void testLookupAfterNamingRestart() throws Exception
+   {
+      log.info("Running testLookupAfterNamingRestart");
+      
+      lookupTest(createNamingEnvironment(NAMING_PORT));
+   }
+   
+   private void lookupTest(Hashtable env) throws Exception
+   {
+      Context ctx1 = createInitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = createInitialContext(env);
+      NamingException ne = null;
+      try
+      {
+         assertEquals(ObjectBinder.VALUE, ctx2.lookup(ObjectBinder.NAME));
+      }
+      catch (NamingException e)
+      {
+         // Cache the exception to fail the test later, after
+         // we check that we can recover
+         log.error("Caught NamingException", e);
+         ne = e;
+      }
+      
+      // We recover from failure
+      if (ne != null)
+      {
+         try
+         {
+            assertEquals(ObjectBinder.VALUE, ctx2.lookup(ObjectBinder.NAME));
+         }
+         catch (Exception e)
+         {
+            log.error("Failed to reacquire server");
+         }
+         // Now fail due to the earlier failure
+         fail(ne.getMessage());         
+      }
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+
+   private Context createInitialContext(Hashtable env) throws NamingException
+   {
+      Context ctx1 = new InitialContext(env);
+      if (ctx1.getEnvironment().get(NamingContext.JNP_DISCOVERY_GROUP) != null)
+      {
+         ctx1.removeFromEnvironment(Context.PROVIDER_URL);
+      }
+      return ctx1;
+   }
+   
+   public void testList() throws Exception
+   {
+      log.info("Running testList()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         NamingEnumeration list = ctx2.list(ObjectBinder.SUBCONTEXT_NAME);
+         assertNotNull("NamingEnumeration returned", list);
+         assertTrue("NamingEnumeration has entry", list.hasMoreElements());
+         NameClassPair pair = (NameClassPair) list.next();
+         assertEquals(ObjectBinder.NAME, pair.getName());
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+   
+   public void testListBindings() throws Exception
+   {
+      log.info("Running testListBindings()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         NamingEnumeration list = ctx2.listBindings(ObjectBinder.SUBCONTEXT_NAME);
+         assertNotNull("NamingEnumeration returned", list);
+         assertTrue("NamingEnumeration has entry", list.hasMoreElements());
+         Binding binding = (Binding) list.next();
+         assertEquals(ObjectBinder.NAME, binding.getName());
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+   
+   public void testLookupLink() throws Exception
+   {
+      log.info("Running testLookupLink()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         Object obj = ctx2.lookupLink(ObjectBinder.NAME);
+         if (obj instanceof MarshalledValuePair)
+            obj = ((MarshalledValuePair) obj).get();
+         assertEquals(ObjectBinder.VALUE, obj);
+      }
+      catch (NamingException e)
+      {         
+         if (e.getCause() instanceof NullPointerException)
+         {
+            log.error("Caught known failure JBAS-4616", e);
+         }
+         else
+         {
+            log.error("Caught NamingException", e);
+            fail(e.getMessage());
+         }
+      }
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+   
+   public void testRebind() throws Exception
+   {
+      log.info("Running testRebind()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         ctx2.rebind(ObjectBinder.NAME, ObjectBinder.VALUE);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      // Confirm the original context is still good
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+   }
+   
+   public void testUnbind() throws Exception
+   {
+      log.info("Running testUnbind()");
+      
+      Properties env = createNamingEnvironment(NAMING_PORT);
+      
+      Context ctx1 = new InitialContext(env);
+      assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
+      
+      // HOLD ONTO REF to ctx1 so the ref to it does not get gc'ed from
+      // static map in org.jnp.interfaces.NamingContext.
+      
+      // Redeploy the naming service
+      redeployNaming();
+      
+      Context ctx2 = new InitialContext(env);
+      try
+      {
+         ctx2.unbind(ObjectBinder.NAME);
+      }
+      catch (NamingException e)
+      {
+         log.error("Caught NamingException", e);
+         fail(e.getMessage());
+      }
+      
+      // Confirm the original context is still good
+      ctx1.bind(BIND_NAME, BIND_VALUE);
+   }
+   
+   public void testBadBindingHALookup() throws Exception
+   {
+      log.info("Running testBadBindingHALookup");
+      
+      badBindingLookupTest(HA_NAMING_PORT);
+   }
+
+   public void testBadBindingLookup() throws Exception
+   {
+      log.info("Running testBadBindingLookup");
+      
+      badBindingLookupTest(NAMING_PORT);
+   }
+   
+   /**
+    * Tests a lookup of an object that deliberately throws
+    * java.rmi.NoSuchObjectException when deserialized. Used 
+    * to check that this doesn't confuse the NamingContext.
+    * 
+    * @param port
+    * @throws Exception
+    */
+   private void badBindingLookupTest(String port) throws Exception
+   {
+      Properties env = createNamingEnvironment(port);
+      
+      Context ctx = new InitialContext(env);
+      try
+      {
+         ctx.lookup(ObjectBinder.BAD_BINDING);
+         fail("Did not fail in lookup of " + ObjectBinder.BAD_BINDING);
+      }
+      catch (NamingException good)
+      {
+         log.debug("Caught NamingException as expected: " + 
+                   good.getLocalizedMessage() + " -- cause: " + 
+                   good.getCause());
+      }
+      
+      // We recover from failure
+      assertEquals(ObjectBinder.VALUE, ctx.lookup(ObjectBinder.NAME));
+   }
+
+   private Properties createNamingEnvironment(String port)
+   {
+      String namingURL = getServerHost() + ":" + port;
+      Properties env = new Properties();
+      env.setProperty(Context.PROVIDER_URL, namingURL);
+      env.setProperty(NamingContext.JNP_DISABLE_DISCOVERY, "true");
+      return env;
+   }
+
+   private Properties createNamingEnvironment(String mcastAddress, String mcastPort)
+   {
+      Properties env = new Properties();
+//      env.setProperty(NamingContext.JNP_PARTITION_NAME, PARTITION_NAME);
+      env.setProperty(NamingContext.JNP_DISCOVERY_GROUP, mcastAddress);
+      env.setProperty(NamingContext.JNP_DISCOVERY_PORT, mcastPort);
+      return env;
+   }
+
+   private void redeployNaming() throws Exception
+   {
+      deployed = false;
+      redeploy("naming-restart.sar");
+      deployed = true;
+   }
+
+}

Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/naming/restart (from rev 71081, branches/Branch_4_2/testsuite/src/resources/naming/restart)




More information about the jboss-cvs-commits mailing list