[jboss-cvs] JBossAS SVN: r65552 - in branches/Branch_4_2/testsuite: src/main/org/jboss/test/naming and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Sep 22 01:24:57 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-09-22 01:24:57 -0400 (Sat, 22 Sep 2007)
New Revision: 65552

Added:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
   branches/Branch_4_2/testsuite/src/resources/naming/restart/
Modified:
   branches/Branch_4_2/testsuite/imports/sections/naming.xml
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java
   branches/Branch_4_2/testsuite/src/resources/naming/restart/jboss-service.xml
Log:
[JBAS-4615] Flush cached Naming stub and retry on NoSuchObjectException
[JBAS-4622] Ensure JBAS-4615 fix works when no java.naming.provider.url is specified

Modified: branches/Branch_4_2/testsuite/imports/sections/naming.xml
===================================================================
--- branches/Branch_4_2/testsuite/imports/sections/naming.xml	2007-09-22 05:21:28 UTC (rev 65551)
+++ branches/Branch_4_2/testsuite/imports/sections/naming.xml	2007-09-22 05:24:57 UTC (rev 65552)
@@ -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/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart (from rev 65512, branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/main/org/jboss/test/naming/restart)

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java	2007-09-20 23:58:12 UTC (rev 65512)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java	2007-09-22 05:24:57 UTC (rev 65552)
@@ -43,6 +43,7 @@
    public RestartHANamingService()
    {
       super();
+      this.replicantName = "RestartHAJNDI";
    }
 
    protected void createService() throws Exception

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java	2007-09-20 23:58:12 UTC (rev 65512)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java	2007-09-22 05:24:57 UTC (rev 65552)
@@ -25,7 +25,6 @@
 import java.rmi.server.UnicastRemoteObject;
 
 import org.jboss.naming.NamingService;
-import org.jnp.interfaces.Naming;
 import org.jnp.server.Main;
 
 /**
@@ -39,14 +38,6 @@
    implements RestartNamingServiceMBean
 {
 
-   /* (non-Javadoc)
-    * @see org.jboss.test.naming.restart.RestartNamingServiceMBean#getNaming()
-    */
-   public Naming getNamingInstance()
-   {
-      return getNamingServer().getServer();
-   }
-   
    protected void startService() throws Exception
    {
       Main main = getNamingServer();
@@ -59,7 +50,7 @@
    protected void stopService() throws Exception
    {
       super.stopService();
-      UnicastRemoteObject.unexportObject(getNamingServer().getServer(), true);
+      UnicastRemoteObject.unexportObject(getNamingInstance(), true);
    }
    
    

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java	2007-09-20 23:58:12 UTC (rev 65512)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingServiceMBean.java	2007-09-22 05:24:57 UTC (rev 65552)
@@ -2,6 +2,7 @@
 
 import org.jboss.naming.NamingServiceMBean;
 import org.jnp.interfaces.Naming;
+import org.jnp.server.NamingBean;
 
 public interface RestartNamingServiceMBean extends NamingServiceMBean
 {
@@ -12,5 +13,7 @@
    void setInstallGlobalService(boolean installGlobal);
 
    Naming getNamingInstance();
+   
+   void setNaming(NamingBean bean);
 
 }
\ No newline at end of file

Copied: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java (from rev 65512, branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java)
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	2007-09-22 05:24:57 UTC (rev 65552)
@@ -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/Branch_4_2/testsuite/src/resources/naming/restart (from rev 65512, branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/resources/naming/restart)

Modified: branches/Branch_4_2/testsuite/src/resources/naming/restart/jboss-service.xml
===================================================================
--- branches/JBoss_4_0_5_GA_CP06_JBAS-4631/testsuite/src/resources/naming/restart/jboss-service.xml	2007-09-20 23:58:12 UTC (rev 65512)
+++ branches/Branch_4_2/testsuite/src/resources/naming/restart/jboss-service.xml	2007-09-22 05:24:57 UTC (rev 65552)
@@ -11,6 +11,15 @@
    <!-- ==================================================================== -->
    <!-- JNDI                                                                 -->
    <!-- ==================================================================== -->
+   
+   <mbean code="org.jboss.test.naming.restart.RestartNamingBean"
+      name="jboss:service=RestartNamingBean">
+      
+      <!-- IMPORTANT Ensure we use our own NamingServer and don't screw up the
+           static ref to the std one in the server-side NamingContext class -->
+      <attribute name="UseGlobalService">false</attribute>      
+      <attribute name="InstallGlobalService">false</attribute>
+   </mbean>
 
    <!-- Use our own NamingService subclass that unexports the NamingServer
         in stopService().  This better simulates a server shutdown. 
@@ -32,6 +41,9 @@
       <attribute name="RmiBindAddress">${jboss.bind.address}</attribute>
       <depends optional-attribute-name="LookupPool"
          proxy-type="attribute">jboss.system:service=ThreadPool</depends>
+         
+      <depends optional-attribute-name="Naming"
+         proxy-type="attribute">jboss:service=RestartNamingBean</depends>
    </mbean>
 
    <!-- Our own HA-JNDI that we can redeploy.  Subclasses std HA-JNDI service




More information about the jboss-cvs-commits mailing list