[jboss-cvs] JBoss Messaging SVN: r6060 - in trunk: tests/jms-tests/src/org/jboss/test/messaging/jms and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 11 09:36:06 EDT 2009
Author: jmesnil
Date: 2009-03-11 09:36:06 -0400 (Wed, 11 Mar 2009)
New Revision: 6060
Added:
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeReconnectionTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMContext.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMNameParser.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/NonSerializableFactory.java
Removed:
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeMBeanTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/ReconnectTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/ReconnectWithRecoveryTest.java
Modified:
trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
Log:
bridge tests cleanup
* moved jms bridge tests to integration/jms/bridge
* refactored them to use 2 invm servers instead of spawned ones
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java 2009-03-11 12:56:14 UTC (rev 6059)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -156,6 +156,9 @@
// Read-only?
protected boolean readOnly;
+ // Read-only?
+ protected boolean propertiesReadOnly;
+
// Cache it
private Destination dest;
@@ -220,6 +223,8 @@
this.readOnly = true;
+ this.propertiesReadOnly = true;
+
this.session = session;
}
@@ -525,6 +530,8 @@
{
message.removeProperty(propName);
}
+
+ propertiesReadOnly = false;
}
public void clearBody() throws JMSException
@@ -963,7 +970,10 @@
private void checkProperty(final String name, final Object value) throws JMSException
{
- checkWrite();
+ if (propertiesReadOnly)
+ {
+ throw new MessageNotWriteableException("Message is read-only");
+ }
if (name == null)
{
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge (from rev 5986, trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge)
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeMBeanTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/BridgeMBeanTest.java 2009-03-04 07:37:42 UTC (rev 5986)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeMBeanTest.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -1,741 +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.test.messaging.jms.bridge;
-
-import java.io.ByteArrayOutputStream;
-import java.util.Properties;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-/**
- * A BridgeMBeanTest
- *
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class BridgeMBeanTest extends BridgeTestBase
-{
- private static final Logger log = Logger.getLogger(BridgeMBeanTest.class);
-
- public BridgeMBeanTest(String name)
- {
- super(name);
- }
-
- private static ObjectName sourceProviderLoader;
-
- private static ObjectName targetProviderLoader;
-
- public void setUp() throws Exception
- {
- boolean first = firstTime;
-
- super.setUp();
-
- if (first)
- {
- Properties props1 = new Properties();
- props1.putAll(ServerManagement.getJNDIEnvironment(0));
-
- Properties props2 = new Properties();
- props2.putAll(ServerManagement.getJNDIEnvironment(1));
-
- installJMSProviderLoader(0, props1, "/XAConnectionFactory", "adaptor1");
-
- installJMSProviderLoader(0, props2, "/XAConnectionFactory", "adaptor2");
-
- sourceProviderLoader = new ObjectName("jboss.messaging:service=JMSProviderLoader,name=adaptor1");
- targetProviderLoader = new ObjectName("jboss.messaging:service=JMSProviderLoader,name=adaptor2");
- }
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testStopStartPauseResume() throws Exception
- {
- Connection connSource = null;
-
- Connection connTarget = null;
-
- ObjectName on = null;
-
- try
- {
- on = deployBridge(0, "Bridge1", sourceProviderLoader, targetProviderLoader,
- "/queue/sourceQueue", "/queue/targetQueue",
- null, null, null, null,
- QualityOfServiceMode.AT_MOST_ONCE, null, 1,
- -1, null, null, 5000, -1, false);
- log.info("Deployed bridge");
-
- ServerManagement.getServer(0).invoke(on, "create", new Object[0], new String[0]);
-
- log.info("Created bridge");
-
- connSource = cf0.createConnection();
-
- connTarget = cf1.createConnection();
-
- connTarget.start();
-
- connSource.start();
-
- final int NUM_MESSAGES = 50;
-
- Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSource.createProducer(sourceQueue);
-
- Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sessTarget.createConsumer(targetQueue);
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSource.createTextMessage("message" + i);
-
- prod.send(tm);
- }
-
- //It's stopped so no messages should be received
-
- checkEmpty(targetQueue, 1);
-
- //Start it
-
- log.info("Starting bridge");
- ServerManagement.getServer(0).invoke(on, "start", new Object[0], new String[0]);
- log.info("Started bridge");
-
- //Now should receive the messages
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(2000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
- }
-
- checkEmpty(targetQueue, 1);
-
- //Send some more
-
- for (int i = NUM_MESSAGES; i < 2 * NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSource.createTextMessage("message" + i);
-
- prod.send(tm);
- }
-
- //These should be received too
-
- for (int i = NUM_MESSAGES; i < 2 * NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(2000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
- }
-
- checkEmpty(targetQueue, 1);
-
- //Pause it
-
- ServerManagement.getServer(0).invoke(on, "pause", new Object[0], new String[0]);
-
- boolean isPaused = ((Boolean)ServerManagement.getAttribute(on, "Paused")).booleanValue();
-
- assertTrue(isPaused);
-
- // Send some more
-
- for (int i = 2 * NUM_MESSAGES; i < 3 * NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSource.createTextMessage("message" + i);
-
- prod.send(tm);
- }
-
- //These shouldn't be received
-
- checkEmpty(targetQueue, 1);
-
- // Resume
-
- ServerManagement.getServer(0).invoke(on, "resume", new Object[0], new String[0]);
-
- //Now messages should be received
-
- for (int i = 2 * NUM_MESSAGES; i < 3 * NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(2000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
- }
-
- checkEmpty(targetQueue, 1);
-
- isPaused = ((Boolean)ServerManagement.getAttribute(on, "Paused")).booleanValue();
-
- assertFalse(isPaused);
-
- //Stop
-
- ServerManagement.getServer(0).invoke(on, "stop", new Object[0], new String[0]);
-
- boolean isStarted = ((Boolean)ServerManagement.getAttribute(on, "Started")).booleanValue();
-
- assertFalse(isStarted);
- }
- finally
- {
- if (connSource != null)
- {
- connSource.close();
- }
-
- if (connTarget != null)
- {
- connTarget.close();
- }
-
- try
- {
- if (on != null)
- {
- ServerManagement.getServer(0).invoke(on, "stop", new Object[0], new String[0]);
- ServerManagement.getServer(0).invoke(on, "destroy", new Object[0], new String[0]);
- }
- }
- catch(Exception e)
- {
- //Ignore
- }
- }
- }
-
- public void testDeploy() throws Exception
- {
- ObjectName on = null;
-
- try
- {
- on = deployBridge(0, "Bridge2", sourceProviderLoader, targetProviderLoader,
- "/queue/sourceQueue", "/queue/targetQueue",
- null, null, null, null,
- QualityOfServiceMode.ONCE_AND_ONLY_ONCE, null, 1,
- -1, null, null, 5000, -1, false);
-
- log.trace("Constructed bridge");
-
- ServerManagement.getServer(0).invoke(on, "create", new Object[0], new String[0]);
-
- log.trace("Created bridge");
-
- {
- ObjectName sourceProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "SourceProviderLoader");
- assertEquals(sourceProviderLoader, sourceProviderLoader2);
- ServerManagement.setAttribute(on, "SourceProviderLoader", "jboss.messaging:service=JMSProviderLoader,name=blah");
- sourceProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "SourceProviderLoader");
- assertEquals(new ObjectName("jboss.messaging:service=JMSProviderLoader,name=blah"), sourceProviderLoader2);
- ServerManagement.setAttribute(on, "SourceProviderLoader", sourceProviderLoader.toString());
- }
-
- {
- ObjectName targetProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "TargetProviderLoader");
- assertEquals(targetProviderLoader, targetProviderLoader2);
- ServerManagement.setAttribute(on, "TargetProviderLoader", "jboss.messaging:service=JMSProviderLoader,name=blah2");
- targetProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "TargetProviderLoader");
- assertEquals(new ObjectName("jboss.messaging:service=JMSProviderLoader,name=blah2"), targetProviderLoader2);
- ServerManagement.setAttribute(on, "TargetProviderLoader", targetProviderLoader.toString());
-
- }
-
- {
- String destLookup = (String)ServerManagement.getAttribute(on, "SourceDestinationLookup");
- assertEquals("/queue/sourceQueue", destLookup);
- ServerManagement.setAttribute(on, "SourceDestinationLookup", "/queue/WibbleQueue");
- destLookup = (String)ServerManagement.getAttribute(on, "SourceDestinationLookup");
- assertEquals("/queue/WibbleQueue", destLookup);
- ServerManagement.setAttribute(on, "SourceDestinationLookup", "/queue/sourceQueue");
- }
-
- {
- String destLookup = (String)ServerManagement.getAttribute(on, "TargetDestinationLookup");
- assertEquals("/queue/targetQueue", destLookup);
- ServerManagement.setAttribute(on, "TargetDestinationLookup", "/queue/WibbleQueue");
- destLookup = (String)ServerManagement.getAttribute(on, "TargetDestinationLookup");
- assertEquals("/queue/WibbleQueue", destLookup);
- ServerManagement.setAttribute(on, "TargetDestinationLookup", "/queue/targetQueue");
- }
-
- {
- String username = (String)ServerManagement.getAttribute(on, "SourceUsername");
- assertEquals(null, username);
- ServerManagement.setAttribute(on, "SourceUsername", "bob");
- username = (String)ServerManagement.getAttribute(on, "SourceUsername");
- assertEquals("bob", username);
- ServerManagement.setAttribute(on, "SourceUsername", null);
- }
-
- {
- String password = (String)ServerManagement.getAttribute(on, "SourcePassword");
- assertEquals(null, password);
- ServerManagement.setAttribute(on, "SourcePassword", "eek");
- password = (String)ServerManagement.getAttribute(on, "SourcePassword");
- assertEquals("eek", password);
- ServerManagement.setAttribute(on, "SourcePassword", null);
- }
-
- {
- String username = (String)ServerManagement.getAttribute(on, "TargetUsername");
- assertEquals(null, username);
- ServerManagement.setAttribute(on, "TargetUsername", "bob");
- username = (String)ServerManagement.getAttribute(on, "TargetUsername");
- assertEquals("bob", username);
- ServerManagement.setAttribute(on, "TargetUsername", null);
- }
-
- {
- String password = (String)ServerManagement.getAttribute(on, "TargetPassword");
- assertEquals(null, password);
- ServerManagement.setAttribute(on, "TargetPassword", "eek");
- password = (String)ServerManagement.getAttribute(on, "TargetPassword");
- assertEquals("eek", password);
- ServerManagement.setAttribute(on, "TargetPassword", null);
- }
-
- {
- Integer qos = (Integer)ServerManagement.getAttribute(on, "QualityOfServiceMode");
- assertEquals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE.intValue(), qos.intValue());
- ServerManagement.setAttribute(on, "QualityOfServiceMode", String.valueOf(QualityOfServiceMode.AT_MOST_ONCE.intValue()));
- qos = (Integer)ServerManagement.getAttribute(on, "QualityOfServiceMode");
- assertEquals(new Integer(QualityOfServiceMode.AT_MOST_ONCE.intValue()), qos);
- ServerManagement.setAttribute(on, "QualityOfServiceMode", String.valueOf(QualityOfServiceMode.ONCE_AND_ONLY_ONCE.intValue()));
- }
-
- {
- String selector = (String)ServerManagement.getAttribute(on, "Selector");
- assertEquals(null, selector);
- ServerManagement.setAttribute(on, "Selector", "god='dead'");
- selector = (String)ServerManagement.getAttribute(on, "Selector");
- assertEquals("god='dead'", selector);
- ServerManagement.setAttribute(on, "Selector", null);
- }
-
- {
- Integer maxBatchSize = (Integer)ServerManagement.getAttribute(on, "MaxBatchSize");
- assertEquals(1, maxBatchSize.intValue());
- ServerManagement.setAttribute(on, "MaxBatchSize", "10");
- maxBatchSize = (Integer)ServerManagement.getAttribute(on, "MaxBatchSize");
- assertEquals(10, maxBatchSize.intValue());
- ServerManagement.setAttribute(on, "MaxBatchSize", "1");
- }
-
- {
- Long maxBatchTime = (Long)ServerManagement.getAttribute(on, "MaxBatchTime");
- assertEquals(-1, maxBatchTime.longValue());
- ServerManagement.setAttribute(on, "MaxBatchTime", "3000");
- maxBatchTime = (Long)ServerManagement.getAttribute(on, "MaxBatchTime");
- assertEquals(3000, maxBatchTime.longValue());
- ServerManagement.setAttribute(on, "MaxBatchTime", "-1");
- }
-
- {
- String subName = (String)ServerManagement.getAttribute(on, "SubName");
- assertEquals(null, subName);
- ServerManagement.setAttribute(on, "SubName", "submarine");
- subName = (String)ServerManagement.getAttribute(on, "SubName");
- assertEquals("submarine", subName);
- ServerManagement.setAttribute(on, "SubName", null);
- }
-
- {
- String clientID = (String)ServerManagement.getAttribute(on, "ClientID");
- assertEquals(null, clientID);
- ServerManagement.setAttribute(on, "ClientID", "clientid-123");
- clientID = (String)ServerManagement.getAttribute(on, "ClientID");
- assertEquals("clientid-123", clientID);
- ServerManagement.setAttribute(on, "ClientID", null);
- }
-
- {
- Long failureRetryInterval = (Long)ServerManagement.getAttribute(on, "FailureRetryInterval");
- assertEquals(5000, failureRetryInterval.longValue());
- ServerManagement.setAttribute(on, "FailureRetryInterval", "10000");
- failureRetryInterval = (Long)ServerManagement.getAttribute(on, "FailureRetryInterval");
- assertEquals(10000, failureRetryInterval.longValue());
- ServerManagement.setAttribute(on, "FailureRetryInterval", "5000");
- }
-
- {
- Integer maxRetries = (Integer)ServerManagement.getAttribute(on, "MaxRetries");
- assertEquals(-1, maxRetries.intValue());
- ServerManagement.setAttribute(on, "MaxRetries", "1000");
- maxRetries = (Integer)ServerManagement.getAttribute(on, "MaxRetries");
- assertEquals(1000, maxRetries.intValue());
- ServerManagement.setAttribute(on, "MaxRetries", "-1");
- }
-
- ServerManagement.getServer(0).invoke(on, "start", new Object[0], new String[0]);
-
- //Should not be able to change attributes when bridge is started - need to stop first
-
- {
- ObjectName sourceProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "SourceProviderLoader");
- assertEquals(sourceProviderLoader, sourceProviderLoader2);
- ServerManagement.setAttribute(on, "SourceProviderLoader", "jboss.messaging:service=JMSProviderLoader,name=blah");
- sourceProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "SourceProviderLoader");
- assertEquals(sourceProviderLoader, sourceProviderLoader2);
- }
-
- {
- ObjectName targetProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "TargetProviderLoader");
- assertEquals(targetProviderLoader, targetProviderLoader2);
- ServerManagement.setAttribute(on, "TargetProviderLoader", "jboss.messaging:service=JMSProviderLoader,name=blah2");
- targetProviderLoader2 = (ObjectName)ServerManagement.getAttribute(on, "TargetProviderLoader");
- assertEquals(targetProviderLoader, targetProviderLoader2);
-
- }
-
- {
- String destLookup = (String)ServerManagement.getAttribute(on, "SourceDestinationLookup");
- assertEquals("/queue/sourceQueue", destLookup);
- ServerManagement.setAttribute(on, "SourceDestinationLookup", "/queue/WibbleQueue");
- destLookup = (String)ServerManagement.getAttribute(on, "SourceDestinationLookup");
- assertEquals("/queue/sourceQueue", destLookup);
- }
-
- {
- String destLookup = (String)ServerManagement.getAttribute(on, "TargetDestinationLookup");
- assertEquals("/queue/targetQueue", destLookup);
- ServerManagement.setAttribute(on, "TargetDestinationLookup", "/queue/WibbleQueue");
- destLookup = (String)ServerManagement.getAttribute(on, "TargetDestinationLookup");
- assertEquals("/queue/targetQueue", destLookup);
- }
-
- {
- String username = (String)ServerManagement.getAttribute(on, "SourceUsername");
- assertEquals(null, username);
- ServerManagement.setAttribute(on, "SourceUsername", "bob");
- username = (String)ServerManagement.getAttribute(on, "SourceUsername");
- assertEquals(null, username);
- }
-
- {
- String password = (String)ServerManagement.getAttribute(on, "SourcePassword");
- assertEquals(null, password);
- ServerManagement.setAttribute(on, "SourcePassword", "eek");
- password = (String)ServerManagement.getAttribute(on, "SourcePassword");
- assertEquals(null, password);
- }
-
- {
- String username = (String)ServerManagement.getAttribute(on, "TargetUsername");
- assertEquals(null, username);
- ServerManagement.setAttribute(on, "TargetUsername", "bob");
- username = (String)ServerManagement.getAttribute(on, "TargetUsername");
- assertEquals(null, username);
- }
-
- {
- String password = (String)ServerManagement.getAttribute(on, "TargetPassword");
- assertEquals(null, password);
- ServerManagement.setAttribute(on, "TargetPassword", "eek");
- password = (String)ServerManagement.getAttribute(on, "TargetPassword");
- assertEquals(null, password);
- }
-
- {
- Integer qos = (Integer)ServerManagement.getAttribute(on, "QualityOfServiceMode");
- assertEquals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE.intValue(), qos.intValue());
- ServerManagement.setAttribute(on, "QualityOfServiceMode", String.valueOf(QualityOfServiceMode.AT_MOST_ONCE.intValue()));
- qos = (Integer)ServerManagement.getAttribute(on, "QualityOfServiceMode");
- assertEquals(new Integer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE.intValue()), qos);
- }
-
- {
- String selector = (String)ServerManagement.getAttribute(on, "Selector");
- assertEquals(null, selector);
- ServerManagement.setAttribute(on, "Selector", "god='dead'");
- selector = (String)ServerManagement.getAttribute(on, "Selector");
- assertEquals(null, selector);
- }
-
- {
- Integer maxBatchSize = (Integer)ServerManagement.getAttribute(on, "MaxBatchSize");
- assertEquals(1, maxBatchSize.intValue());
- ServerManagement.setAttribute(on, "MaxBatchSize", "10");
- maxBatchSize = (Integer)ServerManagement.getAttribute(on, "MaxBatchSize");
- assertEquals(1, maxBatchSize.intValue());
- }
-
- {
- Long maxBatchTime = (Long)ServerManagement.getAttribute(on, "MaxBatchTime");
- assertEquals(-1, maxBatchTime.longValue());
- ServerManagement.setAttribute(on, "MaxBatchTime", "3000");
- maxBatchTime = (Long)ServerManagement.getAttribute(on, "MaxBatchTime");
- assertEquals(-1, maxBatchTime.longValue());
- }
-
- {
- String subName = (String)ServerManagement.getAttribute(on, "SubName");
- assertEquals(null, subName);
- ServerManagement.setAttribute(on, "SubName", "submarine");
- subName = (String)ServerManagement.getAttribute(on, "SubName");
- assertEquals(null, subName);
- }
-
- {
- String clientID = (String)ServerManagement.getAttribute(on, "ClientID");
- assertEquals(null, clientID);
- ServerManagement.setAttribute(on, "ClientID", "clientid-123");
- clientID = (String)ServerManagement.getAttribute(on, "ClientID");
- assertEquals(null, clientID);
- }
-
- {
- Long failureRetryInterval = (Long)ServerManagement.getAttribute(on, "FailureRetryInterval");
- assertEquals(5000, failureRetryInterval.longValue());
- ServerManagement.setAttribute(on, "FailureRetryInterval", "10000");
- failureRetryInterval = (Long)ServerManagement.getAttribute(on, "FailureRetryInterval");
- assertEquals(5000, failureRetryInterval.longValue());
- }
-
- {
- Integer maxRetries = (Integer)ServerManagement.getAttribute(on, "MaxRetries");
- assertEquals(-1, maxRetries.intValue());
- ServerManagement.setAttribute(on, "MaxRetries", "1000");
- maxRetries = (Integer)ServerManagement.getAttribute(on, "MaxRetries");
- assertEquals(-1, maxRetries.intValue());
- }
-
- Properties props1 = new Properties();
- props1.putAll(ServerManagement.getJNDIEnvironment(0));
- Properties props2 = new Properties();
- props2.putAll(ServerManagement.getJNDIEnvironment(1));
- InitialContext icSource = getInitialContext(0);
- InitialContext icTarget = getInitialContext(1);
-
- log.trace("Checking bridged bridge");
-
- checkBridged(icSource, icTarget, "/ConnectionFactory", "/ConnectionFactory",
- "/queue/sourceQueue", "/queue/targetQueue");
-
- log.trace("Checked bridge");
-
- }
- finally
- {
- try
- {
- if (on != null)
- {
- ServerManagement.getServer(0).invoke(on, "stop", new Object[0], new String[0]);
- ServerManagement.getServer(0).invoke(on, "destroy", new Object[0], new String[0]);
- }
- }
- catch(Exception e)
- {
- //Ignore
- }
- }
-
- }
-
-
- private ObjectName deployBridge(int server, String bridgeName,
- ObjectName sourceProviderLoader, ObjectName targetProviderLoader,
- String sourceDestLookup, String targetDestLookup,
- String sourceUsername, String sourcePassword,
- String targetUsername, String targetPassword,
- QualityOfServiceMode qos, String selector, int maxBatchSize,
- long maxBatchTime, String subName, String clientID,
- long failureRetryInterval, int maxRetries, boolean addMessageIDInHeader) throws Exception
- {
- String config =
- "<mbean code=\"org.jboss.messaging.jms.server.bridge.BridgeService\" " +
- "name=\"jboss.messaging:service=Bridge,name=" + bridgeName + "\" " +
- "xmbean-dd=\"xmdesc/Bridge-xmbean.xml\">" +
- "<attribute name=\"SourceProviderLoader\">" + sourceProviderLoader + "</attribute>"+
- "<attribute name=\"TargetProviderLoader\">" + targetProviderLoader + "</attribute>"+
- "<attribute name=\"SourceDestinationLookup\">" + sourceDestLookup + "</attribute>"+
- "<attribute name=\"TargetDestinationLookup\">" + targetDestLookup + "</attribute>";
- if (sourceUsername != null)
- {
- config += "<attribute name=\"SourceUsername\">" + sourceUsername + "</attribute>";
- }
- if (sourcePassword != null)
- {
- config += "<attribute name=\"SourcePassword\">" + sourcePassword +"</attribute>";
- }
- if (targetUsername != null)
- {
- config += "<attribute name=\"TargetUsername\">" + targetUsername +"</attribute>";
- }
- if (targetPassword != null)
- {
- config += "<attribute name=\"TargetPassword\">" + targetPassword + "</attribute>";
- }
- config += "<attribute name=\"QualityOfServiceMode\">" + qos.intValue() +"</attribute>";
- if (selector != null)
- {
- config += "<attribute name=\"Selector\">" + selector + "</attribute>";
- }
- config += "<attribute name=\"MaxBatchSize\">" + maxBatchSize + "</attribute>"+
- "<attribute name=\"MaxBatchTime\">" + maxBatchTime +"</attribute>";
- if (subName != null)
- {
- config += "<attribute name=\"SubName\">" + subName + "</attribute>";
- }
- if (clientID != null)
- {
- config += "<attribute name=\"ClientID\">" + clientID + "</attribute>";
- }
- config += "<attribute name=\"FailureRetryInterval\">" + failureRetryInterval + "</attribute>";
-
- config += "<attribute name=\"MaxRetries\">" + maxRetries +"</attribute>";
-
- config += "<attribute name=\"AddMessageIDInHeader\">" + addMessageIDInHeader + "</attribute>";
- config += "</mbean>";
-
- // TODO: this has to be fixed
- // return ServerManagement.getServer(server).deploy(config);
- return null;
- }
-
- private void checkBridged(InitialContext icSource, InitialContext icTarget,
- String sourceCFLookup, String targetCFLookup,
- String sourceDestLookup, String targetDestLookup)
- throws Exception
- {
- Connection connSource = null;
-
- Connection connTarget = null;
-
- try
- {
- ConnectionFactory cf0 = (ConnectionFactory)icSource.lookup(sourceCFLookup);
-
- ConnectionFactory cf1 = (ConnectionFactory)icTarget.lookup(targetCFLookup);
-
- Destination destSource = (Destination)icSource.lookup(sourceDestLookup);
-
- Destination destTarget = (Destination)icTarget.lookup(targetDestLookup);
-
- connSource = cf0.createConnection();
-
- connTarget = cf1.createConnection();
-
- connTarget.start();
-
- connSource.start();
-
- final int NUM_MESSAGES = 50;
-
- Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSource.createProducer(destSource);
-
- Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sessTarget.createConsumer(destTarget);
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSource.createTextMessage("message" + i);
-
- prod.send(tm);
- }
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(10000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
- }
- }
- finally
- {
- if (connSource != null)
- {
- connSource.close();
- }
-
- if (connTarget != null)
- {
- connTarget.close();
- }
- }
- }
-
- private void installJMSProviderLoader(int server, Properties props, String factoryRef, String name)
- throws Exception
- {
- ByteArrayOutputStream boa = new ByteArrayOutputStream();
- props.store(boa, "");
- String propsString = new String(boa.toByteArray());
-
- String config =
- "<mbean code=\"org.jboss.jms.jndi.JMSProviderLoader\"" +
- " name=\"jboss.messaging:service=JMSProviderLoader,name=" + name + "\">" +
- "<attribute name=\"ProviderName\">" + name + "</attribute>" +
- "<attribute name=\"ProviderAdapterClass\">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>" +
- "<attribute name=\"FactoryRef\">" + factoryRef + "</attribute>" +
- "<attribute name=\"QueueFactoryRef\">" + factoryRef + "</attribute>" +
- "<attribute name=\"TopicFactoryRef\">" + factoryRef + "</attribute>" +
- "<attribute name=\"Properties\">" + propsString + "</attribute></mbean>";
-
- log.info("Installing bridge: " + config);
-
- // TODO: this has to be fixed
- // ServerManagement.getServer(0).deploy(config);
- }
-
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeReconnectionTest.java (from rev 5986, trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeReconnectionTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeReconnectionTest.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -0,0 +1,303 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.integration.jms.bridge;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
+import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
+// import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
+import org.jboss.messaging.tests.unit.util.InVMContext;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class BridgeReconnectionTest extends BridgeTestBase
+{
+ private static final Logger log = Logger.getLogger(BridgeReconnectionTest.class);
+
+ // Crash and reconnect
+
+ // Once and only once
+
+ public void _testCrashAndReconnectDestBasic_OnceAndOnlyOnce_P() throws Exception
+ {
+ testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
+ }
+
+ public void _testCrashAndReconnectDestBasic_OnceAndOnlyOnce_NP() throws Exception
+ {
+ testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
+ }
+
+ // dups ok
+
+ public void testCrashAndReconnectDestBasic_DuplicatesOk_P() throws Exception
+ {
+ testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, true);
+ }
+
+ public void testCrashAndReconnectDestBasic_DuplicatesOk_NP() throws Exception
+ {
+ testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, false);
+ }
+
+ // At most once
+
+ public void testCrashAndReconnectDestBasic_AtMostOnce_P() throws Exception
+ {
+ testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, true);
+ }
+
+ public void testCrashAndReconnectDestBasic_AtMostOnce_NP() throws Exception
+ {
+ testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, false);
+ }
+
+ // Crash tests specific to XA transactions
+
+ public void _testCrashAndReconnectDestCrashBeforePrepare_P() throws Exception
+ {
+ testCrashAndReconnectDestCrashBeforePrepare(true);
+ }
+
+ public void _testCrashAndReconnectDestCrashBeforePrepare_NP() throws Exception
+ {
+ testCrashAndReconnectDestCrashBeforePrepare(false);
+ }
+
+ // Crash before bridge is started
+
+ public void testRetryConnectionOnStartup() throws Exception
+ {
+ server1.stop();
+
+ BridgeImpl bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 1000, -1, QualityOfServiceMode.DUPLICATES_OK,
+ 10, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ try
+ {
+ bridge.start();
+ assertFalse(bridge.isStarted());
+ assertTrue(bridge.isFailed());
+
+ //Restart the server
+ server1.start();
+
+ context1 = new InVMContext();
+ jmsServer1 = JMSServerManagerImpl.newJMSServerManagerImpl(server1.getServer());
+ jmsServer1.start();
+ jmsServer1.setContext(context1);
+
+ createQueue("targetQueue", 1);
+ setUpAdministeredObjects();
+
+ Thread.sleep(3000);
+
+ assertTrue(bridge.isStarted());
+ assertFalse(bridge.isFailed());
+ }
+ finally
+ {
+ try
+ {
+ bridge.stop();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to stop bridge", e);
+ }
+ }
+ }
+
+ /*
+ * Send some messages
+ * Crash the destination server
+ * Bring the destination server back up
+ * Send some more messages
+ * Verify all messages are received
+ */
+ private void testCrashAndReconnectDestBasic(QualityOfServiceMode qosMode, boolean persistent) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 1000, -1, qosMode,
+ 10, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+ bridge.start();
+
+ final int NUM_MESSAGES = 10;
+
+ //Send some messages
+
+ sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2 , persistent);
+
+ //Verify none are received
+
+ checkEmpty(targetQueue, 1);
+
+ //Now crash the dest server
+
+ log.info("About to crash server");
+
+ server1.stop();
+
+ //Wait a while before starting up to simulate the dest being down for a while
+ log.info("Waiting 5 secs before bringing server back up");
+ Thread.sleep(5000);
+ log.info("Done wait");
+
+ //Restart the server
+
+ log.info("Restarting server");
+
+ server1.start();
+
+ context1 = new InVMContext();
+ jmsServer1 = JMSServerManagerImpl.newJMSServerManagerImpl(server1.getServer());
+ jmsServer1.start();
+ jmsServer1.setContext(context1);
+
+ createQueue("targetQueue", 1);
+
+ setUpAdministeredObjects();
+
+ //Send some more messages
+
+ log.info("Sending more messages");
+
+ sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
+
+ log.info("Sent messages");
+
+ checkMessagesReceived(cf1, targetQueue, qosMode, NUM_MESSAGES, false);
+ }
+ finally
+ {
+
+ if (bridge != null)
+ {
+ try
+ {
+ bridge.stop();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to stop bridge", e);
+ }
+ }
+ }
+ }
+
+ /*
+ * Send some messages
+ * Crash the destination server
+ * Set the max batch time such that it will attempt to send the batch while the dest server is down
+ * Bring up the destination server
+ * Send some more messages
+ * Verify all messages are received
+ */
+ private void testCrashAndReconnectDestCrashBeforePrepare(boolean persistent) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 1000, -1, QualityOfServiceMode.ONCE_AND_ONLY_ONCE,
+ 10, 5000,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ final int NUM_MESSAGES = 10;
+ //Send some messages
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
+
+ //verify none are received
+
+ checkEmpty(targetQueue, 1);
+
+ //Now crash the dest server
+
+ log.info("About to crash server");
+
+ server1.stop();
+
+ //Wait a while before starting up to simulate the dest being down for a while
+ log.info("Waiting 5 secs before bringing server back up");
+ Thread.sleep(5000);
+ log.info("Done wait");
+
+ //Restart the server
+ server1.start();
+
+ context1 = new InVMContext();
+ jmsServer1 = JMSServerManagerImpl.newJMSServerManagerImpl(server1.getServer());
+ jmsServer1.start();
+ jmsServer1.setContext(context1);
+
+ createQueue("targetQueue", 1);
+
+ setUpAdministeredObjects();
+
+ sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
+
+ checkMessagesReceived(cf1, targetQueue, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, NUM_MESSAGES, false);
+ }
+ finally
+ {
+
+ if (bridge != null)
+ {
+ try
+ {
+ bridge.stop();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to stop bridge", e);
+ }
+ }
+
+ }
+ }
+
+ // Inner classes -------------------------------------------------------------------
+
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/BridgeTest.java 2009-03-04 07:37:42 UTC (rev 5986)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -1,1584 +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.test.messaging.jms.bridge;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.Connection;
-import javax.jms.DeliveryMode;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
-import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
-import org.jboss.messaging.jms.client.JBossMessage;
-import org.jboss.tm.TransactionManagerLocator;
-
-/**
- * A BridgeTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class BridgeTest extends BridgeTestBase
-{
- private static final Logger log = Logger.getLogger(BridgeTest.class);
-
- public BridgeTest(String name)
- {
- super(name);
- }
-
- // MaxBatchSize but no MaxBatchTime
-
- public void testNoMaxBatchTime_AtMostOnce_P() throws Exception
- {
- testNoMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, true);
- }
-
- public void testNoMaxBatchTime_DuplicatesOk_P() throws Exception
- {
- testNoMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, true);
- }
-
- public void testNoMaxBatchTime_OnceAndOnlyOnce_P() throws Exception
- {
- testNoMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
- }
-
- public void testNoMaxBatchTime_AtMostOnce_NP() throws Exception
- {
- testNoMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, false);
- }
-
- public void testNoMaxBatchTime_DuplicatesOk_NP() throws Exception
- {
- testNoMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, false);
- }
-
- public void testNoMaxBatchTime_OnceAndOnlyOnce_NP() throws Exception
- {
- testNoMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
- }
-
- //Same server
-
- // MaxBatchSize but no MaxBatchTime
-
- public void testNoMaxBatchTimeSameServer_AtMostOnce_P() throws Exception
- {
- testNoMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, true);
- }
-
- public void testNoMaxBatchTimeSameServer_DuplicatesOk_P() throws Exception
- {
- testNoMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, true);
- }
-
- public void testNoMaxBatchTimeSameServer_OnceAndOnlyOnce_P() throws Exception
- {
- testNoMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
- }
-
- public void testNoMaxBatchTimeSameServer_AtMostOnce_NP() throws Exception
- {
- testNoMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, false);
- }
-
- public void testNoMaxBatchTimeSameServer_DuplicatesOk_NP() throws Exception
- {
- testNoMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, false);
- }
-
- public void testNoMaxBatchTimeSameServer_OnceAndOnlyOnce_NP() throws Exception
- {
- testNoMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
- }
-
-
- // MaxBatchTime but no MaxBatchSize
-
- public void testMaxBatchTime_AtMostOnce_P() throws Exception
- {
- this.testMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, true);
- }
-
- public void testMaxBatchTime_DuplicatesOk_P() throws Exception
- {
- this.testMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, true);
- }
-
- public void testMaxBatchTime_OnceAndOnlyOnce_P() throws Exception
- {
- testMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
- }
-
- public void testMaxBatchTime_AtMostOnce_NP() throws Exception
- {
- this.testMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, false);
- }
-
- public void testMaxBatchTime_DuplicatesOk_NP() throws Exception
- {
- this.testMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, false);
- }
-
- public void testMaxBatchTime_OnceAndOnlyOnce_NP() throws Exception
- {
- testMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
- }
-
- // Same server
-
- // MaxBatchTime but no MaxBatchSize
-
- public void testMaxBatchTimeSameServer_AtMostOnce_P() throws Exception
- {
- this.testMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, true);
- }
-
- public void testMaxBatchTimeSameServer_DuplicatesOk_P() throws Exception
- {
- this.testMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, true);
- }
-
- public void testMaxBatchTimeSameServer_OnceAndOnlyOnce_P() throws Exception
- {
- testMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
- }
-
- public void testMaxBatchTimeSameServer_AtMostOnce_NP() throws Exception
- {
- this.testMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, false);
- }
-
- public void testMaxBatchTimeSameServer_DuplicatesOk_NP() throws Exception
- {
- this.testMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, false);
- }
-
- public void testMaxBatchTimeSameServer_OnceAndOnlyOnce_NP() throws Exception
- {
- testMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
- }
-
- // Stress with batch size of 50
-
- public void testStress_AtMostOnce_P_50() throws Exception
- {
- testStress(QualityOfServiceMode.AT_MOST_ONCE, true, 50);
- }
-
- public void testStress_DuplicatesOk_P_50() throws Exception
- {
- testStress(QualityOfServiceMode.DUPLICATES_OK, true, 50);
- }
-
- public void testStress_OnceAndOnlyOnce_P_50() throws Exception
- {
- testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 50);
- }
-
- public void testStress_AtMostOnce_NP_50() throws Exception
- {
- testStress(QualityOfServiceMode.AT_MOST_ONCE, false, 50);
- }
-
- public void testStress_DuplicatesOk_NP_50() throws Exception
- {
- testStress(QualityOfServiceMode.DUPLICATES_OK, false, 50);
- }
-
- public void testStress_OnceAndOnlyOnce_NP_50() throws Exception
- {
- testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 50);
- }
-
- // Stress with batch size of 1
-
- public void testStress_AtMostOnce_P_1() throws Exception
- {
- testStress(QualityOfServiceMode.AT_MOST_ONCE, true, 1);
- }
-
- public void testStress_DuplicatesOk_P_1() throws Exception
- {
- testStress(QualityOfServiceMode.DUPLICATES_OK, true, 1);
- }
-
- public void testStress_OnceAndOnlyOnce_P_1() throws Exception
- {
- testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 1);
- }
-
- public void testStress_AtMostOnce_NP_1() throws Exception
- {
- testStress(QualityOfServiceMode.AT_MOST_ONCE, false, 1);
- }
-
- public void testStress_DuplicatesOk_NP_1() throws Exception
- {
- testStress(QualityOfServiceMode.DUPLICATES_OK, false, 1);
- }
-
- public void testStress_OnceAndOnlyOnce_NP_1() throws Exception
- {
- testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 1);
- }
-
- // Max batch time
-
- public void testStressMaxBatchTime_OnceAndOnlyOnce_NP() throws Exception
- {
- this.testStressBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 200);
- }
-
- public void testStressMaxBatchTime_OnceAndOnlyOnce_P() throws Exception
- {
- this.testStressBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 200);
- }
-
-
- // Stress on same server
-
- // Stress with batch size of 50
-
- public void testStressSameServer_AtMostOnce_P_50() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, true, 50);
- }
-
- public void testStressSameServer_DuplicatesOk_P_50() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, true, 50);
- }
-
- public void testStressSameServer_OnceAndOnlyOnce_P_50() throws Exception
- {
- testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 50);
- }
-
- public void testStressSameServer_AtMostOnce_NP_50() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, false, 50);
- }
-
- public void testStressSameServer_DuplicatesOk_NP_50() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, false, 50);
- }
-
- public void testStressSameServer_OnceAndOnlyOnce_NP_50() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 50);
- }
-
- // Stress with batch size of 1
-
- public void testStressSameServer_AtMostOnce_P_1() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, true, 1);
- }
-
- public void testStressSameServer_DuplicatesOk_P_1() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, true, 1);
- }
-
- public void testStressSameServer_OnceAndOnlyOnce_P_1() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 1);
- }
-
- public void testStressSameServer_AtMostOnce_NP_1() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, false, 1);
- }
-
- public void testStressSameServer_DuplicatesOk_NP_1() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, false, 1);
- }
-
- public void testStressSameServer_OnceAndOnlyOnce_NP_1() throws Exception
- {
- testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 1);
- }
-
- public void testParams() throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- QualityOfServiceMode qosMode = QualityOfServiceMode.AT_MOST_ONCE;
-
- int batchSize = 10;
-
- int maxBatchTime = -1;
-
- String sourceUsername = null;
-
- String sourcePassword = null;
-
- String destUsername = null;
-
- String destPassword = null;
-
- String selector = null;
-
- long failureRetryInterval = 5000;
-
- int maxRetries = 10;
-
- String subName = null;
-
- String clientID = null;
-
- try
- {
- bridge= new BridgeImpl(null, cff1, sourceQueueFactory, targetQueueFactory,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, failureRetryInterval, maxRetries, qosMode,
- batchSize, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, null, sourceQueueFactory, targetQueueFactory,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, failureRetryInterval, maxRetries, qosMode,
- batchSize, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, cff1, null, targetQueueFactory,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, failureRetryInterval, maxRetries, qosMode,
- batchSize, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, null,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, failureRetryInterval, maxRetries, qosMode,
- batchSize, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, -2, maxRetries, qosMode,
- batchSize, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, -1, 10, qosMode,
- batchSize, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, null,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, failureRetryInterval, maxRetries, qosMode,
- 0, maxBatchTime,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- try
- {
- bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, null,
- sourceUsername, sourcePassword, destUsername, destPassword,
- selector, failureRetryInterval, maxRetries, qosMode,
- batchSize, -2,
- subName, clientID, false);
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- public void testSelector() throws Exception
- {
- BridgeImpl bridge = null;
-
- Connection connSource = null;
-
- Connection connTarget = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- String selector = "vegetable='radish'";
-
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- selector, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- null, null, false);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(sourceQueue);
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSend.createTextMessage("message" + i);
-
- if (i >= NUM_MESSAGES / 2)
- {
- tm.setStringProperty("vegetable", "radish");
- }
- else
- {
- tm.setStringProperty("vegetable", "cauliflower");
- }
-
- prod.send(tm);
- }
-
- connTarget = cf1.createConnection();
-
- Session sessRec = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sessRec.createConsumer(targetQueue);
-
- connTarget.start();
-
- for (int i = NUM_MESSAGES / 2 ; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
- }
-
- Message m = cons.receive(1000);
-
- assertNull(m);
-
- }
- finally
- {
- if (connSource != null)
- {
- connSource.close();
- }
-
- if (connTarget != null)
- {
- connTarget.close();
- }
-
- if (bridge != null)
- {
- bridge.stop();
- }
-
- removeAllMessages(sourceQueue.getQueueName(), true, 0);
- }
- }
-
- public void testStartBridgeWithJTATransactionAlreadyRunning() throws Exception
- {
- BridgeImpl bridge = null;
-
- Transaction toResume = null;
-
- Transaction started = null;
-
- TransactionManager mgr = TransactionManagerLocator.getInstance().locate();
-
- try
- {
-
- toResume = mgr.suspend();
-
- mgr.begin();
-
- started = mgr.getTransaction();
-
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- null, null, false);
-
- bridge.start();
-
- this.sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
- }
- finally
- {
- if (started != null)
- {
- try
- {
- started.rollback();
- }
- catch (Exception e)
- {
- log.error("Failed to rollback", e);
- }
- }
-
- if (toResume != null)
- {
- try
- {
- mgr.resume(toResume);
- }
- catch (Exception e)
- {
- log.error("Failed to resume", e);
- }
- }
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- public void testNonDurableSubscriber() throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- null, null, false);
-
- bridge.start();
-
- sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);
-
- checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- public void testDurableSubscriber() throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- "subTest", "clientid123", false);
-
- bridge.start();
-
- sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, true);
-
- checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
-
- //Now unsubscribe
- Connection conn = cf0.createConnection();
- conn.setClientID("clientid123");
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- sess.unsubscribe("subTest");
- conn.close();
- }
- }
-
- public void testMessageIDInHeaderOn() throws Exception
- {
- messageIDInHeader(true);
- }
-
- public void testMessageIDInHeaderOff() throws Exception
- {
- messageIDInHeader(false);
- }
-
- private void messageIDInHeader(boolean on) throws Exception
- {
- BridgeImpl bridge = null;
-
- Connection connSource = null;
-
- Connection connTarget = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- null, null, on);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- connTarget = cf1.createConnection();
-
- log.trace("Sending " + NUM_MESSAGES + " messages");
-
- List ids1 = new ArrayList();
-
- Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSource.createProducer(sourceQueue);
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSource.createTextMessage("message" + i);
-
- //We add some headers to make sure they get passed through ok
- tm.setStringProperty("wib", "uhuh");
- tm.setBooleanProperty("cheese", true);
- tm.setIntProperty("Sausages", 23);
-
- //We add some JMSX ones too
-
- tm.setStringProperty("JMSXGroupID", "mygroup543");
- tm.setIntProperty("JMSXGroupSeq", 777);
-
- prod.send(tm);
-
- ids1.add(tm.getJMSMessageID());
- }
-
- log.trace("Sent the first messages");
-
- Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sessTarget.createConsumer(targetQueue);
-
- connTarget.start();
-
- List msgs = new ArrayList();
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(5000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
-
- assertEquals("uhuh", tm.getStringProperty("wib"));
- assertTrue(tm.getBooleanProperty("cheese"));
- assertEquals(23, tm.getIntProperty("Sausages"));
-
- assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
- assertEquals(777, tm.getIntProperty("JMSXGroupSeq"));
-
- if (on)
- {
- String header = tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
-
- assertNotNull(header);
-
- assertEquals(ids1.get(i), header);
-
- msgs.add(tm);
- }
- }
-
- if (on)
- {
- //Now we send them again back to the source
-
- Iterator iter = msgs.iterator();
-
- List ids2 = new ArrayList();
-
- while (iter.hasNext())
- {
- Message msg = (Message)iter.next();
-
- prod.send(msg);
-
- ids2.add(msg.getJMSMessageID());
- }
-
- //And consume them again
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(5000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
-
- assertEquals("uhuh", tm.getStringProperty("wib"));
- assertTrue(tm.getBooleanProperty("cheese"));
- assertEquals(23, tm.getIntProperty("Sausages"));
-
- assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
- assertEquals(777, tm.getIntProperty("JMSXGroupSeq"));
-
- String header = tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
-
- assertNotNull(header);
-
- assertEquals(ids1.get(i) + "," + ids2.get(i), header);
- }
- }
-
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
-
- if (connSource != null)
- {
- connSource.close();
- }
-
- if (connTarget != null)
- {
- connTarget.close();
- }
- }
- }
-
-
- public void testPropertiesPreservedPOn() throws Exception
- {
- propertiesPreserved(true, true);
- }
-
- public void testPropertiesPreservedNPoff() throws Exception
- {
- propertiesPreserved(false, true);
- }
-
- public void testPropertiesPreservedNPOn() throws Exception
- {
- propertiesPreserved(false, true);
- }
-
- public void testPropertiesPreservedPoff() throws Exception
- {
- propertiesPreserved(true, true);
- }
-
- private void propertiesPreserved(boolean persistent, boolean messageIDInHeader) throws Exception
- {
- BridgeImpl bridge = null;
-
- Connection connSource = null;
-
- Connection connTarget = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- null, null, messageIDInHeader);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- connTarget = cf1.createConnection();
-
- log.trace("Sending " + NUM_MESSAGES + " messages");
-
- Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sessTarget.createConsumer(targetQueue);
-
- connTarget.start();
-
- MessageProducer prod = sessSource.createProducer(sourceQueue);
-
- prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
-
-
-
- TextMessage tm = sessSource.createTextMessage("blahmessage");
-
- prod.setPriority(7);
-
- prod.setTimeToLive(1 * 60 * 60 * 1000);
-
- prod.send(tm);
-
- long expiration = tm.getJMSExpiration();
-
- assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
-
- tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("blahmessage", tm.getText());
-
- assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
-
- assertEquals(7, tm.getJMSPriority());
-
- assertTrue(Math.abs(expiration - tm.getJMSExpiration()) < 100);
-
- Message m = cons.receive(5000);
-
- assertNull(m);
-
-
- //Now do one with expiration = 0
-
-
- tm = sessSource.createTextMessage("blahmessage2");
-
- prod.setPriority(7);
-
- prod.setTimeToLive(0);
-
- prod.send(tm);
-
- assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
-
- tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("blahmessage2", tm.getText());
-
- assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
-
- assertEquals(7, tm.getJMSPriority());
-
- assertEquals(0, tm.getJMSExpiration());
-
- m = cons.receive(5000);
-
- assertNull(m);
-
- tm = sessSource.createTextMessage("blahmessage3");
-
- final boolean myBool = false;
- final byte myByte = (byte)23;
- final double myDouble = 17625765d;
- final float myFloat = 87127.23f;
- final int myInt = 123;
- final long myLong = 81728712;
- final short myShort = (short)88;
- final String myString = "ojweodewj";
- final String myJMSX = "aardvark";
-
- tm.setBooleanProperty("mybool", myBool);
- tm.setByteProperty("mybyte", myByte);
- tm.setDoubleProperty("mydouble", myDouble);
- tm.setFloatProperty("myfloat", myFloat);
- tm.setIntProperty("myint", myInt);
- tm.setLongProperty("mylong", myLong);
- tm.setShortProperty("myshort", myShort);
- tm.setStringProperty("mystring", myString);
-
- tm.setStringProperty("JMSXMyNaughtyJMSXProperty", myJMSX);
-
- prod.send(tm);
-
- tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("blahmessage3", tm.getText());
-
- assertEquals(myBool, tm.getBooleanProperty("mybool"));
- assertEquals(myByte, tm.getByteProperty("mybyte"));
- assertEquals(myDouble, tm.getDoubleProperty("mydouble"));
- assertEquals(myFloat, tm.getFloatProperty("myfloat"));
- assertEquals(myInt, tm.getIntProperty("myint"));
- assertEquals(myLong, tm.getLongProperty("mylong"));
- assertEquals(myShort, tm.getShortProperty("myshort"));
- assertEquals(myString, tm.getStringProperty("mystring"));
- assertEquals(myJMSX, tm.getStringProperty("JMSXMyNaughtyJMSXProperty"));
-
- m = cons.receive(5000);
-
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
-
- if (connSource != null)
- {
- connSource.close();
- }
-
- if (connTarget != null)
- {
- connTarget.close();
- }
- }
- }
-
- public void testNoMessageIDInHeader() throws Exception
- {
- BridgeImpl bridge = null;
-
- Connection connSource = null;
-
- Connection connTarget = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
- 1, -1,
- null, null, false);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- connTarget = cf1.createConnection();
-
- log.trace("Sending " + NUM_MESSAGES + " messages");
-
- Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSource.createProducer(sourceQueue);
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = sessSource.createTextMessage("message" + i);
-
- //We add some headers to make sure they get passed through ok
- tm.setStringProperty("wib", "uhuh");
- tm.setBooleanProperty("cheese", true);
- tm.setIntProperty("Sausages", 23);
-
- prod.send(tm);
- }
-
- log.trace("Sent the first messages");
-
- Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sessTarget.createConsumer(targetQueue);
-
- connTarget.start();
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(5000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
-
- assertEquals("uhuh", tm.getStringProperty("wib"));
- assertTrue(tm.getBooleanProperty("cheese"));
- assertEquals(23, tm.getIntProperty("Sausages"));
-
- String header = tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
-
- assertNull(header);
- }
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
-
- if (connSource != null)
- {
- connSource.close();
- }
-
- if (connTarget != null)
- {
- connTarget.close();
- }
- }
- }
-
-
- // Private -------------------------------------------------------------------------------
-
- private void testStress(QualityOfServiceMode qosMode, boolean persistent, int batchSize) throws Exception
- {
- Connection connSource = null;
-
- BridgeImpl bridge = null;
-
- Thread t = null;
-
- try
- {
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, qosMode,
- batchSize, -1,
- null, null, false);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(sourceQueue);
-
- final int NUM_MESSAGES = 250;
-
- StressSender sender = new StressSender();
- sender.sess = sessSend;
- sender.prod = prod;
- sender.numMessages = NUM_MESSAGES;
- prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
-
- t = new Thread(sender);
-
- t.start();
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
-
- t.join();
-
- if (sender.ex != null)
- {
- //An error occurred during the send
- throw sender.ex;
- }
-
- }
- finally
- {
- if (t != null)
- {
- t.join(10000);
- }
-
- if (connSource != null)
- {
- try
- {
- connSource.close();
- }
- catch (Exception e)
- {
- log.error("Failed to close connection", e);
- }
- }
-
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- private void testStressBatchTime(QualityOfServiceMode qosMode, boolean persistent, int maxBatchTime) throws Exception
- {
- Connection connSource = null;
-
- BridgeImpl bridge = null;
-
- Thread t = null;
-
- try
- {
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, qosMode,
- 2, maxBatchTime,
- null, null, false);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(sourceQueue);
-
- final int NUM_MESSAGES = 5000;
-
- StressSender sender = new StressSender();
- sender.sess = sessSend;
- sender.prod = prod;
- sender.numMessages = NUM_MESSAGES;
- prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
-
- t = new Thread(sender);
-
- t.start();
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
-
- t.join();
-
- if (sender.ex != null)
- {
- //An error occurred during the send
- throw sender.ex;
- }
-
- }
- finally
- {
- if (t != null)
- {
- t.join(10000);
- }
-
- if (connSource != null)
- {
- try
- {
- connSource.close();
- }
- catch (Exception e)
- {
- log.error("Failed to close connection", e);
- }
- }
-
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- //Both source and destination on same rm
- private void testStressSameServer(QualityOfServiceMode qosMode, boolean persistent, int batchSize) throws Exception
- {
- Connection connSource = null;
-
- BridgeImpl bridge = null;
-
- Thread t = null;
-
- try
- {
- bridge = new BridgeImpl(cff0, cff0, sourceQueueFactory, localTargetQueueFactory,
- null, null, null, null,
- null, 5000, 10, qosMode,
- batchSize, -1,
- null, null, false);
-
- bridge.start();
-
- connSource = cf0.createConnection();
-
- Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(sourceQueue);
-
- final int NUM_MESSAGES = 2000;
-
- StressSender sender = new StressSender();
- sender.sess = sessSend;
- sender.prod = prod;
- sender.numMessages = NUM_MESSAGES;
- prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
-
- t = new Thread(sender);
-
- t.start();
-
- this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
-
- t.join();
-
- if (sender.ex != null)
- {
- //An error occurred during the send
- throw sender.ex;
- }
-
- }
- finally
- {
- if (t != null)
- {
- t.join(10000);
- }
-
- if (connSource != null)
- {
- try
- {
- connSource.close();
- }
- catch (Exception e)
- {
- log.error("Failed to close connection", e);
- }
- }
-
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
-
- private void testNoMaxBatchTime(QualityOfServiceMode qosMode, boolean persistent) throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 5000, 10, qosMode,
- NUM_MESSAGES, -1,
- null, null, false);
-
- bridge.start();
-
- //Send half the messges
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
-
- //Verify none are received
-
- this.checkEmpty(targetQueue, 1);
-
- //Send the other half
-
- this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
-
- //This should now be receivable
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
-
- //Send another batch with one more than batch size
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent);
-
- //Make sure only batch size are received
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
-
- //Final batch
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent);
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, NUM_MESSAGES, 1);
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES - 1);
- }
- finally
- {
- if (bridge != null)
- {
- log.info("Stopping bridge");
- bridge.stop();
- }
- }
- }
-
- private void testNoMaxBatchTimeSameServer(QualityOfServiceMode qosMode, boolean persistent) throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- final int NUM_MESSAGES = 10;
-
- bridge = new BridgeImpl(cff0, cff0, sourceQueueFactory, localTargetQueueFactory,
- null, null, null, null,
- null, 5000, 10, qosMode,
- NUM_MESSAGES, -1,
- null, null, false);
-
- bridge.start();
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
-
- this.checkEmpty(targetQueue, 1);
-
- //Send the other half
-
- this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES /2, persistent);
-
-
- //This should now be receivable
-
- this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
-
- this.checkEmpty(localTargetQueue, 0);
-
- this.checkEmpty(sourceQueue, 0);
-
- //Send another batch with one more than batch size
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent);
-
- //Make sure only batch size are received
-
- this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
-
- //Final batch
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent);
-
- this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, NUM_MESSAGES, 1);
-
- this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES - 1);
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- private void testMaxBatchTime(QualityOfServiceMode qosMode, boolean persistent) throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- final long MAX_BATCH_TIME = 3000;
-
- final int MAX_BATCH_SIZE = 100000; // something big so it won't reach it
-
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 3000, 10, qosMode,
- MAX_BATCH_SIZE, MAX_BATCH_TIME,
- null, null, false);
-
- bridge.start();
-
- final int NUM_MESSAGES = 10;
-
- //Send some message
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent);
-
- //Verify none are received
-
- this.checkEmpty(targetQueue, 1);
-
- //Messages should now be receivable
-
- this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
- private void testMaxBatchTimeSameServer(QualityOfServiceMode qosMode, boolean persistent) throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- final long MAX_BATCH_TIME = 3000;
-
- final int MAX_BATCH_SIZE = 100000; // something big so it won't reach it
-
- bridge = new BridgeImpl(cff0, cff0, sourceQueueFactory, localTargetQueueFactory,
- null, null, null, null,
- null, 3000, 10, qosMode,
- MAX_BATCH_SIZE, MAX_BATCH_TIME,
- null, null, false);
-
- bridge.start();
-
- final int NUM_MESSAGES = 10;
-
- //Send some message
-
- //Send some message
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent);
-
- //Verify none are received
-
- this.checkEmpty(localTargetQueue, 0);;
-
- //Messages should now be receivable
-
- this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
- }
- finally
- {
- if (bridge != null)
- {
- bridge.stop();
- }
- }
- }
-
-
- // Inner classes -------------------------------------------------------------------
-
- private static class StressSender implements Runnable
- {
- int numMessages;
-
- Session sess;
-
- MessageProducer prod;
-
- Exception ex;
-
- public void run()
- {
- try
- {
- for (int i = 0; i < numMessages; i++)
- {
- TextMessage tm = sess.createTextMessage("message" + i);
-
- prod.send(tm);
-
- log.trace("Sent message " + i);
- }
- }
- catch (Exception e)
- {
- log.error("Failed to send", e);
- ex = e;
- }
- }
-
- }
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java (from rev 6050, trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/BridgeTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -0,0 +1,1591 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.integration.jms.bridge;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
+import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
+import org.jboss.messaging.jms.client.JBossMessage;
+
+/**
+ * A BridgeTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ *
+ */
+public class BridgeTest extends BridgeTestBase
+{
+ private static final Logger log = Logger.getLogger(BridgeTest.class);
+
+ // MaxBatchSize but no MaxBatchTime
+
+ public void testNoMaxBatchTime_AtMostOnce_P() throws Exception
+ {
+ testNoMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, true);
+ }
+
+ public void testNoMaxBatchTime_DuplicatesOk_P() throws Exception
+ {
+ testNoMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, true);
+ }
+
+ public void testNoMaxBatchTime_OnceAndOnlyOnce_P() throws Exception
+ {
+ testNoMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
+ }
+
+ public void testNoMaxBatchTime_AtMostOnce_NP() throws Exception
+ {
+ testNoMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, false);
+ }
+
+ public void testNoMaxBatchTime_DuplicatesOk_NP() throws Exception
+ {
+ testNoMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, false);
+ }
+
+ public void testNoMaxBatchTime_OnceAndOnlyOnce_NP() throws Exception
+ {
+ testNoMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
+ }
+
+ //Same server
+
+ // MaxBatchSize but no MaxBatchTime
+
+ public void testNoMaxBatchTimeSameServer_AtMostOnce_P() throws Exception
+ {
+ testNoMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, true);
+ }
+
+ public void testNoMaxBatchTimeSameServer_DuplicatesOk_P() throws Exception
+ {
+ testNoMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, true);
+ }
+
+ public void testNoMaxBatchTimeSameServer_OnceAndOnlyOnce_P() throws Exception
+ {
+ testNoMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
+ }
+
+ public void testNoMaxBatchTimeSameServer_AtMostOnce_NP() throws Exception
+ {
+ testNoMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, false);
+ }
+
+ public void testNoMaxBatchTimeSameServer_DuplicatesOk_NP() throws Exception
+ {
+ testNoMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, false);
+ }
+
+ public void testNoMaxBatchTimeSameServer_OnceAndOnlyOnce_NP() throws Exception
+ {
+ testNoMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
+ }
+
+
+ // MaxBatchTime but no MaxBatchSize
+
+ public void testMaxBatchTime_AtMostOnce_P() throws Exception
+ {
+ this.testMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, true);
+ }
+
+ public void testMaxBatchTime_DuplicatesOk_P() throws Exception
+ {
+ this.testMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, true);
+ }
+
+ public void testMaxBatchTime_OnceAndOnlyOnce_P() throws Exception
+ {
+ testMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
+ }
+
+ public void testMaxBatchTime_AtMostOnce_NP() throws Exception
+ {
+ this.testMaxBatchTime(QualityOfServiceMode.AT_MOST_ONCE, false);
+ }
+
+ public void testMaxBatchTime_DuplicatesOk_NP() throws Exception
+ {
+ this.testMaxBatchTime(QualityOfServiceMode.DUPLICATES_OK, false);
+ }
+
+ public void testMaxBatchTime_OnceAndOnlyOnce_NP() throws Exception
+ {
+ testMaxBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
+ }
+
+ // Same server
+
+ // MaxBatchTime but no MaxBatchSize
+
+ public void testMaxBatchTimeSameServer_AtMostOnce_P() throws Exception
+ {
+ this.testMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, true);
+ }
+
+ public void testMaxBatchTimeSameServer_DuplicatesOk_P() throws Exception
+ {
+ this.testMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, true);
+ }
+
+ public void testMaxBatchTimeSameServer_OnceAndOnlyOnce_P() throws Exception
+ {
+ testMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
+ }
+
+ public void testMaxBatchTimeSameServer_AtMostOnce_NP() throws Exception
+ {
+ this.testMaxBatchTimeSameServer(QualityOfServiceMode.AT_MOST_ONCE, false);
+ }
+
+ public void testMaxBatchTimeSameServer_DuplicatesOk_NP() throws Exception
+ {
+ this.testMaxBatchTimeSameServer(QualityOfServiceMode.DUPLICATES_OK, false);
+ }
+
+ public void testMaxBatchTimeSameServer_OnceAndOnlyOnce_NP() throws Exception
+ {
+ testMaxBatchTimeSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
+ }
+
+ // Stress with batch size of 50
+
+ public void testStress_AtMostOnce_P_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.AT_MOST_ONCE, true, 50);
+ }
+
+ public void testStress_DuplicatesOk_P_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.DUPLICATES_OK, true, 50);
+ }
+
+ public void testStress_OnceAndOnlyOnce_P_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 50);
+ }
+
+ public void testStress_AtMostOnce_NP_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.AT_MOST_ONCE, false, 50);
+ }
+
+ public void testStress_DuplicatesOk_NP_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.DUPLICATES_OK, false, 50);
+ }
+
+ public void testStress_OnceAndOnlyOnce_NP_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 50);
+ }
+
+ // Stress with batch size of 1
+
+ public void testStress_AtMostOnce_P_1() throws Exception
+ {
+ testStress(QualityOfServiceMode.AT_MOST_ONCE, true, 1);
+ }
+
+ public void testStress_DuplicatesOk_P_1() throws Exception
+ {
+ testStress(QualityOfServiceMode.DUPLICATES_OK, true, 1);
+ }
+
+ public void testStress_OnceAndOnlyOnce_P_1() throws Exception
+ {
+ testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 1);
+ }
+
+ public void testStress_AtMostOnce_NP_1() throws Exception
+ {
+ testStress(QualityOfServiceMode.AT_MOST_ONCE, false, 1);
+ }
+
+ public void testStress_DuplicatesOk_NP_1() throws Exception
+ {
+ testStress(QualityOfServiceMode.DUPLICATES_OK, false, 1);
+ }
+
+ public void testStress_OnceAndOnlyOnce_NP_1() throws Exception
+ {
+ testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 1);
+ }
+
+ // Max batch time
+
+ public void testStressMaxBatchTime_OnceAndOnlyOnce_NP() throws Exception
+ {
+ this.testStressBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 200);
+ }
+
+ public void testStressMaxBatchTime_OnceAndOnlyOnce_P() throws Exception
+ {
+ this.testStressBatchTime(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 200);
+ }
+
+
+ // Stress on same server
+
+ // Stress with batch size of 50
+
+ public void testStressSameServer_AtMostOnce_P_50() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, true, 50);
+ }
+
+ public void testStressSameServer_DuplicatesOk_P_50() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, true, 50);
+ }
+
+ public void testStressSameServer_OnceAndOnlyOnce_P_50() throws Exception
+ {
+ testStress(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 50);
+ }
+
+ public void testStressSameServer_AtMostOnce_NP_50() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, false, 50);
+ }
+
+ public void testStressSameServer_DuplicatesOk_NP_50() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, false, 50);
+ }
+
+ public void testStressSameServer_OnceAndOnlyOnce_NP_50() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 50);
+ }
+
+ // Stress with batch size of 1
+
+ public void testStressSameServer_AtMostOnce_P_1() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, true, 1);
+ }
+
+ public void testStressSameServer_DuplicatesOk_P_1() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, true, 1);
+ }
+
+ public void testStressSameServer_OnceAndOnlyOnce_P_1() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, 1);
+ }
+
+ public void testStressSameServer_AtMostOnce_NP_1() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.AT_MOST_ONCE, false, 1);
+ }
+
+ public void testStressSameServer_DuplicatesOk_NP_1() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.DUPLICATES_OK, false, 1);
+ }
+
+ public void testStressSameServer_OnceAndOnlyOnce_NP_1() throws Exception
+ {
+ testStressSameServer(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, 1);
+ }
+
+ public void testParams() throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ QualityOfServiceMode qosMode = QualityOfServiceMode.AT_MOST_ONCE;
+
+ int batchSize = 10;
+
+ int maxBatchTime = -1;
+
+ String sourceUsername = null;
+
+ String sourcePassword = null;
+
+ String destUsername = null;
+
+ String destPassword = null;
+
+ String selector = null;
+
+ long failureRetryInterval = 5000;
+
+ int maxRetries = 10;
+
+ String subName = null;
+
+ String clientID = null;
+
+ try
+ {
+ bridge= new BridgeImpl(null, cff1, sourceQueueFactory, targetQueueFactory,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, failureRetryInterval, maxRetries, qosMode,
+ batchSize, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, null, sourceQueueFactory, targetQueueFactory,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, failureRetryInterval, maxRetries, qosMode,
+ batchSize, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, cff1, null, targetQueueFactory,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, failureRetryInterval, maxRetries, qosMode,
+ batchSize, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, null,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, failureRetryInterval, maxRetries, qosMode,
+ batchSize, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, -2, maxRetries, qosMode,
+ batchSize, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, -1, 10, qosMode,
+ batchSize, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, null,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, failureRetryInterval, maxRetries, qosMode,
+ 0, maxBatchTime,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ bridge= new BridgeImpl(cff0, cff1, sourceQueueFactory, null,
+ sourceUsername, sourcePassword, destUsername, destPassword,
+ selector, failureRetryInterval, maxRetries, qosMode,
+ batchSize, -2,
+ subName, clientID, false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ public void testSelector() throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ Connection connSource = null;
+
+ Connection connTarget = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ String selector = "vegetable='radish'";
+
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ selector, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(sourceQueue);
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = sessSend.createTextMessage("message" + i);
+
+ if (i >= NUM_MESSAGES / 2)
+ {
+ tm.setStringProperty("vegetable", "radish");
+ }
+ else
+ {
+ tm.setStringProperty("vegetable", "cauliflower");
+ }
+
+ prod.send(tm);
+ }
+
+ connTarget = cf1.createConnection();
+
+ Session sessRec = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sessRec.createConsumer(targetQueue);
+
+ connTarget.start();
+
+ for (int i = NUM_MESSAGES / 2 ; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+ }
+
+ Message m = cons.receive(1000);
+
+ assertNull(m);
+
+ }
+ finally
+ {
+ if (connSource != null)
+ {
+ connSource.close();
+ }
+
+ if (connTarget != null)
+ {
+ connTarget.close();
+ }
+
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+
+ removeAllMessages(sourceQueue.getQueueName(), 0);
+ }
+ }
+
+ public void testStartBridgeWithJTATransactionAlreadyRunning() throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ Transaction toResume = null;
+
+ Transaction started = null;
+
+ TransactionManager mgr = newTransactionManager();
+
+ try
+ {
+
+ toResume = mgr.suspend();
+
+ mgr.begin();
+
+ started = mgr.getTransaction();
+
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ null, null, false);
+ bridge.setTransactionManager(mgr);
+ bridge.start();
+
+ this.sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+ }
+ finally
+ {
+ if (started != null)
+ {
+ try
+ {
+ started.rollback();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to rollback", e);
+ }
+ }
+
+ if (toResume != null)
+ {
+ try
+ {
+ mgr.resume(toResume);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to resume", e);
+ }
+ }
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ public void testNonDurableSubscriber() throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);
+
+ checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ public void testDurableSubscriber() throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ "subTest", "clientid123", false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, true);
+
+ checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+
+ //Now unsubscribe
+ Connection conn = cf0.createConnection();
+ conn.setClientID("clientid123");
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ sess.unsubscribe("subTest");
+ conn.close();
+ }
+ }
+
+ public void testMessageIDInHeaderOn() throws Exception
+ {
+ messageIDInHeader(true);
+ }
+
+ public void testMessageIDInHeaderOff() throws Exception
+ {
+ messageIDInHeader(false);
+ }
+
+ private void messageIDInHeader(boolean on) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ Connection connSource = null;
+
+ Connection connTarget = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ null, null, on);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ connTarget = cf1.createConnection();
+
+ log.trace("Sending " + NUM_MESSAGES + " messages");
+
+ List ids1 = new ArrayList();
+
+ Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSource.createProducer(sourceQueue);
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = sessSource.createTextMessage("message" + i);
+
+ //We add some headers to make sure they get passed through ok
+ tm.setStringProperty("wib", "uhuh");
+ tm.setBooleanProperty("cheese", true);
+ tm.setIntProperty("Sausages", 23);
+
+ //We add some JMSX ones too
+
+ tm.setStringProperty("JMSXGroupID", "mygroup543");
+ tm.setIntProperty("JMSXGroupSeq", 777);
+
+ prod.send(tm);
+
+ ids1.add(tm.getJMSMessageID());
+ }
+
+ log.trace("Sent the first messages");
+
+ Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sessTarget.createConsumer(targetQueue);
+
+ connTarget.start();
+
+ List msgs = new ArrayList();
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(5000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+
+ assertEquals("uhuh", tm.getStringProperty("wib"));
+ assertTrue(tm.getBooleanProperty("cheese"));
+ assertEquals(23, tm.getIntProperty("Sausages"));
+
+ assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
+ assertEquals(777, tm.getIntProperty("JMSXGroupSeq"));
+
+ if (on)
+ {
+ String header = tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
+
+ assertNotNull(header);
+
+ assertEquals(ids1.get(i), header);
+
+ msgs.add(tm);
+ }
+ }
+
+ if (on)
+ {
+ //Now we send them again back to the source
+
+ Iterator iter = msgs.iterator();
+
+ List ids2 = new ArrayList();
+
+ while (iter.hasNext())
+ {
+ Message msg = (Message)iter.next();
+
+ prod.send(msg);
+
+ ids2.add(msg.getJMSMessageID());
+ }
+
+ //And consume them again
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(5000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+
+ assertEquals("uhuh", tm.getStringProperty("wib"));
+ assertTrue(tm.getBooleanProperty("cheese"));
+ assertEquals(23, tm.getIntProperty("Sausages"));
+
+ assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
+ assertEquals(777, tm.getIntProperty("JMSXGroupSeq"));
+
+ String header = tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
+
+ assertNotNull(header);
+
+ assertEquals(ids1.get(i) + "," + ids2.get(i), header);
+ }
+ }
+
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+
+ if (connSource != null)
+ {
+ connSource.close();
+ }
+
+ if (connTarget != null)
+ {
+ connTarget.close();
+ }
+ }
+ }
+
+
+ public void testPropertiesPreservedPOn() throws Exception
+ {
+ propertiesPreserved(true, true);
+ }
+
+ public void testPropertiesPreservedNPoff() throws Exception
+ {
+ propertiesPreserved(false, true);
+ }
+
+ public void testPropertiesPreservedNPOn() throws Exception
+ {
+ propertiesPreserved(false, true);
+ }
+
+ public void testPropertiesPreservedPoff() throws Exception
+ {
+ propertiesPreserved(true, true);
+ }
+
+ private void propertiesPreserved(boolean persistent, boolean messageIDInHeader) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ Connection connSource = null;
+
+ Connection connTarget = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ null, null, messageIDInHeader);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ connTarget = cf1.createConnection();
+
+ log.trace("Sending " + NUM_MESSAGES + " messages");
+
+ Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sessTarget.createConsumer(targetQueue);
+
+ connTarget.start();
+
+ MessageProducer prod = sessSource.createProducer(sourceQueue);
+
+ prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+
+
+
+ TextMessage tm = sessSource.createTextMessage("blahmessage");
+
+ prod.setPriority(7);
+
+ prod.setTimeToLive(1 * 60 * 60 * 1000);
+
+ prod.send(tm);
+
+ long expiration = tm.getJMSExpiration();
+
+ assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
+
+ tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("blahmessage", tm.getText());
+
+ assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
+
+ assertEquals(7, tm.getJMSPriority());
+
+ assertTrue(Math.abs(expiration - tm.getJMSExpiration()) < 100);
+
+ Message m = cons.receive(5000);
+
+ assertNull(m);
+
+
+ //Now do one with expiration = 0
+
+
+ tm = sessSource.createTextMessage("blahmessage2");
+
+ prod.setPriority(7);
+
+ prod.setTimeToLive(0);
+
+ prod.send(tm);
+
+ assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
+
+ tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("blahmessage2", tm.getText());
+
+ assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT, tm.getJMSDeliveryMode());
+
+ assertEquals(7, tm.getJMSPriority());
+
+ assertEquals(0, tm.getJMSExpiration());
+
+ m = cons.receive(5000);
+
+ assertNull(m);
+
+ tm = sessSource.createTextMessage("blahmessage3");
+
+ final boolean myBool = false;
+ final byte myByte = (byte)23;
+ final double myDouble = 17625765d;
+ final float myFloat = 87127.23f;
+ final int myInt = 123;
+ final long myLong = 81728712;
+ final short myShort = (short)88;
+ final String myString = "ojweodewj";
+ final String myJMSX = "aardvark";
+
+ tm.setBooleanProperty("mybool", myBool);
+ tm.setByteProperty("mybyte", myByte);
+ tm.setDoubleProperty("mydouble", myDouble);
+ tm.setFloatProperty("myfloat", myFloat);
+ tm.setIntProperty("myint", myInt);
+ tm.setLongProperty("mylong", myLong);
+ tm.setShortProperty("myshort", myShort);
+ tm.setStringProperty("mystring", myString);
+
+ tm.setStringProperty("JMSXMyNaughtyJMSXProperty", myJMSX);
+
+ prod.send(tm);
+
+ tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("blahmessage3", tm.getText());
+
+ assertEquals(myBool, tm.getBooleanProperty("mybool"));
+ assertEquals(myByte, tm.getByteProperty("mybyte"));
+ assertEquals(myDouble, tm.getDoubleProperty("mydouble"));
+ assertEquals(myFloat, tm.getFloatProperty("myfloat"));
+ assertEquals(myInt, tm.getIntProperty("myint"));
+ assertEquals(myLong, tm.getLongProperty("mylong"));
+ assertEquals(myShort, tm.getShortProperty("myshort"));
+ assertEquals(myString, tm.getStringProperty("mystring"));
+ assertEquals(myJMSX, tm.getStringProperty("JMSXMyNaughtyJMSXProperty"));
+
+ m = cons.receive(5000);
+
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+
+ if (connSource != null)
+ {
+ connSource.close();
+ }
+
+ if (connTarget != null)
+ {
+ connTarget.close();
+ }
+ }
+ }
+
+ public void testNoMessageIDInHeader() throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ Connection connSource = null;
+
+ Connection connTarget = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
+ 1, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ connTarget = cf1.createConnection();
+
+ log.trace("Sending " + NUM_MESSAGES + " messages");
+
+ Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSource.createProducer(sourceQueue);
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = sessSource.createTextMessage("message" + i);
+
+ //We add some headers to make sure they get passed through ok
+ tm.setStringProperty("wib", "uhuh");
+ tm.setBooleanProperty("cheese", true);
+ tm.setIntProperty("Sausages", 23);
+
+ prod.send(tm);
+ }
+
+ log.trace("Sent the first messages");
+
+ Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sessTarget.createConsumer(targetQueue);
+
+ connTarget.start();
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(5000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+
+ assertEquals("uhuh", tm.getStringProperty("wib"));
+ assertTrue(tm.getBooleanProperty("cheese"));
+ assertEquals(23, tm.getIntProperty("Sausages"));
+
+ String header = tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
+
+ assertNull(header);
+ }
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+
+ if (connSource != null)
+ {
+ connSource.close();
+ }
+
+ if (connTarget != null)
+ {
+ connTarget.close();
+ }
+ }
+ }
+
+
+ // Private -------------------------------------------------------------------------------
+
+ private void testStress(QualityOfServiceMode qosMode, boolean persistent, int batchSize) throws Exception
+ {
+ Connection connSource = null;
+
+ BridgeImpl bridge = null;
+
+ Thread t = null;
+
+ try
+ {
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, qosMode,
+ batchSize, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(sourceQueue);
+
+ final int NUM_MESSAGES = 250;
+
+ StressSender sender = new StressSender();
+ sender.sess = sessSend;
+ sender.prod = prod;
+ sender.numMessages = NUM_MESSAGES;
+ prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+
+ t = new Thread(sender);
+
+ t.start();
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+
+ t.join();
+
+ if (sender.ex != null)
+ {
+ //An error occurred during the send
+ throw sender.ex;
+ }
+
+ }
+ finally
+ {
+ if (t != null)
+ {
+ t.join(10000);
+ }
+
+ if (connSource != null)
+ {
+ try
+ {
+ connSource.close();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to close connection", e);
+ }
+ }
+
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ private void testStressBatchTime(QualityOfServiceMode qosMode, boolean persistent, int maxBatchTime) throws Exception
+ {
+ Connection connSource = null;
+
+ BridgeImpl bridge = null;
+
+ Thread t = null;
+
+ try
+ {
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, qosMode,
+ 2, maxBatchTime,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(sourceQueue);
+
+ final int NUM_MESSAGES = 5000;
+
+ StressSender sender = new StressSender();
+ sender.sess = sessSend;
+ sender.prod = prod;
+ sender.numMessages = NUM_MESSAGES;
+ prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+
+ t = new Thread(sender);
+
+ t.start();
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+
+ t.join();
+
+ if (sender.ex != null)
+ {
+ //An error occurred during the send
+ throw sender.ex;
+ }
+
+ }
+ finally
+ {
+ if (t != null)
+ {
+ t.join(10000);
+ }
+
+ if (connSource != null)
+ {
+ try
+ {
+ connSource.close();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to close connection", e);
+ }
+ }
+
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ //Both source and destination on same rm
+ private void testStressSameServer(QualityOfServiceMode qosMode, boolean persistent, int batchSize) throws Exception
+ {
+ Connection connSource = null;
+
+ BridgeImpl bridge = null;
+
+ Thread t = null;
+
+ try
+ {
+ bridge = new BridgeImpl(cff0, cff0, sourceQueueFactory, localTargetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, qosMode,
+ batchSize, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ connSource = cf0.createConnection();
+
+ Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(sourceQueue);
+
+ final int NUM_MESSAGES = 2000;
+
+ StressSender sender = new StressSender();
+ sender.sess = sessSend;
+ sender.prod = prod;
+ sender.numMessages = NUM_MESSAGES;
+ prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+
+ t = new Thread(sender);
+
+ t.start();
+
+ this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+
+ t.join();
+
+ if (sender.ex != null)
+ {
+ //An error occurred during the send
+ throw sender.ex;
+ }
+
+ }
+ finally
+ {
+ if (t != null)
+ {
+ t.join(10000);
+ }
+
+ if (connSource != null)
+ {
+ try
+ {
+ connSource.close();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to close connection", e);
+ }
+ }
+
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+
+ private void testNoMaxBatchTime(QualityOfServiceMode qosMode, boolean persistent) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, qosMode,
+ NUM_MESSAGES, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ //Send half the messges
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
+
+ //Verify none are received
+
+ this.checkEmpty(targetQueue, 1);
+
+ //Send the other half
+
+ this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
+
+ //This should now be receivable
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+
+ //Send another batch with one more than batch size
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent);
+
+ //Make sure only batch size are received
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+
+ //Final batch
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent);
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, NUM_MESSAGES, 1);
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES - 1);
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ log.info("Stopping bridge");
+ bridge.stop();
+ }
+ }
+ }
+
+ private void testNoMaxBatchTimeSameServer(QualityOfServiceMode qosMode, boolean persistent) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ final int NUM_MESSAGES = 10;
+
+ bridge = new BridgeImpl(cff0, cff0, sourceQueueFactory, localTargetQueueFactory,
+ null, null, null, null,
+ null, 5000, 10, qosMode,
+ NUM_MESSAGES, -1,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
+
+ this.checkEmpty(targetQueue, 1);
+
+ //Send the other half
+
+ this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES /2, persistent);
+
+
+ //This should now be receivable
+
+ this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+
+ this.checkEmpty(localTargetQueue, 0);
+
+ this.checkEmpty(sourceQueue, 0);
+
+ //Send another batch with one more than batch size
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent);
+
+ //Make sure only batch size are received
+
+ this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+
+ //Final batch
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent);
+
+ this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, NUM_MESSAGES, 1);
+
+ this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES - 1);
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ private void testMaxBatchTime(QualityOfServiceMode qosMode, boolean persistent) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ final long MAX_BATCH_TIME = 3000;
+
+ final int MAX_BATCH_SIZE = 100000; // something big so it won't reach it
+
+ bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
+ null, null, null, null,
+ null, 3000, 10, qosMode,
+ MAX_BATCH_SIZE, MAX_BATCH_TIME,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ final int NUM_MESSAGES = 10;
+
+ //Send some message
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent);
+
+ //Verify none are received
+
+ this.checkEmpty(targetQueue, 1);
+
+ //Messages should now be receivable
+
+ this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+ private void testMaxBatchTimeSameServer(QualityOfServiceMode qosMode, boolean persistent) throws Exception
+ {
+ BridgeImpl bridge = null;
+
+ try
+ {
+ final long MAX_BATCH_TIME = 3000;
+
+ final int MAX_BATCH_SIZE = 100000; // something big so it won't reach it
+
+ bridge = new BridgeImpl(cff0, cff0, sourceQueueFactory, localTargetQueueFactory,
+ null, null, null, null,
+ null, 3000, 10, qosMode,
+ MAX_BATCH_SIZE, MAX_BATCH_TIME,
+ null, null, false);
+ bridge.setTransactionManager(newTransactionManager());
+
+ bridge.start();
+
+ final int NUM_MESSAGES = 10;
+
+ //Send some message
+
+ //Send some message
+
+ this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent);
+
+ //Verify none are received
+
+ this.checkEmpty(localTargetQueue, 0);;
+
+ //Messages should now be receivable
+
+ this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+ }
+ finally
+ {
+ if (bridge != null)
+ {
+ bridge.stop();
+ }
+ }
+ }
+
+
+ // Inner classes -------------------------------------------------------------------
+
+ private static class StressSender implements Runnable
+ {
+ int numMessages;
+
+ Session sess;
+
+ MessageProducer prod;
+
+ Exception ex;
+
+ public void run()
+ {
+ try
+ {
+ for (int i = 0; i < numMessages; i++)
+ {
+ TextMessage tm = sess.createTextMessage("message" + i);
+
+ prod.send(tm);
+
+ log.trace("Sent message " + i);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to send", e);
+ ex = e;
+ }
+ }
+
+ }
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/BridgeTestBase.java 2009-03-04 07:37:42 UTC (rev 5986)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -1,324 +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.test.messaging.jms.bridge;
-
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Set;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.DeliveryMode;
-import javax.jms.Destination;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.jms.bridge.ConnectionFactoryFactory;
-import org.jboss.messaging.jms.bridge.DestinationFactory;
-import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
-import org.jboss.messaging.jms.bridge.impl.JNDIConnectionFactoryFactory;
-import org.jboss.messaging.jms.bridge.impl.JNDIDestinationFactory;
-import org.jboss.test.messaging.JBMServerTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.container.ServiceContainer;
-
-/**
- *
- * A BridgeTestBase
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class BridgeTestBase extends JBMServerTestCase
-{
- private static final Logger log = Logger.getLogger(BridgeTestBase.class);
-
- protected static ServiceContainer sc;
-
- protected static ConnectionFactoryFactory cff0, cff1;
-
- protected static ConnectionFactory cf0, cf1;
-
- protected static DestinationFactory sourceQueueFactory, targetQueueFactory, localTargetQueueFactory, sourceTopicFactory;
-
- protected static Queue sourceQueue, targetQueue, localTargetQueue;
-
- protected static Topic sourceTopic;
-
- protected static boolean firstTime = true;
-
- public BridgeTestBase(String name)
- {
- super(name);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- if (firstTime)
- {
- //Start the servers
-
- //ServerManagement.start(0, "all", true);
-
- //ServerManagement.start(1, "all", false);
-
- createQueue("sourceQueue", 0);
-
- createTopic("sourceTopic", 0);
-
- createQueue("localTargetQueue", 0);
-
- createQueue("targetQueue", 1);
-
- setUpAdministeredObjects();
-
- //We need a local transaction and recovery manager
- //We must start this after the remote servers have been created or it won't
- //have deleted the database and the recovery manager may attempt to recover transactions
-
-
- firstTime = false;
- }
-
- }
-
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
-
- checkEmpty(sourceQueue);
- checkEmpty(localTargetQueue);
- checkEmpty(targetQueue, 1);
-
- // Check no subscriptions left lying around
-
- checkNoSubscriptions(sourceTopic);
- }
-
- protected void setUpAdministeredObjects() throws Exception
- {
- InitialContext ic0 = null, ic1 = null;
- try
- {
- Hashtable props0 = ServerManagement.getJNDIEnvironment(0);
-
- Hashtable props1 = ServerManagement.getJNDIEnvironment(1);
-
- cff0 = new JNDIConnectionFactoryFactory(props0, "/ConnectionFactory");
-
- cff1 = new JNDIConnectionFactoryFactory(props1, "/ConnectionFactory");
-
- ic0 = getInitialContext(0);
-
- ic1 = getInitialContext(1);
-
- cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
-
- cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
-
- sourceQueueFactory = new JNDIDestinationFactory(props0, "/queue/sourceQueue");
-
- sourceQueue = (Queue)sourceQueueFactory.createDestination();
-
- targetQueueFactory = new JNDIDestinationFactory(props1, "/queue/targetQueue");
-
- targetQueue = (Queue)targetQueueFactory.createDestination();
-
- sourceTopicFactory = new JNDIDestinationFactory(props0, "/topic/sourceTopic");
-
- sourceTopic = (Topic)sourceTopicFactory.createDestination();
-
- localTargetQueueFactory = new JNDIDestinationFactory(props0, "/queue/localTargetQueue");
-
- localTargetQueue = (Queue)localTargetQueueFactory.createDestination();
- }
- finally
- {
- if (ic0 != null)
- {
- ic0.close();
- }
- if (ic1 != null)
- {
- ic1.close();
- }
- }
- }
-
- protected void sendMessages(ConnectionFactory cf, Destination dest, int start, int numMessages, boolean persistent)
- throws Exception
- {
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sess.createProducer(dest);
-
- prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
-
- for (int i = start; i < start + numMessages; i++)
- {
- TextMessage tm = sess.createTextMessage("message" + i);
-
- prod.send(tm);
- }
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
-
- protected void checkMessagesReceived(ConnectionFactory cf, Destination dest, QualityOfServiceMode qosMode,
- int numMessages, boolean longWaitForFirst) throws Exception
- {
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
-
- conn.start();
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(dest);
-
- // Consume the messages
-
- Set msgs = new HashSet();
-
- int count = 0;
-
- //We always wait longer for the first one - it may take some time to arrive especially if we are
- //waiting for recovery to kick in
- while (true)
- {
- TextMessage tm = (TextMessage)cons.receive(count == 0 ? (longWaitForFirst ? 60000 : 10000) : 5000);
-
- if (tm == null)
- {
- break;
- }
-
- //log.info("Got message " + tm.getText());
-
- msgs.add(tm.getText());
-
- count++;
-
- }
-
- if (qosMode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE || qosMode == QualityOfServiceMode.DUPLICATES_OK)
- {
- //All the messages should be received
-
- for (int i = 0; i < numMessages; i++)
- {
- assertTrue(msgs.contains("message" + i));
- }
-
- //Should be no more
- if (qosMode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE)
- {
- assertEquals(numMessages, msgs.size());
- }
- }
- else if (qosMode == QualityOfServiceMode.AT_MOST_ONCE)
- {
- //No *guarantee* that any messages will be received
- //but you still might get some depending on how/where the crash occurred
- }
-
- log.trace("Check complete");
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
-
- protected void checkAllMessageReceivedInOrder(ConnectionFactory cf, Destination dest, int start, int numMessages) throws Exception
- {
- Connection conn = null;
- try
- {
- conn = cf.createConnection();
-
- conn.start();
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(dest);
-
- // Consume the messages
-
- for (int i = 0; i < numMessages; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(30000);
-
- assertNotNull(tm);
-
- //log.info("Got message " + tm.getText());
-
- assertEquals("message" + (i + start), tm.getText());
- }
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
-
- // Inner classes -------------------------------------------------------------------
-
-}
-
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java (from rev 6042, trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/BridgeTestBase.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -0,0 +1,503 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.integration.jms.bridge;
+
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONNECTION_TTL;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PING_PERIOD;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PRE_ACKNOWLEDGE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.management.ObjectName;
+import javax.transaction.TransactionManager;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+
+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.management.ManagementService;
+import org.jboss.messaging.core.management.ObjectNames;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.jms.bridge.ConnectionFactoryFactory;
+import org.jboss.messaging.jms.bridge.DestinationFactory;
+import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
+import org.jboss.messaging.jms.server.management.JMSQueueControlMBean;
+import org.jboss.messaging.jms.server.management.TopicControlMBean;
+import org.jboss.messaging.tests.unit.util.InVMContext;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ *
+ * A BridgeTestBase
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public abstract class BridgeTestBase extends UnitTestCase
+{
+ private static final Logger log = Logger.getLogger(BridgeTestBase.class);
+
+ protected static ConnectionFactoryFactory cff0, cff1;
+
+ protected static ConnectionFactory cf0, cf1;
+
+ protected static DestinationFactory sourceQueueFactory, targetQueueFactory, localTargetQueueFactory, sourceTopicFactory;
+
+ protected static Queue sourceQueue, targetQueue, localTargetQueue;
+
+ protected static Topic sourceTopic;
+
+ protected static boolean firstTime = true;
+
+ protected MessagingServiceImpl server0;
+
+ protected JMSServerManagerImpl jmsServer0;
+
+ protected MessagingServiceImpl server1;
+
+ protected JMSServerManagerImpl jmsServer1;
+
+ private InVMContext context0;
+
+ protected InVMContext context1;
+
+ private HashMap<String, Object> params1;
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ //Start the servers
+ Configuration conf0 = new ConfigurationImpl();
+ conf0.setSecurityEnabled(false);
+ conf0.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ server0 = Messaging.newNullStorageMessagingService(conf0);
+ server0.start();
+
+ context0 = new InVMContext();
+ jmsServer0 = JMSServerManagerImpl.newJMSServerManagerImpl(server0.getServer());
+ jmsServer0.start();
+ jmsServer0.setContext(context0);
+
+ Configuration conf1 = new ConfigurationImpl();
+ conf1.setSecurityEnabled(false);
+ params1 = new HashMap<String, Object>();
+ params1.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ conf1.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ params1));
+ conf1.setBackup(true);
+ server1 = Messaging.newNullStorageMessagingService(conf1);
+ server1.start();
+
+ context1 = new InVMContext();
+ jmsServer1 = JMSServerManagerImpl.newJMSServerManagerImpl(server1.getServer());
+ jmsServer1.start();
+ jmsServer1.setContext(context1);
+
+ createQueue("sourceQueue", 0);
+
+ jmsServer0.createTopic("sourceTopic", "/topic/sourceTopic");
+
+ createQueue("localTargetQueue", 0);
+
+ createQueue("targetQueue", 1);
+
+ setUpAdministeredObjects();
+
+ //We need a local transaction and recovery manager
+ //We must start this after the remote servers have been created or it won't
+ //have deleted the database and the recovery manager may attempt to recover transactions
+
+ firstTime = false;
+
+ }
+
+ protected void createQueue(String queueName, int index) throws Exception
+ {
+ JMSServerManagerImpl server = jmsServer0;
+ if (index == 1)
+ {
+ server = jmsServer1;
+ }
+ server.createQueue(queueName, "/queue/" + queueName);
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ checkEmpty(sourceQueue, 0);
+ checkEmpty(localTargetQueue, 0);
+ checkEmpty(targetQueue, 1);
+
+ // Check no subscriptions left lying around
+
+ checkNoSubscriptions(sourceTopic, 0);
+
+ server1.stop();
+ server0.stop();
+
+ super.tearDown();
+ }
+
+ protected void setUpAdministeredObjects() throws Exception
+ {
+ cff0 = new ConnectionFactoryFactory()
+ {
+ public ConnectionFactory createConnectionFactory() throws Exception
+ {
+ return new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName()),
+ null,
+ DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
+ DEFAULT_PING_PERIOD,
+ DEFAULT_CONNECTION_TTL,
+ DEFAULT_CALL_TIMEOUT,
+ null,
+ DEFAULT_ACK_BATCH_SIZE,
+ DEFAULT_ACK_BATCH_SIZE,
+ DEFAULT_CONSUMER_WINDOW_SIZE,
+ DEFAULT_CONSUMER_MAX_RATE,
+ DEFAULT_SEND_WINDOW_SIZE,
+ DEFAULT_PRODUCER_MAX_RATE,
+ DEFAULT_MIN_LARGE_MESSAGE_SIZE,
+ DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+ true,
+ true,
+ DEFAULT_AUTO_GROUP,
+ DEFAULT_MAX_CONNECTIONS,
+ DEFAULT_PRE_ACKNOWLEDGE,
+ DEFAULT_RETRY_INTERVAL,
+ DEFAULT_RETRY_INTERVAL_MULTIPLIER,
+ 0,
+ 0);
+ }
+
+ };
+
+ cf0 = cff0.createConnectionFactory();
+
+ cff1 = new ConnectionFactoryFactory()
+ {
+
+ public ConnectionFactory createConnectionFactory() throws Exception
+ {
+ return new JBossConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName(), params1),
+ null,
+ DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
+ DEFAULT_PING_PERIOD,
+ DEFAULT_CONNECTION_TTL,
+ DEFAULT_CALL_TIMEOUT,
+ null,
+ DEFAULT_ACK_BATCH_SIZE,
+ DEFAULT_ACK_BATCH_SIZE,
+ DEFAULT_CONSUMER_WINDOW_SIZE,
+ DEFAULT_CONSUMER_MAX_RATE,
+ DEFAULT_SEND_WINDOW_SIZE,
+ DEFAULT_PRODUCER_MAX_RATE,
+ DEFAULT_MIN_LARGE_MESSAGE_SIZE,
+ DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+ true,
+ true,
+ DEFAULT_AUTO_GROUP,
+ DEFAULT_MAX_CONNECTIONS,
+ DEFAULT_PRE_ACKNOWLEDGE,
+ DEFAULT_RETRY_INTERVAL,
+ DEFAULT_RETRY_INTERVAL_MULTIPLIER,
+ 0,
+ 0);
+ }
+ };
+
+ cf1 = cff1.createConnectionFactory();
+
+ sourceQueueFactory = new DestinationFactory()
+ {
+ public Destination createDestination() throws Exception
+ {
+ return (Destination)context0.lookup("/queue/sourceQueue");
+ }
+ };
+
+ sourceQueue = (Queue)sourceQueueFactory.createDestination();
+
+ targetQueueFactory = new DestinationFactory()
+ {
+ public Destination createDestination() throws Exception
+ {
+ return (Destination)context1.lookup("/queue/targetQueue");
+ }
+ };
+
+ targetQueue = (Queue)targetQueueFactory.createDestination();
+
+ sourceTopicFactory = new DestinationFactory()
+ {
+ public Destination createDestination() throws Exception
+ {
+ return (Destination)context0.lookup("/topic/sourceTopic");
+ }
+ };
+
+ sourceTopic = (Topic)sourceTopicFactory.createDestination();
+
+ localTargetQueueFactory = new DestinationFactory()
+ {
+ public Destination createDestination() throws Exception
+ {
+ return (Destination)context0.lookup("/queue/localTargetQueue");
+ }
+ };
+
+ localTargetQueue = (Queue)localTargetQueueFactory.createDestination();
+ }
+
+ protected void sendMessages(ConnectionFactory cf, Destination dest, int start, int numMessages, boolean persistent)
+ throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess.createProducer(dest);
+
+ prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+
+ for (int i = start; i < start + numMessages; i++)
+ {
+ TextMessage tm = sess.createTextMessage("message" + i);
+
+ prod.send(tm);
+ }
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+
+ protected void checkMessagesReceived(ConnectionFactory cf, Destination dest, QualityOfServiceMode qosMode,
+ int numMessages, boolean longWaitForFirst) throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.start();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(dest);
+
+ // Consume the messages
+
+ Set msgs = new HashSet();
+
+ int count = 0;
+
+ //We always wait longer for the first one - it may take some time to arrive especially if we are
+ //waiting for recovery to kick in
+ while (true)
+ {
+ TextMessage tm = (TextMessage)cons.receive(count == 0 ? (longWaitForFirst ? 60000 : 10000) : 5000);
+
+ if (tm == null)
+ {
+ break;
+ }
+
+ //log.info("Got message " + tm.getText());
+
+ msgs.add(tm.getText());
+
+ count++;
+
+ }
+
+ if (qosMode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE || qosMode == QualityOfServiceMode.DUPLICATES_OK)
+ {
+ //All the messages should be received
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ assertTrue("" + i, msgs.contains("message" + i));
+ }
+
+ //Should be no more
+ if (qosMode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE)
+ {
+ assertEquals(numMessages, msgs.size());
+ }
+ }
+ else if (qosMode == QualityOfServiceMode.AT_MOST_ONCE)
+ {
+ //No *guarantee* that any messages will be received
+ //but you still might get some depending on how/where the crash occurred
+ }
+
+ log.trace("Check complete");
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+
+ protected void checkAllMessageReceivedInOrder(ConnectionFactory cf, Destination dest, int start, int numMessages) throws Exception
+ {
+ Connection conn = null;
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.start();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(dest);
+
+ // Consume the messages
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(30000);
+
+ assertNotNull(tm);
+
+ //log.info("Got message " + tm.getText());
+
+ assertEquals("message" + (i + start), tm.getText());
+ }
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public boolean checkEmpty(Queue queue, int index) throws Exception
+ {
+ ManagementService managementService = server0.getServer().getManagementService();
+ if (index == 1)
+ {
+ managementService = server1.getServer().getManagementService();
+ }
+ ObjectName objectName = ObjectNames.getJMSQueueObjectName(queue.getQueueName());
+ JMSQueueControlMBean queueControl = (JMSQueueControlMBean)managementService.getResource(objectName);
+
+ Integer messageCount = queueControl.getMessageCount();
+
+ if (messageCount > 0)
+ {
+ queueControl.removeAllMessages();
+ }
+ return true;
+ }
+
+ protected void checkNoSubscriptions(Topic topic, int index) throws Exception
+ {
+ ManagementService managementService = server0.getServer().getManagementService();
+ if (index == 1)
+ {
+ managementService = server1.getServer().getManagementService();
+ }
+ ObjectName objectName = ObjectNames.getJMSTopicObjectName(topic.getTopicName());
+ TopicControlMBean topicControl = (TopicControlMBean)managementService.getResource(objectName);
+ assertEquals(0, topicControl.getSubcriptionsCount());
+
+ }
+
+ protected void removeAllMessages(String queueName, int index) throws Exception
+ {
+ ManagementService managementService = server0.getServer().getManagementService();
+ if (index == 1)
+ {
+ managementService = server1.getServer().getManagementService();
+ }
+ ObjectName objectName = ObjectNames.getJMSQueueObjectName(queueName);
+ JMSQueueControlMBean queueControl = (JMSQueueControlMBean)managementService.getResource(objectName);
+ queueControl.removeAllMessages();
+ }
+
+ protected TransactionManager newTransactionManager()
+ {
+ return new TransactionManagerImple();
+ }
+
+ // Inner classes -------------------------------------------------------------------
+
+}
+
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/ReconnectTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java 2009-03-04 07:37:42 UTC (rev 5986)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/ReconnectTest.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -1,288 +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.test.messaging.jms.bridge;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
-import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class ReconnectTest extends BridgeTestBase
-{
- private static final Logger log = Logger.getLogger(ReconnectTest.class);
-
- public ReconnectTest(String name)
- {
- super(name);
- }
-
- // Crash and reconnect
-
- // Once and only once
-
- public void testCrashAndReconnectDestBasic_OnceAndOnlyOnce_P() throws Exception
- {
- testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
- }
-
- public void testCrashAndReconnectDestBasic_OnceAndOnlyOnce_NP() throws Exception
- {
- testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
- }
-
- // dups ok
-
- public void testCrashAndReconnectDestBasic_DuplicatesOk_P() throws Exception
- {
- testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, true);
- }
-
- public void testCrashAndReconnectDestBasic_DuplicatesOk_NP() throws Exception
- {
- testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, false);
- }
-
- // At most once
-
- public void testCrashAndReconnectDestBasic_AtMostOnce_P() throws Exception
- {
- testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, true);
- }
-
- public void testCrashAndReconnectDestBasic_AtMostOnce_NP() throws Exception
- {
- testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, false);
- }
-
- // Crash tests specific to XA transactions
-
- public void testCrashAndReconnectDestCrashBeforePrepare_P() throws Exception
- {
- testCrashAndReconnectDestCrashBeforePrepare(true);
- }
-
- public void testCrashAndReconnectDestCrashBeforePrepare_NP() throws Exception
- {
- testCrashAndReconnectDestCrashBeforePrepare(false);
- }
-
- // Crash before bridge is started
-
- public void testRetryConnectionOnStartup() throws Exception
- {
- ServerManagement.kill(1);
-
- BridgeImpl bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 1000, -1, QualityOfServiceMode.DUPLICATES_OK,
- 10, -1,
- null, null, false);
-
- try
- {
- bridge.start();
- assertFalse(bridge.isStarted());
- assertTrue(bridge.isFailed());
-
- ServerManagement.start(1, "all", false);
- createQueue("targetQueue", 1);
- setUpAdministeredObjects();
-
- Thread.sleep(3000);
-
- assertTrue(bridge.isStarted());
- assertFalse(bridge.isFailed());
- }
- finally
- {
- try
- {
- bridge.stop();
- }
- catch (Exception e)
- {
- log.error("Failed to stop bridge", e);
- }
- }
- }
-
- /*
- * Send some messages
- * Crash the destination server
- * Bring the destination server back up
- * Send some more messages
- * Verify all messages are received
- */
- private void testCrashAndReconnectDestBasic(QualityOfServiceMode qosMode, boolean persistent) throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 1000, -1, qosMode,
- 10, -1,
- null, null, false);
-
- bridge.start();
-
- final int NUM_MESSAGES = 10;
-
- //Send some messages
-
- sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2 , persistent);
-
- //Verify none are received
-
- checkEmpty(targetQueue, 1);
-
- //Now crash the dest server
-
- log.info("About to crash server");
-
- ServerManagement.kill(1);
-
- //Wait a while before starting up to simulate the dest being down for a while
- log.info("Waiting 5 secs before bringing server back up");
- Thread.sleep(5000);
- log.info("Done wait");
-
- //Restart the server
-
- log.info("Restarting server");
-
- ServerManagement.start(1, "all", false);
-
- createQueue("targetQueue", 1);
-
- setUpAdministeredObjects();
-
- //Send some more messages
-
- log.info("Sending more messages");
-
- sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
-
- log.info("Sent messages");
-
- checkMessagesReceived(cf1, targetQueue, qosMode, NUM_MESSAGES, false);
- }
- finally
- {
-
- if (bridge != null)
- {
- try
- {
- bridge.stop();
- }
- catch (Exception e)
- {
- log.error("Failed to stop bridge", e);
- }
- }
- }
- }
-
- /*
- * Send some messages
- * Crash the destination server
- * Set the max batch time such that it will attempt to send the batch while the dest server is down
- * Bring up the destination server
- * Send some more messages
- * Verify all messages are received
- */
- private void testCrashAndReconnectDestCrashBeforePrepare(boolean persistent) throws Exception
- {
- BridgeImpl bridge = null;
-
- try
- {
- bridge = new BridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory,
- null, null, null, null,
- null, 1000, -1, QualityOfServiceMode.ONCE_AND_ONLY_ONCE,
- 10, 5000,
- null, null, false);
-
- bridge.start();
-
- final int NUM_MESSAGES = 10;
- //Send some messages
-
- this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
-
- //verify none are received
-
- checkEmpty(targetQueue, 1);
-
- //Now crash the dest server
-
- log.info("About to crash server");
-
- ServerManagement.kill(1);
-
- //Wait a while before starting up to simulate the dest being down for a while
- log.info("Waiting 5 secs before bringing server back up");
- Thread.sleep(5000);
- log.info("Done wait");
-
- //Restart the server
-
- ServerManagement.start(1, "all", false);
-
- createQueue("targetQueue", 1);
-
- setUpAdministeredObjects();
-
- sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
-
- checkMessagesReceived(cf1, targetQueue, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, NUM_MESSAGES, false);
- }
- finally
- {
-
- if (bridge != null)
- {
- try
- {
- bridge.stop();
- }
- catch (Exception e)
- {
- log.error("Failed to stop bridge", e);
- }
- }
-
- }
- }
-
- // Inner classes -------------------------------------------------------------------
-
-}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/ReconnectWithRecoveryTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/bridge/ReconnectWithRecoveryTest.java 2009-03-04 07:37:42 UTC (rev 5986)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/ReconnectWithRecoveryTest.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -1,157 +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.test.messaging.jms.bridge;
-
-import java.util.Properties;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class ReconnectWithRecoveryTest extends BridgeTestBase
-{
- private static final Logger log = Logger.getLogger(ReconnectTest.class);
-
- public ReconnectWithRecoveryTest(String name)
- {
- super(name);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- //Now install local JMSProviderAdaptor classes
-
- Properties props1 = new Properties();
- props1.putAll(ServerManagement.getJNDIEnvironment(1));
-
- /*JMSProviderAdapter targetAdaptor =
- new TestJMSProviderAdaptor(props1, "/XAConnectionFactory", "adaptor1");
-
- sc.installJMSProviderAdaptor("adaptor1", targetAdaptor);
-
- sc.startRecoveryManager();*/
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
-
- /*sc.stopRecoveryManager();
-
- sc.uninstallJMSProviderAdaptor("adaptor1");*/
-
- log.debug(this + " torn down");
- }
-
- public void testNoop()
- {
-
- }
-
- /*
- * TODO: What to do with this test?
- * Send some messages
- * Crash the server after prepare but on commit
- * Bring up the destination server
- * Send some more messages
- * Verify all messages are received
- */
-// public void testCrashAndReconnectDestCrashOnCommit() throws Exception
-// {
-// Bridge bridge = null;
-//
-// try
-// {
-// final int NUM_MESSAGES = 10;
-//
-// bridge = new Bridge(cff0, cff1, sourceQueueFactory, targetQueueFactory,
-// null, null, null, null,
-// null, 1000, -1, Bridge.QOS_ONCE_AND_ONLY_ONCE,
-// NUM_MESSAGES, -1,
-// null, null, false);
-//
-// bridge.start();
-//
-// //Poison server 1 so it crashes on commit of dest but after prepare
-//
-// //This means the transaction branch on source will get commmitted
-// //but the branch on dest won't be - it will remain prepared
-// //This corresponds to a HeuristicMixedException
-//
-// ServerManagement.poisonTheServer(1, PoisonInterceptor.TYPE_2PC_COMMIT);
-//
-// log.info("Poisoned server");
-//
-// //Send some messages
-//
-// sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, true);
-//
-// //Restart the server
-//
-// //Wait a bit for the batch to be sent - this should cause the server to crash on commit
-//
-// Thread.sleep(3000);
-//
-// log.info("Restarting server");
-//
-// ServerManagement.start(1, "all", false);
-//
-// log.info("Restarted server");
-//
-// deployQueue("targetQueue", 1);
-//
-// this.setUpAdministeredObjects();
-//
-// log.info("Deployed queue");
-//
-// log.info("*** waiting for recovery");
-//
-// //There may be a long wait for the first time (need to let recovery kick in)
-// checkMessagesReceived(cf1, targetQueue, Bridge.QOS_ONCE_AND_ONLY_ONCE, NUM_MESSAGES, true);
-// }
-// finally
-// {
-// if (bridge != null)
-// {
-// try
-// {
-// bridge.stop();
-// }
-// catch (Exception e)
-// {
-// log.error("Failed to stop bridge", e);
-// }
-// }
-// }
-// }
-
- // Inner classes -------------------------------------------------------------------
-}
-
Added: trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMContext.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMContext.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMContext.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -0,0 +1,387 @@
+/*
+ * 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.unit.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+
+import org.jboss.messaging.core.logging.Logger;
+
+
+/**
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 2868 $</tt>
+ *
+ * $Id: InVMContext.java 2868 2007-07-10 20:22:16Z timfox $
+ */
+public class InVMContext implements Context, Serializable
+{
+ // Constants -----------------------------------------------------
+
+ private static final long serialVersionUID = 385743957345L;
+
+ private static final Logger log = Logger.getLogger(InVMContext.class);
+
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ protected Map map;
+ protected NameParser parser = new InVMNameParser();
+ private String nameInNamespace = "";
+
+ // Constructors --------------------------------------------------
+
+ public InVMContext()
+ {
+ map = Collections.synchronizedMap(new HashMap());
+ }
+
+ public InVMContext(String nameInNamespace)
+ {
+ this();
+ this.nameInNamespace = nameInNamespace;
+ }
+ // Context implementation ----------------------------------------
+
+ public Object lookup(Name name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object lookup(String name) throws NamingException
+ {
+ name = trimSlashes(name);
+ int i = name.indexOf("/");
+ String tok = i == -1 ? name : name.substring(0, i);
+ Object value = map.get(tok);
+ if (value == null)
+ {
+ throw new NameNotFoundException("Name not found: " + tok);
+ }
+ if (value instanceof InVMContext && i != -1)
+ {
+ return ((InVMContext)value).lookup(name.substring(i));
+ }
+ if (value instanceof Reference)
+ {
+ Reference ref = (Reference)value;
+ RefAddr refAddr = ref.get("nns");
+
+ // we only deal with references create by NonSerializableFactory
+ String key = (String)refAddr.getContent();
+ return NonSerializableFactory.lookup(key);
+ }
+ else
+ {
+ return value;
+ }
+ }
+
+ public void bind(Name name, Object obj) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void bind(String name, Object obj) throws NamingException
+ {
+ internalBind(name, obj, false);
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void rebind(String name, Object obj) throws NamingException
+ {
+ internalBind(name, obj, true);
+ }
+
+ public void unbind(Name name) throws NamingException
+ {
+ unbind(name.toString());
+ }
+
+ public void unbind(String name) throws NamingException
+ {
+ name = trimSlashes(name);
+ int i = name.indexOf("/");
+ boolean terminal = i == -1;
+ if (terminal)
+ {
+ map.remove(name);
+ }
+ else
+ {
+ String tok = name.substring(0, i);
+ InVMContext c = (InVMContext)map.get(tok);
+ if (c == null)
+ {
+ throw new NameNotFoundException("Context not found: " + tok);
+ }
+ c.unbind(name.substring(i));
+ }
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void rename(String oldName, String newName) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public NamingEnumeration list(Name name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public NamingEnumeration list(String name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public NamingEnumeration listBindings(Name name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public NamingEnumeration listBindings(String contextName) throws NamingException
+ {
+ contextName = trimSlashes(contextName);
+ if (!"".equals(contextName) && !".".equals(contextName))
+ {
+ try
+ {
+ return ((InVMContext)lookup(contextName)).listBindings("");
+ }
+ catch(Throwable t)
+ {
+ throw new NamingException(t.getMessage());
+ }
+ }
+
+ List l = new ArrayList();
+ for(Iterator i = map.keySet().iterator(); i.hasNext(); )
+ {
+ String name = (String)i.next();
+ Object object = map.get(name);
+ l.add(new Binding(name, object));
+ }
+ return new NamingEnumerationImpl(l.iterator());
+ }
+
+ public void destroySubcontext(Name name) throws NamingException
+ {
+ destroySubcontext(name.toString());
+ }
+
+ public void destroySubcontext(String name) throws NamingException
+ {
+ map.remove(trimSlashes(name));
+ }
+
+ public Context createSubcontext(Name name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Context createSubcontext(String name) throws NamingException
+ {
+ name = trimSlashes(name);
+ if (map.get(name) != null)
+ {
+ throw new NameAlreadyBoundException(name);
+ }
+ InVMContext c = new InVMContext(getNameInNamespace());
+ map.put(name, c);
+ return c;
+ }
+
+ public Object lookupLink(Name name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object lookupLink(String name) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException
+ {
+ return getNameParser(name.toString());
+ }
+
+ public NameParser getNameParser(String name) throws NamingException
+ {
+ return parser;
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public String composeName(String name, String prefix) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Hashtable getEnvironment() throws NamingException
+ {
+ Hashtable env = new Hashtable();
+ env.put("java.naming.factory.initial",
+ "org.jboss.test.messaging.tools.container.InVMInitialContextFactory");
+ env.put("java.naming.provider.url", "org.jboss.naming:org.jnp.interface");
+ return env;
+ }
+
+ public void close() throws NamingException
+ {
+ }
+
+ public String getNameInNamespace() throws NamingException
+ {
+ return nameInNamespace;
+ }
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private String trimSlashes(String s)
+ {
+ int i = 0;
+ while(true)
+ {
+ if (i == s.length() || s.charAt(i) != '/')
+ {
+ break;
+ }
+ i++;
+ }
+ s = s.substring(i);
+ i = s.length() - 1;
+ while(true)
+ {
+ if (i == -1 || s.charAt(i) != '/')
+ {
+ break;
+ }
+ i--;
+ }
+ return s.substring(0, i + 1);
+ }
+
+ private void internalBind(String name, Object obj, boolean rebind) throws NamingException
+ {
+ log.debug("Binding " + name + " obj " + obj + " rebind " + rebind);
+ name = trimSlashes(name);
+ int i = name.lastIndexOf("/");
+ InVMContext c = this;
+ if (i != -1)
+ {
+ String path = name.substring(0, i);
+ c = (InVMContext)lookup(path);
+ }
+ name = name.substring(i + 1);
+ if (!rebind && c.map.get(name) != null)
+ {
+ throw new NameAlreadyBoundException(name);
+ }
+ c.map.put(name, obj);
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private class NamingEnumerationImpl implements NamingEnumeration
+ {
+ private Iterator iterator;
+
+ NamingEnumerationImpl(Iterator bindingIterator)
+ {
+ this.iterator = bindingIterator;
+ }
+
+ public void close() throws NamingException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasMore() throws NamingException
+ {
+ return iterator.hasNext();
+ }
+
+ public Object next() throws NamingException
+ {
+ return iterator.next();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return iterator.hasNext();
+ }
+
+ public Object nextElement()
+ {
+ return iterator.next();
+ }
+ }
+}
+
Added: trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMNameParser.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMNameParser.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/InVMNameParser.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -0,0 +1,81 @@
+/*
+ * 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.unit.util;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import javax.naming.CompoundName;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+
+/**
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 2868 $</tt>
+ *
+ * $Id: InVMNameParser.java 2868 2007-07-10 20:22:16Z timfox $
+ */
+public class InVMNameParser implements NameParser, Serializable
+{
+ // Constants -----------------------------------------------------
+
+ private static final long serialVersionUID = 2925203703371001031L;
+
+ // Static --------------------------------------------------------
+
+ static Properties syntax;
+
+ static
+ {
+ syntax = new Properties();
+ syntax.put("jndi.syntax.direction", "left_to_right");
+ syntax.put("jndi.syntax.ignorecase", "false");
+ syntax.put("jndi.syntax.separator", "/");
+ }
+
+ // Attributes ----------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public static Properties getSyntax()
+ {
+ return syntax;
+ }
+
+ public Name parse(String name) throws NamingException
+ {
+ return new CompoundName(name, syntax);
+ }
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Added: trunk/tests/src/org/jboss/messaging/tests/unit/util/NonSerializableFactory.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/NonSerializableFactory.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/NonSerializableFactory.java 2009-03-11 13:36:06 UTC (rev 6060)
@@ -0,0 +1,120 @@
+/*
+ * 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.unit.util;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+
+import org.jboss.util.naming.Util;
+
+/**
+ * used by the default context when running in embedded local configuration
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class NonSerializableFactory implements ObjectFactory
+{
+
+ public NonSerializableFactory()
+ {
+ }
+
+ public static void unbind(Context ctx, String strName)
+ throws NamingException
+ {
+ Name name = ctx.getNameParser("").parse(strName);
+ int size = name.size();
+ String atom = name.get(size - 1);
+ Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1));
+ String key = (new StringBuilder()).append(parentCtx.getNameInNamespace()).append("/").append(atom).toString();
+ getWrapperMap().remove(key);
+ Util.unbind(ctx, strName);
+ }
+
+
+ public static void rebind(Context ctx, String strName, Object value)
+ throws NamingException
+ {
+ Name name = ctx.getNameParser("").parse(strName);
+ int size = name.size();
+ String atom = name.get(size - 1);
+ Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1));
+ String key = (new StringBuilder()).append(parentCtx.getNameInNamespace()).append("/").append(atom).toString();
+ getWrapperMap().put(key, value);
+ String className = value.getClass().getName();
+ String factory = NonSerializableFactory.class.getName();
+ StringRefAddr addr = new StringRefAddr("nns", key);
+ Reference memoryRef = new Reference(className, addr, factory, null);
+ parentCtx.rebind(atom, memoryRef);
+ }
+
+ public static void bind(Context ctx, String strName, Object value)
+ throws NamingException
+ {
+ Name name = ctx.getNameParser("").parse(strName);
+ int size = name.size();
+ String atom = name.get(size - 1);
+ Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1));
+ String key = (new StringBuilder()).append(parentCtx.getNameInNamespace()).append("/").append(atom).toString();
+ getWrapperMap().put(key, value);
+ String className = value.getClass().getName();
+ String factory = NonSerializableFactory.class.getName();
+ StringRefAddr addr = new StringRefAddr("nns", key);
+ Reference memoryRef = new Reference(className, addr, factory, null);
+
+ parentCtx.bind(atom, memoryRef);
+ }
+
+ public static Object lookup(String name) throws NamingException
+ {
+ if(getWrapperMap().get(name) == null)
+ {
+ throw new NamingException(name + " not found");
+ }
+ return getWrapperMap().get(name);
+ }
+
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env)
+ throws Exception
+ {
+ Reference ref = (Reference) obj;
+ RefAddr addr = ref.get("nns");
+ String key = (String) addr.getContent();
+ return getWrapperMap().get(key);
+ }
+
+ public static Map getWrapperMap()
+ {
+ return wrapperMap;
+ }
+
+ private static Map wrapperMap = Collections.synchronizedMap(new HashMap());
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list