[jboss-cvs] JBossAS SVN: r64718 - trunk/testsuite/src/main/org/jboss/test/naming/restart.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 20 15:38:26 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-08-20 15:38:26 -0400 (Mon, 20 Aug 2007)
New Revision: 64718
Added:
trunk/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java
Modified:
trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
Log:
[JBAS-4615] Add tests for all Context methods
Copied: trunk/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java (from rev 64711, branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/naming/restart/NonDeserializable.java 2007-08-20 19:38:26 UTC (rev 64718)
@@ -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");
+ }
+}
Modified: trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java 2007-08-20 19:36:38 UTC (rev 64717)
+++ trunk/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java 2007-08-20 19:38:26 UTC (rev 64718)
@@ -22,15 +22,14 @@
package org.jboss.test.naming.restart;
-import java.rmi.Naming;
-import java.util.Properties;
-
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
import org.jboss.logging.Logger;
import org.jboss.naming.NamingServiceMBean;
import org.jnp.interfaces.MarshalledValuePair;
+import org.jnp.interfaces.Naming;
import org.jnp.interfaces.NamingParser;
/**
@@ -44,11 +43,16 @@
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";
- private String providerURL;
+ public static final String SUBCONTEXT_NAME = "LocalSubcontext";
+// private String providerURL;
private NamingParser parser = new NamingParser();
private NamingServiceMBean naming;
+ /* (non-Javadoc)
+ * @see org.jboss.test.naming.restart.ObjectBinderMBean#setNamingService(org.jboss.naming.NamingServiceMBean)
+ */
public void setNamingService(NamingServiceMBean naming)
{
// this.providerURL = (naming == null)
@@ -69,6 +73,8 @@
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
@@ -80,10 +86,23 @@
// Context ctx = new InitialContext(env);
// ctx.bind(NAME, VALUE);
- naming.getNamingInstance().bind(parser.parse(NAME),
+ Naming namingServer = naming.getNamingInstance();
+ namingServer.bind(parser.parse(NAME),
new MarshalledValuePair(VALUE),
VALUE.getClass().getName());
- log.info("Bound " + VALUE + " to " + naming.getNamingInstance() + " under " + NAME);
+ 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);
+
}
/**
@@ -97,6 +116,8 @@
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
@@ -108,7 +129,42 @@
// Context ctx = new InitialContext(env);
// ctx.unbind(NAME);
- naming.getNamingInstance().unbind(parser.parse(NAME));
- log.info("Unbound " + NAME + " from " + naming.getNamingInstance());
+ 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
+ }
}
}
Modified: trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java 2007-08-20 19:36:38 UTC (rev 64717)
+++ trunk/testsuite/src/main/org/jboss/test/naming/restart/RestartNamingService.java 2007-08-20 19:38:26 UTC (rev 64718)
@@ -25,9 +25,11 @@
import java.rmi.server.UnicastRemoteObject;
import org.jboss.naming.NamingService;
+import org.jnp.server.Main;
/**
- * Overrides NamingService to unexport the naming stub in stopService().
+ * Overrides NamingService in startService() to not use the AS's statically
+ * cached NamingServer and to unexport the naming stub in stopService().
* Used to test what happens when this is done, which is a better simulation
* of the normal way a NamingService is restarted -- via a full server
* restart.
@@ -37,6 +39,15 @@
*/
public class RestartNamingService extends NamingService
{
+ @Override
+ protected void startService() throws Exception
+ {
+ Main main = getNamingServer();
+ main.setUseGlobalService(false);
+ main.setInstallGlobalService(false);
+
+ super.startService();
+ }
@Override
protected void stopService() throws Exception
@@ -44,6 +55,4 @@
super.stopService();
UnicastRemoteObject.unexportObject(getNamingInstance(), true);
}
-
-
}
More information about the jboss-cvs-commits
mailing list