[jboss-cvs] JBossAS SVN: r64710 - in branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming: test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 20 14:11:32 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-08-20 14:11:32 -0400 (Mon, 20 Aug 2007)
New Revision: 64710
Modified:
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/test/NamingRestartUnitTestCase.java
Log:
[JBAS-4574] Add further tests
Modified: 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 2007-08-20 16:34:02 UTC (rev 64709)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/restart/ObjectBinder.java 2007-08-20 18:11:32 UTC (rev 64710)
@@ -42,6 +42,7 @@
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;
@@ -62,6 +63,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
@@ -82,6 +85,13 @@
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)
@@ -93,6 +103,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
@@ -132,6 +144,15 @@
{
// 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: branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java 2007-08-20 16:34:02 UTC (rev 64709)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/testsuite/src/main/org/jboss/test/naming/test/NamingRestartUnitTestCase.java 2007-08-20 18:11:32 UTC (rev 64710)
@@ -53,7 +53,7 @@
private static final String SUBCONTEXT_NAME = "RemoteSubcontext";
- private static boolean deployed = true;
+ private static boolean deployed = false;
public NamingRestartUnitTestCase(String name)
{
@@ -62,7 +62,7 @@
public static Test suite() throws Exception
{
- return getDeploySetup(NamingRestartUnitTestCase.class, "naming-restart.sar");
+ return getDeploySetup(NamingRestartUnitTestCase.class, null);
}
protected void setUp() throws Exception
@@ -71,8 +71,22 @@
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()");
@@ -100,6 +114,9 @@
}
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
@@ -129,6 +146,9 @@
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
@@ -186,6 +206,9 @@
// Now fail due to the earlier failure
fail(ne.getMessage());
}
+
+ // Confirm the original context is still good
+ assertEquals(ObjectBinder.VALUE, ctx1.lookup(ObjectBinder.NAME));
}
public void testList() throws Exception
@@ -217,6 +240,9 @@
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
@@ -248,6 +274,9 @@
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
@@ -278,6 +307,9 @@
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
@@ -305,6 +337,9 @@
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
@@ -332,8 +367,54 @@
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(haNamingPort);
+ }
+ public void testBadBindingLookup() throws Exception
+ {
+ log.info("Running testBadBindingLookup");
+
+ badBindingLookupTest(namingPort);
+ }
+
+ /**
+ * 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;
More information about the jboss-cvs-commits
mailing list