[jboss-cvs] JBossAS SVN: r61076 - in trunk/testsuite/src/main/org/jboss/test: naming/test and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Mar 4 17:03:50 EST 2007
Author: bstansberry at jboss.com
Date: 2007-03-04 17:03:50 -0500 (Sun, 04 Mar 2007)
New Revision: 61076
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java
trunk/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java
Log:
Limit autodiscovery packet TTL
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java 2007-03-04 21:57:03 UTC (rev 61075)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java 2007-03-04 22:03:50 UTC (rev 61076)
@@ -400,7 +400,10 @@
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
-
+ // Don't let the discovery packet off the test server so we don't
+ // get spurious responses from other servers on the network
+ env.put("jnp.discoveryTTL", "1");
+
if (autoDisabled)
{
env.put("jnp.disableDiscovery", "true");
Modified: trunk/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java 2007-03-04 21:57:03 UTC (rev 61075)
+++ trunk/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java 2007-03-04 22:03:50 UTC (rev 61076)
@@ -236,6 +236,9 @@
env.setProperty(Context.PROVIDER_URL, "jnp://" + serverHost + ":65535/");
env.setProperty("jnp.localAddress", serverHost);
env.setProperty("jnp.partitionName", "DefaultPartition");
+ // Don't let the discovery packet off the test server so we don't
+ // get spurious responses from other servers on the network
+ env.setProperty("jnp.discoveryTTL", "1");
if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
{
// Server is not listening for discovery on std multicast address
@@ -284,6 +287,9 @@
env.setProperty(Context.PROVIDER_URL, "jnp://" + serverHost + ":65535/");
env.setProperty("jnp.localAddress", serverHost);
env.setProperty("jnp.discoveryPort", "1102");
+ // Don't let the discovery packet off the test server so we don't
+ // get spurious responses from other servers on the network
+ env.setProperty("jnp.discoveryTTL", "1");
if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
{
// Server is not listening for discovery on std multicast address
Modified: trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java 2007-03-04 21:57:03 UTC (rev 61075)
+++ trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java 2007-03-04 22:03:50 UTC (rev 61076)
@@ -24,13 +24,11 @@
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.net.URLClassLoader;
import java.util.Properties;
import java.util.Random;
-import java.util.Vector;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -62,6 +60,7 @@
{
private static final String DISCOVERY_GROUP = System.getProperty("jbosstest.udpGroup");
+ private static File customJndiDir = null;
private static File customJndiProperties = null;
// NOTE: these variables must be static as apparently a separate instance
@@ -91,7 +90,8 @@
// 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);
+ URL[] urls = new URL[]{ customJndiProperties.toURL() };
+ ClassLoader cl = new URLClassLoader(urls, tccl);
Thread.currentThread().setContextClassLoader(cl);
}
@@ -490,25 +490,29 @@
{
getLog().debug("+++ Enter testRetryWithJnpAndAutoDiscovery()");
+ // Create a jndi.properties in the temp dir with special configs
+ // to prevent autodiscovery spuriously discovering random servers
+ // on the network. When the RetryCaller runs, it will create a
+ // special classloader that will pick up this file
+ if (customJndiDir == null)
+ customJndiDir = new File(System.getProperty("java.io.tempdir"),
+ "retry-int-test");
+ if (!customJndiDir.exists())
+ customJndiDir.mkdir();
+ customJndiProperties = new File(customJndiDir, "jndi.properties");
+ FileOutputStream fos = new FileOutputStream(customJndiProperties);
+ OutputStreamWriter writer = new OutputStreamWriter(fos);
+ writer.write("jnp.discoveryTTL=1\n");
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);
- }
+ writer.close();
+ getLog().debug("Created custom jndi.properties at " + customJndiProperties +
+ " -- DISCOVERY_GROUP is " + DISCOVERY_GROUP);
+
Properties env = getNamingProperties("org.jnp.interfaces.NamingContextFactory", true);
InitialContext ctx = new InitialContext(env);
@@ -560,6 +564,9 @@
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, namingFactoryClass);
env.setProperty(Context.PROVIDER_URL, urls[0]);
+ // Don't let the discovery packet off the test server so we don't
+ // get spurious responses from other servers on the network
+ env.setProperty("jnp.discoveryTTL", "1");
if (!autoDiscovery)
{
@@ -634,6 +641,22 @@
customJndiProperties = null;
}
+ if (customJndiDir != null)
+ {
+ try
+ {
+ customJndiDir.delete();
+ if (customJndiDir.exists())
+ customJndiDir.deleteOnExit();
+ }
+ catch (Exception e)
+ {
+ log.error("problem cleaning customJndiDir", e);
+ }
+
+ customJndiProperties = null;
+ }
+
if (System.getProperty("JBossCluster-DoFail") != null)
System.setProperty("JBossCluster-DoFail", "false");
@@ -670,46 +693,6 @@
protected void setDeployed1(boolean deployed)
{
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