[jboss-cvs] JBoss Messaging SVN: r5350 - in trunk: examples/messaging/src/org/jboss/messaging/example and 31 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 13 12:01:13 EST 2008
Author: timfox
Date: 2008-11-13 12:01:13 -0500 (Thu, 13 Nov 2008)
New Revision: 5350
Added:
trunk/src/main/org/jboss/messaging/core/server/impl/Forwarder.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleOutflowTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java
Removed:
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ActivationTimeoutTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailBackupServerTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverExpiredMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverManagementTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverNoSessionsFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverScheduledMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/MultiThreadRandomFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/RandomFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ReplicateConnectionFailureTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleAutomaticFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleManualFailoverTest.java
Modified:
trunk/.classpath
trunk/examples/messaging/src/org/jboss/messaging/example/ManagementClient.java
trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java
trunk/examples/messaging/src/org/jboss/messaging/example/WildCardClient.java
trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java
trunk/src/main/org/jboss/messaging/core/client/ClientSession.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
trunk/src/main/org/jboss/messaging/core/config/Configuration.java
trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java
trunk/src/main/org/jboss/messaging/core/logging/Logger.java
trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java
trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java
trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateQueueMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendMessage.java
trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java
trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/basic/AutoGroupClientTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/basic/CoreClientTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/consumer/ConsumerTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/scheduling/ScheduledMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/xa/BasicXaRecoveryTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/xa/XaTimeoutTest.java
trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
trunk/tests/src/org/jboss/messaging/tests/soak/failover/RandomFailoverSoakTest.java
trunk/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplWildcardManagerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/SimpleAddressManagerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessageReferenceImplTest.java
Log:
Beginnings of clustered queues
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/.classpath 2008-11-13 17:01:13 UTC (rev 5350)
@@ -13,7 +13,6 @@
</classpathentry>
<classpathentry kind="src" path="tests/jms-tests/src"/>
<classpathentry kind="lib" path="thirdparty/oswego-concurrent/lib/concurrent.jar"/>
- <classpathentry kind="lib" path="thirdparty/jgroups/lib/jgroups.jar"/>
<classpathentry kind="lib" path="thirdparty/apache-log4j/lib/log4j.jar"/>
<classpathentry kind="lib" path="thirdparty/junit/lib/junit.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/profiler/jvmti/lib/jboss-profiler-jvmti.jar"/>
@@ -24,9 +23,6 @@
<classpathentry kind="lib" path="thirdparty/jboss/aop/lib/jrockit-pluggable-instrumentor.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/aop/lib/pluggable-instrumentor.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jbossxb/lib/jboss-xml-binding.jar"/>
- <classpathentry kind="lib" path="thirdparty/retrotranslator/lib/backport-util-concurrent.jar"/>
- <classpathentry kind="lib" path="thirdparty/retrotranslator/lib/retrotranslator-runtime.jar"/>
- <classpathentry kind="lib" path="thirdparty/retrotranslator/lib/retrotranslator-transformer.jar"/>
<classpathentry kind="lib" path="thirdparty/trove/lib/trove.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jbossts14/lib/jbossjta.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/aop/lib/jboss-aop-jdk50.jar"/>
Modified: trunk/examples/messaging/src/org/jboss/messaging/example/ManagementClient.java
===================================================================
--- trunk/examples/messaging/src/org/jboss/messaging/example/ManagementClient.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/examples/messaging/src/org/jboss/messaging/example/ManagementClient.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -55,7 +55,7 @@
// add temporary destination and queue
clientSession.addDestination(replytoQueue, false, true);
- clientSession.createQueue(replytoQueue, replytoQueue, null, false, true);
+ clientSession.createQueue(replytoQueue, replytoQueue, null, false, true, true);
// create a management message to subscribe to notifications from the
// server
Modified: trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java
===================================================================
--- trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -61,7 +61,7 @@
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.integration.transports.netty.NettyConnectorFactory"));
clientSession = sessionFactory.createSession(false, true, true);
SimpleString atestq = new SimpleString("atestq");
- clientSession.createQueue(atestq, atestq, null, false, true);
+ clientSession.createQueue(atestq, atestq, null, false, true, true);
ClientProducer clientProducer = clientSession.createProducer(atestq);
ClientMessage message = clientSession.createClientMessage(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
Modified: trunk/examples/messaging/src/org/jboss/messaging/example/WildCardClient.java
===================================================================
--- trunk/examples/messaging/src/org/jboss/messaging/example/WildCardClient.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/examples/messaging/src/org/jboss/messaging/example/WildCardClient.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -39,6 +39,7 @@
public class WildCardClient
{
final static Logger log = Logger.getLogger(WildCardClient.class);
+
public static void main(final String[] args)
{
ClientSession clientSession = null;
@@ -46,23 +47,28 @@
SimpleString wildCardQ = new SimpleString("queuejms.#");
try
{
- ClientSessionFactory sessionFactory =
- new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.integration.transports.netty.NettyConnectorFactory"));
+ ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.netty.NettyConnectorFactory"));
clientSession = sessionFactory.createSession(false, true, true);
SimpleString queue = new SimpleString("queuejms.testQueue");
SimpleString queue2 = new SimpleString("queuejms.MyQueue");
ClientProducer clientProducer = clientSession.createProducer(queue);
ClientProducer clientProducer2 = clientSession.createProducer(queue2);
- ClientMessage message = clientSession.createClientMessage(JBossTextMessage.TYPE, false, 0,
- System.currentTimeMillis(), (byte) 1);
+ ClientMessage message = clientSession.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
message.getBody().putString("This is a message from queue " + queue);
- ClientMessage message2 = clientSession.createClientMessage(JBossTextMessage.TYPE, false, 0,
- System.currentTimeMillis(), (byte) 1);
+ ClientMessage message2 = clientSession.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
message2.getBody().putString("This is a message from queue " + queue2);
-
- clientSession.createQueue(wildCardQ, wildCardQ, null, false, true);clientConsumer = clientSession.createConsumer(wildCardQ);
+ clientSession.createQueue(wildCardQ, wildCardQ, null, false, true, true);
+ clientConsumer = clientSession.createConsumer(wildCardQ);
clientProducer.send(message);
log.info("message sent to " + queue);
clientProducer2.send(message2);
@@ -75,13 +81,13 @@
msg2.acknowledge();
log.info("message received: " + msg2.getBody().getString());
}
- catch(Exception e)
+ catch (Exception e)
{
e.printStackTrace();
}
finally
{
- if(clientConsumer != null)
+ if (clientConsumer != null)
{
try
{
Modified: trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -23,6 +23,7 @@
package org.jboss.messaging.core.client;
import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.util.SimpleString;
/**
@@ -33,9 +34,9 @@
{
SimpleString getAddress();
- void send(ClientMessage message) throws MessagingException;
+ void send(Message message) throws MessagingException;
- void send(SimpleString address, ClientMessage message) throws MessagingException;
+ void send(SimpleString address, Message message) throws MessagingException;
void registerAcknowledgementHandler(AcknowledgementHandler handler);
Modified: trunk/src/main/org/jboss/messaging/core/client/ClientSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientSession.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientSession.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -44,7 +44,8 @@
SimpleString queueName,
SimpleString filterString,
boolean durable,
- boolean temporary) throws MessagingException;
+ boolean temporary,
+ boolean fanout) throws MessagingException;
void deleteQueue(SimpleString queueName) throws MessagingException;
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -16,6 +16,7 @@
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.impl.MessageImpl;
import org.jboss.messaging.core.remoting.Channel;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionSendMessage;
@@ -100,14 +101,14 @@
return address;
}
- public void send(final ClientMessage msg) throws MessagingException
+ public void send(final Message msg) throws MessagingException
{
checkClosed();
doSend(null, msg);
}
- public void send(final SimpleString address, final ClientMessage msg) throws MessagingException
+ public void send(final SimpleString address, final Message msg) throws MessagingException
{
checkClosed();
@@ -179,7 +180,7 @@
closed = true;
}
- private void doSend(final SimpleString address, final ClientMessage msg) throws MessagingException
+ private void doSend(final SimpleString address, final Message msg) throws MessagingException
{
if (address != null)
{
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -200,11 +200,12 @@
final SimpleString queueName,
final SimpleString filterString,
final boolean durable,
- final boolean temp) throws MessagingException
+ final boolean temp,
+ final boolean fanout) throws MessagingException
{
checkClosed();
- SessionCreateQueueMessage request = new SessionCreateQueueMessage(address, queueName, filterString, durable, temp);
+ SessionCreateQueueMessage request = new SessionCreateQueueMessage(address, queueName, filterString, durable, temp, fanout);
channel.sendBlocking(request);
}
Modified: trunk/src/main/org/jboss/messaging/core/config/Configuration.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/Configuration.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/config/Configuration.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -89,6 +89,10 @@
void setBackupConnectorConfiguration(TransportConfiguration config);
+ Set<OutflowConfiguration> getOutflowConfigurations();
+
+ void setOutFlowConfigurations(final Set<OutflowConfiguration> configs);
+
SimpleString getManagementAddress();
void setManagementAddress(SimpleString address);
Modified: trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -18,6 +18,7 @@
import java.util.Set;
import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.OutflowConfiguration;
import org.jboss.messaging.core.config.TransportConfiguration;
import org.jboss.messaging.core.server.JournalType;
import org.jboss.messaging.util.SimpleString;
@@ -109,6 +110,8 @@
protected Set<TransportConfiguration> acceptorConfigs = new HashSet<TransportConfiguration>();
protected TransportConfiguration backupConnectorConfig;
+
+ protected Set<OutflowConfiguration> outFlowConfigs = new HashSet<OutflowConfiguration>();
// Paging related attributes
@@ -249,7 +252,17 @@
{
backupConnectorConfig = config;
}
+
+ public Set<OutflowConfiguration> getOutflowConfigurations()
+ {
+ return outFlowConfigs;
+ }
+ public void setOutFlowConfigurations(final Set<OutflowConfiguration> configs)
+ {
+ this.outFlowConfigs = configs;
+ }
+
public String getBindingsDirectory()
{
return bindingsDirectory;
@@ -439,6 +452,7 @@
{
this.managementAddress = address;
}
+
@Override
public boolean equals(final Object other)
Modified: trunk/src/main/org/jboss/messaging/core/logging/Logger.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/logging/Logger.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/logging/Logger.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -25,8 +25,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
-import java.util.logging.Handler;
-import java.util.logging.LogRecord;
/**
*
Modified: trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -113,7 +113,8 @@
@Parameter(name = "address", desc = "Address of the queue") String address,
@Parameter(name = "name", desc = "Name of the queue") String name,
@Parameter(name = "filter", desc = "Filter of the queue") String filter,
- @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable
+ @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable,
+ @Parameter(name = "fanout", desc = "Should the queue be bound as a fanout binding") boolean fanout
)
throws Exception;
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -389,17 +389,19 @@
return postOffice.addDestination(new SimpleString(address), false);
}
+ //TODO - do we really need this method?
public void createQueue(final String address, final String name) throws Exception
{
SimpleString sAddress = new SimpleString(address);
SimpleString sName = new SimpleString(name);
if (postOffice.getBinding(sAddress) == null)
{
- postOffice.addBinding(sAddress, sName, null, true, false);
+ postOffice.addBinding(sAddress, sName, null, true, false, true);
}
}
- public void createQueue(final String address, final String name, final String filterStr, final boolean durable) throws Exception
+ public void createQueue(final String address, final String name, final String filterStr, final boolean durable,
+ final boolean fanout) throws Exception
{
SimpleString sAddress = new SimpleString(address);
SimpleString sName = new SimpleString(name);
@@ -411,7 +413,7 @@
}
if (postOffice.getBinding(sAddress) == null)
{
- postOffice.addBinding(sAddress, sName, filter, durable, false);
+ postOffice.addBinding(sAddress, sName, filter, durable, false, fanout);
}
}
Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -126,12 +126,13 @@
return globalMode.get();
}
+ //FIXME - this is not thread safe
public PagingStore getPageStore(final SimpleString storeName) throws Exception
{
PagingStore store = stores.get(storeName);
+
if (store == null)
{
-
store = newStore(storeName);
PagingStore oldStore = stores.putIfAbsent(storeName, store);
@@ -145,7 +146,6 @@
}
return store;
-
}
/** this will be set by the postOffice itself.
@@ -370,7 +370,7 @@
if (store.isDropWhenMaxSize() && size > 0)
{
// if destination configured to drop messages && size is over the
- // limit, we return -1 what means drop the message
+ // limit, we return -1 which means drop the message
if (store.getAddressSize() + size > maxSize || maxGlobalSize > 0 && globalSize.get() + size > maxGlobalSize)
{
if (!store.isDroppedMessage())
@@ -388,7 +388,6 @@
}
else
{
-
long currentGlobalSize = globalSize.addAndGet(size);
final long addressSize = store.addAddressSize(size);
Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -284,9 +284,11 @@
// this address
if (dropMessagesOnSize)
{
+ //TODO - why?
return false;
}
+ //TODO why calc this before checking currentPage?
int bytesToWrite = fileFactory.calculateBlockSize(message.getEncodeSize() + PageImpl.SIZE_RECORD);
// The only thing single-threaded done on paging is positioning and
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 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -22,6 +22,8 @@
package org.jboss.messaging.core.persistence.impl.journal;
+import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
+
import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -493,7 +495,8 @@
BindingEncoding bindingEncoding = new BindingEncoding(binding.getQueue().getName(),
binding.getAddress(),
- filterString);
+ filterString,
+ binding.isFanout());
bindingsJournal.appendAddRecord(queueID, BINDING_RECORD, bindingEncoding);
}
@@ -578,7 +581,7 @@
Queue queue = queueFactory.createQueue(id, encodeBinding.queueName, filter, true, false);
- Binding binding = new BindingImpl(encodeBinding.address, queue);
+ Binding binding = new BindingImpl(encodeBinding.address, queue, encodeBinding.fanout);
bindings.add(binding);
}
@@ -876,16 +879,22 @@
SimpleString filter;
+ boolean fanout;
+
public BindingEncoding()
{
}
- public BindingEncoding(final SimpleString queueName, final SimpleString address, final SimpleString filter)
+ public BindingEncoding(final SimpleString queueName,
+ final SimpleString address,
+ final SimpleString filter,
+ final boolean fanout)
{
super();
this.queueName = queueName;
this.address = address;
this.filter = filter;
+ this.fanout = fanout;
}
public void decode(final MessagingBuffer buffer)
@@ -893,6 +902,7 @@
queueName = buffer.getSimpleString();
address = buffer.getSimpleString();
filter = buffer.getNullableSimpleString();
+ fanout = buffer.getBoolean();
}
public void encode(final MessagingBuffer buffer)
@@ -900,12 +910,14 @@
buffer.putSimpleString(queueName);
buffer.putSimpleString(address);
buffer.putNullableSimpleString(filter);
+ buffer.putBoolean(fanout);
}
public int getEncodeSize()
{
return SimpleString.sizeofString(queueName) + SimpleString.sizeofString(address) + 1 + // HasFilter?
- ((filter != null) ? SimpleString.sizeofString(filter) : 0);
+ ((filter != null) ? SimpleString.sizeofString(filter) : 0) +
+ SIZE_BOOLEAN;
}
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -38,4 +38,10 @@
SimpleString getAddress();
Queue getQueue();
+
+ boolean isFanout();
+
+ long getRoutings();
+
+ void incrementRoutings();
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -62,7 +62,7 @@
boolean containsDestination(SimpleString address);
Binding addBinding(SimpleString address, SimpleString queueName, Filter filter,
- boolean durable, boolean temporary) throws Exception;
+ boolean durable, boolean temporary, boolean fanout) throws Exception;
Binding removeBinding(SimpleString queueName) throws Exception;
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -39,15 +39,21 @@
private final Queue queue;
+ private final boolean fanout;
+
private boolean hashAssigned;
private int hash;
+
+ private volatile long routings;
- public BindingImpl(final SimpleString address, final Queue queue)
+ public BindingImpl(final SimpleString address, final Queue queue, final boolean fanout)
{
this.address = address;
this.queue = queue;
+
+ this.fanout = fanout;
}
public SimpleString getAddress()
@@ -59,6 +65,21 @@
{
return queue;
}
+
+ public boolean isFanout()
+ {
+ return fanout;
+ }
+
+ public long getRoutings()
+ {
+ return routings;
+ }
+
+ public void incrementRoutings()
+ {
+ routings++;
+ }
public boolean equals(Object other)
{
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -77,9 +77,9 @@
private final ManagementService managementService;
private final ResourceManager resourceManager;
-
+
private Map<SimpleString, SendLock> addressLocks = new HashMap<SimpleString, SendLock>();
-
+
public PostOfficeImpl(final StorageManager storageManager,
final PagingManager pagingManager,
final QueueFactory queueFactory,
@@ -110,7 +110,7 @@
addressManager = new SimpleAddressManager();
}
- this.backup = backup;
+ this.backup = backup;
}
// MessagingComponent implementation ---------------------------------------
@@ -123,7 +123,7 @@
pagingManager.start();
}
-
+
// Injecting the postoffice (itself) on queueFactory for paging-control
queueFactory.setPostOffice(this);
@@ -137,13 +137,13 @@
pagingManager.stop();
addressManager.clear();
-
- //Release all the locks
- for (SendLock lock: addressLocks.values())
+
+ // Release all the locks
+ for (SendLock lock : addressLocks.values())
{
lock.close();
}
-
+
addressLocks.clear();
started = false;
@@ -166,7 +166,7 @@
{
storageManager.addDestination(address);
}
-
+
managementService.registerAddress(address);
}
@@ -178,14 +178,14 @@
boolean removed = addressManager.removeDestination(address);
if (removed)
- {
+ {
if (durable)
{
storageManager.deleteDestination(address);
}
managementService.unregisterAddress(address);
}
-
+
addressLocks.remove(address);
return removed;
@@ -201,19 +201,20 @@
return addressManager.getDestinations();
}
- //TODO - needs to be synchronized to prevent happening concurrently with activate().
- //(and possible removeBinding and other methods)
- //Otherwise can have situation where createQueue comes in before failover, then failover occurs
- //and post office is activated but queue remains unactivated after failover so delivery never occurs
- //even though failover is complete
- //TODO - more subtle locking could be used -this is a bit heavy handed
+ // TODO - needs to be synchronized to prevent happening concurrently with activate().
+ // (and possible removeBinding and other methods)
+ // Otherwise can have situation where createQueue comes in before failover, then failover occurs
+ // and post office is activated but queue remains unactivated after failover so delivery never occurs
+ // even though failover is complete
+ // TODO - more subtle locking could be used -this is a bit heavy handed
public synchronized Binding addBinding(final SimpleString address,
final SimpleString queueName,
final Filter filter,
final boolean durable,
- boolean temporary) throws Exception
+ final boolean temporary,
+ final boolean fanout) throws Exception
{
- Binding binding = createBinding(address, queueName, filter, durable, temporary);
+ Binding binding = createBinding(address, queueName, filter, durable, temporary, fanout);
addBindingInMemory(binding);
@@ -221,7 +222,7 @@
{
storageManager.addBinding(binding);
}
-
+
return binding;
}
@@ -285,6 +286,10 @@
if (bindings != null)
{
+ Binding theBinding = null;
+
+ long lowestRoutings = 0;
+
for (Binding binding : bindings)
{
Queue queue = binding.getQueue();
@@ -293,17 +298,41 @@
if (filter == null || filter.match(message))
{
- MessageReference reference = message.createReference(queue);
+ if (binding.isFanout())
+ {
+ //Fanout bindings always get the reference
+ MessageReference reference = message.createReference(queue);
- refs.add(reference);
+ refs.add(reference);
+ }
+ else
+ {
+ //We choose the queue with the lowest routings value
+ long routings = binding.getRoutings();
+
+ if (routings <= lowestRoutings)
+ {
+ //TODO - take num consumers into account
+ lowestRoutings = routings;
+
+ theBinding = binding;
+ }
+ }
}
}
+
+ if (theBinding != null)
+ {
+ MessageReference reference = message.createReference(theBinding.getQueue());
+
+ refs.add(reference);
+
+ theBinding.incrementRoutings();
+ }
}
return refs;
}
-
-
}
public PagingManager getPagingManager()
@@ -323,33 +352,33 @@
Map<SimpleString, Binding> nameMap = addressManager.getBindings();
List<Queue> queues = new ArrayList<Queue>();
-
+
for (Binding binding : nameMap.values())
{
Queue queue = binding.getQueue();
-
+
boolean activated = queue.activate();
-
+
if (!activated)
- {
+ {
queues.add(queue);
}
}
-
+
return queues;
}
-
+
public synchronized SendLock getAddressLock(final SimpleString address)
{
SendLock lock = addressLocks.get(address);
-
+
if (lock == null)
{
lock = new SendLockImpl();
-
+
addressLocks.put(address, lock);
}
-
+
return lock;
}
@@ -359,7 +388,8 @@
final SimpleString name,
final Filter filter,
final boolean durable,
- final boolean temporary) throws Exception
+ final boolean temporary,
+ final boolean fanout) throws Exception
{
Queue queue = queueFactory.createQueue(-1, name, filter, durable, false);
@@ -368,7 +398,7 @@
queue.setBackup();
}
- Binding binding = new BindingImpl(address, queue);
+ Binding binding = new BindingImpl(address, queue, fanout);
return binding;
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -85,7 +85,7 @@
// add this as a wildcard binding and add a new binding to any linked addresses.
for (Address destination : add.getLinkedAddresses())
{
- BindingImpl binding1 = new BindingImpl(destination.getAddress(), binding.getQueue());
+ BindingImpl binding1 = new BindingImpl(destination.getAddress(), binding.getQueue(), binding.isFanout());
super.addMapping(destination.getAddress(), binding1);
}
List<Binding> bindings = new CopyOnWriteArrayList<Binding>();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateQueueMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateQueueMessage.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateQueueMessage.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -41,13 +41,15 @@
private SimpleString filterString;
private boolean durable;
private boolean temporary;
+ private boolean fanout;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
public SessionCreateQueueMessage(final SimpleString address, final SimpleString queueName,
- final SimpleString filterString, final boolean durable, final boolean temporary)
+ final SimpleString filterString, final boolean durable, final boolean temporary,
+ final boolean fanout)
{
super(SESS_CREATEQUEUE);
@@ -56,6 +58,7 @@
this.filterString = filterString;
this.durable = durable;
this.temporary = temporary;
+ this.fanout = fanout;
}
public SessionCreateQueueMessage()
@@ -103,6 +106,11 @@
return temporary;
}
+ public boolean isFanout()
+ {
+ return fanout;
+ }
+
public void encodeBody(final MessagingBuffer buffer)
{
buffer.putSimpleString(address);
@@ -110,6 +118,7 @@
buffer.putNullableSimpleString(filterString);
buffer.putBoolean(durable);
buffer.putBoolean(temporary);
+ buffer.putBoolean(fanout);
}
public void decodeBody(final MessagingBuffer buffer)
@@ -119,6 +128,7 @@
filterString = buffer.getNullableSimpleString();
durable = buffer.getBoolean();
temporary = buffer.getBoolean();
+ fanout = buffer.getBoolean();
}
public boolean equals(Object other)
@@ -134,7 +144,8 @@
r.queueName.equals(this.queueName) &&
(r.filterString == null ? this.filterString == null : r.filterString.equals(this.filterString)) &&
r.durable == this.durable &&
- r.temporary == this.temporary;
+ r.temporary == this.temporary &&
+ r.fanout == this.fanout;
}
// Package protected ---------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendMessage.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendMessage.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -24,6 +24,7 @@
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.core.server.ServerMessage;
import org.jboss.messaging.core.server.impl.ServerMessageImpl;
@@ -42,7 +43,7 @@
// Attributes ----------------------------------------------------
- private ClientMessage clientMessage;
+ private Message clientMessage;
private ServerMessage serverMessage;
@@ -52,7 +53,7 @@
// Constructors --------------------------------------------------
- public SessionSendMessage(final ClientMessage message, final boolean requiresResponse)
+ public SessionSendMessage(final Message message, final boolean requiresResponse)
{
super(SESS_SEND);
@@ -65,24 +66,10 @@
{
super(SESS_SEND);
}
-
- protected SessionSendMessage(final byte type, final ClientMessage message, final boolean requiresResponse)
- {
- super(type);
-
- this.clientMessage = message;
-
- this.requiresResponse = requiresResponse;
- }
-
- protected SessionSendMessage(byte type)
- {
- super(type);
- }
-
+
// Public --------------------------------------------------------
- public ClientMessage getClientMessage()
+ public Message getClientMessage()
{
return clientMessage;
}
Added: trunk/src/main/org/jboss/messaging/core/server/impl/Forwarder.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/Forwarder.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/Forwarder.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,255 @@
+/*
+ * 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.core.server.impl;
+
+import java.util.LinkedList;
+import java.util.concurrent.Executor;
+
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.persistence.StorageManager;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.server.Consumer;
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.core.transaction.Transaction;
+import org.jboss.messaging.core.transaction.impl.TransactionImpl;
+import org.jboss.messaging.util.Future;
+
+/**
+ * A Forwarder
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 12 Nov 2008 11:37:35
+ *
+ *
+ */
+public class Forwarder implements Consumer
+{
+ // Constants -----------------------------------------------------
+
+ private static final Logger log = Logger.getLogger(Forwarder.class);
+
+ // Attributes ----------------------------------------------------
+
+ private final Queue queue;
+
+ private Executor executor;
+
+ private volatile boolean busy;
+
+ private int maxBatchSize;
+
+ private long maxBatchTime;
+
+ private int count;
+
+ private java.util.Queue<MessageReference> refs = new LinkedList<MessageReference>();
+
+ private boolean closed;
+
+ private Transaction tx;
+
+ private final StorageManager storageManager;
+
+ private final PostOffice postOffice;
+
+ private final HierarchicalRepository<QueueSettings> queueSettingsRepository;
+
+ private final ClientSession session;
+
+ private final ClientProducer producer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public Forwarder(final Queue queue,
+ final TransportConfiguration connectorConfig, final Executor executor, final int maxBatchSize,
+ final long maxBatchTime,
+ final StorageManager storageManager, final PostOffice postOffice,
+ final HierarchicalRepository<QueueSettings> queueSettingsRepository)
+ throws Exception
+ {
+ this.queue = queue;
+
+ this.executor = executor;
+
+ this.maxBatchSize = maxBatchSize;
+
+ this.maxBatchTime = maxBatchTime;
+
+ this.storageManager = storageManager;
+
+ this.postOffice = postOffice;
+
+ this.queueSettingsRepository = queueSettingsRepository;
+
+ createTx();
+
+ ClientSessionFactory csf = new ClientSessionFactoryImpl(connectorConfig);
+
+ session = csf.createSession(false, false, false);
+
+ producer = session.createProducer(null);
+
+ queue.addConsumer(this);
+ }
+
+ public synchronized void close() throws Exception
+ {
+ closed = true;
+
+ queue.removeConsumer(this);
+
+ // Wait until all batches are complete
+
+ Future future = new Future();
+
+ executor.execute(future);
+
+ boolean ok = future.await(10000);
+
+ if (!ok)
+ {
+ log.warn("Timed out waiting for batch to be sent");
+ }
+ }
+
+ // Consumer implementation ---------------------------------------
+
+ public HandleStatus handle(final MessageReference reference) throws Exception
+ {
+ if (busy)
+ {
+ return HandleStatus.BUSY;
+ }
+
+ synchronized (this)
+ {
+ if (closed)
+ {
+ return HandleStatus.BUSY;
+ }
+
+ refs.add(reference);
+
+ count++;
+
+ if (count == maxBatchSize)
+ {
+ busy = true;
+
+ executor.execute(new BatchSender());
+ }
+
+ return HandleStatus.HANDLED;
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private void sendBatch()
+ {
+ try
+ {
+ synchronized (this)
+ {
+ // /TODO initially we just send batch in one tx and then acknowledge in another tx locally
+ // In event of failure this could result in duplicates on restart.
+ // To remedy that we will implement duplicate detection on the sendee by adding a unique header
+ // in the first message in the tx, and storing it on the server side.
+
+ while (true)
+ {
+ MessageReference ref = refs.poll();
+
+ if (ref == null)
+ {
+ break;
+ }
+
+ tx.addAcknowledgement(ref);
+
+ Message message = ref.getMessage();
+
+ producer.send(message.getDestination(), message);
+ }
+
+ session.commit();
+
+ tx.commit();
+
+ createTx();
+
+ busy = false;
+ }
+
+ queue.deliverAsync(executor);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to forward batch", e);
+
+ try
+ {
+ tx.rollback(queueSettingsRepository);
+ }
+ catch (Exception e2)
+ {
+ log.error("Failed to rollback", e2);
+ }
+ }
+ }
+
+ private void createTx()
+ {
+ tx = new TransactionImpl(storageManager, postOffice);
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private class BatchSender implements Runnable
+ {
+ public void run()
+ {
+ sendBatch();
+ }
+ }
+
+}
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -165,13 +165,14 @@
{
SimpleString dlq = queueSettingsRepository.getMatch(queue.getName().toString()).getDLQ();
+ //FIXME - this is not thread safe
if (dlq != null)
{
Binding dlqBinding = postOffice.getBinding(dlq);
if (dlqBinding == null)
{
- dlqBinding = postOffice.addBinding(dlq, dlq, null, true, false);
+ dlqBinding = postOffice.addBinding(dlq, dlq, null, true, false, false);
}
move(dlqBinding, persistenceManager, postOffice, false);
@@ -200,7 +201,7 @@
//might try and create the binding twice?
if (expiryBinding == null)
{
- expiryBinding = postOffice.addBinding(expiryQueue, expiryQueue, null, true, false);
+ expiryBinding = postOffice.addBinding(expiryQueue, expiryQueue, null, true, false, false);
}
move(expiryBinding, persistenceManager, postOffice, true);
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -25,8 +26,11 @@
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.OutflowConfiguration;
import org.jboss.messaging.core.config.TransportConfiguration;
import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.filter.impl.FilterImpl;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.management.ManagementService;
import org.jboss.messaging.core.management.MessagingServerControlMBean;
@@ -35,6 +39,7 @@
import org.jboss.messaging.core.paging.impl.PagingManagerFactoryNIO;
import org.jboss.messaging.core.paging.impl.PagingManagerImpl;
import org.jboss.messaging.core.persistence.StorageManager;
+import org.jboss.messaging.core.postoffice.Binding;
import org.jboss.messaging.core.postoffice.PostOffice;
import org.jboss.messaging.core.postoffice.impl.PostOfficeImpl;
import org.jboss.messaging.core.remoting.Channel;
@@ -63,6 +68,8 @@
import org.jboss.messaging.util.ExecutorFactory;
import org.jboss.messaging.util.JBMThreadFactory;
import org.jboss.messaging.util.OrderedExecutorFactory;
+import org.jboss.messaging.util.SimpleString;
+import org.jboss.messaging.util.UUIDGenerator;
import org.jboss.messaging.util.VersionLoader;
/**
@@ -262,6 +269,8 @@
ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS);
}
remotingService.setMessagingServer(this);
+
+ startOutflows();
started = true;
}
@@ -272,6 +281,8 @@
{
return;
}
+
+ stopOutflows();
asyncDeliveryPool.shutdown();
@@ -299,7 +310,7 @@
queueFactory = null;
resourceManager = null;
serverManagement = null;
-
+
started = false;
}
@@ -448,6 +459,53 @@
connection.freeze();
}
}
+
+ private Set<Forwarder> forwarders = new HashSet<Forwarder>();
+
+ private void startOutflows() throws Exception
+ {
+ Set<OutflowConfiguration> outflows = configuration.getOutflowConfigurations();
+
+ for (OutflowConfiguration outflowConfig: outflows)
+ {
+ for (TransportConfiguration connectorConfig: outflowConfig.getConnectors())
+ {
+ SimpleString queueName = new SimpleString("outflow." + outflowConfig.getName() + "." +
+ UUIDGenerator.getInstance().generateSimpleStringUUID());
+
+ Binding binding = postOffice.getBinding(queueName);
+
+ //TODO need to delete store and forward queues that are no longer in the config
+ //and also allow ability to change filterstring etc. while keeping the same name
+ if (binding == null)
+ {
+ SimpleString address = new SimpleString(outflowConfig.getAddress());
+
+ SimpleString filterString = outflowConfig.getFilterString() == null ? null : new SimpleString(outflowConfig.getFilterString());
+
+ Filter filter = filterString == null ? null : new FilterImpl(filterString);
+
+ binding = postOffice.addBinding(address, queueName, filter, true, false, outflowConfig.isFanout());
+ }
+
+ Forwarder forwarder = new Forwarder(binding.getQueue(), connectorConfig, executorFactory.getExecutor(),
+ outflowConfig.getMaxBatchSize(), outflowConfig.getMaxBatchTime(),
+ storageManager, postOffice, queueSettingsRepository);
+
+ forwarders.add(forwarder);
+
+ binding.getQueue().addConsumer(forwarder);
+ }
+ }
+ }
+
+ private void stopOutflows() throws Exception
+ {
+ for (Forwarder forwarder: forwarders)
+ {
+ forwarder.close();
+ }
+ }
public ReattachSessionResponseMessage reattachSession(final RemotingConnection connection,
final String name,
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -126,7 +126,7 @@
// Queue implementation
// -------------------------------------------------------------------
-
+
public boolean isClustered()
{
return clustered;
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -94,7 +94,7 @@
}
refCount.incrementAndGet();
-
+
return ref;
}
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -420,6 +420,8 @@
boolean temporary = packet.isTemporary();
boolean durable = packet.isDurable();
+
+ boolean fanout = packet.isFanout();
Packet response = null;
@@ -445,7 +447,7 @@
filter = new FilterImpl(filterString);
}
- binding = postOffice.addBinding(address, queueName, filter, durable, temporary);
+ binding = postOffice.addBinding(address, queueName, filter, durable, temporary, fanout);
if (temporary)
{
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -522,7 +522,7 @@
queueName = new SimpleString(UUID.randomUUID().toString());
- session.createQueue(dest.getSimpleAddress(), queueName, coreFilterString, false, true);
+ session.createQueue(dest.getSimpleAddress(), queueName, coreFilterString, false, true, true);
consumer = session.createConsumer(queueName, null, false);
@@ -549,7 +549,7 @@
if (!subResponse.isExists())
{
- session.createQueue(dest.getSimpleAddress(), queueName, coreFilterString, true, false);
+ session.createQueue(dest.getSimpleAddress(), queueName, coreFilterString, true, false, true);
}
else
{
@@ -583,7 +583,7 @@
session.deleteQueue(queueName);
// Create the new one
- session.createQueue(dest.getSimpleAddress(), queueName, coreFilterString, true, false);
+ session.createQueue(dest.getSimpleAddress(), queueName, coreFilterString, true, false, true);
}
}
@@ -668,7 +668,7 @@
SimpleString simpleAddress = queue.getSimpleAddress();
- session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), null, false, true);
+ session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), null, false, true, false);
session.addDestination(queue.getSimpleAddress(), false, true);
Modified: trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -126,6 +126,11 @@
{
message.acknowledge();
}
+
+ if (consumer.isClosed())
+ {
+ log.info("not acking, consumer is closed");
+ }
}
catch (MessagingException e)
{
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1071,7 +1071,7 @@
{
conn.close();
}
- }
+ }
}
public void testMessageListenerClientAck() throws Exception
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/basic/AutoGroupClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/basic/AutoGroupClientTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/basic/AutoGroupClientTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -72,7 +72,7 @@
sf.setAutoGroup(true);
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -133,7 +133,7 @@
sf.setAutoGroup(true);
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
ClientProducer producer2 = session.createProducer(QUEUE);
@@ -201,7 +201,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/basic/CoreClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/basic/CoreClientTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/basic/CoreClientTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -80,7 +80,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -108,7 +108,7 @@
new String[] { Integer.toString(numberOfConnectionsOnTheClient) });
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientConsumer consumer = session.createConsumer(QUEUE);
ClientProducer producer = session.createProducer(QUEUE);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -106,7 +106,7 @@
ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.integration.transports.netty.NettyConnectorFactory"));
session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
consumer = session.createConsumer(QUEUE);
session.start();
}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ActivationTimeoutTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ActivationTimeoutTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ActivationTimeoutTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,307 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A ActivationTimeoutTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 4 Nov 2008 16:54:50
- *
- *
- */
-public class ActivationTimeoutTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(SimpleAutomaticFailoverTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final long ACTIVATION_TIMEOUT = 5000;
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testTimeoutAfterConsumerFailsToReattach() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- ClientSessionFactoryInternal sf2 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
- sf2.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
- log.info("Sent messages");
-
- ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
-
- ClientSession session2 = sf2.createSession(false, true, true);
-
- //Create another consumer so we have two consumers on the queue
- ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
-
- long start = System.currentTimeMillis();
-
- RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
-
- // Now we fail ONLY the connections on sf1, not on sf2
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- session1.start();
-
- //The messages should not be delivered until after activationTimeout ms, since
- //session 2 didn't reattach
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer1.receive(2 * ACTIVATION_TIMEOUT);
-
- assertNotNull(message);
-
- if (i == 0)
- {
- long now = System.currentTimeMillis();
-
- assertTrue(now - start >= ACTIVATION_TIMEOUT);
- }
-
- assertEquals("aardvarks", message.getBody().getString());
-
- assertEquals(i, message.getProperty(new SimpleString("count")));
-
- message.acknowledge();
- }
-
- ClientMessage message = consumer1.receive(1000);
-
- assertNull(message);
-
- session1.close();
-
- RemotingConnection conn2 = ((ClientSessionImpl)session2).getConnection();
-
- conn2.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- session2.close();
- }
-
- public void testTimeoutAfterAllConsumerFailsToReattach() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- ClientSessionFactoryInternal sf2 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
- sf2.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
- log.info("Sent messages");
-
-
- ClientSession session2 = sf2.createSession(false, true, true);
-
- ClientConsumer consumer1 = session2.createConsumer(ADDRESS);
-
- ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
-
- long start = System.currentTimeMillis();
-
- RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
-
- // Now we fail ONLY the connections on sf1, not on sf2
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- session1.start();
-
- //The messages should not be delivered until after activationTimeout ms, since
- //session 2 didn't reattach
-
- //We now create a new consumer but it shouldn't receive the messages until after the timeout
-
- ClientConsumer consumer3 = session1.createConsumer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer3.receive(2 * ACTIVATION_TIMEOUT);
-
- assertNotNull(message);
-
- if (i == 0)
- {
- long now = System.currentTimeMillis();
-
- assertTrue(now - start >= ACTIVATION_TIMEOUT);
- }
-
- assertEquals("aardvarks", message.getBody().getString());
-
- assertEquals(i, message.getProperty(new SimpleString("count")));
-
- message.acknowledge();
- }
-
- ClientMessage message = consumer3.receive(1000);
-
- assertNull(message);
-
- session1.close();
-
- RemotingConnection conn2 = ((ClientSessionImpl)session2).getConnection();
-
- conn2.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- session2.close();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupConf.setQueueActivationTimeout(ACTIVATION_TIMEOUT);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailBackupServerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailBackupServerTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailBackupServerTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,222 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A FailBackupServerTest
- *
- * Make sure live sever continues ok if backup server fails
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 6 Nov 2008 11:27:17
- *
- *
- */
-public class FailBackupServerTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(FailBackupServerTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testFailBackup() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
-
- session1.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer1.receive(1000);
-
- assertNotNull(message);
-
- assertEquals("aardvarks", message.getBody().getString());
-
- assertEquals(i, message.getProperty(new SimpleString("count")));
-
- if (i == 0)
- {
- // Fail all the replicating connections - this simulates the backup server crashing
-
- Set<RemotingConnection> conns = liveService.getServer().getRemotingService().getConnections();
-
- for (RemotingConnection conn : conns)
- {
- log.info("Failing replicating connection");
- conn.getReplicatingConnection().fail(new MessagingException(MessagingException.NOT_CONNECTED, "blah"));
- }
- }
-
- message.acknowledge();
- }
-
- ClientMessage message = consumer1.receive(1000);
-
- assertNull(message);
-
- // Send some more
-
- for (int i = 0; i < numMessages; i++)
- {
- message = session1.createClientMessage(JBossTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- message = consumer1.receive(1000);
-
- assertNotNull(message);
-
- assertEquals("aardvarks", message.getBody().getString());
-
- assertEquals(i, message.getProperty(new SimpleString("count")));
-
- message.acknowledge();
- }
-
- message = consumer1.receive(1000);
-
- assertNull(message);
-
- session1.close();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverExpiredMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverExpiredMessageTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverExpiredMessageTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,233 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A FailoverExpiredMessageTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 5 Nov 2008 09:33:32
- *
- *
- */
-public class FailoverExpiredMessageTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(FailoverExpiredMessageTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- /*
- * Set messages to expire very soon, send a load of them, so at some of them get expired when they reach the client
- * After failover make sure all are received ok
- */
- public void testExpiredBeforeConsumption() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- session1.start();
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 10000;
-
- //Set time to live so at least some of them will more than likely expire before they are consumed by the client
-
- long now = System.currentTimeMillis();
-
- long expire = now + 5000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
- false,
- expire,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
- ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
-
- final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
-
- Thread t = new Thread()
- {
- public void run()
- {
- try
- {
- //Sleep a little while to ensure that some messages are consumed before failover
- Thread.sleep(5000);
- }
- catch (InterruptedException e)
- {
- }
-
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
- }
- };
-
- t.start();
-
- int count = 0;
-
- while (true)
- {
- ClientMessage message = consumer1.receive(1000);
-
- if (message != null)
- {
- message.acknowledge();
-
- //We sleep a little to make sure messages aren't consumed too quickly and some
- //will expire before reaching consumer
- Thread.sleep(1);
-
- count++;
- }
- else
- {
- log.info("message was null");
- break;
- }
- }
-
- log.info("Got " + count + " messages");
-
- t.join();
-
- session1.close();
-
- //Make sure no more messages
- ClientSession session2 = sf1.createSession(false, true, true);
-
- session2.start();
-
- ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
-
- ClientMessage message = consumer2.receive(1000);
-
- assertNull(message);
-
- session2.close();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
-
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverManagementTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverManagementTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverManagementTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,313 +0,0 @@
-/*
- * 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.cluster;
-
-import static org.jboss.messaging.core.config.impl.ConfigurationImpl.DEFAULT_MANAGEMENT_ADDRESS;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.Notification;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.client.management.impl.ManagementHelper;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A FailoverManagementTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 5 Nov 2008 15:05:14
- *
- *
- */
-public class FailoverManagementTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(FailoverManagementTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testManagementMessages() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- SimpleString replyTo = new SimpleString("replyto");
-
- session1.createQueue(replyTo, new SimpleString("replyto"), null, false, false);
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 10;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage msg = session1.createClientMessage(false);
-
- msg.getBody().flip();
-
- producer.send(msg);
- }
-
- for (int i = 0; i < numMessages / 2; i++)
- {
- ClientMessage managementMessage = session1.createClientMessage(false);
-
- ManagementHelper.putAttributes(managementMessage,
- replyTo,
- ManagementServiceImpl.getQueueObjectName(ADDRESS, ADDRESS),
- "MessageCount");
-
- managementMessage.getBody().flip();
-
- producer.send(DEFAULT_MANAGEMENT_ADDRESS, managementMessage);
- }
-
- ClientConsumer consumer1 = session1.createConsumer(replyTo);
-
- final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
-
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- //Send the other half
- for (int i = 0; i < numMessages / 2; i++)
- {
- ClientMessage managementMessage = session1.createClientMessage(false);
-
- ManagementHelper.putAttributes(managementMessage,
- replyTo,
- ManagementServiceImpl.getQueueObjectName(ADDRESS, ADDRESS),
- "MessageCount");
-
- managementMessage.getBody().flip();
-
- producer.send(DEFAULT_MANAGEMENT_ADDRESS, managementMessage);
- }
-
- session1.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer1.receive(1000);
-
- assertNotNull(message);
-
- message.acknowledge();
-
- assertTrue(ManagementHelper.isAttributesResult(message));
-
- assertEquals(numMessages, message.getProperty(new SimpleString("MessageCount")));
- }
-
- session1.close();
-
- //Make sure no more messages
- ClientSession session2 = sf1.createSession(false, true, true);
-
- session2.start();
-
- ClientConsumer consumer2 = session2.createConsumer(replyTo);
-
- ClientMessage message = consumer2.receive(1000);
-
- assertNull(message);
-
- session2.close();
- }
-
- public void testManagementMessages2() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- SimpleString replyTo = new SimpleString("replyto");
-
- session1.createQueue(replyTo, new SimpleString("replyto"), null, false, false);
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 10;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage msg = session1.createClientMessage(false);
-
- msg.getBody().flip();
-
- producer.send(msg);
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage managementMessage = session1.createClientMessage(false);
-
- ManagementHelper.putAttributes(managementMessage,
- replyTo,
- ManagementServiceImpl.getQueueObjectName(ADDRESS, ADDRESS),
- "MessageCount");
-
- managementMessage.getBody().flip();
-
- producer.send(DEFAULT_MANAGEMENT_ADDRESS, managementMessage);
- }
-
- ClientConsumer consumer1 = session1.createConsumer(replyTo);
-
-
- session1.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer1.receive(1000);
-
- assertNotNull(message);
-
- if (i == 0)
- {
- //Fail after receipt but before ack
- final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
-
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
- }
-
- message.acknowledge();
-
- assertTrue(ManagementHelper.isAttributesResult(message));
-
- assertEquals(numMessages, message.getProperty(new SimpleString("MessageCount")));
- }
-
- session1.close();
-
- //Make sure no more messages
- ClientSession session2 = sf1.createSession(false, true, true);
-
- session2.start();
-
- ClientConsumer consumer2 = session2.createConsumer(replyTo);
-
- ClientMessage message = consumer2.receive(1000);
-
- assertNull(message);
-
- session2.close();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
-
-
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverNoSessionsFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverNoSessionsFailoverTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverNoSessionsFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,225 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- * Test situation where none of the sessions failover, but a new session is created
- *
- * A FailoverNoSessionsFailoverTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 6 Nov 2008 17:39:23
- *
- *
- */
-public class FailoverNoSessionsFailoverTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(FailoverNoSessionsFailoverTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testNoFailoverAndCreateNewSession() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
-
- session1.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer1.receive(1000);
-
- assertNotNull(message);
-
- assertEquals("aardvarks", message.getBody().getString());
-
- assertEquals(i, message.getProperty(new SimpleString("count")));
-
- message.acknowledge();
- }
-
- ClientMessage message = consumer1.receive(1000);
-
- assertNull(message);
-
- session1.close();
-
- //Now create another sesion direct on the backup
-
- ClientSessionFactoryInternal sf2 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf2.setSendWindowSize(32 * 1024);
-
- ClientSession session2 = sf2.createSession(false, true, true);
-
- ClientProducer producer2 = session2.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = session2.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message2.putIntProperty(new SimpleString("count"), i);
- message2.getBody().putString("aardvarks");
- message2.getBody().flip();
- producer2.send(message2);
- }
-
- ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
-
- session2.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = consumer2.receive(1000);
-
- assertNotNull(message2);
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- ClientMessage message2 = consumer2.receive(1000);
-
- assertNull(message2);
-
- session2.close();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
-
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverScheduledMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverScheduledMessageTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverScheduledMessageTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,228 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.message.impl.MessageImpl;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A FailoverScheduledMessageTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 5 Nov 2008 11:18:51
- *
- */
-public class FailoverScheduledMessageTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(FailoverScheduledMessageTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- /*
- * Send some scheduled messsages on live
- * Let some fire on live
- * Failover
- * Let rest fire on backup
- * Assert no duplicates and all are received ok
- */
- public void testScheduled() throws Exception
- {
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf1.setSendWindowSize(32 * 1024);
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- session1.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- session1.start();
-
- ClientProducer producer = session1.createProducer(ADDRESS);
-
- final int numMessages = 10;
-
- long now = System.currentTimeMillis();
-
- final long delay = 200;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- long deliveryTime = now + delay * i;
- message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, deliveryTime);
- producer.send(message);
- }
-
- ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
-
- final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
-
- Thread t = new Thread()
- {
- public void run()
- {
- try
- {
- //Sleep a little while to ensure that some messages are consumed before failover
- Thread.sleep(delay * numMessages / 2);
- }
- catch (InterruptedException e)
- {
- }
-
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
- }
- };
-
- t.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = consumer1.receive(delay * 2);
-
- assertNotNull(message);
-
- log.info("got message " + i);
-
- message.acknowledge();
- }
-
- ClientMessage message = consumer1.receive(delay * 2);
-
- assertNull(message);
-
- t.join();
-
- session1.close();
-
- //Make sure no more messages
- ClientSession session2 = sf1.createSession(false, true, true);
-
- session2.start();
-
- ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
-
- message = consumer2.receive(1000);
-
- assertNull(message);
-
- session2.close();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
-
-
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/MultiThreadRandomFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/MultiThreadRandomFailoverTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/MultiThreadRandomFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,1566 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.MessageHandler;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- * A MultiThreadRandomFailoverTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- */
-public class MultiThreadRandomFailoverTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(MultiThreadRandomFailoverTest.class);
-
- // Constants -----------------------------------------------------
-
- private static final int RECEIVE_TIMEOUT = 30000;
-
- private static final int NUM_THREADS = 10;
-
- // Attributes ----------------------------------------------------
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- private Timer timer;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testA() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestA(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testB() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestB(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testC() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestC(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testD() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestD(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testE() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestE(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testF() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestF(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testG() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestG(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testH() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestH(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testI() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestI(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testJ() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestJ(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testK() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestK(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- public void testL() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestL(sf);
- }
- }, NUM_THREADS);
- }
-
- // public void testM() throws Exception
- // {
- // runTestMultipleThreads(new RunnableT()
- // {
- // public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- // {
- // doTestM(sf, threadNum);
- // }
- // }, NUM_THREADS);
- // }
-
- public void testN() throws Exception
- {
- runTestMultipleThreads(new RunnableT()
- {
- public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- doTestN(sf, threadNum);
- }
- }, NUM_THREADS);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void doTestA(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler(threadNum, numMessages);
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(5000, TimeUnit.MILLISECONDS);
-
- if (!ok)
- {
- throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
- }
-
- if (handler.failure != null)
- {
- throw new Exception("Handler failed: " + handler.failure);
- }
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestB(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler(threadNum, numMessages);
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- if (!ok)
- {
- throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
- }
-
- if (handler.failure != null)
- {
- throw new Exception("Handler failed: " + handler.failure);
- }
- }
-
- sessSend.close();
-
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
-
- }
-
- protected void doTestC(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, false, false);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.rollback();
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.commit();
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler(threadNum, numMessages);
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- if (!ok)
- {
- throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
- }
-
- if (handler.failure != null)
- {
- throw new Exception("Handler failed: " + handler.failure);
- }
- }
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
- }
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestD(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + " sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, false, false);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.rollback();
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.commit();
-
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler(threadNum, numMessages);
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- if (!ok)
- {
- throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
- }
-
- if (handler.failure != null)
- {
- throw new Exception("Handler failed: " + handler.failure);
- }
- }
-
- handlers.clear();
-
- // Set handlers to null
- for (ClientConsumer consumer : consumers)
- {
- consumer.setMessageHandler(null);
- }
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- // New handlers
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler(threadNum, numMessages);
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- if (!ok)
- {
- throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
- }
-
- if (handler.failure != null)
- {
- throw new Exception("Handler failed on rollback: " + handler.failure);
- }
- }
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + " sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- // Now with synchronous receive()
-
- protected void doTestE(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- consumeMessages(consumers, numMessages, threadNum);
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestF(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- consumeMessages(consumers, numMessages, threadNum);
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestG(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, false, false);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.rollback();
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.commit();
-
- consumeMessages(consumers, numMessages, threadNum);
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- consumeMessages(consumers, numMessages, threadNum);
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestH(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, false, false);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.rollback();
-
- sendMessages(sessSend, producer, numMessages, threadNum);
-
- sessSend.commit();
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- consumeMessages(consumers, numMessages, threadNum);
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- consumeMessages(consumers, numMessages, threadNum);
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString(threadNum + "sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestI(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- ClientSession sessCreate = sf.createSession(false, true, true);
-
- sessCreate.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false);
-
- ClientSession sess = sf.createSession(false, true, true);
-
- sess.start();
-
- ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
-
- ClientProducer producer = sess.createProducer(ADDRESS);
-
- ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.getBody().flip();
-
- producer.send(message);
-
- ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(message2);
-
- message2.acknowledge();
-
- sess.close();
-
- sessCreate.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
-
- sessCreate.close();
- }
-
- protected void doTestJ(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- ClientSession sessCreate = sf.createSession(false, true, true);
-
- sessCreate.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false);
-
- ClientSession sess = sf.createSession(false, true, true);
-
- sess.start();
-
- ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
-
- ClientProducer producer = sess.createProducer(ADDRESS);
-
- ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.getBody().flip();
-
- producer.send(message);
-
- ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(message2);
-
- message2.acknowledge();
-
- sess.close();
-
- sessCreate.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
-
- sessCreate.close();
- }
-
- protected void doTestK(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- ClientSession s = sf.createSession(false, false, false);
-
- s.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false);
-
- final int numConsumers = 100;
-
- for (int i = 0; i < numConsumers; i++)
- {
- ClientConsumer consumer = s.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
-
- consumer.close();
- }
-
- s.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
-
- s.close();
- }
-
- protected void doTestL(final ClientSessionFactory sf) throws Exception
- {
- ClientSession s = sf.createSession(false, false, false);
-
- final int numSessions = 100;
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession session = sf.createSession(false, false, false);
-
- session.close();
- }
-
- s.close();
- }
-
- // Browsers
- // FIXME - this test won't work until we use a proper iterator for browsing a queue.
- // Making a copy of the queue for a browser consumer doesn't work well with replication since
- // When replicating the create consumer (browser) to the backup, when executed on the backup the
- // backup may have different messages in its queue since been added on different threads.
- // So when replicating deliveries they may not be found.
- // https://jira.jboss.org/jira/browse/JBMESSAGING-1433
- // protected void doTestM(final ClientSessionFactory sf, final int threadNum) throws Exception
- // {
- // long start = System.currentTimeMillis();
- //
- // ClientSession sessSend = sf.createSession(false, true, true, false);
- //
- // ClientSession sessConsume = sf.createSession(false, true, true, false);
- //
- // sessConsume.createQueue(ADDRESS, new SimpleString(threadNum + "sub"), null, false, false);
- //
- // final int numMessages = 100;
- //
- // ClientProducer producer = sessSend.createProducer(ADDRESS);
- //
- // sendMessages(sessSend, producer, numMessages, threadNum);
- //
- // ClientConsumer browser = sessConsume.createConsumer(new SimpleString(threadNum + "sub"),
- // null, false, true);
- //
- // Map<Integer, Integer> consumerCounts = new HashMap<Integer, Integer>();
- //
- // for (int i = 0; i < numMessages; i++)
- // {
- // ClientMessage msg = browser.receive(RECEIVE_TIMEOUT);
- //
- // assertNotNull(msg);
- //
- // int tn = (Integer)msg.getProperty(new SimpleString("threadnum"));
- // int cnt = (Integer)msg.getProperty(new SimpleString("count"));
- //
- // Integer c = consumerCounts.get(tn);
- // if (c == null)
- // {
- // c = new Integer(cnt);
- // }
- //
- // if (cnt != c.intValue())
- // {
- // throw new Exception("Invalid count, expected " + c + " got " + cnt);
- // }
- //
- // c++;
- //
- // //Wrap
- // if (c == numMessages)
- // {
- // c = 0;
- // }
- //
- // consumerCounts.put(tn, c);
- //
- // msg.acknowledge();
- // }
- //
- // sessConsume.close();
- //
- // sessConsume = sf.createSession(false, true, true, false);
- //
- // browser = sessConsume.createConsumer(new SimpleString(threadNum + "sub"),
- // null, false, true);
- //
- // //Messages should still be there
- //
- // consumerCounts.clear();
- //
- // for (int i = 0; i < numMessages; i++)
- // {
- // ClientMessage msg = browser.receive(RECEIVE_TIMEOUT);
- //
- // assertNotNull(msg);
- //
- // int tn = (Integer)msg.getProperty(new SimpleString("threadnum"));
- // int cnt = (Integer)msg.getProperty(new SimpleString("count"));
- //
- // Integer c = consumerCounts.get(tn);
- // if (c == null)
- // {
- // c = new Integer(cnt);
- // }
- //
- // if (cnt != c.intValue())
- // {
- // throw new Exception("Invalid count, expected " + c + " got " + cnt);
- // }
- //
- // c++;
- //
- // //Wrap
- // if (c == numMessages)
- // {
- // c = 0;
- // }
- //
- // consumerCounts.put(tn, c);
- //
- // msg.acknowledge();
- // }
- //
- // sessConsume.close();
- //
- // sessSend.deleteQueue(new SimpleString(threadNum + "sub"));
- //
- // sessSend.close();
- //
- // long end = System.currentTimeMillis();
- //
- // log.info("duration " + (end - start));
- // }
-
- protected void doTestN(final ClientSessionFactory sf, final int threadNum) throws Exception
- {
- ClientSession sessCreate = sf.createSession(false, true, true);
-
- sessCreate.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false);
-
- ClientSession sess = sf.createSession(false, true, true);
-
- sess.stop();
-
- sess.start();
-
- sess.stop();
-
- ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
-
- ClientProducer producer = sess.createProducer(ADDRESS);
-
- ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.getBody().flip();
-
- producer.send(message);
-
- sess.start();
-
- ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(message2);
-
- message2.acknowledge();
-
- sess.stop();
-
- sess.start();
-
- sess.close();
-
- sessCreate.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
-
- sessCreate.close();
- }
-
- protected int getNumIterations()
- {
- return 20;
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- log.info("************ Starting test " + this.getName());
-
- timer = new Timer();
- }
-
- protected void tearDown() throws Exception
- {
- log.info("************* Ending test " + this.getName());
-
- if (liveService != null && liveService.isStarted())
- {
- liveService.stop();
- }
- if (backupService != null && backupService.isStarted())
- {
- backupService.stop();
- }
- timer.cancel();
-
- super.tearDown();
- }
-
- // Private -------------------------------------------------------
-
- private void runTestMultipleThreads(final RunnableT runnable, final int numThreads) throws Exception
- {
- final int numIts = getNumIterations();
-
- for (int its = 0; its < numIts; its++)
- {
- log.info("************ ITERATION: " + its);
- start();
-
- final ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, false, false);
-
- Failer failer = startFailer(1000, session);
-
- class Runner extends Thread
- {
- private volatile Throwable throwable;
-
- private final RunnableT test;
-
- private final int threadNum;
-
- Runner(final RunnableT test, final int threadNum)
- {
- this.test = test;
-
- this.threadNum = threadNum;
- }
-
- public void run()
- {
- try
- {
- test.run(sf, threadNum);
- }
- catch (Throwable t)
- {
- throwable = t;
-
- log.error("Failed to run test", t);
- }
- }
- }
-
- do
- {
- List<Runner> threads = new ArrayList<Runner>();
-
- for (int i = 0; i < numThreads; i++)
- {
- Runner runner = new Runner(runnable, i);
-
- threads.add(runner);
-
- runner.start();
- }
-
- for (Runner thread : threads)
- {
- thread.join();
-
- assertNull(thread.throwable);
- }
-
- runnable.checkFail();
- }
- while (!failer.isExecuted());
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
-
- stop();
- }
- }
-
- private Failer startFailer(final long time, final ClientSession session)
- {
- Failer failer = new Failer(session);
-
- timer.schedule(failer, (long)(time * Math.random()), 100);
-
- return failer;
- }
-
- private void start() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- // We need to sleep > 16 ms otherwise the id generators on live and backup could be initialised
- // with the same time component
- Thread.sleep(17);
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- private void stop() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- private void sendMessages(final ClientSession sessSend,
- final ClientProducer producer,
- final int numMessages,
- final int threadNum) throws Exception
- {
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("threadnum"), threadNum);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
- }
-
- private void consumeMessages(final Set<ClientConsumer> consumers, final int numMessages, final int threadNum) throws Exception
- {
- // We make sure the messages arrive in the order they were sent from a particular producer
- Map<ClientConsumer, Map<Integer, Integer>> counts = new HashMap<ClientConsumer, Map<Integer, Integer>>();
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- Map<Integer, Integer> consumerCounts = counts.get(consumer);
-
- if (consumerCounts == null)
- {
- consumerCounts = new HashMap<Integer, Integer>();
- counts.put(consumer, consumerCounts);
- }
-
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(msg);
-
- int tn = (Integer)msg.getProperty(new SimpleString("threadnum"));
- int cnt = (Integer)msg.getProperty(new SimpleString("count"));
-
- // log.info("Got message " + tn + ":" + cnt);
-
- Integer c = consumerCounts.get(tn);
- if (c == null)
- {
- c = new Integer(cnt);
- }
-
- if (tn == threadNum && cnt != c.intValue())
- {
- throw new Exception("Invalid count, expected " + tn + ": " + c + " got " + cnt);
- }
-
- c++;
-
- // Wrap
- if (c == numMessages)
- {
- c = 0;
- }
-
- consumerCounts.put(tn, c);
-
- msg.acknowledge();
- }
- }
- }
-
- // Inner classes -------------------------------------------------
-
- private class Failer extends TimerTask
- {
- private final ClientSession session;
-
- private boolean executed;
-
- public Failer(final ClientSession session)
- {
- this.session = session;
- }
-
- public synchronized void run()
- {
- log.info("** Failing connection");
-
- RemotingConnectionImpl conn = (RemotingConnectionImpl)((ClientSessionImpl)session).getConnection();
-
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED, "blah"));
-
- log.info("** Fail complete");
-
- cancel();
-
- executed = true;
- }
-
- public synchronized boolean isExecuted()
- {
- return executed;
- }
- }
-
- private abstract class RunnableT extends Thread
- {
- private volatile String failReason;
-
- private volatile Throwable throwable;
-
- public void setFailed(final String reason, final Throwable throwable)
- {
- this.failReason = reason;
- this.throwable = throwable;
- }
-
- public void checkFail()
- {
- if (throwable != null)
- {
- log.error("Test failed: " + failReason, throwable);
- }
- if (failReason != null)
- {
- fail(failReason);
- }
- }
-
- public abstract void run(final ClientSessionFactory sf, final int threadNum) throws Exception;
- }
-
- private class MyHandler implements MessageHandler
- {
- final CountDownLatch latch = new CountDownLatch(1);
-
- private Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
-
- volatile String failure;
-
- final int tn;
-
- final int numMessages;
-
- volatile boolean done;
-
- MyHandler(final int threadNum, final int numMessages)
- {
- this.tn = threadNum;
-
- this.numMessages = numMessages;
- }
-
- public void onMessage(ClientMessage message)
- {
- try
- {
- message.acknowledge();
- }
- catch (MessagingException me)
- {
- log.error("Failed to process", me);
- }
-
- if (done)
- {
- return;
- }
-
- int threadNum = (Integer)message.getProperty(new SimpleString("threadnum"));
- int cnt = (Integer)message.getProperty(new SimpleString("count"));
-
- Integer c = counts.get(threadNum);
- if (c == null)
- {
- c = new Integer(cnt);
- }
-
- //log.info(System.identityHashCode(this) + " consumed message " + threadNum + ":" + cnt);
-
- if (tn == threadNum && cnt != c.intValue())
- {
- failure = "Invalid count, expected " + threadNum + ":" + c + " got " + cnt;
- log.error(failure);
-
- latch.countDown();
- }
-
- if (tn == threadNum && c == numMessages - 1)
- {
- done = true;
- latch.countDown();
- }
-
- c++;
- // Wrap around at numMessages
- if (c == numMessages)
- {
- c = 0;
- }
-
- counts.put(threadNum, c);
-
- }
- }
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/RandomFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/RandomFailoverTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/RandomFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,1544 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.MessageHandler;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionInternal;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- * A RandomFailoverSoakTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- */
-public class RandomFailoverTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(RandomFailoverTest.class);
-
- // Constants -----------------------------------------------------
-
- private static final int RECEIVE_TIMEOUT = 10000;
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- private Timer timer;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
-
- public void testA() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestA(sf);
- }
- });
- }
-
- public void testB() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestB(sf);
- }
- });
- }
-
- public void testC() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestC(sf);
- }
- });
- }
-
- public void testD() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestD(sf);
- }
- });
- }
-
- public void testE() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestE(sf);
- }
- });
- }
-
- public void testF() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestF(sf);
- }
- });
- }
-
- public void testG() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestG(sf);
- }
- });
- }
-
- public void testH() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestH(sf);
- }
- });
- }
-
- public void testI() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestI(sf);
- }
- });
- }
-
- public void testJ() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestJ(sf);
- }
- });
- }
-
- public void testK() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestK(sf);
- }
- });
- }
-
- public void testL() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestL(sf);
- }
- });
- }
-
- public void testN() throws Exception
- {
- runTest(new RunnableT()
- {
- public void run(final ClientSessionFactory sf) throws Exception
- {
- doTestN(sf);
- }
- });
- }
-
- public void runTest(final RunnableT runnable) throws Exception
- {
- final int numIts = getNumIterations();
-
- for (int its = 0; its < numIts; its++)
- {
- start();
-
- ClientSessionFactoryImpl sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, false, false);
-
- Failer failer = startFailer(1000, session);
-
- log.info("***************Iteration: " + its);
- do
- {
- runnable.run(sf);
- }
- while (!failer.isExecuted());
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
-
- stop();
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void doTestA(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- log.info("starting================");
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- class MyHandler implements MessageHandler
- {
- final CountDownLatch latch = new CountDownLatch(1);
-
- volatile int count;
-
- public void onMessage(ClientMessage message)
- {
- if (count == numMessages)
- {
- fail("Too many messages");
- }
-
- assertEquals(count, message.getProperty(new SimpleString("count")));
-
- count++;
-
- try
- {
- message.acknowledge();
- }
- catch (MessagingException me)
- {
- log.error("Failed to process", me);
- }
-
- if (count == numMessages)
- {
- latch.countDown();
- }
- }
- }
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler();
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(5000, TimeUnit.MILLISECONDS);
-
- assertTrue("Didn't receive all messages", ok);
- }
-
- log.info("*** closing sessions");
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
- log.info("*** closed sessions");
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestB(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 50;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- class MyHandler implements MessageHandler
- {
- final CountDownLatch latch = new CountDownLatch(1);
-
- volatile int count;
-
- public void onMessage(ClientMessage message)
- {
- if (count == numMessages)
- {
- fail("Too many messages");
- }
-
- assertEquals(count, message.getProperty(new SimpleString("count")));
-
- count++;
-
- if (count == numMessages)
- {
- latch.countDown();
- }
- }
- }
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler();
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
- }
-
- sessSend.close();
-
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
-
- }
-
- protected void doTestC(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.rollback();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.commit();
-
- class MyHandler implements MessageHandler
- {
- final CountDownLatch latch = new CountDownLatch(1);
-
- volatile int count;
-
- public void onMessage(ClientMessage message)
- {
- if (count == numMessages)
- {
- fail("Too many messages");
- }
-
- assertEquals(count, message.getProperty(new SimpleString("count")));
-
- count++;
-
- if (count == numMessages)
- {
- latch.countDown();
- }
- }
- }
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler();
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
- }
-
- handlers.clear();
-
- // New handlers
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler();
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
- }
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestD(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.rollback();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.commit();
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- class MyHandler implements MessageHandler
- {
- final CountDownLatch latch = new CountDownLatch(1);
-
- volatile int count;
-
- public void onMessage(ClientMessage message)
- {
- if (count == numMessages)
- {
- fail("Too many messages");
- }
-
- assertEquals(count, message.getProperty(new SimpleString("count")));
-
- count++;
-
- if (count == numMessages)
- {
- latch.countDown();
- }
- }
- }
-
- Set<MyHandler> handlers = new HashSet<MyHandler>();
-
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler();
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
- }
-
- handlers.clear();
-
- // New handlers
- for (ClientConsumer consumer : consumers)
- {
- MyHandler handler = new MyHandler();
-
- consumer.setMessageHandler(handler);
-
- handlers.add(handler);
- }
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- for (MyHandler handler : handlers)
- {
- boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
- }
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- // Now with synchronous receive()
-
- protected void doTestE(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(msg);
-
- assertEquals(i, msg.getProperty(new SimpleString("count")));
-
- msg.acknowledge();
- }
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receiveImmediate();
-
- assertNull(msg);
- }
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestF(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, true, true);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, true, true);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- if (msg == null)
- {
- throw new IllegalStateException("Failed to receive message " + i);
- }
-
- assertNotNull(msg);
-
- assertEquals(i, msg.getProperty(new SimpleString("count")));
-
- msg.acknowledge();
- }
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receiveImmediate();
-
- assertNull(msg);
- }
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- assertEquals(1, ((ClientSessionFactoryImpl)sf).numSessions());
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestG(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.start();
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, false, false);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.rollback();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.commit();
-
- log.info("sent and committed");
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(msg);
-
- assertEquals(i, msg.getProperty(new SimpleString("count")));
-
- msg.acknowledge();
- }
- }
-
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receiveImmediate();
-
- assertNull(msg);
- }
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(msg);
-
- assertEquals(i, msg.getProperty(new SimpleString("count")));
-
- msg.acknowledge();
- }
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receiveImmediate();
-
- assertNull(msg);
- }
- }
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestH(final ClientSessionFactory sf) throws Exception
- {
- long start = System.currentTimeMillis();
-
- ClientSession s = sf.createSession(false, false, false);
-
- final int numMessages = 100;
-
- final int numSessions = 10;
-
- Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
- Set<ClientSession> sessions = new HashSet<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- ClientSession sessConsume = sf.createSession(false, false, false);
-
- sessConsume.createQueue(ADDRESS, subName, null, false, false);
-
- ClientConsumer consumer = sessConsume.createConsumer(subName);
-
- consumers.add(consumer);
-
- sessions.add(sessConsume);
- }
-
- ClientSession sessSend = sf.createSession(false, false, false);
-
- ClientProducer producer = sessSend.createProducer(ADDRESS);
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.rollback();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().flip();
- producer.send(message);
- }
-
- sessSend.commit();
-
- for (ClientSession session : sessions)
- {
- session.start();
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(msg);
-
- assertEquals(i, msg.getProperty(new SimpleString("count")));
-
- msg.acknowledge();
- }
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receiveImmediate();
-
- assertNull(msg);
- }
- }
-
- for (ClientSession session : sessions)
- {
- session.rollback();
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(msg);
-
- assertEquals(i, msg.getProperty(new SimpleString("count")));
-
- msg.acknowledge();
- }
- }
-
- for (int i = 0; i < numMessages; i++)
- {
- for (ClientConsumer consumer : consumers)
- {
- ClientMessage msg = consumer.receiveImmediate();
-
- assertNull(msg);
- }
- }
-
- for (ClientSession session : sessions)
- {
- session.commit();
- }
-
- sessSend.close();
- for (ClientSession session : sessions)
- {
- session.close();
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- SimpleString subName = new SimpleString("sub" + i);
-
- s.deleteQueue(subName);
- }
-
- s.close();
-
- long end = System.currentTimeMillis();
-
- log.info("duration " + (end - start));
- }
-
- protected void doTestI(final ClientSessionFactory sf) throws Exception
- {
- ClientSession sessCreate = sf.createSession(false, true, true);
-
- sessCreate.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientSession sess = sf.createSession(false, true, true);
-
- sess.start();
-
- ClientConsumer consumer = sess.createConsumer(ADDRESS);
-
- ClientProducer producer = sess.createProducer(ADDRESS);
-
- ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.getBody().flip();
-
- producer.send(message);
-
- ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(message2);
-
- message2.acknowledge();
-
- sess.close();
-
- sessCreate.deleteQueue(ADDRESS);
-
- sessCreate.close();
- }
-
- protected void doTestJ(final ClientSessionFactory sf) throws Exception
- {
- ClientSession sessCreate = sf.createSession(false, true, true);
-
- sessCreate.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientSession sess = sf.createSession(false, true, true);
-
- sess.start();
-
- ClientConsumer consumer = sess.createConsumer(ADDRESS);
-
- ClientProducer producer = sess.createProducer(ADDRESS);
-
- ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.getBody().flip();
-
- producer.send(message);
-
- ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(message2);
-
- message2.acknowledge();
-
- sess.close();
-
- sessCreate.deleteQueue(ADDRESS);
-
- sessCreate.close();
- }
-
- protected void doTestK(final ClientSessionFactory sf) throws Exception
- {
- ClientSession s = sf.createSession(false, false, false);
-
- s.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- final int numConsumers = 100;
-
- for (int i = 0; i < numConsumers; i++)
- {
- ClientConsumer consumer = s.createConsumer(ADDRESS);
-
- consumer.close();
- }
-
- s.deleteQueue(ADDRESS);
-
- s.close();
- }
-
- protected void doTestL(final ClientSessionFactory sf) throws Exception
- {
- ClientSession s = sf.createSession(false, false, false);
-
- final int numSessions = 100;
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession session = sf.createSession(false, false, false);
-
- session.close();
- }
-
- s.close();
- }
-
-
- protected void doTestN(final ClientSessionFactory sf) throws Exception
- {
- ClientSession sessCreate = sf.createSession(false, true, true);
-
- sessCreate.createQueue(ADDRESS, new SimpleString(ADDRESS.toString()), null, false, false);
-
- ClientSession sess = sf.createSession(false, true, true);
-
- sess.stop();
-
- sess.start();
-
- sess.stop();
-
- ClientConsumer consumer = sess.createConsumer(new SimpleString(ADDRESS.toString()));
-
- ClientProducer producer = sess.createProducer(ADDRESS);
-
- ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.getBody().flip();
-
- producer.send(message);
-
- sess.start();
-
- ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
-
- assertNotNull(message2);
-
- message2.acknowledge();
-
- sess.stop();
-
- sess.start();
-
- sess.close();
-
- sessCreate.deleteQueue(new SimpleString(ADDRESS.toString()));
-
- sessCreate.close();
- }
-
- protected int getNumIterations()
- {
- return 20;
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- log.info("*********** created timer");
- timer = new Timer(true);
-
- log.info("************ Starting test " + this.getName());
- }
-
- protected void tearDown() throws Exception
- {
- timer.cancel();
-
- log.info("************ Ended test " + this.getName());
-
- super.tearDown();
- }
-
- // Private -------------------------------------------------------
-
- private Failer startFailer(final long time, final ClientSession session)
- {
- Failer failer = new Failer((ClientSessionInternal)session);
-
- timer.schedule(failer, (long)(time * Math.random()), 100);
-
- return failer;
- }
-
- private void start() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- // We need to sleep > 16 ms otherwise the id generators on live and backup could be initialised
- // with the same time component
- Thread.sleep(17);
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- private void stop() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Inner classes -------------------------------------------------
-
- class Failer extends TimerTask
- {
- private final ClientSessionInternal session;
-
- private boolean executed;
-
- public Failer(final ClientSessionInternal session)
- {
- this.session = session;
- }
-
- public synchronized void run()
- {
- log.info("** Failing connection");
-
- session.getConnection().fail(new MessagingException(MessagingException.NOT_CONNECTED, "oops"));
-
- log.info("** Fail complete");
-
- cancel();
-
- executed = true;
- }
-
- public synchronized boolean isExecuted()
- {
- return executed;
- }
- }
-
- public abstract class RunnableT
- {
- abstract void run(final ClientSessionFactory sf) throws Exception;
- }
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ReplicateConnectionFailureTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ReplicateConnectionFailureTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ReplicateConnectionFailureTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,190 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-
-/**
- *
- * A ReplicateConnectionFailureTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 6 Nov 2008 08:42:36
- *
- * Test whether when a connection is failed on the server since server receives no ping, that close
- * is replicated to backup.
- *
- */
-public class ReplicateConnectionFailureTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(ReplicateConnectionFailureTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testFailConnection() throws Exception
- {
- final long pingPeriod = 500;
-
- // TODO - use the defaults!!
- ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams),
- pingPeriod,
- ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
- ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
- ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
- ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
- ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
- ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
- ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
- ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_PERSISTENT_SEND,
- ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
- ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS,
- ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE);
-
- sf1.setSendWindowSize(32 * 1024);
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- ClientSession session1 = sf1.createSession(false, true, true);
-
- // One connection
- assertEquals(1, liveService.getServer().getRemotingService().getConnections().size());
-
- // One replicating connection per session + one backup connection per session
- assertEquals(2, backupService.getServer().getRemotingService().getConnections().size());
-
- session1.close();
-
- log.info("recreating");
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- session1 = sf1.createSession(false, true, true);
-
- assertEquals(1, liveService.getServer().getRemotingService().getConnections().size());
-
- assertEquals(2, backupService.getServer().getRemotingService().getConnections().size());
-
- final RemotingConnectionImpl conn1 = (RemotingConnectionImpl)((ClientSessionImpl)session1).getConnection();
-
- conn1.stopPingingAfterOne();
-
- Thread.sleep(3 * pingPeriod);
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- // Should be one connection left to the backup - the other one (replicating connection) should be automatically
- // closed
- assertEquals(1, backupService.getServer().getRemotingService().getConnections().size());
-
- session1.close();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setConnectionScanPeriod(100);
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setConnectionScanPeriod(100);
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleAutomaticFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleAutomaticFailoverTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleAutomaticFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,834 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.FailureListener;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A SimpleAutomaticFailoverTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class SimpleAutomaticFailoverTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(SimpleAutomaticFailoverTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService liveService;
-
- private MessagingService backupService;
-
- private final Map<String, Object> backupParams = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testReplication() throws Exception
- {
- ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 100;
-
- log.info("Sending messages");
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- log.info("sent messages");
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- // log.info("Got message " + message2);
-
- assertEquals("aardvarks", message2.getBody().getString());
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- // ClientMessage message3 = consumer.receive(250);
-
- // assertNull(message3);
-
- session.close();
- }
-
- public void testFailoverSameConnectionFactory() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn1 = ((ClientSessionImpl)session).getConnection();
-
- // Simulate failure on connection
- conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages / 2; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- session.close();
-
- session = sf.createSession(false, true, true);
-
- consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = numMessages / 2; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- ClientMessage message3 = consumer.receive(250);
-
- session.close();
-
- assertNull(message3);
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testFailoverChangeConnectionFactory() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages / 2; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- session.close();
-
- sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- session = sf.createSession(false, true, true);
-
- consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = numMessages / 2; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- ClientMessage message3 = consumer.receive(250);
-
- assertNull(message3);
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testNoMessagesLeftAfterFailoverNewSession() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- session.close();
-
- sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- session = sf.createSession(false, true, true);
-
- consumer = session.createConsumer(ADDRESS);
-
- ClientMessage message3 = consumer.receive(250);
-
- assertNull(message3);
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testCreateMoreSessionsAfterFailover() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- ClientSession session1 = sf.createSession(false, true, true);
-
- ClientSession session2 = sf.createSession(false, true, true);
-
- ClientSession session3 = sf.createSession(false, true, true);
-
- session.close();
-
- session1.close();
-
- session2.close();
-
- session3.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testFailureListenerCalledOnFailure() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- final CountDownLatch latch = new CountDownLatch(1);
-
- class MyListener implements FailureListener
- {
- public void connectionFailed(final MessagingException me)
- {
- latch.countDown();
- }
- }
-
- conn.addFailureListener(new MyListener());
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- session.close();
-
- sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- session = sf.createSession(false, true, true);
-
- consumer = session.createConsumer(ADDRESS);
-
- ClientMessage message3 = consumer.receive(250);
-
- assertNull(message3);
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testFailoverMultipleSessions() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- final int numSessions = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS * 2;
-
- List<ClientSession> sessions = new ArrayList<ClientSession>();
-
- List<ClientConsumer> consumers = new ArrayList<ClientConsumer>();
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession sess = sf.createSession(false, true, true);
-
- SimpleString queueName = new SimpleString("subscription" + i);
-
- sess.createQueue(ADDRESS, queueName, null, false, false);
-
- ClientConsumer consumer = sess.createConsumer(queueName);
-
- sess.start();
-
- sessions.add(sess);
-
- consumers.add(consumer);
- }
-
- ClientSession session = sf.createSession(false, true, true);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 100;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientConsumer cons = consumers.get(i);
-
- for (int j = 0; j < numMessages; j++)
- {
- ClientMessage message2 = cons.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(j, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- ClientMessage message3 = cons.receive(250);
-
- assertNull(message3);
- }
-
- session.close();
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession sess = sessions.get(i);
-
- sess.close();
- }
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testAllConnectionsReturned() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- final int numSessions = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS * 2;
-
- List<ClientSession> sessions = new ArrayList<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession sess = sf.createSession(false, true, true);
-
- sessions.add(sess);
- }
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession sess = sessions.get(i);
-
- sess.close();
- }
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testAllConnectionsReturnedAfterFailover() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- final int numSessions = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS * 2;
-
- List<ClientSession> sessions = new ArrayList<ClientSession>();
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession sess = sf.createSession(false, true, true);
-
- sessions.add(sess);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)sessions.get(0)).getConnection();
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- for (int i = 0; i < numSessions; i++)
- {
- ClientSession sess = sessions.get(i);
-
- sess.close();
- }
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- public void testFailureAfterFailover() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
- new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
-
- sf.setSendWindowSize(32 * 1024);
-
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- // Consume half of them
-
- for (int i = 0; i < numMessages / 2; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- RemotingConnection conn2 = ((ClientSessionImpl)session).getConnection();
-
- final CountDownLatch latch = new CountDownLatch(1);
-
- class MyListener implements FailureListener
- {
- public void connectionFailed(final MessagingException me)
- {
- latch.countDown();
- }
- }
-
- conn2.addFailureListener(new MyListener());
-
- assertFalse(conn == conn2);
-
- conn2.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
-
- try
- {
- session.createQueue(new SimpleString("blah"), new SimpleString("blah"), null, false, false);
-
- fail("Should throw exception");
- }
- catch (MessagingException me)
- {
- assertEquals(MessagingException.OBJECT_CLOSED, me.getCode());
- }
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- Configuration backupConf = new ConfigurationImpl();
- backupConf.setSecurityEnabled(false);
- backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- backupConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- backupParams));
- backupConf.setBackup(true);
- backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
- backupService.start();
-
- Configuration liveConf = new ConfigurationImpl();
- liveConf.setSecurityEnabled(false);
- liveConf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- backupParams));
- liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
- liveService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
- backupService.stop();
-
- assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
- liveService.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleManualFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleManualFailoverTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleManualFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -1,215 +0,0 @@
-/*
- * 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.cluster;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
-import org.jboss.messaging.core.client.impl.ClientSessionImpl;
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.FailureListener;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
-import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A SimpleAutomaticFailoverTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class SimpleManualFailoverTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(SimpleManualFailoverTest.class);
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
-
- private MessagingService server0Service;
-
- private MessagingService server1Service;
-
- private Map<String, Object> server1Params = new HashMap<String, Object>();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private ClientSession sendAndConsume(final ClientSessionFactory sf) throws Exception
- {
- ClientSession session = sf.createSession(false, true, true);
-
- session.createQueue(ADDRESS, ADDRESS, null, false, false);
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- final int numMessages = 1000;
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
- false,
- 0,
- System.currentTimeMillis(),
- (byte)1);
- message.putIntProperty(new SimpleString("count"), i);
- message.getBody().putString("aardvarks");
- message.getBody().flip();
- producer.send(message);
- }
-
- ClientConsumer consumer = session.createConsumer(ADDRESS);
-
- session.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- ClientMessage message2 = consumer.receive();
-
- assertEquals("aardvarks", message2.getBody().getString());
-
- assertEquals(i, message2.getProperty(new SimpleString("count")));
-
- message2.acknowledge();
- }
-
- ClientMessage message3 = consumer.receive(250);
-
- assertNull(message3);
-
- return session;
- }
-
- public void testFailover() throws Exception
- {
- ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"));
-
- ClientSession session = sendAndConsume(sf);
-
- final CountDownLatch latch = new CountDownLatch(1);
-
- class MyListener implements FailureListener
- {
- public void connectionFailed(MessagingException me)
- {
- log.info("*** connection failed");
- latch.countDown();
- }
- }
-
- RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
-
- conn.addFailureListener(new MyListener());
-
- // Simulate failure on connection
- conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
-
- // Wait to be informed of failure
-
- boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
-
- assertTrue(ok);
-
- log.info("closing session");
- session.close();
- log.info("closed session");
-
- sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
- server1Params));
-
- session = sendAndConsume(sf);
-
- session.close();
-
- assertEquals(0, sf.numSessions());
-
- assertEquals(0, sf.numConnections());
-
- assertEquals(0, sf.numBackupConnections());
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void setUp() throws Exception
- {
- Configuration server1Conf = new ConfigurationImpl();
- server1Conf.setSecurityEnabled(false);
- server1Params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
- server1Conf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
- server1Params));
- server1Service = MessagingServiceImpl.newNullStorageMessagingServer(server1Conf);
- server1Service.start();
-
- Configuration server0Conf = new ConfigurationImpl();
- server0Conf.setSecurityEnabled(false);
- server0Conf.getAcceptorConfigurations()
- .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
- server0Service = MessagingServiceImpl.newNullStorageMessagingServer(server0Conf);
- server0Service.start();
- }
-
- protected void tearDown() throws Exception
- {
- assertEquals(0, server1Service.getServer().getRemotingService().getConnections().size());
-
- server1Service.stop();
-
- assertEquals(0, server0Service.getServer().getRemotingService().getConnections().size());
-
- server0Service.stop();
-
- assertEquals(0, InVMRegistry.instance.size());
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Added: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleOutflowTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleOutflowTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleOutflowTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,188 @@
+/*
+ * 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.cluster.distribution;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.OutflowConfiguration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A ActivationTimeoutTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 4 Nov 2008 16:54:50
+ *
+ *
+ */
+public class SimpleOutflowTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(SimpleOutflowTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private MessagingService service0;
+
+ private MessagingService service1;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testSimpleOutflow() throws Exception
+ {
+ Configuration service0Conf = new ConfigurationImpl();
+ service0Conf.setSecurityEnabled(false);
+ Map<String, Object> service0Params = new HashMap<String, Object>();
+ service0Params.put(TransportConstants.SERVER_ID_PROP_NAME, 0);
+ service0Conf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ service0Params));
+
+ Configuration service1Conf = new ConfigurationImpl();
+ service1Conf.setSecurityEnabled(false);
+ Map<String, Object> service1Params = new HashMap<String, Object>();
+ service1Params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+
+ service1Conf.getAcceptorConfigurations().add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ service1Params));
+ service1 = MessagingServiceImpl.newNullStorageMessagingServer(service1Conf);
+ service1.start();
+
+ List<TransportConfiguration> connectors = new ArrayList<TransportConfiguration>();
+ TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ service1Params);
+ connectors.add(server1tc);
+
+ final SimpleString testAddress = new SimpleString("testaddress");
+
+ OutflowConfiguration ofconfig = new OutflowConfiguration("outflow1", testAddress.toString(), null, true, 1, 0, connectors);
+ Set<OutflowConfiguration> ofconfigs = new HashSet<OutflowConfiguration>();
+ ofconfigs.add(ofconfig);
+ service0Conf.setOutFlowConfigurations(ofconfigs);
+
+ service0 = MessagingServiceImpl.newNullStorageMessagingServer(service0Conf);
+ service0.start();
+
+ TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ service0Params);
+
+ ClientSessionFactory csf0 = new ClientSessionFactoryImpl(server0tc);
+
+ ClientSession session0 = csf0.createSession(false, true, true);
+
+ ClientSessionFactory csf1 = new ClientSessionFactoryImpl(server1tc);
+
+ ClientSession session1 = csf1.createSession(false, true, true);
+
+ session0.createQueue(testAddress, testAddress, null, false, false, true);
+
+ session1.createQueue(testAddress, testAddress, null, false, false, true);
+
+ ClientProducer prod0 = session0.createProducer(testAddress);
+
+ ClientConsumer cons0 = session0.createConsumer(testAddress);
+
+ ClientConsumer cons1 = session1.createConsumer(testAddress);
+
+ session0.start();
+
+ session1.start();
+
+ SimpleString propKey = new SimpleString("hello");
+ SimpleString propVal = new SimpleString("world");
+
+ ClientMessage message = session0.createClientMessage(false);
+ message.putStringProperty(propKey, propVal);
+ message.getBody().flip();
+
+ prod0.send(message);
+
+ ClientMessage rmessage0 = cons0.receive(1000);
+
+ assertNotNull(rmessage0);
+
+ assertEquals(propVal, rmessage0.getProperty(propKey));
+
+ ClientMessage rmessage1 = cons1.receive(1000);
+
+ assertNotNull(rmessage1);
+
+ assertEquals(propVal, rmessage1.getProperty(propKey));
+
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ service0.stop();
+
+ assertEquals(0, service0.getServer().getRemotingService().getConnections().size());
+
+ service1.stop();
+
+ assertEquals(0, service1.getServer().getRemotingService().getConnections().size());
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ActivationTimeoutTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,307 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A ActivationTimeoutTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 4 Nov 2008 16:54:50
+ *
+ *
+ */
+public class ActivationTimeoutTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(SimpleAutomaticFailoverTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final long ACTIVATION_TIMEOUT = 5000;
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testTimeoutAfterConsumerFailsToReattach() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ ClientSessionFactoryInternal sf2 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+ sf2.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+ log.info("Sent messages");
+
+ ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
+
+ ClientSession session2 = sf2.createSession(false, true, true);
+
+ //Create another consumer so we have two consumers on the queue
+ ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
+
+ long start = System.currentTimeMillis();
+
+ RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
+
+ // Now we fail ONLY the connections on sf1, not on sf2
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ session1.start();
+
+ //The messages should not be delivered until after activationTimeout ms, since
+ //session 2 didn't reattach
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer1.receive(2 * ACTIVATION_TIMEOUT);
+
+ assertNotNull(message);
+
+ if (i == 0)
+ {
+ long now = System.currentTimeMillis();
+
+ assertTrue(now - start >= ACTIVATION_TIMEOUT);
+ }
+
+ assertEquals("aardvarks", message.getBody().getString());
+
+ assertEquals(i, message.getProperty(new SimpleString("count")));
+
+ message.acknowledge();
+ }
+
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNull(message);
+
+ session1.close();
+
+ RemotingConnection conn2 = ((ClientSessionImpl)session2).getConnection();
+
+ conn2.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ session2.close();
+ }
+
+ public void testTimeoutAfterAllConsumerFailsToReattach() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ ClientSessionFactoryInternal sf2 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+ sf2.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+ log.info("Sent messages");
+
+
+ ClientSession session2 = sf2.createSession(false, true, true);
+
+ ClientConsumer consumer1 = session2.createConsumer(ADDRESS);
+
+ ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
+
+ long start = System.currentTimeMillis();
+
+ RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
+
+ // Now we fail ONLY the connections on sf1, not on sf2
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ session1.start();
+
+ //The messages should not be delivered until after activationTimeout ms, since
+ //session 2 didn't reattach
+
+ //We now create a new consumer but it shouldn't receive the messages until after the timeout
+
+ ClientConsumer consumer3 = session1.createConsumer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer3.receive(2 * ACTIVATION_TIMEOUT);
+
+ assertNotNull(message);
+
+ if (i == 0)
+ {
+ long now = System.currentTimeMillis();
+
+ assertTrue(now - start >= ACTIVATION_TIMEOUT);
+ }
+
+ assertEquals("aardvarks", message.getBody().getString());
+
+ assertEquals(i, message.getProperty(new SimpleString("count")));
+
+ message.acknowledge();
+ }
+
+ ClientMessage message = consumer3.receive(1000);
+
+ assertNull(message);
+
+ session1.close();
+
+ RemotingConnection conn2 = ((ClientSessionImpl)session2).getConnection();
+
+ conn2.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ session2.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupConf.setQueueActivationTimeout(ACTIVATION_TIMEOUT);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailBackupServerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,222 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A FailBackupServerTest
+ *
+ * Make sure live sever continues ok if backup server fails
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 6 Nov 2008 11:27:17
+ *
+ *
+ */
+public class FailBackupServerTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(FailBackupServerTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testFailBackup() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
+
+ session1.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNotNull(message);
+
+ assertEquals("aardvarks", message.getBody().getString());
+
+ assertEquals(i, message.getProperty(new SimpleString("count")));
+
+ if (i == 0)
+ {
+ // Fail all the replicating connections - this simulates the backup server crashing
+
+ Set<RemotingConnection> conns = liveService.getServer().getRemotingService().getConnections();
+
+ for (RemotingConnection conn : conns)
+ {
+ log.info("Failing replicating connection");
+ conn.getReplicatingConnection().fail(new MessagingException(MessagingException.NOT_CONNECTED, "blah"));
+ }
+ }
+
+ message.acknowledge();
+ }
+
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNull(message);
+
+ // Send some more
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ message = session1.createClientMessage(JBossTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ message = consumer1.receive(1000);
+
+ assertNotNull(message);
+
+ assertEquals("aardvarks", message.getBody().getString());
+
+ assertEquals(i, message.getProperty(new SimpleString("count")));
+
+ message.acknowledge();
+ }
+
+ message = consumer1.receive(1000);
+
+ assertNull(message);
+
+ session1.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverExpiredMessageTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,233 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A FailoverExpiredMessageTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 5 Nov 2008 09:33:32
+ *
+ *
+ */
+public class FailoverExpiredMessageTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(FailoverExpiredMessageTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ /*
+ * Set messages to expire very soon, send a load of them, so at some of them get expired when they reach the client
+ * After failover make sure all are received ok
+ */
+ public void testExpiredBeforeConsumption() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ session1.start();
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 10000;
+
+ //Set time to live so at least some of them will more than likely expire before they are consumed by the client
+
+ long now = System.currentTimeMillis();
+
+ long expire = now + 5000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ expire,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+ ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
+
+ final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
+
+ Thread t = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ //Sleep a little while to ensure that some messages are consumed before failover
+ Thread.sleep(5000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+ }
+ };
+
+ t.start();
+
+ int count = 0;
+
+ while (true)
+ {
+ ClientMessage message = consumer1.receive(1000);
+
+ if (message != null)
+ {
+ message.acknowledge();
+
+ //We sleep a little to make sure messages aren't consumed too quickly and some
+ //will expire before reaching consumer
+ Thread.sleep(1);
+
+ count++;
+ }
+ else
+ {
+ log.info("message was null");
+ break;
+ }
+ }
+
+ log.info("Got " + count + " messages");
+
+ t.join();
+
+ session1.close();
+
+ //Make sure no more messages
+ ClientSession session2 = sf1.createSession(false, true, true);
+
+ session2.start();
+
+ ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
+
+ ClientMessage message = consumer2.receive(1000);
+
+ assertNull(message);
+
+ session2.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
+
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverManagementTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,313 @@
+/*
+ * 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.cluster.failover;
+
+import static org.jboss.messaging.core.config.impl.ConfigurationImpl.DEFAULT_MANAGEMENT_ADDRESS;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.Notification;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.client.management.impl.ManagementHelper;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A FailoverManagementTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 5 Nov 2008 15:05:14
+ *
+ *
+ */
+public class FailoverManagementTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(FailoverManagementTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testManagementMessages() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ SimpleString replyTo = new SimpleString("replyto");
+
+ session1.createQueue(replyTo, new SimpleString("replyto"), null, false, false, true);
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 10;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage msg = session1.createClientMessage(false);
+
+ msg.getBody().flip();
+
+ producer.send(msg);
+ }
+
+ for (int i = 0; i < numMessages / 2; i++)
+ {
+ ClientMessage managementMessage = session1.createClientMessage(false);
+
+ ManagementHelper.putAttributes(managementMessage,
+ replyTo,
+ ManagementServiceImpl.getQueueObjectName(ADDRESS, ADDRESS),
+ "MessageCount");
+
+ managementMessage.getBody().flip();
+
+ producer.send(DEFAULT_MANAGEMENT_ADDRESS, managementMessage);
+ }
+
+ ClientConsumer consumer1 = session1.createConsumer(replyTo);
+
+ final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
+
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ //Send the other half
+ for (int i = 0; i < numMessages / 2; i++)
+ {
+ ClientMessage managementMessage = session1.createClientMessage(false);
+
+ ManagementHelper.putAttributes(managementMessage,
+ replyTo,
+ ManagementServiceImpl.getQueueObjectName(ADDRESS, ADDRESS),
+ "MessageCount");
+
+ managementMessage.getBody().flip();
+
+ producer.send(DEFAULT_MANAGEMENT_ADDRESS, managementMessage);
+ }
+
+ session1.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNotNull(message);
+
+ message.acknowledge();
+
+ assertTrue(ManagementHelper.isAttributesResult(message));
+
+ assertEquals(numMessages, message.getProperty(new SimpleString("MessageCount")));
+ }
+
+ session1.close();
+
+ //Make sure no more messages
+ ClientSession session2 = sf1.createSession(false, true, true);
+
+ session2.start();
+
+ ClientConsumer consumer2 = session2.createConsumer(replyTo);
+
+ ClientMessage message = consumer2.receive(1000);
+
+ assertNull(message);
+
+ session2.close();
+ }
+
+ public void testManagementMessages2() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ SimpleString replyTo = new SimpleString("replyto");
+
+ session1.createQueue(replyTo, new SimpleString("replyto"), null, false, false, true);
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 10;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage msg = session1.createClientMessage(false);
+
+ msg.getBody().flip();
+
+ producer.send(msg);
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage managementMessage = session1.createClientMessage(false);
+
+ ManagementHelper.putAttributes(managementMessage,
+ replyTo,
+ ManagementServiceImpl.getQueueObjectName(ADDRESS, ADDRESS),
+ "MessageCount");
+
+ managementMessage.getBody().flip();
+
+ producer.send(DEFAULT_MANAGEMENT_ADDRESS, managementMessage);
+ }
+
+ ClientConsumer consumer1 = session1.createConsumer(replyTo);
+
+
+ session1.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNotNull(message);
+
+ if (i == 0)
+ {
+ //Fail after receipt but before ack
+ final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
+
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+ }
+
+ message.acknowledge();
+
+ assertTrue(ManagementHelper.isAttributesResult(message));
+
+ assertEquals(numMessages, message.getProperty(new SimpleString("MessageCount")));
+ }
+
+ session1.close();
+
+ //Make sure no more messages
+ ClientSession session2 = sf1.createSession(false, true, true);
+
+ session2.start();
+
+ ClientConsumer consumer2 = session2.createConsumer(replyTo);
+
+ ClientMessage message = consumer2.receive(1000);
+
+ assertNull(message);
+
+ session2.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
+
+
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverNoSessionsFailoverTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,225 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * Test situation where none of the sessions failover, but a new session is created
+ *
+ * A FailoverNoSessionsFailoverTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 6 Nov 2008 17:39:23
+ *
+ *
+ */
+public class FailoverNoSessionsFailoverTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(FailoverNoSessionsFailoverTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testNoFailoverAndCreateNewSession() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
+
+ session1.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNotNull(message);
+
+ assertEquals("aardvarks", message.getBody().getString());
+
+ assertEquals(i, message.getProperty(new SimpleString("count")));
+
+ message.acknowledge();
+ }
+
+ ClientMessage message = consumer1.receive(1000);
+
+ assertNull(message);
+
+ session1.close();
+
+ //Now create another sesion direct on the backup
+
+ ClientSessionFactoryInternal sf2 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf2.setSendWindowSize(32 * 1024);
+
+ ClientSession session2 = sf2.createSession(false, true, true);
+
+ ClientProducer producer2 = session2.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = session2.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message2.putIntProperty(new SimpleString("count"), i);
+ message2.getBody().putString("aardvarks");
+ message2.getBody().flip();
+ producer2.send(message2);
+ }
+
+ ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
+
+ session2.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer2.receive(1000);
+
+ assertNotNull(message2);
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ ClientMessage message2 = consumer2.receive(1000);
+
+ assertNull(message2);
+
+ session2.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
+
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/FailoverScheduledMessageTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,228 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A FailoverScheduledMessageTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 5 Nov 2008 11:18:51
+ *
+ */
+public class FailoverScheduledMessageTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(FailoverScheduledMessageTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ /*
+ * Send some scheduled messsages on live
+ * Let some fire on live
+ * Failover
+ * Let rest fire on backup
+ * Assert no duplicates and all are received ok
+ */
+ public void testScheduled() throws Exception
+ {
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ session1.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ session1.start();
+
+ ClientProducer producer = session1.createProducer(ADDRESS);
+
+ final int numMessages = 10;
+
+ long now = System.currentTimeMillis();
+
+ final long delay = 200;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session1.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ long deliveryTime = now + delay * i;
+ message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, deliveryTime);
+ producer.send(message);
+ }
+
+ ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
+
+ final RemotingConnection conn1 = ((ClientSessionImpl)session1).getConnection();
+
+ Thread t = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ //Sleep a little while to ensure that some messages are consumed before failover
+ Thread.sleep(delay * numMessages / 2);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+ }
+ };
+
+ t.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer1.receive(delay * 2);
+
+ assertNotNull(message);
+
+ log.info("got message " + i);
+
+ message.acknowledge();
+ }
+
+ ClientMessage message = consumer1.receive(delay * 2);
+
+ assertNull(message);
+
+ t.join();
+
+ session1.close();
+
+ //Make sure no more messages
+ ClientSession session2 = sf1.createSession(false, true, true);
+
+ session2.start();
+
+ ClientConsumer consumer2 = session2.createConsumer(ADDRESS);
+
+ message = consumer2.receive(1000);
+
+ assertNull(message);
+
+ session2.close();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
+
+
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/MultiThreadRandomFailoverTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,1566 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.MessageHandler;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * A MultiThreadRandomFailoverTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ */
+public class MultiThreadRandomFailoverTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(MultiThreadRandomFailoverTest.class);
+
+ // Constants -----------------------------------------------------
+
+ private static final int RECEIVE_TIMEOUT = 30000;
+
+ private static final int NUM_THREADS = 10;
+
+ // Attributes ----------------------------------------------------
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ private Timer timer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testA() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestA(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testB() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestB(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testC() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestC(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testD() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestD(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testE() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestE(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testF() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestF(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testG() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestG(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testH() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestH(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testI() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestI(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testJ() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestJ(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testK() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestK(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ public void testL() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestL(sf);
+ }
+ }, NUM_THREADS);
+ }
+
+ // public void testM() throws Exception
+ // {
+ // runTestMultipleThreads(new RunnableT()
+ // {
+ // public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ // {
+ // doTestM(sf, threadNum);
+ // }
+ // }, NUM_THREADS);
+ // }
+
+ public void testN() throws Exception
+ {
+ runTestMultipleThreads(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ doTestN(sf, threadNum);
+ }
+ }, NUM_THREADS);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void doTestA(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler(threadNum, numMessages);
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(5000, TimeUnit.MILLISECONDS);
+
+ if (!ok)
+ {
+ throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
+ }
+
+ if (handler.failure != null)
+ {
+ throw new Exception("Handler failed: " + handler.failure);
+ }
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestB(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler(threadNum, numMessages);
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ if (!ok)
+ {
+ throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
+ }
+
+ if (handler.failure != null)
+ {
+ throw new Exception("Handler failed: " + handler.failure);
+ }
+ }
+
+ sessSend.close();
+
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+
+ }
+
+ protected void doTestC(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, false, false);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.rollback();
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.commit();
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler(threadNum, numMessages);
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ if (!ok)
+ {
+ throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
+ }
+
+ if (handler.failure != null)
+ {
+ throw new Exception("Handler failed: " + handler.failure);
+ }
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestD(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + " sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, false, false);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.rollback();
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.commit();
+
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler(threadNum, numMessages);
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ if (!ok)
+ {
+ throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
+ }
+
+ if (handler.failure != null)
+ {
+ throw new Exception("Handler failed: " + handler.failure);
+ }
+ }
+
+ handlers.clear();
+
+ // Set handlers to null
+ for (ClientConsumer consumer : consumers)
+ {
+ consumer.setMessageHandler(null);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ // New handlers
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler(threadNum, numMessages);
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ if (!ok)
+ {
+ throw new Exception("Timed out waiting for messages on handler " + System.identityHashCode(handler) + " threadnum " + threadNum);
+ }
+
+ if (handler.failure != null)
+ {
+ throw new Exception("Handler failed on rollback: " + handler.failure);
+ }
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + " sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ // Now with synchronous receive()
+
+ protected void doTestE(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ consumeMessages(consumers, numMessages, threadNum);
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestF(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ consumeMessages(consumers, numMessages, threadNum);
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestG(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, false, false);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.rollback();
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.commit();
+
+ consumeMessages(consumers, numMessages, threadNum);
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ consumeMessages(consumers, numMessages, threadNum);
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestH(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, false, false);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.rollback();
+
+ sendMessages(sessSend, producer, numMessages, threadNum);
+
+ sessSend.commit();
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ consumeMessages(consumers, numMessages, threadNum);
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ consumeMessages(consumers, numMessages, threadNum);
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString(threadNum + "sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestI(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ ClientSession sessCreate = sf.createSession(false, true, true);
+
+ sessCreate.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false, true);
+
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sess.start();
+
+ ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
+
+ ClientProducer producer = sess.createProducer(ADDRESS);
+
+ ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.getBody().flip();
+
+ producer.send(message);
+
+ ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(message2);
+
+ message2.acknowledge();
+
+ sess.close();
+
+ sessCreate.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
+
+ sessCreate.close();
+ }
+
+ protected void doTestJ(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ ClientSession sessCreate = sf.createSession(false, true, true);
+
+ sessCreate.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false, true);
+
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sess.start();
+
+ ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
+
+ ClientProducer producer = sess.createProducer(ADDRESS);
+
+ ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.getBody().flip();
+
+ producer.send(message);
+
+ ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(message2);
+
+ message2.acknowledge();
+
+ sess.close();
+
+ sessCreate.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
+
+ sessCreate.close();
+ }
+
+ protected void doTestK(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ ClientSession s = sf.createSession(false, false, false);
+
+ s.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false, true);
+
+ final int numConsumers = 100;
+
+ for (int i = 0; i < numConsumers; i++)
+ {
+ ClientConsumer consumer = s.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
+
+ consumer.close();
+ }
+
+ s.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
+
+ s.close();
+ }
+
+ protected void doTestL(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numSessions = 100;
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession session = sf.createSession(false, false, false);
+
+ session.close();
+ }
+
+ s.close();
+ }
+
+ // Browsers
+ // FIXME - this test won't work until we use a proper iterator for browsing a queue.
+ // Making a copy of the queue for a browser consumer doesn't work well with replication since
+ // When replicating the create consumer (browser) to the backup, when executed on the backup the
+ // backup may have different messages in its queue since been added on different threads.
+ // So when replicating deliveries they may not be found.
+ // https://jira.jboss.org/jira/browse/JBMESSAGING-1433
+ // protected void doTestM(final ClientSessionFactory sf, final int threadNum) throws Exception
+ // {
+ // long start = System.currentTimeMillis();
+ //
+ // ClientSession sessSend = sf.createSession(false, true, true, false);
+ //
+ // ClientSession sessConsume = sf.createSession(false, true, true, false);
+ //
+ // sessConsume.createQueue(ADDRESS, new SimpleString(threadNum + "sub"), null, false, false);
+ //
+ // final int numMessages = 100;
+ //
+ // ClientProducer producer = sessSend.createProducer(ADDRESS);
+ //
+ // sendMessages(sessSend, producer, numMessages, threadNum);
+ //
+ // ClientConsumer browser = sessConsume.createConsumer(new SimpleString(threadNum + "sub"),
+ // null, false, true);
+ //
+ // Map<Integer, Integer> consumerCounts = new HashMap<Integer, Integer>();
+ //
+ // for (int i = 0; i < numMessages; i++)
+ // {
+ // ClientMessage msg = browser.receive(RECEIVE_TIMEOUT);
+ //
+ // assertNotNull(msg);
+ //
+ // int tn = (Integer)msg.getProperty(new SimpleString("threadnum"));
+ // int cnt = (Integer)msg.getProperty(new SimpleString("count"));
+ //
+ // Integer c = consumerCounts.get(tn);
+ // if (c == null)
+ // {
+ // c = new Integer(cnt);
+ // }
+ //
+ // if (cnt != c.intValue())
+ // {
+ // throw new Exception("Invalid count, expected " + c + " got " + cnt);
+ // }
+ //
+ // c++;
+ //
+ // //Wrap
+ // if (c == numMessages)
+ // {
+ // c = 0;
+ // }
+ //
+ // consumerCounts.put(tn, c);
+ //
+ // msg.acknowledge();
+ // }
+ //
+ // sessConsume.close();
+ //
+ // sessConsume = sf.createSession(false, true, true, false);
+ //
+ // browser = sessConsume.createConsumer(new SimpleString(threadNum + "sub"),
+ // null, false, true);
+ //
+ // //Messages should still be there
+ //
+ // consumerCounts.clear();
+ //
+ // for (int i = 0; i < numMessages; i++)
+ // {
+ // ClientMessage msg = browser.receive(RECEIVE_TIMEOUT);
+ //
+ // assertNotNull(msg);
+ //
+ // int tn = (Integer)msg.getProperty(new SimpleString("threadnum"));
+ // int cnt = (Integer)msg.getProperty(new SimpleString("count"));
+ //
+ // Integer c = consumerCounts.get(tn);
+ // if (c == null)
+ // {
+ // c = new Integer(cnt);
+ // }
+ //
+ // if (cnt != c.intValue())
+ // {
+ // throw new Exception("Invalid count, expected " + c + " got " + cnt);
+ // }
+ //
+ // c++;
+ //
+ // //Wrap
+ // if (c == numMessages)
+ // {
+ // c = 0;
+ // }
+ //
+ // consumerCounts.put(tn, c);
+ //
+ // msg.acknowledge();
+ // }
+ //
+ // sessConsume.close();
+ //
+ // sessSend.deleteQueue(new SimpleString(threadNum + "sub"));
+ //
+ // sessSend.close();
+ //
+ // long end = System.currentTimeMillis();
+ //
+ // log.info("duration " + (end - start));
+ // }
+
+ protected void doTestN(final ClientSessionFactory sf, final int threadNum) throws Exception
+ {
+ ClientSession sessCreate = sf.createSession(false, true, true);
+
+ sessCreate.createQueue(ADDRESS, new SimpleString(threadNum + ADDRESS.toString()), null, false, false, true);
+
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sess.stop();
+
+ sess.start();
+
+ sess.stop();
+
+ ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + ADDRESS.toString()));
+
+ ClientProducer producer = sess.createProducer(ADDRESS);
+
+ ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.getBody().flip();
+
+ producer.send(message);
+
+ sess.start();
+
+ ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(message2);
+
+ message2.acknowledge();
+
+ sess.stop();
+
+ sess.start();
+
+ sess.close();
+
+ sessCreate.deleteQueue(new SimpleString(threadNum + ADDRESS.toString()));
+
+ sessCreate.close();
+ }
+
+ protected int getNumIterations()
+ {
+ return 20;
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ log.info("************ Starting test " + this.getName());
+
+ timer = new Timer();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ log.info("************* Ending test " + this.getName());
+
+ if (liveService != null && liveService.isStarted())
+ {
+ liveService.stop();
+ }
+ if (backupService != null && backupService.isStarted())
+ {
+ backupService.stop();
+ }
+ timer.cancel();
+
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+ private void runTestMultipleThreads(final RunnableT runnable, final int numThreads) throws Exception
+ {
+ final int numIts = getNumIterations();
+
+ for (int its = 0; its < numIts; its++)
+ {
+ log.info("************ ITERATION: " + its);
+ start();
+
+ final ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, false, false);
+
+ Failer failer = startFailer(1000, session);
+
+ class Runner extends Thread
+ {
+ private volatile Throwable throwable;
+
+ private final RunnableT test;
+
+ private final int threadNum;
+
+ Runner(final RunnableT test, final int threadNum)
+ {
+ this.test = test;
+
+ this.threadNum = threadNum;
+ }
+
+ public void run()
+ {
+ try
+ {
+ test.run(sf, threadNum);
+ }
+ catch (Throwable t)
+ {
+ throwable = t;
+
+ log.error("Failed to run test", t);
+ }
+ }
+ }
+
+ do
+ {
+ List<Runner> threads = new ArrayList<Runner>();
+
+ for (int i = 0; i < numThreads; i++)
+ {
+ Runner runner = new Runner(runnable, i);
+
+ threads.add(runner);
+
+ runner.start();
+ }
+
+ for (Runner thread : threads)
+ {
+ thread.join();
+
+ assertNull(thread.throwable);
+ }
+
+ runnable.checkFail();
+ }
+ while (!failer.isExecuted());
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+
+ stop();
+ }
+ }
+
+ private Failer startFailer(final long time, final ClientSession session)
+ {
+ Failer failer = new Failer(session);
+
+ timer.schedule(failer, (long)(time * Math.random()), 100);
+
+ return failer;
+ }
+
+ private void start() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ // We need to sleep > 16 ms otherwise the id generators on live and backup could be initialised
+ // with the same time component
+ Thread.sleep(17);
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ private void stop() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ private void sendMessages(final ClientSession sessSend,
+ final ClientProducer producer,
+ final int numMessages,
+ final int threadNum) throws Exception
+ {
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("threadnum"), threadNum);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+ }
+
+ private void consumeMessages(final Set<ClientConsumer> consumers, final int numMessages, final int threadNum) throws Exception
+ {
+ // We make sure the messages arrive in the order they were sent from a particular producer
+ Map<ClientConsumer, Map<Integer, Integer>> counts = new HashMap<ClientConsumer, Map<Integer, Integer>>();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ Map<Integer, Integer> consumerCounts = counts.get(consumer);
+
+ if (consumerCounts == null)
+ {
+ consumerCounts = new HashMap<Integer, Integer>();
+ counts.put(consumer, consumerCounts);
+ }
+
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(msg);
+
+ int tn = (Integer)msg.getProperty(new SimpleString("threadnum"));
+ int cnt = (Integer)msg.getProperty(new SimpleString("count"));
+
+ // log.info("Got message " + tn + ":" + cnt);
+
+ Integer c = consumerCounts.get(tn);
+ if (c == null)
+ {
+ c = new Integer(cnt);
+ }
+
+ if (tn == threadNum && cnt != c.intValue())
+ {
+ throw new Exception("Invalid count, expected " + tn + ": " + c + " got " + cnt);
+ }
+
+ c++;
+
+ // Wrap
+ if (c == numMessages)
+ {
+ c = 0;
+ }
+
+ consumerCounts.put(tn, c);
+
+ msg.acknowledge();
+ }
+ }
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private class Failer extends TimerTask
+ {
+ private final ClientSession session;
+
+ private boolean executed;
+
+ public Failer(final ClientSession session)
+ {
+ this.session = session;
+ }
+
+ public synchronized void run()
+ {
+ log.info("** Failing connection");
+
+ RemotingConnectionImpl conn = (RemotingConnectionImpl)((ClientSessionImpl)session).getConnection();
+
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED, "blah"));
+
+ log.info("** Fail complete");
+
+ cancel();
+
+ executed = true;
+ }
+
+ public synchronized boolean isExecuted()
+ {
+ return executed;
+ }
+ }
+
+ private abstract class RunnableT extends Thread
+ {
+ private volatile String failReason;
+
+ private volatile Throwable throwable;
+
+ public void setFailed(final String reason, final Throwable throwable)
+ {
+ this.failReason = reason;
+ this.throwable = throwable;
+ }
+
+ public void checkFail()
+ {
+ if (throwable != null)
+ {
+ log.error("Test failed: " + failReason, throwable);
+ }
+ if (failReason != null)
+ {
+ fail(failReason);
+ }
+ }
+
+ public abstract void run(final ClientSessionFactory sf, final int threadNum) throws Exception;
+ }
+
+ private class MyHandler implements MessageHandler
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ private Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
+
+ volatile String failure;
+
+ final int tn;
+
+ final int numMessages;
+
+ volatile boolean done;
+
+ MyHandler(final int threadNum, final int numMessages)
+ {
+ this.tn = threadNum;
+
+ this.numMessages = numMessages;
+ }
+
+ public void onMessage(ClientMessage message)
+ {
+ try
+ {
+ message.acknowledge();
+ }
+ catch (MessagingException me)
+ {
+ log.error("Failed to process", me);
+ }
+
+ if (done)
+ {
+ return;
+ }
+
+ int threadNum = (Integer)message.getProperty(new SimpleString("threadnum"));
+ int cnt = (Integer)message.getProperty(new SimpleString("count"));
+
+ Integer c = counts.get(threadNum);
+ if (c == null)
+ {
+ c = new Integer(cnt);
+ }
+
+ //log.info(System.identityHashCode(this) + " consumed message " + threadNum + ":" + cnt);
+
+ if (tn == threadNum && cnt != c.intValue())
+ {
+ failure = "Invalid count, expected " + threadNum + ":" + c + " got " + cnt;
+ log.error(failure);
+
+ latch.countDown();
+ }
+
+ if (tn == threadNum && c == numMessages - 1)
+ {
+ done = true;
+ latch.countDown();
+ }
+
+ c++;
+ // Wrap around at numMessages
+ if (c == numMessages)
+ {
+ c = 0;
+ }
+
+ counts.put(threadNum, c);
+
+ }
+ }
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/RandomFailoverTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,1544 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.MessageHandler;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionInternal;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * A RandomFailoverSoakTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ */
+public class RandomFailoverTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(RandomFailoverTest.class);
+
+ // Constants -----------------------------------------------------
+
+ private static final int RECEIVE_TIMEOUT = 10000;
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ private Timer timer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+
+ public void testA() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestA(sf);
+ }
+ });
+ }
+
+ public void testB() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestB(sf);
+ }
+ });
+ }
+
+ public void testC() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestC(sf);
+ }
+ });
+ }
+
+ public void testD() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestD(sf);
+ }
+ });
+ }
+
+ public void testE() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestE(sf);
+ }
+ });
+ }
+
+ public void testF() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestF(sf);
+ }
+ });
+ }
+
+ public void testG() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestG(sf);
+ }
+ });
+ }
+
+ public void testH() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestH(sf);
+ }
+ });
+ }
+
+ public void testI() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestI(sf);
+ }
+ });
+ }
+
+ public void testJ() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestJ(sf);
+ }
+ });
+ }
+
+ public void testK() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestK(sf);
+ }
+ });
+ }
+
+ public void testL() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestL(sf);
+ }
+ });
+ }
+
+ public void testN() throws Exception
+ {
+ runTest(new RunnableT()
+ {
+ public void run(final ClientSessionFactory sf) throws Exception
+ {
+ doTestN(sf);
+ }
+ });
+ }
+
+ public void runTest(final RunnableT runnable) throws Exception
+ {
+ final int numIts = getNumIterations();
+
+ for (int its = 0; its < numIts; its++)
+ {
+ start();
+
+ ClientSessionFactoryImpl sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, false, false);
+
+ Failer failer = startFailer(1000, session);
+
+ log.info("***************Iteration: " + its);
+ do
+ {
+ runnable.run(sf);
+ }
+ while (!failer.isExecuted());
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+
+ stop();
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void doTestA(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ log.info("starting================");
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ class MyHandler implements MessageHandler
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ volatile int count;
+
+ public void onMessage(ClientMessage message)
+ {
+ if (count == numMessages)
+ {
+ fail("Too many messages");
+ }
+
+ assertEquals(count, message.getProperty(new SimpleString("count")));
+
+ count++;
+
+ try
+ {
+ message.acknowledge();
+ }
+ catch (MessagingException me)
+ {
+ log.error("Failed to process", me);
+ }
+
+ if (count == numMessages)
+ {
+ latch.countDown();
+ }
+ }
+ }
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler();
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(5000, TimeUnit.MILLISECONDS);
+
+ assertTrue("Didn't receive all messages", ok);
+ }
+
+ log.info("*** closing sessions");
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+ log.info("*** closed sessions");
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestB(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 50;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ class MyHandler implements MessageHandler
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ volatile int count;
+
+ public void onMessage(ClientMessage message)
+ {
+ if (count == numMessages)
+ {
+ fail("Too many messages");
+ }
+
+ assertEquals(count, message.getProperty(new SimpleString("count")));
+
+ count++;
+
+ if (count == numMessages)
+ {
+ latch.countDown();
+ }
+ }
+ }
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler();
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+ }
+
+ sessSend.close();
+
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+
+ }
+
+ protected void doTestC(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.rollback();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.commit();
+
+ class MyHandler implements MessageHandler
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ volatile int count;
+
+ public void onMessage(ClientMessage message)
+ {
+ if (count == numMessages)
+ {
+ fail("Too many messages");
+ }
+
+ assertEquals(count, message.getProperty(new SimpleString("count")));
+
+ count++;
+
+ if (count == numMessages)
+ {
+ latch.countDown();
+ }
+ }
+ }
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler();
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+ }
+
+ handlers.clear();
+
+ // New handlers
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler();
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestD(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.rollback();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.commit();
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ class MyHandler implements MessageHandler
+ {
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ volatile int count;
+
+ public void onMessage(ClientMessage message)
+ {
+ if (count == numMessages)
+ {
+ fail("Too many messages");
+ }
+
+ assertEquals(count, message.getProperty(new SimpleString("count")));
+
+ count++;
+
+ if (count == numMessages)
+ {
+ latch.countDown();
+ }
+ }
+ }
+
+ Set<MyHandler> handlers = new HashSet<MyHandler>();
+
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler();
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+ }
+
+ handlers.clear();
+
+ // New handlers
+ for (ClientConsumer consumer : consumers)
+ {
+ MyHandler handler = new MyHandler();
+
+ consumer.setMessageHandler(handler);
+
+ handlers.add(handler);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ for (MyHandler handler : handlers)
+ {
+ boolean ok = handler.latch.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ // Now with synchronous receive()
+
+ protected void doTestE(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("count")));
+
+ msg.acknowledge();
+ }
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receiveImmediate();
+
+ assertNull(msg);
+ }
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestF(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, true, true);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, true, true);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ if (msg == null)
+ {
+ throw new IllegalStateException("Failed to receive message " + i);
+ }
+
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("count")));
+
+ msg.acknowledge();
+ }
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receiveImmediate();
+
+ assertNull(msg);
+ }
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ assertEquals(1, ((ClientSessionFactoryImpl)sf).numSessions());
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestG(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.start();
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, false, false);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.rollback();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.commit();
+
+ log.info("sent and committed");
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("count")));
+
+ msg.acknowledge();
+ }
+ }
+
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receiveImmediate();
+
+ assertNull(msg);
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("count")));
+
+ msg.acknowledge();
+ }
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receiveImmediate();
+
+ assertNull(msg);
+ }
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestH(final ClientSessionFactory sf) throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numMessages = 100;
+
+ final int numSessions = 10;
+
+ Set<ClientConsumer> consumers = new HashSet<ClientConsumer>();
+ Set<ClientSession> sessions = new HashSet<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ ClientSession sessConsume = sf.createSession(false, false, false);
+
+ sessConsume.createQueue(ADDRESS, subName, null, false, false, true);
+
+ ClientConsumer consumer = sessConsume.createConsumer(subName);
+
+ consumers.add(consumer);
+
+ sessions.add(sessConsume);
+ }
+
+ ClientSession sessSend = sf.createSession(false, false, false);
+
+ ClientProducer producer = sessSend.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.rollback();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = sessSend.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ sessSend.commit();
+
+ for (ClientSession session : sessions)
+ {
+ session.start();
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("count")));
+
+ msg.acknowledge();
+ }
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receiveImmediate();
+
+ assertNull(msg);
+ }
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.rollback();
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("count")));
+
+ msg.acknowledge();
+ }
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ for (ClientConsumer consumer : consumers)
+ {
+ ClientMessage msg = consumer.receiveImmediate();
+
+ assertNull(msg);
+ }
+ }
+
+ for (ClientSession session : sessions)
+ {
+ session.commit();
+ }
+
+ sessSend.close();
+ for (ClientSession session : sessions)
+ {
+ session.close();
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ SimpleString subName = new SimpleString("sub" + i);
+
+ s.deleteQueue(subName);
+ }
+
+ s.close();
+
+ long end = System.currentTimeMillis();
+
+ log.info("duration " + (end - start));
+ }
+
+ protected void doTestI(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession sessCreate = sf.createSession(false, true, true);
+
+ sessCreate.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sess.start();
+
+ ClientConsumer consumer = sess.createConsumer(ADDRESS);
+
+ ClientProducer producer = sess.createProducer(ADDRESS);
+
+ ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.getBody().flip();
+
+ producer.send(message);
+
+ ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(message2);
+
+ message2.acknowledge();
+
+ sess.close();
+
+ sessCreate.deleteQueue(ADDRESS);
+
+ sessCreate.close();
+ }
+
+ protected void doTestJ(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession sessCreate = sf.createSession(false, true, true);
+
+ sessCreate.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sess.start();
+
+ ClientConsumer consumer = sess.createConsumer(ADDRESS);
+
+ ClientProducer producer = sess.createProducer(ADDRESS);
+
+ ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.getBody().flip();
+
+ producer.send(message);
+
+ ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(message2);
+
+ message2.acknowledge();
+
+ sess.close();
+
+ sessCreate.deleteQueue(ADDRESS);
+
+ sessCreate.close();
+ }
+
+ protected void doTestK(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession s = sf.createSession(false, false, false);
+
+ s.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ final int numConsumers = 100;
+
+ for (int i = 0; i < numConsumers; i++)
+ {
+ ClientConsumer consumer = s.createConsumer(ADDRESS);
+
+ consumer.close();
+ }
+
+ s.deleteQueue(ADDRESS);
+
+ s.close();
+ }
+
+ protected void doTestL(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession s = sf.createSession(false, false, false);
+
+ final int numSessions = 100;
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession session = sf.createSession(false, false, false);
+
+ session.close();
+ }
+
+ s.close();
+ }
+
+
+ protected void doTestN(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession sessCreate = sf.createSession(false, true, true);
+
+ sessCreate.createQueue(ADDRESS, new SimpleString(ADDRESS.toString()), null, false, false, true);
+
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sess.stop();
+
+ sess.start();
+
+ sess.stop();
+
+ ClientConsumer consumer = sess.createConsumer(new SimpleString(ADDRESS.toString()));
+
+ ClientProducer producer = sess.createProducer(ADDRESS);
+
+ ClientMessage message = sess.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.getBody().flip();
+
+ producer.send(message);
+
+ sess.start();
+
+ ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
+
+ assertNotNull(message2);
+
+ message2.acknowledge();
+
+ sess.stop();
+
+ sess.start();
+
+ sess.close();
+
+ sessCreate.deleteQueue(new SimpleString(ADDRESS.toString()));
+
+ sessCreate.close();
+ }
+
+ protected int getNumIterations()
+ {
+ return 20;
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ log.info("*********** created timer");
+ timer = new Timer(true);
+
+ log.info("************ Starting test " + this.getName());
+ }
+
+ protected void tearDown() throws Exception
+ {
+ timer.cancel();
+
+ log.info("************ Ended test " + this.getName());
+
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+ private Failer startFailer(final long time, final ClientSession session)
+ {
+ Failer failer = new Failer((ClientSessionInternal)session);
+
+ timer.schedule(failer, (long)(time * Math.random()), 100);
+
+ return failer;
+ }
+
+ private void start() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ // We need to sleep > 16 ms otherwise the id generators on live and backup could be initialised
+ // with the same time component
+ Thread.sleep(17);
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ private void stop() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Inner classes -------------------------------------------------
+
+ class Failer extends TimerTask
+ {
+ private final ClientSessionInternal session;
+
+ private boolean executed;
+
+ public Failer(final ClientSessionInternal session)
+ {
+ this.session = session;
+ }
+
+ public synchronized void run()
+ {
+ log.info("** Failing connection");
+
+ session.getConnection().fail(new MessagingException(MessagingException.NOT_CONNECTED, "oops"));
+
+ log.info("** Fail complete");
+
+ cancel();
+
+ executed = true;
+ }
+
+ public synchronized boolean isExecuted()
+ {
+ return executed;
+ }
+ }
+
+ public abstract class RunnableT
+ {
+ abstract void run(final ClientSessionFactory sf) throws Exception;
+ }
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/ReplicateConnectionFailureTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,190 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+
+/**
+ *
+ * A ReplicateConnectionFailureTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Created 6 Nov 2008 08:42:36
+ *
+ * Test whether when a connection is failed on the server since server receives no ping, that close
+ * is replicated to backup.
+ *
+ */
+public class ReplicateConnectionFailureTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(ReplicateConnectionFailureTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testFailConnection() throws Exception
+ {
+ final long pingPeriod = 500;
+
+ // TODO - use the defaults!!
+ ClientSessionFactoryInternal sf1 = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams),
+ pingPeriod,
+ ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT,
+ ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE,
+ ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE,
+ ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE,
+ ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE,
+ ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+ ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
+ ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_PERSISTENT_SEND,
+ ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP,
+ ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS,
+ ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE);
+
+ sf1.setSendWindowSize(32 * 1024);
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ ClientSession session1 = sf1.createSession(false, true, true);
+
+ // One connection
+ assertEquals(1, liveService.getServer().getRemotingService().getConnections().size());
+
+ // One replicating connection per session + one backup connection per session
+ assertEquals(2, backupService.getServer().getRemotingService().getConnections().size());
+
+ session1.close();
+
+ log.info("recreating");
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ session1 = sf1.createSession(false, true, true);
+
+ assertEquals(1, liveService.getServer().getRemotingService().getConnections().size());
+
+ assertEquals(2, backupService.getServer().getRemotingService().getConnections().size());
+
+ final RemotingConnectionImpl conn1 = (RemotingConnectionImpl)((ClientSessionImpl)session1).getConnection();
+
+ conn1.stopPingingAfterOne();
+
+ Thread.sleep(3 * pingPeriod);
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ // Should be one connection left to the backup - the other one (replicating connection) should be automatically
+ // closed
+ assertEquals(1, backupService.getServer().getRemotingService().getConnections().size());
+
+ session1.close();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setConnectionScanPeriod(100);
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setConnectionScanPeriod(100);
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleAutomaticFailoverTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,834 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.FailureListener;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A SimpleAutomaticFailoverTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SimpleAutomaticFailoverTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(SimpleAutomaticFailoverTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService liveService;
+
+ private MessagingService backupService;
+
+ private final Map<String, Object> backupParams = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testReplication() throws Exception
+ {
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 100;
+
+ log.info("Sending messages");
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ log.info("sent messages");
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ // log.info("Got message " + message2);
+
+ assertEquals("aardvarks", message2.getBody().getString());
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ // ClientMessage message3 = consumer.receive(250);
+
+ // assertNull(message3);
+
+ session.close();
+ }
+
+ public void testFailoverSameConnectionFactory() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn1 = ((ClientSessionImpl)session).getConnection();
+
+ // Simulate failure on connection
+ conn1.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages / 2; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ session.close();
+
+ session = sf.createSession(false, true, true);
+
+ consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = numMessages / 2; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ ClientMessage message3 = consumer.receive(250);
+
+ session.close();
+
+ assertNull(message3);
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testFailoverChangeConnectionFactory() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages / 2; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ session.close();
+
+ sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ session = sf.createSession(false, true, true);
+
+ consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = numMessages / 2; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ ClientMessage message3 = consumer.receive(250);
+
+ assertNull(message3);
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testNoMessagesLeftAfterFailoverNewSession() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ session.close();
+
+ sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ session = sf.createSession(false, true, true);
+
+ consumer = session.createConsumer(ADDRESS);
+
+ ClientMessage message3 = consumer.receive(250);
+
+ assertNull(message3);
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testCreateMoreSessionsAfterFailover() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ ClientSession session1 = sf.createSession(false, true, true);
+
+ ClientSession session2 = sf.createSession(false, true, true);
+
+ ClientSession session3 = sf.createSession(false, true, true);
+
+ session.close();
+
+ session1.close();
+
+ session2.close();
+
+ session3.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testFailureListenerCalledOnFailure() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ class MyListener implements FailureListener
+ {
+ public void connectionFailed(final MessagingException me)
+ {
+ latch.countDown();
+ }
+ }
+
+ conn.addFailureListener(new MyListener());
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ session.close();
+
+ sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ session = sf.createSession(false, true, true);
+
+ consumer = session.createConsumer(ADDRESS);
+
+ ClientMessage message3 = consumer.receive(250);
+
+ assertNull(message3);
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testFailoverMultipleSessions() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ final int numSessions = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS * 2;
+
+ List<ClientSession> sessions = new ArrayList<ClientSession>();
+
+ List<ClientConsumer> consumers = new ArrayList<ClientConsumer>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession sess = sf.createSession(false, true, true);
+
+ SimpleString queueName = new SimpleString("subscription" + i);
+
+ sess.createQueue(ADDRESS, queueName, null, false, false, true);
+
+ ClientConsumer consumer = sess.createConsumer(queueName);
+
+ sess.start();
+
+ sessions.add(sess);
+
+ consumers.add(consumer);
+ }
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 100;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientConsumer cons = consumers.get(i);
+
+ for (int j = 0; j < numMessages; j++)
+ {
+ ClientMessage message2 = cons.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(j, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ ClientMessage message3 = cons.receive(250);
+
+ assertNull(message3);
+ }
+
+ session.close();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession sess = sessions.get(i);
+
+ sess.close();
+ }
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testAllConnectionsReturned() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ final int numSessions = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS * 2;
+
+ List<ClientSession> sessions = new ArrayList<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sessions.add(sess);
+ }
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession sess = sessions.get(i);
+
+ sess.close();
+ }
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testAllConnectionsReturnedAfterFailover() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ final int numSessions = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS * 2;
+
+ List<ClientSession> sessions = new ArrayList<ClientSession>();
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession sess = sf.createSession(false, true, true);
+
+ sessions.add(sess);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)sessions.get(0)).getConnection();
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ for (int i = 0; i < numSessions; i++)
+ {
+ ClientSession sess = sessions.get(i);
+
+ sess.close();
+ }
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ public void testFailureAfterFailover() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"),
+ new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+
+ sf.setSendWindowSize(32 * 1024);
+
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ // Consume half of them
+
+ for (int i = 0; i < numMessages / 2; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ RemotingConnection conn2 = ((ClientSessionImpl)session).getConnection();
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ class MyListener implements FailureListener
+ {
+ public void connectionFailed(final MessagingException me)
+ {
+ latch.countDown();
+ }
+ }
+
+ conn2.addFailureListener(new MyListener());
+
+ assertFalse(conn == conn2);
+
+ conn2.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+
+ try
+ {
+ session.createQueue(new SimpleString("blah"), new SimpleString("blah"), null, false, false, true);
+
+ fail("Should throw exception");
+ }
+ catch (MessagingException me)
+ {
+ assertEquals(MessagingException.OBJECT_CLOSED, me.getCode());
+ }
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupService = MessagingServiceImpl.newNullStorageMessagingServer(backupConf);
+ backupService.start();
+
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ liveConf.setBackupConnectorConfiguration(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams));
+ liveService = MessagingServiceImpl.newNullStorageMessagingServer(liveConf);
+ liveService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
+
+ backupService.stop();
+
+ assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
+
+ liveService.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java (from rev 5347, trunk/tests/src/org/jboss/messaging/tests/integration/cluster/SimpleManualFailoverTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -0,0 +1,215 @@
+/*
+ * 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.cluster.failover;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryInternal;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.FailureListener;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A SimpleAutomaticFailoverTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SimpleManualFailoverTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(SimpleManualFailoverTest.class);
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private static final SimpleString ADDRESS = new SimpleString("FailoverTestAddress");
+
+ private MessagingService server0Service;
+
+ private MessagingService server1Service;
+
+ private Map<String, Object> server1Params = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private ClientSession sendAndConsume(final ClientSessionFactory sf) throws Exception
+ {
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(ADDRESS, ADDRESS, null, false, false, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 1000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
+ false,
+ 0,
+ System.currentTimeMillis(),
+ (byte)1);
+ message.putIntProperty(new SimpleString("count"), i);
+ message.getBody().putString("aardvarks");
+ message.getBody().flip();
+ producer.send(message);
+ }
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message2 = consumer.receive();
+
+ assertEquals("aardvarks", message2.getBody().getString());
+
+ assertEquals(i, message2.getProperty(new SimpleString("count")));
+
+ message2.acknowledge();
+ }
+
+ ClientMessage message3 = consumer.receive(250);
+
+ assertNull(message3);
+
+ return session;
+ }
+
+ public void testFailover() throws Exception
+ {
+ ClientSessionFactoryInternal sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"));
+
+ ClientSession session = sendAndConsume(sf);
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ class MyListener implements FailureListener
+ {
+ public void connectionFailed(MessagingException me)
+ {
+ log.info("*** connection failed");
+ latch.countDown();
+ }
+ }
+
+ RemotingConnection conn = ((ClientSessionImpl)session).getConnection();
+
+ conn.addFailureListener(new MyListener());
+
+ // Simulate failure on connection
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED));
+
+ // Wait to be informed of failure
+
+ boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
+
+ assertTrue(ok);
+
+ log.info("closing session");
+ session.close();
+ log.info("closed session");
+
+ sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ server1Params));
+
+ session = sendAndConsume(sf);
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+
+ assertEquals(0, sf.numBackupConnections());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void setUp() throws Exception
+ {
+ Configuration server1Conf = new ConfigurationImpl();
+ server1Conf.setSecurityEnabled(false);
+ server1Params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ server1Conf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ server1Params));
+ server1Service = MessagingServiceImpl.newNullStorageMessagingServer(server1Conf);
+ server1Service.start();
+
+ Configuration server0Conf = new ConfigurationImpl();
+ server0Conf.setSecurityEnabled(false);
+ server0Conf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ server0Service = MessagingServiceImpl.newNullStorageMessagingServer(server0Conf);
+ server0Service.start();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ assertEquals(0, server1Service.getServer().getRemotingService().getConnections().size());
+
+ server1Service.stop();
+
+ assertEquals(0, server0Service.getServer().getRemotingService().getConnections().size());
+
+ server0Service.stop();
+
+ assertEquals(0, InVMRegistry.instance.size());
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/consumer/ConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/consumer/ConsumerTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/consumer/ConsumerTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -77,7 +77,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -122,7 +122,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -168,7 +168,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -204,7 +204,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -241,7 +241,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -285,7 +285,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -318,7 +318,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
@@ -353,7 +353,7 @@
ClientSession session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, null, false, false);
+ session.createQueue(QUEUE, QUEUE, null, false, false, true);
ClientProducer producer = session.createProducer(QUEUE);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -121,7 +121,7 @@
SimpleString jmsQueueName = new SimpleString(JBossQueue.JMS_QUEUE_ADDRESS_PREFIX + "myqueue");
- coreSession.createQueue(jmsQueueName, jmsQueueName, null, false, false);
+ coreSession.createQueue(jmsQueueName, jmsQueueName, null, false, false, true);
Queue queue = sess.createQueue("myqueue");
@@ -217,7 +217,7 @@
SimpleString jmsQueueName = new SimpleString(JBossQueue.JMS_QUEUE_ADDRESS_PREFIX + "myqueue");
- coreSessionLive.createQueue(jmsQueueName, jmsQueueName, null, false, false);
+ coreSessionLive.createQueue(jmsQueueName, jmsQueueName, null, false, false, true);
Queue queue = sessLive.createQueue("myqueue");
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/scheduling/ScheduledMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/scheduling/ScheduledMessageTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/scheduling/ScheduledMessageTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -168,7 +168,7 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage message = createMessage(session, "m1");
long time = System.currentTimeMillis();
@@ -210,8 +210,8 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
- session.createQueue(atestq, atestq2, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
+ session.createQueue(atestq, atestq2, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage message = createMessage(session, "m1");
producer.send(message);
@@ -265,8 +265,8 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
- session.createQueue(atestq, atestq2, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
+ session.createQueue(atestq, atestq2, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage message = createMessage(session, "m1");
producer.send(message);
@@ -325,7 +325,7 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
false,
@@ -381,7 +381,7 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage m1 = createMessage(session, "m1");
ClientMessage m2 = createMessage(session, "m2");
@@ -467,7 +467,7 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage m1 = createMessage(session, "m1");
ClientMessage m2 = createMessage(session, "m2");
@@ -554,7 +554,7 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(false, true, false);
- session.createQueue(atestq, atestq, null, true, true);
+ session.createQueue(atestq, atestq, null, true, true, true);
ClientProducer producer = session.createProducer(atestq);
ClientMessage m1 = createMessage(session, "m1");
ClientMessage m2 = createMessage(session, "m2");
@@ -633,7 +633,7 @@
// then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
ClientSession session = sessionFactory.createSession(true, false, false);
- session.createQueue(atestq, atestq, null, true, false);
+ session.createQueue(atestq, atestq, null, true, false, true);
session.start(xid, XAResource.TMNOFLAGS);
ClientProducer producer = session.createProducer(atestq);
ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/xa/BasicXaRecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/xa/BasicXaRecoveryTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/xa/BasicXaRecoveryTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -94,7 +94,7 @@
//then we create a client as normal
sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
clientSession = sessionFactory.createSession(true, false, false);
- clientSession.createQueue(atestq, atestq, null, true, true);
+ clientSession.createQueue(atestq, atestq, null, true, true, true);
clientProducer = clientSession.createProducer(atestq);
clientConsumer = clientSession.createConsumer(atestq);
}
@@ -261,7 +261,7 @@
addSettings();
- clientSession.createQueue(pageQueue, pageQueue, null, true, true);
+ clientSession.createQueue(pageQueue, pageQueue, null, true, true, true);
clientSession.start(xid, XAResource.TMNOFLAGS);
@@ -337,7 +337,7 @@
addSettings();
- clientSession.createQueue(pageQueue, pageQueue, null, true, true);
+ clientSession.createQueue(pageQueue, pageQueue, null, true, true, true);
clientSession.start(xid, XAResource.TMNOFLAGS);
@@ -1011,7 +1011,7 @@
ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
SimpleString anewtestq = new SimpleString("anewtestq");
- clientSession.createQueue(anewtestq, anewtestq, null, true, true);
+ clientSession.createQueue(anewtestq, anewtestq, null, true, true, true);
ClientProducer clientProducer3 = clientSession2.createProducer(anewtestq);
clientProducer2.send(m1);
clientProducer2.send(m2);
@@ -1101,7 +1101,7 @@
ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
SimpleString anewtestq = new SimpleString("anewtestq");
- clientSession.createQueue(anewtestq, anewtestq, null, true, true);
+ clientSession.createQueue(anewtestq, anewtestq, null, true, true, true);
ClientProducer clientProducer3 = clientSession2.createProducer(anewtestq);
clientProducer2.send(m1);
clientProducer2.send(m2);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/xa/XaTimeoutTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/xa/XaTimeoutTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/xa/XaTimeoutTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -85,7 +85,7 @@
//then we create a client as normal
sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(CONNECTOR_FACTORY));
clientSession = sessionFactory.createSession(true, false, false);
- clientSession.createQueue(atestq, atestq, null, true, true);
+ clientSession.createQueue(atestq, atestq, null, true, true, true);
clientProducer = clientSession.createProducer(atestq);
clientConsumer = clientSession.createConsumer(atestq);
}
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -33,9 +33,10 @@
*/
public class FakeBinding implements Binding
{
+
private SimpleString address;
private Queue queue;
-
+
public FakeBinding(final SimpleString address, final Queue queue)
{
this.address = address;
@@ -52,4 +53,17 @@
return queue;
}
+ public boolean isFanout()
+ {
+ return false;
+ }
+
+ public long getRoutings()
+ {
+ return 0;
+ }
+
+ public void incrementRoutings()
+ {
+ }
}
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -60,7 +60,8 @@
SimpleString queueName,
Filter filter,
boolean durable,
- boolean temporary) throws Exception
+ boolean temporary,
+ boolean fanout) throws Exception
{
Queue queue = queueFactory.createQueue(-1, queueName, filter, durable, false);
Binding binding = new FakeBinding(address, queue);
Modified: trunk/tests/src/org/jboss/messaging/tests/soak/failover/RandomFailoverSoakTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/soak/failover/RandomFailoverSoakTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/soak/failover/RandomFailoverSoakTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -23,7 +23,7 @@
package org.jboss.messaging.tests.soak.failover;
-import org.jboss.messaging.tests.integration.cluster.RandomFailoverTest;
+import org.jboss.messaging.tests.integration.cluster.failover.RandomFailoverTest;
/**
* A RandomFailoverSoakTest
Modified: trunk/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -90,8 +90,8 @@
SimpleString address = new SimpleString("page-adr");
SimpleString queue[] = new SimpleString[] { new SimpleString("queue1"), new SimpleString("queue2") };
- session.createQueue(address, queue[0], null, true, false);
- session.createQueue(address, queue[1], null, true, false);
+ session.createQueue(address, queue[0], null, true, false, true);
+ session.createQueue(address, queue[1], null, true, false, true);
ClientProducer prod = session.createProducer(address);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -377,7 +377,7 @@
Binding newBinding = createMock(Binding.class);
expect(
postOffice.addBinding(new SimpleString(address), new SimpleString(
- name), null, true, false)).andReturn(newBinding);
+ name), null, true, false, true)).andReturn(newBinding);
replayMockedAttributes();
replay(newBinding);
@@ -395,18 +395,19 @@
String filter = "color = 'green'";
boolean durable = true;
boolean temporary = false;
+ boolean fanout = true;
expect(postOffice.getBinding(new SimpleString(address))).andReturn(null);
Binding newBinding = createMock(Binding.class);
expect(
postOffice.addBinding(eq(new SimpleString(address)),
eq(new SimpleString(name)), isA(Filter.class), eq(durable)
- , eq(temporary))).andReturn(newBinding);
+ , eq(temporary), eq(fanout))).andReturn(newBinding);
replayMockedAttributes();
replay(newBinding);
MessagingServerControl control = createControl();
- control.createQueue(address, name, filter, durable);
+ control.createQueue(address, name, filter, durable, fanout);
verify(newBinding);
verifyMockedAttributes();
@@ -424,12 +425,12 @@
Binding newBinding = createMock(Binding.class);
expect(
postOffice.addBinding(new SimpleString(address), new SimpleString(
- name), null, durable, temporary)).andReturn(newBinding);
+ name), null, durable, temporary, true)).andReturn(newBinding);
replay(newBinding);
replayMockedAttributes();
MessagingServerControl control = createControl();
- control.createQueue(address, name, filter, durable);
+ control.createQueue(address, name, filter, durable, true);
verify(newBinding);
verifyMockedAttributes();
@@ -447,12 +448,12 @@
Binding newBinding = createMock(Binding.class);
expect(
postOffice.addBinding(new SimpleString(address), new SimpleString(
- name), null, durable, temporary)).andReturn(newBinding);
+ name), null, durable, temporary, true)).andReturn(newBinding);
replay(newBinding);
replayMockedAttributes();
MessagingServerControl control = createControl();
- control.createQueue(address, name, filter, durable);
+ control.createQueue(address, name, filter, durable, true);
verify(newBinding);
verifyMockedAttributes();
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -437,7 +437,7 @@
EasyMock.expect(queue.getFilter()).andStubReturn(filter);
SimpleString address = new SimpleString("aijsiajs");
- Binding binding = new BindingImpl(address, queue);
+ Binding binding = new BindingImpl(address, queue, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream daos = new DataOutputStream(baos);
@@ -450,13 +450,14 @@
byte[] addressBytes = binding.getAddress().getData();
daos.writeInt(addressBytes.length);
daos.write(addressBytes);
- daos.writeBoolean(filter != null);
+ daos.writeBoolean(filter != null);
if (filter != null)
{
byte[] filterBytes = queueFilter.getData();
daos.writeInt(filterBytes.length);
daos.write(filterBytes);
}
+ daos.writeBoolean(true);
daos.flush();
byte[] data = baos.toByteArray();
@@ -639,6 +640,7 @@
daos.writeInt(filterBytes.length);
daos.write(filterBytes);
}
+ daos.writeBoolean(true);
daos.flush();
byte[] data = baos.toByteArray();
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -598,13 +598,13 @@
final SimpleString condition = new SimpleString("queue.wibble");
- Binding expected = new BindingImpl(condition, queue);
+ Binding expected = new BindingImpl(condition, queue, true);
pm.addBinding(EasyMock.eq(expected));
EasyMock.replay(qf, pm, filter);
- po.addBinding(condition, name, filter, durable, false);
+ po.addBinding(condition, name, filter, durable, false, true);
EasyMock.verify(qf, pm, filter);
@@ -640,7 +640,7 @@
final SimpleString condition = new SimpleString("queue.wibble");
- Binding expected = new BindingImpl(condition, queue);
+ Binding expected = new BindingImpl(condition, queue, true);
pm.addBinding(EasyMock.eq(expected));
@@ -648,7 +648,7 @@
EasyMock.replay(qf, pm, filter);
- po.addBinding(condition, name, filter, durable, false);
+ po.addBinding(condition, name, filter, durable, false, true);
po.removeBinding(name);
@@ -664,7 +664,7 @@
EasyMock.replay(qf, pm, filter);
- po.addBinding(condition, name, filter, durable2, false);
+ po.addBinding(condition, name, filter, durable2, false, true);
po.removeBinding(name);
@@ -689,15 +689,15 @@
SimpleString squeue5 = new SimpleString("queue5");
SimpleString squeue6 = new SimpleString("queue6");
- po.addBinding(condition1, squeue1, null, false, false);
+ po.addBinding(condition1, squeue1, null, false, false, true);
Map<SimpleString, List<Binding>> mappings = po.getMappings();
assertEquals(1, mappings.size());
- po.addBinding(condition1, squeue2, null, false, false);
+ po.addBinding(condition1, squeue2, null, false, false, true);
mappings = po.getMappings();
assertEquals(1, mappings.size());
- po.addBinding(condition1, squeue3, null, false, false);
+ po.addBinding(condition1, squeue3, null, false, false, true);
mappings = po.getMappings();
assertEquals(1, mappings.size());
@@ -719,17 +719,17 @@
final SimpleString condition2 = new SimpleString("queue.wibble2");
- po.addBinding(condition2, squeue4, null, false, false);
+ po.addBinding(condition2, squeue4, null, false, false, true);
mappings = po.getMappings();
assertEquals(2, mappings.size());
- po.addBinding(condition2, squeue5, null, false, false);
+ po.addBinding(condition2, squeue5, null, false, false, true);
mappings = po.getMappings();
assertEquals(2, mappings.size());
final SimpleString condition3 = new SimpleString("topic.wibblexyz");
- po.addBinding(condition3, squeue6, null, false, false);
+ po.addBinding(condition3, squeue6, null, false, false, true);
mappings = po.getMappings();
assertEquals(3, mappings.size());
@@ -907,7 +907,7 @@
EasyMock.replay(pm, qf, queue);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false, true);
assertNotNull(postOffice.getBinding(queueName));
EasyMock.verify(pm, qf, queue);
}
@@ -946,9 +946,9 @@
EasyMock.replay(pm, qf, queue, queue2, queue3);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false);
- postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, true, false);
- postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, true, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false, true);
+ postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, true, false, true);
+ postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, true, false, true);
assertNotNull(postOffice.getBinding(queueName));
assertNotNull(postOffice.getBinding(queueName2));
assertNotNull(postOffice.getBinding(queueName3));
@@ -978,7 +978,7 @@
EasyMock.replay(pm, qf, queue);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false, true);
assertNotNull(postOffice.getBinding(queueName));
EasyMock.verify(pm, qf, queue);
}
@@ -1014,9 +1014,9 @@
EasyMock.replay(pm, qf, queue, queue2, queue3);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false);
- postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, false, false);
- postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, false, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false, true);
+ postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, false, false, true);
+ postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, false, false, true);
assertNotNull(postOffice.getBinding(queueName));
assertNotNull(postOffice.getBinding(queueName2));
assertNotNull(postOffice.getBinding(queueName3));
@@ -1048,10 +1048,10 @@
EasyMock.replay(pm, qf, queue);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false, true);
try
{
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false, true);
fail("should throw exception");
}
catch (IllegalStateException e)
@@ -1088,7 +1088,7 @@
EasyMock.replay(pm, qf, queue);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false, true);
postOffice.removeBinding(queueName);
assertNull(postOffice.getBinding(queueName));
EasyMock.verify(pm, qf, queue);
@@ -1132,9 +1132,9 @@
EasyMock.replay(pm, qf, queue, queue2, queue3);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false);
- postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, true, false);
- postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, true, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, true, false, true);
+ postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, true, false, true);
+ postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, true, false, true);
postOffice.removeBinding(queueName);
postOffice.removeBinding(queueName3);
assertNull(postOffice.getBinding(queueName));
@@ -1167,7 +1167,7 @@
EasyMock.replay(pm, qf, queue);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false, true);
postOffice.removeBinding(queueName);
assertNull(postOffice.getBinding(queueName));
EasyMock.verify(pm, qf, queue);
@@ -1207,9 +1207,9 @@
EasyMock.replay(pm, qf, queue, queue2, queue3);
postOffice.start();
- postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false);
- postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, false, false);
- postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, false, false);
+ postOffice.addBinding(new SimpleString("testAddress"), queueName, filter, false, false, true);
+ postOffice.addBinding(new SimpleString("testAddress2"), queueName2, filter, false, false, true);
+ postOffice.addBinding(new SimpleString("testAddress3"), queueName3, filter, false, false, true);
postOffice.removeBinding(queueName);
postOffice.removeBinding(queueName3);
assertNull(postOffice.getBinding(queueName));
@@ -1342,7 +1342,7 @@
EasyMock.replay(pm, qf, message, queue, messageReference);
postOffice.start();
- postOffice.addBinding(address, queueName, null, false, false);
+ postOffice.addBinding(address, queueName, null, false, false, true);
List<MessageReference> references = postOffice.route(message);
@@ -1388,7 +1388,7 @@
EasyMock.replay(pm, pgm, qf, message, queue);
postOffice.start();
- postOffice.addBinding(address, queueName, null, false, false);
+ postOffice.addBinding(address, queueName, null, false, false, true);
List<MessageReference> references = postOffice.route(message);
@@ -1426,7 +1426,7 @@
EasyMock.expect(message.createReference(queue)).andReturn(messageReference);
EasyMock.replay(pm, qf, message, queue, messageReference, filter);
postOffice.start();
- postOffice.addBinding(address, queueName, filter, false, false);
+ postOffice.addBinding(address, queueName, filter, false, false, true);
List<MessageReference> references = postOffice.route(message);
EasyMock.verify(pm, qf, message, queue, messageReference, filter);
assertTrue(postOffice.isStarted());
@@ -1462,7 +1462,7 @@
EasyMock.expect(filter.match(message)).andReturn(false);
EasyMock.replay(pm, qf, message, queue, messageReference, filter);
postOffice.start();
- postOffice.addBinding(address, queueName, filter, false, false);
+ postOffice.addBinding(address, queueName, filter, false, false, true);
List<MessageReference> references = postOffice.route(message);
EasyMock.verify(pm, qf, message, queue, messageReference, filter);
assertTrue(postOffice.isStarted());
@@ -1510,9 +1510,9 @@
EasyMock.expect(message.createReference(queue3)).andReturn(messageReference3);
EasyMock.replay(pm, qf, message, queue, queue2, queue3, messageReference);
postOffice.start();
- postOffice.addBinding(address, queueName, null, false, false);
- postOffice.addBinding(address, queueName2, null, false, false);
- postOffice.addBinding(address, queueName3, null, false, false);
+ postOffice.addBinding(address, queueName, null, false, false, true);
+ postOffice.addBinding(address, queueName2, null, false, false, true);
+ postOffice.addBinding(address, queueName3, null, false, false, true);
List<MessageReference> references = postOffice.route(message);
EasyMock.verify(pm, qf, message, queue, queue2, queue3, messageReference);
assertTrue(postOffice.isStarted());
@@ -1566,9 +1566,9 @@
EasyMock.expect(message.createReference(queue3)).andReturn(messageReference3);
EasyMock.replay(pm, qf, message, queue, queue2, queue3, messageReference, filter, filter2);
postOffice.start();
- postOffice.addBinding(address, queueName, null, false, false);
- postOffice.addBinding(address, queueName2, null, false, false);
- postOffice.addBinding(address, queueName3, null, false, false);
+ postOffice.addBinding(address, queueName, null, false, false, true);
+ postOffice.addBinding(address, queueName2, null, false, false, true);
+ postOffice.addBinding(address, queueName3, null, false, false, true);
List<MessageReference> references = postOffice.route(message);
EasyMock.verify(pm, qf, message, queue, queue2, queue3, messageReference, filter, filter2);
assertTrue(postOffice.isStarted());
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplWildcardManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplWildcardManagerTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/PostOfficeImplWildcardManagerTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -95,7 +95,7 @@
assertTrue(postOffice.containsDestination(address));
assertTrue(postOffice.containsDestination(address2));
assertTrue(postOffice.containsDestination(address3));
- postOffice.addBinding(new SimpleString("test.*"), queueName, null, false, false);
+ postOffice.addBinding(new SimpleString("test.*"), queueName, null, false, false, true);
postOffice.route(message);
postOffice.route(message2);
postOffice.route(message3);
@@ -157,8 +157,8 @@
postOffice.addDestination(address2, true);
postOffice.addDestination(address3, true);
postOffice.addDestination(address4, true);
- postOffice.addBinding(new SimpleString("test.*"), queueName, null, false, false);
- postOffice.addBinding(new SimpleString("test2.*"), queueName2, null, false, false);
+ postOffice.addBinding(new SimpleString("test.*"), queueName, null, false, false, true);
+ postOffice.addBinding(new SimpleString("test2.*"), queueName2, null, false, false, true);
postOffice.route(message);
postOffice.route(message2);
postOffice.route(message3);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/SimpleAddressManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/SimpleAddressManagerTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/SimpleAddressManagerTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -134,15 +134,15 @@
EasyMock.expect(q4.getName()).andStubReturn(qName4);
EasyMock.expect(q5.getName()).andStubReturn(qName5);
EasyMock.replay(q, q2, q3, q4, q5);
- BindingImpl b1 = new BindingImpl(address, q);
+ BindingImpl b1 = new BindingImpl(address, q, true);
sam.addBinding(b1);
- BindingImpl b2 = new BindingImpl(address2, q2);
+ BindingImpl b2 = new BindingImpl(address2, q2, true);
sam.addBinding(b2);
- BindingImpl b3 = new BindingImpl(address3, q3);
+ BindingImpl b3 = new BindingImpl(address3, q3, true);
sam.addBinding(b3);
- BindingImpl b4 = new BindingImpl(address4, q4);
+ BindingImpl b4 = new BindingImpl(address4, q4, true);
sam.addBinding(b4);
- BindingImpl b5 = new BindingImpl(address5, q5);
+ BindingImpl b5 = new BindingImpl(address5, q5, true);
sam.addBinding(b5);
assertEquals(sam.getBinding(qName), b1);
assertEquals(sam.getBinding(qName2), b2);
@@ -176,15 +176,15 @@
EasyMock.expect(q4.getName()).andStubReturn(qName4);
EasyMock.expect(q5.getName()).andStubReturn(qName5);
EasyMock.replay(q, q2, q3, q4, q5);
- BindingImpl b1 = new BindingImpl(address, q);
+ BindingImpl b1 = new BindingImpl(address, q, true);
sam.addBinding(b1);
- BindingImpl b2 = new BindingImpl(address2, q2);
+ BindingImpl b2 = new BindingImpl(address2, q2, true);
sam.addBinding(b2);
- BindingImpl b3 = new BindingImpl(address3, q3);
+ BindingImpl b3 = new BindingImpl(address3, q3, true);
sam.addBinding(b3);
- BindingImpl b4 = new BindingImpl(address4, q4);
+ BindingImpl b4 = new BindingImpl(address4, q4, true);
sam.addBinding(b4);
- BindingImpl b5 = new BindingImpl(address5, q5);
+ BindingImpl b5 = new BindingImpl(address5, q5, true);
sam.addBinding(b5);
assertEquals(sam.getBinding(qName), b1);
assertEquals(sam.getBinding(qName2), b2);
@@ -210,7 +210,7 @@
Queue q = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q.getName()).andStubReturn(qName);
EasyMock.replay(q);
- BindingImpl b1 = new BindingImpl(address, q);
+ BindingImpl b1 = new BindingImpl(address, q, true);
sam.addBinding(b1);
try
{
@@ -231,7 +231,7 @@
SimpleString qName = new SimpleString("q1");
Queue q = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q.getName()).andStubReturn(qName);
- BindingImpl b1 = new BindingImpl(address, q);
+ BindingImpl b1 = new BindingImpl(address, q, true);
EasyMock.replay(q);
sam.addMapping(address, b1);
assertNotNull(sam.getBindings(address));
@@ -246,7 +246,7 @@
SimpleString qName = new SimpleString("q1");
Queue q = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q.getName()).andStubReturn(qName);
- BindingImpl b1 = new BindingImpl(address, q);
+ BindingImpl b1 = new BindingImpl(address, q, true);
EasyMock.replay(q);
sam.addMapping(address, b1);
assertNotNull(sam.getBindings(address));
@@ -276,11 +276,11 @@
EasyMock.expect(q4.getName()).andStubReturn(qName4);
Queue q5 = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q5.getName()).andStubReturn(qName5);
- BindingImpl b1 = new BindingImpl(address, q);
- BindingImpl b2 = new BindingImpl(address, q2);
- BindingImpl b3 = new BindingImpl(address, q3);
- BindingImpl b4 = new BindingImpl(address, q4);
- BindingImpl b5 = new BindingImpl(address, q5);
+ BindingImpl b1 = new BindingImpl(address, q, true);
+ BindingImpl b2 = new BindingImpl(address, q2, true);
+ BindingImpl b3 = new BindingImpl(address, q3, true);
+ BindingImpl b4 = new BindingImpl(address, q4, true);
+ BindingImpl b5 = new BindingImpl(address, q5, true);
EasyMock.replay(q, q2, q3, q4, q5);
sam.addMapping(address, b1);
sam.addMapping(address, b2);
@@ -315,11 +315,11 @@
EasyMock.expect(q4.getName()).andStubReturn(qName4);
Queue q5 = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q5.getName()).andStubReturn(qName5);
- BindingImpl b1 = new BindingImpl(address, q);
- BindingImpl b2 = new BindingImpl(address, q2);
- BindingImpl b3 = new BindingImpl(address, q3);
- BindingImpl b4 = new BindingImpl(address, q4);
- BindingImpl b5 = new BindingImpl(address, q5);
+ BindingImpl b1 = new BindingImpl(address, q, true);
+ BindingImpl b2 = new BindingImpl(address, q2, true);
+ BindingImpl b3 = new BindingImpl(address, q3, true);
+ BindingImpl b4 = new BindingImpl(address, q4, true);
+ BindingImpl b5 = new BindingImpl(address, q5, true);
EasyMock.replay(q, q2, q3, q4, q5);
sam.addMapping(address, b1);
sam.addMapping(address, b2);
@@ -365,11 +365,11 @@
EasyMock.expect(q4.getName()).andStubReturn(qName4);
Queue q5 = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q5.getName()).andStubReturn(qName5);
- BindingImpl b1 = new BindingImpl(address, q);
- BindingImpl b2 = new BindingImpl(address2, q2);
- BindingImpl b3 = new BindingImpl(address3, q3);
- BindingImpl b4 = new BindingImpl(address4, q4);
- BindingImpl b5 = new BindingImpl(address5, q5);
+ BindingImpl b1 = new BindingImpl(address, q, true);
+ BindingImpl b2 = new BindingImpl(address2, q2, true);
+ BindingImpl b3 = new BindingImpl(address3, q3, true);
+ BindingImpl b4 = new BindingImpl(address4, q4, true);
+ BindingImpl b5 = new BindingImpl(address5, q5, true);
EasyMock.replay(q, q2, q3, q4, q5);
sam.addMapping(address, b1);
sam.addMapping(address2, b2);
@@ -416,11 +416,11 @@
EasyMock.expect(q4.getName()).andStubReturn(qName4);
Queue q5 = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q5.getName()).andStubReturn(qName5);
- BindingImpl b1 = new BindingImpl(address, q);
- BindingImpl b2 = new BindingImpl(address2, q2);
- BindingImpl b3 = new BindingImpl(address3, q3);
- BindingImpl b4 = new BindingImpl(address4, q4);
- BindingImpl b5 = new BindingImpl(address5, q5);
+ BindingImpl b1 = new BindingImpl(address, q, true);
+ BindingImpl b2 = new BindingImpl(address2, q2, true);
+ BindingImpl b3 = new BindingImpl(address3, q3, true);
+ BindingImpl b4 = new BindingImpl(address4, q4, true);
+ BindingImpl b5 = new BindingImpl(address5, q5, true);
EasyMock.replay(q, q2, q3, q4, q5);
sam.addMapping(address, b1);
sam.addMapping(address2, b2);
@@ -498,16 +498,16 @@
EasyMock.expect(q9.getName()).andStubReturn(qName9);
Queue q10 = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q10.getName()).andStubReturn(qName10);
- BindingImpl b1 = new BindingImpl(address, q);
- BindingImpl b2 = new BindingImpl(address2, q2);
- BindingImpl b3 = new BindingImpl(address3, q3);
- BindingImpl b4 = new BindingImpl(address4, q4);
- BindingImpl b5 = new BindingImpl(address5, q5);
- BindingImpl b6 = new BindingImpl(address6, q6);
- BindingImpl b7 = new BindingImpl(address7, q7);
- BindingImpl b8 = new BindingImpl(address8, q8);
- BindingImpl b9 = new BindingImpl(address9, q9);
- BindingImpl b10 = new BindingImpl(address10, q10);
+ BindingImpl b1 = new BindingImpl(address, q, true);
+ BindingImpl b2 = new BindingImpl(address2, q2, true);
+ BindingImpl b3 = new BindingImpl(address3, q3, true);
+ BindingImpl b4 = new BindingImpl(address4, q4, true);
+ BindingImpl b5 = new BindingImpl(address5, q5, true);
+ BindingImpl b6 = new BindingImpl(address6, q6, true);
+ BindingImpl b7 = new BindingImpl(address7, q7, true);
+ BindingImpl b8 = new BindingImpl(address8, q8, true);
+ BindingImpl b9 = new BindingImpl(address9, q9, true);
+ BindingImpl b10 = new BindingImpl(address10, q10, true);
EasyMock.replay(q);
sam.addMapping(address, b1);
sam.addMapping(address2, b2);
@@ -578,16 +578,16 @@
EasyMock.expect(q9.getName()).andStubReturn(qName9);
Queue q10 = EasyMock.createStrictMock(Queue.class);
EasyMock.expect(q10.getName()).andStubReturn(qName10);
- BindingImpl b1 = new BindingImpl(address, q);
- BindingImpl b2 = new BindingImpl(address2, q2);
- BindingImpl b3 = new BindingImpl(address3, q3);
- BindingImpl b4 = new BindingImpl(address4, q4);
- BindingImpl b5 = new BindingImpl(address5, q5);
- BindingImpl b6 = new BindingImpl(address6, q6);
- BindingImpl b7 = new BindingImpl(address7, q7);
- BindingImpl b8 = new BindingImpl(address8, q8);
- BindingImpl b9 = new BindingImpl(address9, q9);
- BindingImpl b10 = new BindingImpl(address10, q10);
+ BindingImpl b1 = new BindingImpl(address, q, true);
+ BindingImpl b2 = new BindingImpl(address2, q2, true);
+ BindingImpl b3 = new BindingImpl(address3, q3, true);
+ BindingImpl b4 = new BindingImpl(address4, q4, true);
+ BindingImpl b5 = new BindingImpl(address5, q5, true);
+ BindingImpl b6 = new BindingImpl(address6, q6, true);
+ BindingImpl b7 = new BindingImpl(address7, q7, true);
+ BindingImpl b8 = new BindingImpl(address8, q8, true);
+ BindingImpl b9 = new BindingImpl(address9, q9, true);
+ BindingImpl b10 = new BindingImpl(address10, q10, true);
EasyMock.replay(q, q2, q3, q4, q5);
sam.addMapping(address, b1);
sam.addMapping(address2, b2);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessageReferenceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessageReferenceImplTest.java 2008-11-13 16:55:59 UTC (rev 5349)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessageReferenceImplTest.java 2008-11-13 17:01:13 UTC (rev 5350)
@@ -242,7 +242,7 @@
sm.updateDeliveryCount(messageReference);
EasyMock.expect(po.getBinding(dlqName)).andReturn(null);
- EasyMock.expect(po.addBinding(dlqName, dlqName, null, true, false)).andReturn(dlqBinding);
+ EasyMock.expect(po.addBinding(dlqName, dlqName, null, true, false, false)).andReturn(dlqBinding);
EasyMock.expect(serverMessage.copy()).andReturn(serverMessage);
@@ -402,7 +402,7 @@
EasyMock.expect(sm.generateUniqueID()).andReturn(2l);
EasyMock.expect(sm.generateUniqueID()).andReturn(1l);
EasyMock.expect(po.getBinding(expQName)).andReturn(null);
- EasyMock.expect(po.addBinding(expQName, expQName, null, true, false)).andReturn(expQBinding);
+ EasyMock.expect(po.addBinding(expQName, expQName, null, true, false, false)).andReturn(expQBinding);
EasyMock.expect(serverMessage.copy()).andReturn(serverMessage);
// serverMessage.setMessageID(2);
EasyMock.expect(serverMessage.getDestination()).andReturn(queueName);
More information about the jboss-cvs-commits
mailing list