[jboss-cvs] JBossAS SVN: r64668 - branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 17 15:41:53 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-08-17 15:41:53 -0400 (Fri, 17 Aug 2007)
New Revision: 64668
Added:
branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java
branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java
branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
Log:
[JBAS-4574] Test for JBAS-4574
Added: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java (rev 0)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java 2007-08-17 19:41:53 UTC (rev 64668)
@@ -0,0 +1,111 @@
+/*
+ * 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.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 implements ObjectBinderMBean
+{
+ 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 RestartNamingServiceMBean naming;
+
+ /* (non-Javadoc)
+ * @see org.jboss.test.naming.restart.ObjectBinderMBean#setNamingService(org.jboss.naming.NamingServiceMBean)
+ */
+ public void setNamingService(RestartNamingServiceMBean naming)
+ {
+// this.providerURL = (naming == null)
+// ? null
+// : naming.getBindAddress() + ":" + naming.getPort();
+ this.naming = naming;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.test.naming.restart.ObjectBinderMBean#start()
+ */
+ 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);
+ }
+
+ /* (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);
+
+ // 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: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java (rev 0)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java 2007-08-17 19:41:53 UTC (rev 64668)
@@ -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
Property changes on: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinderMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java (rev 0)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java 2007-08-17 19:41:53 UTC (rev 64668)
@@ -0,0 +1,77 @@
+/*
+ * 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();
+ }
+
+ 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);
+ }
+ }
+}
Property changes on: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartHANamingService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java (rev 0)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java 2007-08-17 19:41:53 UTC (rev 64668)
@@ -0,0 +1,67 @@
+/*
+ * 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.interfaces.Naming;
+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
+{
+
+ /* (non-Javadoc)
+ * @see org.jboss.test.naming.restart.RestartNamingServiceMBean#getNaming()
+ */
+ public Naming getNamingInstance()
+ {
+ return getNamingServer().getServer();
+ }
+
+ 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(getNamingServer().getServer(), true);
+ }
+
+
+
+}
Property changes on: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list