[jboss-cvs] JBoss Messaging SVN: r1699 - in branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools: . jmx jmx/rmi jndi
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 4 05:33:05 EST 2006
Author: ovidiu.feodorov at jboss.com
Date: 2006-12-04 05:33:01 -0500 (Mon, 04 Dec 2006)
New Revision: 1699
Added:
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/Constants.java
Modified:
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactory.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactoryBuilder.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java
Log:
modified test JNDI support to allow for multiple JNDI spaces in the same VM
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/ServerManagement.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/ServerManagement.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -112,7 +112,7 @@
if (isLocal())
{
- servers[index] = new LocalTestServer();
+ servers[index] = new LocalTestServer(index);
return;
}
@@ -585,20 +585,20 @@
public static Hashtable getJNDIEnvironment()
{
+ return getJNDIEnvironment(0);
+ }
+
+ public static Hashtable getJNDIEnvironment(int serverIndex)
+ {
if (isLocal())
{
- return InVMInitialContextFactory.getJNDIEnvironment();
+ return InVMInitialContextFactory.getJNDIEnvironment(serverIndex);
}
else
{
- return getJNDIEnvironment(0);
+ return RemoteInitialContextFactory.getJNDIEnvironment(serverIndex);
}
}
-
- public static Hashtable getJNDIEnvironment(int index)
- {
- return RemoteInitialContextFactory.getJNDIEnvironment(index);
- }
// Attributes ----------------------------------------------------
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -279,14 +279,15 @@
//TODO: need to think more about this; if I don't do it, though, bind() fails because it tries to use "java.naming.provider.url"
try
{
- NamingManager.setInitialContextFactoryBuilder(new InVMInitialContextFactoryBuilder());
+ NamingManager.
+ setInitialContextFactoryBuilder(new InVMInitialContextFactoryBuilder());
}
catch(IllegalStateException e)
{
// OK
}
- Hashtable t = InVMInitialContextFactory.getJNDIEnvironment();
+ Hashtable t = InVMInitialContextFactory.getJNDIEnvironment(serverIndex);
System.setProperty("java.naming.factory.initial",
(String)t.get("java.naming.factory.initial"));
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -41,6 +41,7 @@
import org.jboss.messaging.core.plugin.postoffice.cluster.DefaultClusteredPostOffice;
import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jndi.Constants;
import org.jboss.test.messaging.tools.jboss.MBeanConfigurationElement;
import org.jboss.test.messaging.tools.jboss.ServiceDeploymentDescriptor;
import org.jboss.test.messaging.tools.jmx.MockJBossSecurityManager;
@@ -62,7 +63,17 @@
private static final Logger log = Logger.getLogger(LocalTestServer.class);
// Static --------------------------------------------------------
-
+
+ public static void setEnvironmentServerIndex(int serverIndex)
+ {
+ System.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, Integer.toString(serverIndex));
+ }
+
+ public static void clearEnvironmentServerIndex()
+ {
+ System.getProperty(Constants.SERVER_INDEX_PROPERTY_NAME, null);
+ }
+
// Attributes ----------------------------------------------------
private ServiceContainer sc;
@@ -108,22 +119,31 @@
log.debug("starting service container");
- sc = new ServiceContainer(containerConfig, null, serverIndex);
- sc.start();
+ try
+ {
+ setEnvironmentServerIndex(serverIndex);
- if (this.getDatabaseType().equals("hsqldb") && sc.isClustered())
- {
- throw new IllegalStateException("The test server cannot be started in clustered mode with hsqldb as a database - must use a shared database");
+ sc = new ServiceContainer(containerConfig, null, serverIndex);
+ sc.start();
+
+ if (this.getDatabaseType().equals("hsqldb") && sc.isClustered())
+ {
+ throw new IllegalStateException("The test server cannot be started in clustered mode with hsqldb as a database - must use a shared database");
+ }
+
+ if ("none".equals(containerConfig))
+ {
+ return;
+ }
+
+ startServerPeer(serverIndex, null, null, sc.isClustered());
+
+ log.info("server started");
}
-
- if ("none".equals(containerConfig))
+ finally
{
- return;
+ clearEnvironmentServerIndex();
}
-
- startServerPeer(serverIndex, null, null, sc.isClustered());
-
- log.info("server started");
}
public synchronized void stop() throws Exception
Added: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/Constants.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/Constants.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/Constants.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -0,0 +1,36 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.messaging.tools.jndi;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class Constants
+{
+ // Constants -----------------------------------------------------
+
+ public static final String SERVER_INDEX_PROPERTY_NAME = "jboss.messaging.test.server.index";
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactory.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactory.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactory.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -25,6 +25,8 @@
import javax.naming.NamingException;
import javax.naming.Context;
import java.util.Hashtable;
+import java.util.List;
+import java.util.ArrayList;
/**
* An in-VM JNDI InitialContextFactory. Lightweight JNDI implementation used for testing.
@@ -38,44 +40,99 @@
{
// Constants -----------------------------------------------------
- private static InVMContext initialContext;
-
// Static --------------------------------------------------------
+ // List<InitialContext>
+ private static List initialContexts;
+
+ static
+ {
+ initialContexts = new ArrayList();
+ }
+
+ public static Hashtable getJNDIEnvironment()
+ {
+ return getJNDIEnvironment(0);
+ }
+
/**
* @return the JNDI environment to use to get this InitialContextFactory.
*/
- public static Hashtable getJNDIEnvironment()
+ public static Hashtable getJNDIEnvironment(int serverIndex)
{
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"org.jboss.messaging.tools.jndi.InVMInitialContextFactory");
env.put("java.naming.provider.url", "");
env.put("java.naming.factory.url.pkgs", "");
+ env.put(Constants.SERVER_INDEX_PROPERTY_NAME, Integer.toString(serverIndex));
return env;
}
// Attributes ----------------------------------------------------
-
+
// Constructors --------------------------------------------------
-
+
// Public --------------------------------------------------------
public Context getInitialContext(Hashtable environment) throws NamingException
{
- if (initialContext == null)
+ // try first in the environment passed as argument ...
+ String s = (String)environment.get(Constants.SERVER_INDEX_PROPERTY_NAME);
+
+ if (s == null)
{
- initialContext = new InVMContext();
- initialContext.bind("java:/", new InVMContext());
+ // ... then in the global environment
+ s = System.getProperty(Constants.SERVER_INDEX_PROPERTY_NAME);
+
+ if (s == null)
+ {
+ throw new NamingException("Cannot figure out server index!");
+ }
}
- return initialContext;
+
+ int serverIndex;
+
+ try
+ {
+ serverIndex = Integer.parseInt(s);
+ }
+ catch(Exception e)
+ {
+ throw new NamingException("Failure parsing \"" +
+ Constants.SERVER_INDEX_PROPERTY_NAME +"\". " +
+ s + " is not an integer");
+ }
+
+ int size = initialContexts.size();
+
+ // pad the list to the right size
+
+ if (size <= serverIndex)
+ {
+ for(int i = 0; i < serverIndex - size + 1; i++)
+ {
+ initialContexts.add(null);
+ }
+ }
+
+ InVMContext ic = (InVMContext)initialContexts.get(serverIndex);
+
+ if (ic == null)
+ {
+ ic = new InVMContext();
+ ic.bind("java:/", new InVMContext());
+ initialContexts.set(serverIndex, ic);
+ }
+
+ return ic;
}
// Package protected ---------------------------------------------
-
+
// Protected -----------------------------------------------------
-
+
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
}
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactoryBuilder.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactoryBuilder.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/InVMInitialContextFactoryBuilder.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -35,9 +35,34 @@
*/
public class InVMInitialContextFactoryBuilder implements InitialContextFactoryBuilder
{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public InVMInitialContextFactoryBuilder()
+ {
+ }
+
+ // InitialContextFactoryBuilder implementation -------------------
+
public InitialContextFactory createInitialContextFactory(Hashtable environment)
throws NamingException
{
return new InVMInitialContextFactory();
}
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
}
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java 2006-12-04 02:58:19 UTC (rev 1698)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java 2006-12-04 10:33:01 UTC (rev 1699)
@@ -42,21 +42,20 @@
// Static --------------------------------------------------------
- private static RemoteContext[] initialContexts = new RemoteContext[RMITestServer.RMI_REGISTRY_PORTS.length];
+ private static RemoteContext[] initialContexts =
+ new RemoteContext[RMITestServer.RMI_REGISTRY_PORTS.length];
- private static final String REMOTE_SERVER_INDEX_KEY_NAME = "jboss.messaging.test.remoteserverindex";
-
/**
* @return the JNDI environment to use to get this InitialContextFactory.
*/
- public static Hashtable getJNDIEnvironment(int index)
+ public static Hashtable getJNDIEnvironment(int serverIndex)
{
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"org.jboss.test.messaging.tools.jndi.RemoteInitialContextFactory");
env.put("java.naming.provider.url", "");
env.put("java.naming.factory.url.pkgs", "");
- env.put(REMOTE_SERVER_INDEX_KEY_NAME, String.valueOf(index));
+ env.put(Constants.SERVER_INDEX_PROPERTY_NAME, Integer.toString(serverIndex));
return env;
}
@@ -68,11 +67,12 @@
public Context getInitialContext(Hashtable environment) throws NamingException
{
- String s = (String)environment.get(REMOTE_SERVER_INDEX_KEY_NAME);
+ String s = (String)environment.get(Constants.SERVER_INDEX_PROPERTY_NAME);
if (s == null)
{
- throw new IllegalArgumentException("Initial context environment must contain entry for " + REMOTE_SERVER_INDEX_KEY_NAME);
+ throw new IllegalArgumentException("Initial context environment must contain " +
+ "entry for " + Constants.SERVER_INDEX_PROPERTY_NAME);
}
int remoteServerIndex = Integer.parseInt(s);
More information about the jboss-cvs-commits
mailing list