[jboss-cvs] JBossAS SVN: r60976 - branches/Branch_4_2/testsuite/src/main/org/jboss/test/testbeancluster/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 27 21:55:56 EST 2007
Author: bstansberry at jboss.com
Date: 2007-02-27 21:55:55 -0500 (Tue, 27 Feb 2007)
New Revision: 60976
Modified:
branches/Branch_4_2/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java
Log:
If server has -u set, client should use the value for HA-JNDI discovery
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java 2007-02-28 02:53:42 UTC (rev 60975)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java 2007-02-28 02:55:55 UTC (rev 60976)
@@ -21,8 +21,15 @@
*/
package org.jboss.test.testbeancluster.test;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.util.Enumeration;
import java.util.Properties;
import java.util.Random;
+import java.util.Vector;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -52,6 +59,10 @@
*/
public class RetryInterceptorUnitTestCase extends JBossClusteredTestCase
{
+ private static final String DISCOVERY_GROUP = System.getProperty("jbosstest.udpGroup");
+
+ private static File customJndiProperties = null;
+
// NOTE: these variables must be static as apparently a separate instance
// of this class is created for each test.
private static boolean deployed0 = false;
@@ -69,8 +80,20 @@
public void run()
{
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try
{
+ if (customJndiProperties != null)
+ {
+ // Create a special classloader that will read in the
+ // customJndiProperties file and include it in any
+ // getResources("jndi.properties") request.
+ // We use this to allow running the server with
+ // HA-JNDI autodiscovery set to a custom address
+ ClassLoader cl = new CustomJndiPropertiesClassLoader(tccl);
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+
// Establish an initial context on this thread with the
// given properties -- needed for JBoss NamingContextFactory
// to work properly. Meaningless otherwise
@@ -80,8 +103,12 @@
}
catch (Throwable t)
{
- failure = t;
+ failure = t;
}
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
}
protected abstract void executeTest() throws Throwable;
@@ -461,6 +488,26 @@
public void testRetryWithJnpAndAutoDiscovery() throws Exception
{
getLog().debug("+++ Enter testRetryWithJnpAndAutoDiscovery()");
+
+ if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
+ {
+ // The server isn't listening on the std multicast address
+ // for auto discovery, so we have to pretend there is a jndi.properties
+ // telling the NamingContext what address to use
+ customJndiProperties = File.createTempFile("jnp-discoveryGroup", ".properties");
+ FileOutputStream fos = new FileOutputStream(customJndiProperties);
+ OutputStreamWriter writer = new OutputStreamWriter(fos);
+ writer.write("jnp.discoveryGroup=" + DISCOVERY_GROUP);
+ writer.close();
+ getLog().debug("Created custom jndi.properties at " + customJndiProperties +
+ " -- DISCOVERY_GROUP is " + DISCOVERY_GROUP);
+ }
+ else
+ {
+ getLog().debug("Not creating custom jndi.properties -- " +
+ "DISCOVERY_GROUP is " + DISCOVERY_GROUP);
+ }
+
Properties env = getNamingProperties("org.jnp.interfaces.NamingContextFactory", true);
InitialContext ctx = new InitialContext(env);
@@ -512,8 +559,17 @@
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, namingFactoryClass);
env.setProperty(Context.PROVIDER_URL, urls[0]);
+
if (!autoDiscovery)
+ {
env.setProperty("jnp.disableDiscovery", "true");
+ }
+ else if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
+ {
+ // Use the multicast address this test environment is using
+ env.put("jnp.discoveryGroup", DISCOVERY_GROUP);
+ }
+
return env;
}
@@ -561,6 +617,22 @@
{
super.tearDown();
+ if (customJndiProperties != null)
+ {
+ try
+ {
+ customJndiProperties.delete();
+ if (customJndiProperties.exists())
+ customJndiProperties.deleteOnExit();
+ }
+ catch (Exception e)
+ {
+ log.error("problem cleaning customJndiProperties", e);
+ }
+
+ customJndiProperties = null;
+ }
+
if (System.getProperty("JBossCluster-DoFail") != null)
System.setProperty("JBossCluster-DoFail", "false");
@@ -598,5 +670,45 @@
{
deployed1 = deployed;
}
+
+ static class CustomJndiPropertiesClassLoader extends ClassLoader
+ {
+ private static final Logger log = Logger.getLogger(CustomJndiPropertiesClassLoader.class);
+
+ CustomJndiPropertiesClassLoader(ClassLoader parent)
+ {
+ super(parent);
+ log.info("Constructed; using customJndiProperties " + customJndiProperties);
+ }
+ /**
+ * If customJndiProperties exists, include its URL in any request
+ * for "jndi.properties"
+ */
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException
+ {
+ Enumeration<URL> result = super.getResources(name);
+
+ if (customJndiProperties != null
+ && "jndi.properties".equals(name))
+ {
+ log.info("Adding custom jndi.properties");
+
+ Vector<URL> v = new Vector<URL>();
+ v.add(customJndiProperties.toURL());
+ if (result != null)
+ {
+ while (result.hasMoreElements())
+ v.add(result.nextElement());
+ }
+ result = v.elements();
+ }
+
+ return result;
+ }
+
+
+ }
+
}
More information about the jboss-cvs-commits
mailing list