[jboss-cvs] JBossAS SVN: r60977 - in branches/Branch_4_0/testsuite: src/main/org/jboss/test/cluster/jmx/test and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 27 22:34:10 EST 2007
Author: bstansberry at jboss.com
Date: 2007-02-27 22:34:09 -0500 (Tue, 27 Feb 2007)
New Revision: 60977
Modified:
branches/Branch_4_0/testsuite/build.xml
branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java
branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/partition/test/PartitionRestartUnitTestCase.java
branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java
branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
branches/Branch_4_0/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java
Log:
Support HA-JNDI discovery when -u is used on server side
Modified: branches/Branch_4_0/testsuite/build.xml
===================================================================
--- branches/Branch_4_0/testsuite/build.xml 2007-02-28 02:55:55 UTC (rev 60976)
+++ branches/Branch_4_0/testsuite/build.xml 2007-02-28 03:34:09 UTC (rev 60977)
@@ -71,6 +71,9 @@
<!-- A blank value will prevent the -u option from being passed -->
<!-- Override this in the local.properties or pass to Ant as -DupdGroup=128.x.x.x -->
<property name="udpGroup" value=""/>
+ <!-- Same thing, but passed to the client -->
+ <property name="jbosstest.udpGroup" value="${udpGroup}"/>
+
<!-- =================== -->
<!-- Basic Configuration -->
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java 2007-02-28 02:55:55 UTC (rev 60976)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/jmx/test/HAInvokerUnitTestCase.java 2007-02-28 03:34:09 UTC (rev 60977)
@@ -21,6 +21,11 @@
*/
package org.jboss.test.cluster.jmx.test;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
import org.jboss.invocation.ServiceUnavailableException;
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.test.JBossClusteredTestCase;
@@ -54,9 +59,16 @@
public void testHAProxyFailover()
throws Exception
{
- getLog().debug("testHAProxyFailover");
+ getLog().debug("testHAProxyFailover");
- HAServiceRemote remote = (HAServiceRemote) getInitialContext().lookup("jmx/HAService");
+ String[] urls = getNamingURLs();
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ env.setProperty(Context.PROVIDER_URL, urls[0]);
+ Context ctx = new InitialContext(env);
+
+ HAServiceRemote remote = (HAServiceRemote) ctx.lookup("jmx/HAService");
assertEquals("Hello", remote.hello());
String nodeA = remote.getClusterNode();
assertNotNull("Got clusterNode", nodeA);
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/partition/test/PartitionRestartUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/partition/test/PartitionRestartUnitTestCase.java 2007-02-28 02:55:55 UTC (rev 60976)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/partition/test/PartitionRestartUnitTestCase.java 2007-02-28 03:34:09 UTC (rev 60977)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.cluster.partition.test;
+import java.util.Properties;
+
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -64,7 +66,12 @@
RMIAdaptor[] adaptors = this.getAdaptors();
- Context ctx = new InitialContext();
+ String[] urls = getNamingURLs();
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ env.setProperty(Context.PROVIDER_URL, urls[0]);
+ Context ctx = new InitialContext(env);
getLog().debug("OK");
getLog().debug("");
@@ -124,7 +131,12 @@
Object[] params = new Object[0];
String[] types = new String[0];
adaptor.invoke(partition, "stop", params, types);
+
+ sleep(2000);
+
adaptor.invoke(partition, "start", params, types);
+
+ sleep(2000);
}
}
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java 2007-02-28 02:55:55 UTC (rev 60976)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java 2007-02-28 03:34:09 UTC (rev 60977)
@@ -48,6 +48,7 @@
private static final String NODE1_JNDI = System.getProperty("node1.jndi.url");
private static final String NODE0_HAJNDI = System.getProperty("node0.hajndi.url");
private static final String NODE1_HAJNDI = System.getProperty("node1.hajndi.url");
+ private static final String DISCOVERY_GROUP = System.getProperty("jbosstest.udpGroup");
// BINDING KEYS and VALUES
private static final String LOCAL0_KEY = "org.jboss.test.cluster.test.Local0Key";
@@ -70,8 +71,7 @@
public static Test suite() throws Exception
{
- Test t1 = JBossClusteredTestCase.getDeploySetup(HAJndiTestCase.class, "cross-server.jar");
- return t1;
+ return getDeploySetup(HAJndiTestCase.class, "cross-server.jar");
}
/**
@@ -338,8 +338,16 @@
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");
+
if (autoDisabled)
+ {
env.put("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);
+ }
Context naming = new InitialContext (env);
return naming;
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java 2007-02-28 02:55:55 UTC (rev 60976)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java 2007-02-28 03:34:09 UTC (rev 60977)
@@ -41,6 +41,8 @@
*/
public class SimpleUnitTestCase extends JBossTestCase
{
+ private static final String DISCOVERY_GROUP = System.getProperty("jbosstest.udpGroup", "");
+
/**
* Constructor for the SimpleUnitTestCase object
*
@@ -228,7 +230,7 @@
*
* @throws Exception
*/
- public void testHaParitionName() throws Exception
+ public void testHaPartitionName() throws Exception
{
getLog().debug("+++ testHjnp.localAddressaParitionName");
Properties env = new Properties();
@@ -236,6 +238,12 @@
env.setProperty(Context.PROVIDER_URL, "jnp://" + serverHost + ":65535/");
env.setProperty("jnp.localAddress", serverHost);
env.setProperty("jnp.partitionName", "DefaultPartition");
+ if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
+ {
+ // Server is not listening for discovery on std multicast address
+ // so we need to use the correct one
+ env.setProperty("jnp.discoveryGroup", DISCOVERY_GROUP);
+ }
getLog().debug("Creating InitialContext with env="+env);
InitialContext ctx = new InitialContext(env);
getLog().debug("Created InitialContext");
@@ -278,6 +286,12 @@
env.setProperty(Context.PROVIDER_URL, "jnp://" + serverHost + ":65535/");
env.setProperty("jnp.localAddress", serverHost);
env.setProperty("jnp.discoveryPort", "1102");
+ if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
+ {
+ // Server is not listening for discovery on std multicast address
+ // so we need to use the correct one
+ env.setProperty("jnp.discoveryGroup", DISCOVERY_GROUP);
+ }
getLog().debug("Creating InitialContext with env="+env);
InitialContext ctx = new InitialContext(env);
getLog().debug("Created InitialContext");
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java 2007-02-28 02:55:55 UTC (rev 60976)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java 2007-02-28 03:34:09 UTC (rev 60977)
@@ -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,44 @@
{
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"
+ */
+ public Enumeration getResources(String name) throws IOException
+ {
+ Enumeration result = super.getResources(name);
+
+ if (customJndiProperties != null
+ && "jndi.properties".equals(name))
+ {
+ log.info("Adding custom jndi.properties");
+
+ Vector v = new Vector();
+ 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