[jboss-cvs] JBossAS SVN: r64587 - in trunk/testsuite/src: main/org/jboss/test/naming/restart and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 14 16:20:09 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-08-14 16:20:09 -0400 (Tue, 14 Aug 2007)
New Revision: 64587

Added:
   trunk/testsuite/src/main/org/jboss/test/naming/restart/
   trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
   trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
   trunk/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
   trunk/testsuite/src/resources/naming/restart/
   trunk/testsuite/src/resources/naming/restart/naming-restart-beans.xml
Log:
Add test of naming proxy validity following server-side restart

Added: trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java	2007-08-14 20:20:09 UTC (rev 64587)
@@ -0,0 +1,114 @@
+/*
+ * 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.Naming;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.naming.NamingServiceMBean;
+import org.jnp.interfaces.MarshalledValuePair;
+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
+{
+   private static Logger log = Logger.getLogger(ObjectBinder.class);
+   
+   public static final String NAME = "NamingRestartBinding";
+   public static final String VALUE = "VALUE";
+   private String providerURL;  
+   private NamingParser parser = new NamingParser();
+   private NamingServiceMBean naming;
+   
+   public void setNamingService(NamingServiceMBean naming)
+   {
+//      this.providerURL = (naming == null) 
+//                              ? null 
+//                              : naming.getBindAddress() + ":" + naming.getPort();
+      this.naming = naming;
+   }
+   
+   /**
+    * Bind an object both in standard JNDI (to expose via HA-JNDI) and in our
+    * injected NamingServer
+    * 
+    * @throws Exception
+    */
+   public void start() throws Exception
+   {      
+      // Standard JNDI
+      Context ctx = new InitialContext();
+      ctx.bind(NAME, VALUE);
+      log.info("Bound " + VALUE + " to " + ctx + " under " + NAME);
+      
+      // 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.getNamingInstance().bind(parser.parse(NAME), 
+                                      new MarshalledValuePair(VALUE), 
+                                      VALUE.getClass().getName());
+      log.info("Bound " + VALUE + " to " + naming.getNamingInstance() + " under " + NAME);
+   }
+   
+   /**
+    * Undoes the bindings done in start().
+    * 
+    * @throws Exception
+    */
+   public void stop() throws Exception
+   {
+      // Standard JNDI
+      Context ctx = new InitialContext();
+      ctx.unbind(NAME);
+      log.info("Unbound " + NAME + " 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.getNamingInstance().unbind(parser.parse(NAME));
+      log.info("Unbound " + NAME + " from " + naming.getNamingInstance());
+   }
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java	2007-08-14 20:20:09 UTC (rev 64587)
@@ -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.rmi.server.UnicastRemoteObject;
+
+import org.jboss.naming.NamingService;
+
+/**
+ * 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
+{
+
+   @Override
+   protected void stopService() throws Exception
+   {
+      super.stopService();
+      UnicastRemoteObject.unexportObject(getNamingInstance(), false);
+   }
+   
+   
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: trunk/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java	2007-08-14 20:20:09 UTC (rev 64587)
@@ -0,0 +1,128 @@
+/*
+ * 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.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.naming.restart.ObjectBinder;
+
+/**
+ * A NamingRestartUnitTestCase.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class NamingRestartUnitTestCase extends JBossTestCase
+{
+   private static final String namingPort = "9099";
+   private static final String haNamingPort = "1110";
+ 
+   private static boolean deployed = true;
+   
+   public NamingRestartUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(NamingRestartUnitTestCase.class, "naming-restart.sar");
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      if (!deployed)
+         deploy("naming-restart.sar");
+   }
+   
+   public void testLookupAfterHANamingRestart() throws Exception
+   {
+      namingRestartTest(haNamingPort);
+   }
+
+   public void testLookupAfterNamingRestart() throws Exception
+   {
+      namingRestartTest(namingPort);
+   }
+   
+   private void namingRestartTest(String port) throws Exception
+   {
+      String namingURL = getServerHost() + ":" + port;
+      Properties env = new Properties();
+      env.setProperty("java.naming.provider.url", namingURL);
+      env.setProperty("jnp.disableDiscovery", "true");
+      
+      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
+      deployed = false;
+      redeploy("naming-restart.sar");
+      deployed = true;
+      
+      Context ctx2 = new InitialContext(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());         
+      }
+      
+      
+   }
+
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: trunk/testsuite/src/resources/naming/restart/naming-restart-beans.xml
===================================================================
--- trunk/testsuite/src/resources/naming/restart/naming-restart-beans.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/naming/restart/naming-restart-beans.xml	2007-08-14 20:20:09 UTC (rev 64587)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="RestartNamingBean" class="org.jnp.server.NamingBeanImpl">
+      <property name="useGlobalService">false</property>      
+      <property name="installGlobalService">false</property>
+   </bean>
+   
+   <!--bean name="RestartNamingService" class="org.jboss.test.naming.restart.RestartNamingService" -->
+   <bean name="RestartNamingService" class="org.jboss.naming.NamingService">
+   
+      <property name="callByValue">false</property>
+      <property name="port">9099</property>
+      <property name="bindAddress">${jboss.bind.address}</property>
+      <property name="rmiPort">9098</property>
+      <property name="rmiBindAddress">${jboss.bind.address}</property>
+      <property name="lookupPool"><inject bean="jboss.system:service=ThreadPool"/></property>   
+      <property name="naming"><inject bean="RestartNamingBean"/></property>
+   </bean>
+   
+   <bean name="RestartHAJNDI" class="org.jboss.ha.jndi.HANamingService">
+   	
+   	<depends>HAPartition</depends>
+      	       
+      <property name="HAPartition"><inject bean="HAPartition"/></property>
+      <property name="clusteredCache"><inject bean="DefaultPartition-HAPartitionCache" property="cache"/></property>
+      
+      <!-- Bind address of bootstrap and HA-JNDI RMI endpoints -->
+      <property name="bindAddress">${jboss.bind.address}</property>
+      <!-- Port on which the HA-JNDI stub is made available -->
+      <property name="port">1110</property>
+      <!-- RmiPort to be used by the HA-JNDI service once bound. 0 => auto. -->
+      <property name="rmiPort">1111</property>
+      <!-- Accept backlog of the bootstrap socket -->
+      <property name="backlog">50</property>
+      <!-- The thread pool service used to control the bootstrap and
+      auto discovery lookups -->
+      <property name="lookupPool"><inject bean="jboss.system:service=ThreadPool"/></property>
+
+      <!-- A flag to disable the auto discovery via multicast -->
+      <property name="discoveryDisabled">true</property>
+      <!-- The load balancing policy for HA-JNDI -->
+      <property name="loadBalancePolicy">org.jboss.ha.framework.interfaces.RoundRobin</property>
+      
+   </bean>
+   
+   <bean name="RestartObjectBinder" class="org.jboss.test.naming.restart.ObjectBinder">
+      <property name="namingService"><inject bean="RestartNamingService"/></property>      
+   </bean>
+
+   
+</deployment>
\ No newline at end of file


Property changes on: trunk/testsuite/src/resources/naming/restart/naming-restart-beans.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list