[jboss-cvs] JBoss Messaging SVN: r7309 - in trunk: src/main/org/jboss/messaging/core/deployers and 11 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 11 13:12:14 EDT 2009
Author: timfox
Date: 2009-06-11 13:12:13 -0400 (Thu, 11 Jun 2009)
New Revision: 7309
Added:
trunk/tests/config/server-start-stop-backup-config1.xml
trunk/tests/config/server-start-stop-backup-jms-config1.xml
trunk/tests/config/server-start-stop-config1.xml
trunk/tests/config/server-start-stop-jms-config1.xml
trunk/tests/config/server-start-stop-live-config1.xml
trunk/tests/config/server-start-stop-live-jms-config1.xml
trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopWithReplicationTest.java
Modified:
trunk/src/config/stand-alone/non-clustered/jbm-jboss-beans.xml
trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java
trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
trunk/src/main/org/jboss/messaging/core/management/impl/ReplicationOperationInvokerImpl.java
trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMRegistry.java
trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java
trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java
trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
various tweaks, fixes and https://jira.jboss.org/jira/browse/JBMESSAGING-1646
Modified: trunk/src/config/stand-alone/non-clustered/jbm-jboss-beans.xml
===================================================================
--- trunk/src/config/stand-alone/non-clustered/jbm-jboss-beans.xml 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/config/stand-alone/non-clustered/jbm-jboss-beans.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -33,7 +33,7 @@
<!-- The core server -->
<bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
- <start ignored="true"/>
+ <start ignored="true"/>
<stop ignored="true"/>
<constructor>
<parameter>
Modified: trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -22,6 +22,8 @@
package org.jboss.messaging.core.deployers;
+import java.util.List;
+
import org.jboss.messaging.core.server.MessagingComponent;
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -98,7 +98,7 @@
// Constants -----------------------------------------------------
public static final String CLUSTER_MANAGEMENT_ROLE = "cluster.management";
-
+
private static final Logger log = Logger.getLogger(ManagementServiceImpl.class);
private final MBeanServer mbeanServer;
@@ -143,22 +143,20 @@
private ReplicationOperationInvoker replicationInvoker;
- // Static --------------------------------------------------------
-
+ // Static --------------------------------------------------------
+
private static void checkDefaultManagementClusterCredentials(String user, String password)
{
- if (ConfigurationImpl.DEFAULT_MANAGEMENT_CLUSTER_USER.equals(user)
- && ConfigurationImpl.DEFAULT_MANAGEMENT_CLUSTER_PASSWORD.equals(password))
+ if (ConfigurationImpl.DEFAULT_MANAGEMENT_CLUSTER_USER.equals(user) && ConfigurationImpl.DEFAULT_MANAGEMENT_CLUSTER_PASSWORD.equals(password))
{
- log.warn("It has been detected that the cluster admin user and password which are used to " +
- "replicate management operation from one node to the other have not been changed from the installation default. " +
- "Please see the JBoss Messaging user guide for instructions on how to do this.");
+ log.warn("It has been detected that the cluster admin user and password which are used to " + "replicate management operation from one node to the other have not been changed from the installation default. "
+ + "Please see the JBoss Messaging user guide for instructions on how to do this.");
}
}
-
+
// Constructor ----------------------------------------------------
- public ManagementServiceImpl(final MBeanServer mbeanServer, final Configuration configuration)
+ public ManagementServiceImpl(final MBeanServer mbeanServer, final Configuration configuration, final int managementConnectorID)
{
this.mbeanServer = mbeanServer;
this.jmxManagementEnabled = configuration.isJMXManagementEnabled();
@@ -170,7 +168,7 @@
this.managementRequestTimeout = configuration.getManagementRequestTimeout();
checkDefaultManagementClusterCredentials(managementClusterUser, managementClusterPassword);
-
+
registry = new HashMap<String, Object>();
broadcaster = new NotificationBroadcasterSupport();
notificationsEnabled = true;
@@ -181,7 +179,8 @@
replicationInvoker = new ReplicationOperationInvokerImpl(managementClusterUser,
managementClusterPassword,
managementAddress,
- managementRequestTimeout);
+ managementRequestTimeout,
+ managementConnectorID);
}
// Public --------------------------------------------------------
@@ -194,15 +193,15 @@
}
public MessagingServerControlImpl registerServer(final PostOffice postOffice,
- final StorageManager storageManager,
- final Configuration configuration,
- final HierarchicalRepository<AddressSettings> addressSettingsRepository,
- final HierarchicalRepository<Set<Role>> securityRepository,
- final ResourceManager resourceManager,
- final RemotingService remotingService,
- final MessagingServer messagingServer,
- final QueueFactory queueFactory,
- final boolean backup) throws Exception
+ final StorageManager storageManager,
+ final Configuration configuration,
+ final HierarchicalRepository<AddressSettings> addressSettingsRepository,
+ final HierarchicalRepository<Set<Role>> securityRepository,
+ final ResourceManager resourceManager,
+ final RemotingService remotingService,
+ final MessagingServer messagingServer,
+ final QueueFactory queueFactory,
+ final boolean backup) throws Exception
{
this.postOffice = postOffice;
this.addressSettingsRepository = addressSettingsRepository;
@@ -222,14 +221,14 @@
messagingServer.getSecurityRepository().addMatch(configuration.getManagementNotificationAddress().toString(), roles);
messagingServer.getSecurityRepository().addMatch(configuration.getManagementNotificationAddress() + ".*", roles);
}
-
+
messagingServerControl = new MessagingServerControlImpl(postOffice,
- configuration,
- resourceManager,
- remotingService,
- messagingServer,
- messageCounterManager,
- broadcaster);
+ configuration,
+ resourceManager,
+ remotingService,
+ messagingServer,
+ messageCounterManager,
+ broadcaster);
ObjectName objectName = ObjectNames.getMessagingServerObjectName();
registerInJMX(objectName, new ReplicationAwareMessagingServerControlWrapper(messagingServerControl,
replicationInvoker));
@@ -272,7 +271,10 @@
final SimpleString address,
final StorageManager storageManager) throws Exception
{
- QueueControlImpl queueControl = new QueueControlImpl(queue, address.toString(), postOffice, addressSettingsRepository);
+ QueueControlImpl queueControl = new QueueControlImpl(queue,
+ address.toString(),
+ postOffice,
+ addressSettingsRepository);
MessageCounter counter = new MessageCounter(queue.getName().toString(),
null,
queueControl,
@@ -747,19 +749,18 @@
for (int i = 0; i < paramTypes.length; i++)
{
if (params[i] == null)
- {
+ {
continue;
}
// System.out.format("param=%s, expecting=%s\n", params[i].getClass(), paramTypes[i]);
// System.out.println(!paramTypes[i].isAssignableFrom(params[i].getClass()));
// System.out.println(paramTypes[i] == Long.TYPE && params[i].getClass() == Integer.class);
- if (paramTypes[i].isAssignableFrom(params[i].getClass())
- || (paramTypes[i] == Long.TYPE && params[i].getClass() == Integer.class)
- || (paramTypes[i] == Double.TYPE && params[i].getClass() == Integer.class)
- || (paramTypes[i] == Long.TYPE && params[i].getClass() == Long.class)
- || (paramTypes[i] == Double.TYPE && params[i].getClass() == Double.class)
- || (paramTypes[i] == Integer.TYPE && params[i].getClass() == Integer.class)
- || (paramTypes[i] == Boolean.TYPE && params[i].getClass() == Boolean.class))
+ if (paramTypes[i].isAssignableFrom(params[i].getClass()) || (paramTypes[i] == Long.TYPE && params[i].getClass() == Integer.class) ||
+ (paramTypes[i] == Double.TYPE && params[i].getClass() == Integer.class) ||
+ (paramTypes[i] == Long.TYPE && params[i].getClass() == Long.class) ||
+ (paramTypes[i] == Double.TYPE && params[i].getClass() == Double.class) ||
+ (paramTypes[i] == Integer.TYPE && params[i].getClass() == Integer.class) ||
+ (paramTypes[i] == Boolean.TYPE && params[i].getClass() == Boolean.class))
{
// parameter match
}
@@ -769,7 +770,7 @@
break; // parameter check loop
}
}
-
+
if (match)
{
method = m;
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/ReplicationOperationInvokerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/ReplicationOperationInvokerImpl.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/ReplicationOperationInvokerImpl.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -22,6 +22,8 @@
package org.jboss.messaging.core.management.impl;
+import java.util.HashMap;
+
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientRequestor;
import org.jboss.messaging.core.client.ClientSession;
@@ -32,6 +34,7 @@
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.management.ReplicationOperationInvoker;
import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
import org.jboss.messaging.utils.SimpleString;
/**
@@ -61,6 +64,8 @@
private ClientRequestor requestor;
+ private final int managementConnectorID;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -72,12 +77,14 @@
public ReplicationOperationInvokerImpl(final String clusterUser,
final String clusterPassword,
final SimpleString managementAddress,
- final long managementRequestTimeout)
+ final long managementRequestTimeout,
+ final int managementConnectorID)
{
this.timeout = managementRequestTimeout;
this.clusterUser = clusterUser;
this.clusterPassword = clusterPassword;
this.managementAddress = managementAddress;
+ this.managementConnectorID = managementConnectorID;
}
// Public --------------------------------------------------------
@@ -86,7 +93,15 @@
{
if (clientSession == null)
{
- ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName(),
+ new HashMap<String, Object>()
+ {
+ {
+ put(TransportConstants.SERVER_ID_PROP_NAME,
+ managementConnectorID);
+ }
+ }));
+
clientSession = sf.createSession(clusterUser, clusterPassword, false, true, true, false, 1);
requestor = new ClientRequestor(clientSession, managementAddress);
clientSession.start();
Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -145,7 +145,7 @@
private final int perfBlastPages;
public JournalStorageManager(final Configuration config, final Executor executor)
- {
+ {
this.executor = executor;
if (config.getJournalType() != JournalType.NIO && config.getJournalType() != JournalType.ASYNCIO)
@@ -243,7 +243,7 @@
}
public long generateUniqueID()
- {
+ {
long id = idGenerator.generateID();
return id;
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMRegistry.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMRegistry.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMRegistry.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -21,6 +21,7 @@
*/
package org.jboss.messaging.core.remoting.impl.invm;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -70,4 +71,9 @@
{
return this.acceptors.size();
}
+
+ public Map<Integer, InVMAcceptor> getAcceptors()
+ {
+ return acceptors;
+ }
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -41,6 +41,8 @@
import org.jboss.messaging.core.remoting.impl.Pinger;
import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
import org.jboss.messaging.core.remoting.server.RemotingService;
@@ -97,6 +99,8 @@
private Map<Object, Pinger> pingRunnables = new ConcurrentHashMap<Object, Pinger>();
+ private final int managementConnectorID;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -105,7 +109,8 @@
final MessagingServer server,
final ManagementService managementService,
final Executor threadPool,
- final ScheduledExecutorService scheduledThreadPool)
+ final ScheduledExecutorService scheduledThreadPool,
+ final int managementConnectorID)
{
transportConfigs = config.getAcceptorConfigurations();
@@ -128,6 +133,7 @@
this.managementService = managementService;
this.threadPool = threadPool;
this.scheduledThreadPool = scheduledThreadPool;
+ this.managementConnectorID = managementConnectorID;
}
// RemotingService implementation -------------------------------
@@ -141,25 +147,52 @@
// when JMX is enabled, it requires a INVM acceptor to send the core messages
// corresponding to the JMX management operations (@see ReplicationAwareStandardMBeanWrapper)
+ // we create one with a special negative id - this is a hack and instead, management should not use a connector to connect
if (config.isJMXManagementEnabled())
{
- boolean invmAcceptorConfigured = false;
-
+ boolean alreadyConfigured = false;
for (TransportConfiguration config : transportConfigs)
{
- if (InVMAcceptorFactory.class.getName().equals(config.getFactoryClassName()))
+ if (config.getClass().getName().equals(InVMAcceptorFactory.class.getName()))
{
- invmAcceptorConfigured = true;
+ int serverID = 0;
+ if (config.getParams() != null)
+ {
+ Integer iserverid = (Integer)config.getParams().get(TransportConstants.SERVER_ID_PROP_NAME);
+
+ if (iserverid != null)
+ {
+ serverID = iserverid;
+ }
+ }
+
+ if (serverID == managementConnectorID)
+ {
+ alreadyConfigured = true;
+ }
}
}
-
- if (!invmAcceptorConfigured)
+ if (!alreadyConfigured)
{
transportConfigs.add(new TransportConfiguration(InVMAcceptorFactory.class.getName(),
- new HashMap<String, Object>(),
- "in-vm"));
+ new HashMap<String, Object>()
+ {
+ {
+ put(TransportConstants.SERVER_ID_PROP_NAME,
+ managementConnectorID);
+ }
+ }));
}
}
+
+ //Now we also need to create a invmacceptor with id 0 if it doesn't already exist - this is simple because
+ //lots of tests assume this - this requirement should also be removed
+ //this is a bad thing to do since does not play well when there are multiple servers in the same VM.
+
+ if (InVMRegistry.instance.getAcceptor(0) == null)
+ {
+ transportConfigs.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
+ }
ClassLoader loader = Thread.currentThread().getContextClassLoader();
@@ -355,10 +388,10 @@
public void cancelPingerForConnectionID(final Object connectionID)
{
Pinger pinger = pingRunnables.get(connectionID);
-
+
pinger.close();
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -369,7 +402,8 @@
final long clientFailureCheckPeriod,
final long connectionTTL)
{
- if ((connectionTTL <= 0 || clientFailureCheckPeriod <= 0) && connectionTTL != -1 && clientFailureCheckPeriod != -1)
+ if ((connectionTTL <= 0 || clientFailureCheckPeriod <= 0) && connectionTTL != -1 &&
+ clientFailureCheckPeriod != -1)
{
log.warn("Invalid values of connectionTTL/clientFailureCheckPeriod");
@@ -384,7 +418,7 @@
if (connectionTTLToUse != -1)
{
FailedConnectionRunnable runnable = new FailedConnectionRunnable(conn);
-
+
Future<?> connectionTTLFuture = scheduledThreadPool.scheduleAtFixedRate(runnable,
connectionTTLToUse,
connectionTTLToUse,
@@ -401,7 +435,10 @@
{
Pinger pingRunnable = new Pinger(conn);
- Future<?> pingFuture = scheduledThreadPool.scheduleAtFixedRate(pingRunnable, 0, pingPeriod, TimeUnit.MILLISECONDS);
+ Future<?> pingFuture = scheduledThreadPool.scheduleAtFixedRate(pingRunnable,
+ 0,
+ pingPeriod,
+ TimeUnit.MILLISECONDS);
pingRunnable.setFuture(pingFuture);
@@ -521,7 +558,7 @@
{
return;
}
-
+
if (!conn.isDataReceived())
{
removeConnection(conn.getID());
@@ -532,7 +569,7 @@
conn.fail(me);
}
else
- {
+ {
conn.clearDataReceived();
}
}
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -27,6 +27,7 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.management.MBeanServer;
@@ -195,7 +196,10 @@
private ConnectionManager replicatingConnectionManager;
-
+ private int managementConnectorID;
+
+ private static AtomicInteger managementConnectorSequence = new AtomicInteger(0);
+
// Constructors
// ---------------------------------------------------------------------------------
@@ -218,7 +222,7 @@
{
this(configuration, null, securityManager);
}
-
+
public MessagingServerImpl(Configuration configuration,
MBeanServer mbeanServer,
final JBMSecurityManager securityManager)
@@ -247,8 +251,10 @@
this.addressSettingsRepository = new HierarchicalObjectRepository<AddressSettings>();
addressSettingsRepository.setDefault(new AddressSettings());
+
+ this.managementConnectorID = managementConnectorSequence.decrementAndGet();
}
-
+
// lifecycle methods
// ----------------------------------------------------------------
@@ -279,7 +285,7 @@
}
public synchronized void stop() throws Exception
- {
+ {
if (!started)
{
return;
@@ -306,7 +312,10 @@
addressSettingsDeployer.stop();
- queueDeployer.stop();
+ if (queueDeployer != null)
+ {
+ queueDeployer.stop();
+ }
if (securityDeployer != null)
{
@@ -610,6 +619,8 @@
throw new IllegalStateException("Live and backup unique ids different (" + liveUniqueID + ":" + backupID + "). You're probably trying to restart a live backup pair after a crash");
}
+
+ log.info("Backup server is now operational");
}
}
@@ -765,7 +776,7 @@
}
}
- private void checkActivate(final RemotingConnection connection)
+ private void checkActivate(final RemotingConnection connection) throws Exception
{
if (configuration.isBackup())
{
@@ -790,6 +801,13 @@
{
clusterManager.activate();
}
+
+ if (configuration.isFileDeploymentEnabled())
+ {
+ queueDeployer = new QueueDeployer(deploymentManager, messagingServerControl);
+
+ queueDeployer.start();
+ }
}
}
@@ -852,11 +870,11 @@
new org.jboss.messaging.utils.JBMThreadFactory("JBM-scheduled-threads",
false));
- managementService = new ManagementServiceImpl(mbeanServer, configuration);
-
- remotingService = new RemotingServiceImpl(configuration, this, managementService, threadPool, scheduledPool);
+ managementService = new ManagementServiceImpl(mbeanServer, configuration, managementConnectorID);
+
+ remotingService = new RemotingServiceImpl(configuration, this, managementService, threadPool, scheduledPool, managementConnectorID);
}
-
+
private void initialisePart2() throws Exception
{
// Create the hard-wired components
@@ -962,8 +980,9 @@
deployQueuesFromConfiguration();
// Deploy any predefined queues
-
- if (configuration.isFileDeploymentEnabled())
+
+ // We don't activate queue deployer on the backup - all queues deployed on live are deployed on backup by replicating them
+ if (configuration.isFileDeploymentEnabled() && !configuration.isBackup())
{
queueDeployer = new QueueDeployer(deploymentManager, messagingServerControl);
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -494,6 +494,11 @@
{
return sessionFactory;
}
+
+ public void close()
+ {
+ sessionFactory.close();
+ }
// Package protected ----------------------------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -22,10 +22,22 @@
package org.jboss.messaging.jms.server.impl;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.deployers.Deployer;
import org.jboss.messaging.core.deployers.DeploymentManager;
import org.jboss.messaging.core.deployers.impl.FileDeploymentManager;
+import org.jboss.messaging.core.deployers.impl.XmlDeployer;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.server.ActivateCallback;
import org.jboss.messaging.core.server.MessagingServer;
@@ -37,19 +49,7 @@
import org.jboss.messaging.jms.server.management.JMSManagementService;
import org.jboss.messaging.jms.server.management.impl.JMSManagementServiceImpl;
import org.jboss.messaging.utils.Pair;
-import org.jboss.messaging.utils.SimpleString;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
/**
* A Deployer used to create and add to JNDI queues, topics and connection
* factories. Typically this would only be used in an app server env.
@@ -79,7 +79,7 @@
private JMSManagementService jmsManagementService;
- private Deployer jmsDeployer;
+ private XmlDeployer jmsDeployer;
private boolean started;
@@ -87,11 +87,24 @@
private DeploymentManager deploymentManager;
+ private final String configFileName;
+
+ private boolean contextSet;
+
public JMSServerManagerImpl(final MessagingServer server) throws Exception
{
this.server = server;
+
+ this.configFileName = null;
}
+ public JMSServerManagerImpl(final MessagingServer server, final String configFileName) throws Exception
+ {
+ this.server = server;
+
+ this.configFileName = configFileName;
+ }
+
// ActivateCallback implementation -------------------------------------
public synchronized void activated()
@@ -106,6 +119,11 @@
jmsDeployer = new JMSServerDeployer(this, deploymentManager, server.getConfiguration());
+ if (configFileName != null)
+ {
+ jmsDeployer.setConfigFileNames(new String[] { configFileName });
+ }
+
jmsDeployer.start();
deploymentManager.start();
@@ -124,8 +142,8 @@
{
return;
}
-
- if (context == null)
+
+ if (!contextSet)
{
context = new InitialContext();
}
@@ -167,7 +185,10 @@
connectionFactories.clear();
connectionFactoryBindings.clear();
- context.close();
+ if (context != null)
+ {
+ context.close();
+ }
server.stop();
@@ -182,8 +203,10 @@
// JMSServerManager implementation -------------------------------
public synchronized void setContext(final Context context)
- {
+ {
this.context = context;
+
+ this.contextSet = true;
}
public synchronized String getVersion()
@@ -193,28 +216,34 @@
return server.getMessagingServerControl().getVersion();
}
- public synchronized boolean createQueue(final String queueName, final String jndiBinding, final String selectorString, boolean durable) throws Exception
+ public synchronized boolean createQueue(final String queueName,
+ final String jndiBinding,
+ final String selectorString,
+ boolean durable) throws Exception
{
checkInitialised();
JBossQueue jBossQueue = new JBossQueue(queueName);
-
- //Convert from JMS selector to core filter
+
+ // Convert from JMS selector to core filter
String coreFilterString = null;
if (selectorString != null)
{
coreFilterString = SelectorTranslator.convertToJBMFilterString(selectorString);
}
-
- server.getMessagingServerControl().deployQueue(jBossQueue.getAddress(), jBossQueue.getAddress(), coreFilterString, durable);
-
+
+ server.getMessagingServerControl().deployQueue(jBossQueue.getAddress(),
+ jBossQueue.getAddress(),
+ coreFilterString,
+ durable);
+
boolean added = bindToJndi(jndiBinding, jBossQueue);
-
+
if (added)
{
addToDestinationBindings(queueName, jndiBinding);
}
-
+
jmsManagementService.registerQueue(jBossQueue, jndiBinding);
return added;
}
@@ -248,12 +277,15 @@
{
return false;
}
- Iterator<String> iter = jndiBindings.iterator();
- while (iter.hasNext())
+ if (context != null)
{
- String jndiBinding = (String)iter.next();
- context.unbind(jndiBinding);
- iter.remove();
+ Iterator<String> iter = jndiBindings.iterator();
+ while (iter.hasNext())
+ {
+ String jndiBinding = (String)iter.next();
+ context.unbind(jndiBinding);
+ iter.remove();
+ }
}
return true;
}
@@ -281,16 +313,16 @@
return true;
}
-
+
public synchronized void createConnectionFactory(String name,
- List<Pair<TransportConfiguration, TransportConfiguration>> connectorConfigs,
+ List<Pair<TransportConfiguration, TransportConfiguration>> connectorConfigs,
List<String> jndiBindings) throws Exception
{
checkInitialised();
JBossConnectionFactory cf = connectionFactories.get(name);
if (cf == null)
{
- cf = new JBossConnectionFactory(connectorConfigs);
+ cf = new JBossConnectionFactory(connectorConfigs);
}
bindConnectionFactory(cf, name, jndiBindings);
@@ -547,16 +579,19 @@
{
return false;
}
- for (String jndiBinding : jndiBindings)
+ if (context != null)
{
- try
+ for (String jndiBinding : jndiBindings)
{
- context.unbind(jndiBinding);
+ try
+ {
+ context.unbind(jndiBinding);
+ }
+ catch (NameNotFoundException e)
+ {
+ // this is ok.
+ }
}
- catch (NameNotFoundException e)
- {
- // this is ok.
- }
}
connectionFactoryBindings.remove(name);
connectionFactories.remove(name);
@@ -627,34 +662,36 @@
private boolean bindToJndi(final String jndiName, final Object objectToBind) throws NamingException
{
- String parentContext;
- String jndiNameInContext;
- int sepIndex = jndiName.lastIndexOf('/');
- if (sepIndex == -1)
+ if (context != null)
{
- parentContext = "";
- }
- else
- {
- parentContext = jndiName.substring(0, sepIndex);
- }
- jndiNameInContext = jndiName.substring(sepIndex + 1);
- try
- {
- context.lookup(jndiName);
-
- log.warn("Binding for " + jndiName + " already exists");
- return false;
- }
- catch (Throwable e)
- {
- // OK
- }
-
- Context c = org.jboss.messaging.utils.JNDIUtil.createContext(context, parentContext);
-
- c.rebind(jndiNameInContext, objectToBind);
-
+ String parentContext;
+ String jndiNameInContext;
+ int sepIndex = jndiName.lastIndexOf('/');
+ if (sepIndex == -1)
+ {
+ parentContext = "";
+ }
+ else
+ {
+ parentContext = jndiName.substring(0, sepIndex);
+ }
+ jndiNameInContext = jndiName.substring(sepIndex + 1);
+ try
+ {
+ context.lookup(jndiName);
+
+ log.warn("Binding for " + jndiName + " already exists");
+ return false;
+ }
+ catch (Throwable e)
+ {
+ // OK
+ }
+
+ Context c = org.jboss.messaging.utils.JNDIUtil.createContext(context, parentContext);
+
+ c.rebind(jndiNameInContext, objectToBind);
+ }
return true;
}
Added: trunk/tests/config/server-start-stop-backup-config1.xml
===================================================================
--- trunk/tests/config/server-start-stop-backup-config1.xml (rev 0)
+++ trunk/tests/config/server-start-stop-backup-config1.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,50 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+ <clustered>true</clustered>
+
+ <backup>true</backup>
+
+ <journal-directory>/tmp/jbm-unit-test/start-stop-data-backup</journal-directory>
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+
+ <security-settings>
+ <security-setting match="jms.#">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <queues>
+ <queue name="myQueue">
+ <address>myAddress</address>
+ </queue>
+
+ <queue name="jms.queue.myJMSQueue">
+ <address>jms.queue.myJMSAddress</address>
+ </queue>
+ </queues>
+
+</configuration>
+
Added: trunk/tests/config/server-start-stop-backup-jms-config1.xml
===================================================================
--- trunk/tests/config/server-start-stop-backup-jms-config1.xml (rev 0)
+++ trunk/tests/config/server-start-stop-backup-jms-config1.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty-connector"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="myJMSQueue">
+ <entry name="myJMSQueue"/>
+ </queue>
+
+</configuration>
\ No newline at end of file
Added: trunk/tests/config/server-start-stop-config1.xml
===================================================================
--- trunk/tests/config/server-start-stop-config1.xml (rev 0)
+++ trunk/tests/config/server-start-stop-config1.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,40 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ </connector>
+ </connectors>
+
+ <journal-directory>/tmp/jbm-unit-test/start-stop-data</journal-directory>
+
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ </acceptor>
+ </acceptors>
+
+ <security-settings>
+ <security-setting match="jms.#">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <queues>
+ <queue name="myQueue">
+ <address>myAddress</address>
+ </queue>
+
+ <queue name="jms.queue.myJMSQueue">
+ <address>jms.queue.myJMSAddress</address>
+ </queue>
+ </queues>
+
+</configuration>
Added: trunk/tests/config/server-start-stop-jms-config1.xml
===================================================================
--- trunk/tests/config/server-start-stop-jms-config1.xml (rev 0)
+++ trunk/tests/config/server-start-stop-jms-config1.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty-connector"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="myJMSQueue">
+ <entry name="myJMSQueue"/>
+ </queue>
+
+</configuration>
\ No newline at end of file
Added: trunk/tests/config/server-start-stop-live-config1.xml
===================================================================
--- trunk/tests/config/server-start-stop-live-config1.xml (rev 0)
+++ trunk/tests/config/server-start-stop-live-config1.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,54 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../../../src/schema/jbm-configuration.xsd">
+ <clustered>true</clustered>
+
+ <backup-connector-ref connector-name="backup-connector"/>
+
+ <journal-directory>/tmp/jbm-unit-test/start-stop-data-live</journal-directory>
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5445" type="Integer"/>
+ </connector>
+
+ <connector name="backup-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5445" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <security-settings>
+ <security-setting match="jms.#">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <queues>
+ <queue name="myQueue">
+ <address>myAddress</address>
+ </queue>
+
+ <queue name="jms.queue.myJMSQueue">
+ <address>jms.queue.myJMSAddress</address>
+ </queue>
+ </queues>
+
+</configuration>
+
Added: trunk/tests/config/server-start-stop-live-jms-config1.xml
===================================================================
--- trunk/tests/config/server-start-stop-live-jms-config1.xml (rev 0)
+++ trunk/tests/config/server-start-stop-live-jms-config1.xml 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty-connector"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="myJMSQueue">
+ <entry name="myJMSQueue"/>
+ </queue>
+
+</configuration>
\ No newline at end of file
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -182,6 +182,8 @@
assertEquals(0, sf.numSessions());
assertEquals(0, sf.numConnections());
+
+ sf.close();
stop();
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -1348,10 +1348,13 @@
protected void stop() throws Exception
{
+ log.info("** Stopping server");
backupServer.stop();
liveServer.stop();
-
+
+ System.gc();
+
assertEquals(0, InVMRegistry.instance.size());
}
Added: trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopTest.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat
+ * Middleware LLC, and individual contributors by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.jms.server;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.FileConfiguration;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.security.JBMSecurityManager;
+import org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.jms.server.JMSServerManager;
+import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ *
+ * A JMSServerStartStopTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class JMSServerStartStopTest extends UnitTestCase
+{
+ private static final Logger log = Logger.getLogger(JMSServerStartStopTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private JMSServerManager liveJMSServer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testStopStart1() throws Exception
+ {
+ final int numMessages = 5;
+
+ for (int j = 0; j < numMessages; j++)
+ {
+ log.info("Iteration " + j);
+
+ start();
+
+ JBossConnectionFactory jbcf = new JBossConnectionFactory(new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName()));
+
+
+ jbcf.setBlockOnPersistentSend(true);
+ jbcf.setBlockOnNonPersistentSend(true);
+
+ Connection conn = jbcf.createConnection();
+
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = sess.createQueue("myJMSQueue");
+
+ MessageProducer producer = sess.createProducer(queue);
+
+ TextMessage tm = sess.createTextMessage("message" + j);
+
+ producer.send(tm);
+
+ conn.close();
+
+ jbcf.close();
+
+ stop();
+ }
+
+ JBossConnectionFactory jbcf = new JBossConnectionFactory(new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName()));
+
+ jbcf.setBlockOnPersistentSend(true);
+ jbcf.setBlockOnNonPersistentSend(true);
+
+ Connection conn = jbcf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = sess.createQueue("myJMSQueue");
+
+ MessageConsumer consumer = sess.createConsumer(queue);
+
+ conn.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ TextMessage tm = (TextMessage)consumer.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+ }
+
+ conn.close();
+
+ jbcf.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+ private void stop() throws Exception
+ {
+ liveJMSServer.stop();
+ }
+
+ private void start() throws Exception
+ {
+ FileConfiguration fc = new FileConfiguration();
+
+ fc.setConfigurationUrl("server-start-stop-config1.xml");
+
+ fc.start();
+
+ JBMSecurityManager sm = new JBMSecurityManagerImpl();
+
+ MessagingServer liveServer = new MessagingServerImpl(fc, sm);
+
+ liveJMSServer = new JMSServerManagerImpl(liveServer, "server-start-stop-jms-config1.xml");
+
+ liveJMSServer.setContext(null);
+
+ liveJMSServer.start();
+ }
+
+
+ // Inner classes -------------------------------------------------
+
+}
Added: trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopWithReplicationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopWithReplicationTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/server/JMSServerStartStopWithReplicationTest.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -0,0 +1,247 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat
+ * Middleware LLC, and individual contributors by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.jms.server;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.FileConfiguration;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.security.JBMSecurityManager;
+import org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.jms.server.JMSServerManager;
+import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ *
+ * A JMSServerStartStopWithReplicationTest
+ *
+ * Make sure live backup pair can be stopped and started ok multiple times with predefined queues etc
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class JMSServerStartStopWithReplicationTest extends UnitTestCase
+{
+ private static final Logger log = Logger.getLogger(JMSServerStartStopWithReplicationTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ private JMSServerManager liveJMSServer;
+
+ private JMSServerManager backupJMSServer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testStopStartBackupBeforeLive() throws Exception
+ {
+ testStopStart1(true);
+ }
+
+ public void testStopStartLiveBeforeBackup() throws Exception
+ {
+ testStopStart1(false);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+ private void testStopStart1(final boolean backupBeforeLive) throws Exception
+ {
+ final int numMessages = 5;
+
+ for (int j = 0; j < numMessages; j++)
+ {
+ log.info("Iteration " + j);
+
+ startBackup();
+ startLive();
+
+ JBossConnectionFactory jbcf = new JBossConnectionFactory(new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName()),
+ new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName(),
+ backupParams));
+
+ jbcf.setBlockOnPersistentSend(true);
+ jbcf.setBlockOnNonPersistentSend(true);
+
+ Connection conn = jbcf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = sess.createQueue("myJMSQueue");
+
+ MessageProducer producer = sess.createProducer(queue);
+
+ TextMessage tm = sess.createTextMessage("message" + j);
+
+ producer.send(tm);
+
+ conn.close();
+
+ jbcf.close();
+
+ if (backupBeforeLive)
+ {
+ stopBackup();
+ stopLive();
+ }
+ else
+ {
+ stopLive();
+ stopBackup();
+ }
+ }
+
+ startBackup();
+ startLive();
+
+ JBossConnectionFactory jbcf = new JBossConnectionFactory(new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName()),
+ new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName(),
+ backupParams));
+
+ jbcf.setBlockOnPersistentSend(true);
+ jbcf.setBlockOnNonPersistentSend(true);
+
+ Connection conn = jbcf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = sess.createQueue("myJMSQueue");
+
+ MessageConsumer consumer = sess.createConsumer(queue);
+
+ conn.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ TextMessage tm = (TextMessage)consumer.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+ }
+
+ conn.close();
+
+ jbcf.close();
+
+ if (backupBeforeLive)
+ {
+ stopBackup();
+ stopLive();
+ }
+ else
+ {
+ stopLive();
+ stopBackup();
+ }
+ }
+
+ private void stopLive() throws Exception
+ {
+ liveJMSServer.stop();
+ }
+
+ private void stopBackup() throws Exception
+ {
+ backupJMSServer.stop();
+ }
+
+ private void startLive() throws Exception
+ {
+ FileConfiguration fcLive = new FileConfiguration();
+
+ fcLive.setConfigurationUrl("server-start-stop-live-config1.xml");
+
+ fcLive.start();
+
+ JBMSecurityManager smLive = new JBMSecurityManagerImpl();
+
+ MessagingServer liveServer = new MessagingServerImpl(fcLive, smLive);
+
+ liveJMSServer = new JMSServerManagerImpl(liveServer, "server-start-stop-live-jms-config1.xml");
+
+ liveJMSServer.setContext(null);
+
+ liveJMSServer.start();
+ }
+
+ private void startBackup() throws Exception
+ {
+ FileConfiguration fcBackup = new FileConfiguration();
+
+ fcBackup.setConfigurationUrl("server-start-stop-backup-config1.xml");
+
+ fcBackup.start();
+
+ JBMSecurityManager smBackup = new JBMSecurityManagerImpl();
+
+ MessagingServer liveServer = new MessagingServerImpl(fcBackup, smBackup);
+
+ backupJMSServer = new JMSServerManagerImpl(liveServer, "server-start-stop-backup-jms-config1.xml");
+
+ backupJMSServer.setContext(null);
+
+ backupJMSServer.start();
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2009-06-11 12:28:06 UTC (rev 7308)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2009-06-11 17:12:13 UTC (rev 7309)
@@ -258,9 +258,7 @@
protected String getJournalDir(int index, boolean backup)
{
String dir = getJournalDir(testDir) + index + "-" + (backup ? "B" : "L");
-
- log.info("dir is " + dir);
-
+
return dir;
}
More information about the jboss-cvs-commits
mailing list