merge #77 - Only check TM exists for JMSBridge with ONCE_ONLY

This commit is contained in:
Andy Taylor 2015-01-23 10:43:32 +00:00
commit 45a081c72a
4 changed files with 24 additions and 30 deletions

View File

@ -406,8 +406,7 @@ public final class JMSBridgeImpl implements JMSBridge
boolean ok; boolean ok;
// Check to see if the QoSMode requires a TM // Check to see if the QoSMode requires a TM
if (qualityOfServiceMode.equals(QualityOfServiceMode.AT_MOST_ONCE) || if (qualityOfServiceMode.equals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE) && sourceCff != targetCff)
qualityOfServiceMode.equals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE))
{ {
if (tm == null) if (tm == null)
{ {

View File

@ -39,7 +39,9 @@ import org.apache.activemq.jms.bridge.ConnectionFactoryFactory;
import org.apache.activemq.jms.bridge.QualityOfServiceMode; import org.apache.activemq.jms.bridge.QualityOfServiceMode;
import org.apache.activemq.jms.bridge.impl.JMSBridgeImpl; import org.apache.activemq.jms.bridge.impl.JMSBridgeImpl;
import org.apache.activemq.jms.client.ActiveMQMessage; import org.apache.activemq.jms.client.ActiveMQMessage;
import org.apache.activemq.service.extensions.ServiceUtils;
import org.apache.activemq.tests.integration.IntegrationTestLogger; import org.apache.activemq.tests.integration.IntegrationTestLogger;
import org.apache.activemq.tests.integration.ra.DummyTransactionManager;
import org.apache.activemq.utils.DefaultSensitiveStringCodec; import org.apache.activemq.utils.DefaultSensitiveStringCodec;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -407,7 +409,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -447,6 +448,7 @@ public class JMSBridgeTest extends BridgeTestBase
checkAllMessageReceivedInOrder(cf1, targetQueue, NUM_MESSAGES, 1, false); checkAllMessageReceivedInOrder(cf1, targetQueue, NUM_MESSAGES, 1, false);
checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES - 1, false); checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES - 1, false);
} }
finally finally
{ {
@ -759,7 +761,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -848,7 +849,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -936,7 +936,6 @@ public class JMSBridgeTest extends BridgeTestBase
bridge = new JMSBridgeImpl(cff0, cff1, sourceQueueFactory, bridge = new JMSBridgeImpl(cff0, cff1, sourceQueueFactory,
targetQueueFactory, "guest", mask, "guest", mask, null, 5000, targetQueueFactory, "guest", mask, "guest", mask, null, 5000,
10, QualityOfServiceMode.AT_MOST_ONCE, 1, -1, null, null, false); 10, QualityOfServiceMode.AT_MOST_ONCE, 1, -1, null, null, false);
bridge.setTransactionManager(newTransactionManager());
bridge.setUseMaskedPassword(true); bridge.setUseMaskedPassword(true);
@ -1023,7 +1022,6 @@ public class JMSBridgeTest extends BridgeTestBase
bridge = new JMSBridgeImpl(cff0, cff1, sourceQueueFactory, bridge = new JMSBridgeImpl(cff0, cff1, sourceQueueFactory,
targetQueueFactory, "guest", mask, "guest", mask, null, 5000, targetQueueFactory, "guest", mask, "guest", mask, null, 5000,
10, QualityOfServiceMode.AT_MOST_ONCE, 1, -1, null, null, false); 10, QualityOfServiceMode.AT_MOST_ONCE, 1, -1, null, null, false);
bridge.setTransactionManager(newTransactionManager());
bridge.setUseMaskedPassword(true); bridge.setUseMaskedPassword(true);
bridge.setPasswordCodec(codec.getClass().getName() + ";key=bridgekey"); bridge.setPasswordCodec(codec.getClass().getName() + ";key=bridgekey");
@ -1138,7 +1136,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(mgr);
bridge.start(); bridge.start();
sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false, largeMessage); sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false, largeMessage);
@ -1214,7 +1211,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -1268,7 +1264,6 @@ public class JMSBridgeTest extends BridgeTestBase
"subTest", "subTest",
"clientid123", "clientid123",
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -1333,7 +1328,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
on); on);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -1541,7 +1535,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
messageIDInHeader); messageIDInHeader);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -1716,7 +1709,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -1802,6 +1794,7 @@ public class JMSBridgeTest extends BridgeTestBase
{ {
factInUse0 = cff0xa; factInUse0 = cff0xa;
factInUse1 = cff1xa; factInUse1 = cff1xa;
ServiceUtils.setTransactionManager(newTransactionManager());
} }
try try
@ -1823,7 +1816,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -1896,6 +1888,7 @@ public class JMSBridgeTest extends BridgeTestBase
{ {
factInUse0 = cff0xa; factInUse0 = cff0xa;
factInUse1 = cff1xa; factInUse1 = cff1xa;
ServiceUtils.setTransactionManager(newTransactionManager());
} }
try try
@ -1917,7 +1910,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -2010,7 +2002,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -2079,6 +2070,7 @@ public class JMSBridgeTest extends BridgeTestBase
{ {
factInUse0 = cff0xa; factInUse0 = cff0xa;
factInUse1 = cff1xa; factInUse1 = cff1xa;
ServiceUtils.setTransactionManager(newTransactionManager());
} }
try try
{ {
@ -2101,7 +2093,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -2155,6 +2146,7 @@ public class JMSBridgeTest extends BridgeTestBase
if (qosMode.equals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE)) if (qosMode.equals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE))
{ {
factInUse0 = cff0xa; factInUse0 = cff0xa;
ServiceUtils.setTransactionManager(newTransactionManager());
} }
try try
@ -2178,7 +2170,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -2233,6 +2224,7 @@ public class JMSBridgeTest extends BridgeTestBase
{ {
factInUse0 = cff0xa; factInUse0 = cff0xa;
factInUse1 = cff1xa; factInUse1 = cff1xa;
ServiceUtils.setTransactionManager(newTransactionManager());
} }
try try
@ -2258,7 +2250,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -2293,6 +2284,7 @@ public class JMSBridgeTest extends BridgeTestBase
if (qosMode.equals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE)) if (qosMode.equals(QualityOfServiceMode.ONCE_AND_ONLY_ONCE))
{ {
factInUse0 = cff0xa; factInUse0 = cff0xa;
ServiceUtils.setTransactionManager(newTransactionManager());
} }
try try
@ -2318,7 +2310,6 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
null, null,
false); false);
bridge.setTransactionManager(newTransactionManager());
bridge.start(); bridge.start();
@ -2350,8 +2341,9 @@ public class JMSBridgeTest extends BridgeTestBase
@Test @Test
public void testSetTMClass() throws Exception public void testSetTMClass() throws Exception
{ {
JMSBridgeImpl bridge = null; TransactionManagerLocatorImpl.tm = new DummyTransactionManager();
JMSBridgeImpl bridge = null;
try try
{ {
bridge = new JMSBridgeImpl(cff0, bridge = new JMSBridgeImpl(cff0,
@ -2365,7 +2357,7 @@ public class JMSBridgeTest extends BridgeTestBase
null, null,
3000, 3000,
10, 10,
QualityOfServiceMode.AT_MOST_ONCE, QualityOfServiceMode.ONCE_AND_ONLY_ONCE,
10000, 10000,
3000, 3000,
null, null,
@ -2421,7 +2413,6 @@ public class JMSBridgeTest extends BridgeTestBase
return newTransactionManager(); return newTransactionManager();
} }
// Inner classes ------------------------------------------------------------------- // Inner classes -------------------------------------------------------------------
private static class StressSender implements Runnable private static class StressSender implements Runnable
@ -2455,5 +2446,4 @@ public class JMSBridgeTest extends BridgeTestBase
} }
} }
} }

View File

@ -19,7 +19,6 @@ package org.apache.activemq.tests.integration.jms.bridge;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
import org.apache.activemq.service.extensions.transactions.TransactionManagerLocator; import org.apache.activemq.service.extensions.transactions.TransactionManagerLocator;
/** /**
@ -28,11 +27,16 @@ import org.apache.activemq.service.extensions.transactions.TransactionManagerLoc
public class TransactionManagerLocatorImpl implements TransactionManagerLocator public class TransactionManagerLocatorImpl implements TransactionManagerLocator
{ {
public static TransactionManager tm = new TransactionManagerImple(); public static TransactionManager tm = null;
@Override @Override
public TransactionManager getTransactionManager() public TransactionManager getTransactionManager()
{ {
return tm; return tm;
} }
public void setTransactionManager(TransactionManager transactionManager)
{
tm = transactionManager;
}
} }

View File

@ -46,6 +46,7 @@ import org.apache.activemq.jms.server.config.ConnectionFactoryConfiguration;
import org.apache.activemq.jms.server.config.impl.ConnectionFactoryConfigurationImpl; import org.apache.activemq.jms.server.config.impl.ConnectionFactoryConfigurationImpl;
import org.apache.activemq.jms.server.impl.JMSServerManagerImpl; import org.apache.activemq.jms.server.impl.JMSServerManagerImpl;
import org.apache.activemq.service.extensions.ServiceUtils; import org.apache.activemq.service.extensions.ServiceUtils;
import org.apache.activemq.tests.integration.jms.bridge.TransactionManagerLocatorImpl;
import org.apache.activemq.tests.integration.ra.DummyTransactionManager; import org.apache.activemq.tests.integration.ra.DummyTransactionManager;
import org.apache.activemq.tests.unit.util.InVMNamingContext; import org.apache.activemq.tests.unit.util.InVMNamingContext;
import org.junit.After; import org.junit.After;
@ -59,7 +60,6 @@ import org.junit.Before;
*/ */
public class JMSTestBase extends ServiceTestBase public class JMSTestBase extends ServiceTestBase
{ {
protected ActiveMQServer server; protected ActiveMQServer server;
protected JMSServerManagerImpl jmsServer; protected JMSServerManagerImpl jmsServer;
@ -153,9 +153,6 @@ public class JMSTestBase extends ServiceTestBase
{ {
super.setUp(); super.setUp();
// Load Arjuna TM if one is not already set.
if (ServiceUtils.getTransactionManager() == null) useRealTransactionManager();
mbeanServer = MBeanServerFactory.createMBeanServer(); mbeanServer = MBeanServerFactory.createMBeanServer();
Configuration conf = createDefaultConfig(true) Configuration conf = createDefaultConfig(true)
@ -237,6 +234,9 @@ public class JMSTestBase extends ServiceTestBase
mbeanServer = null; mbeanServer = null;
TransactionManagerLocatorImpl.tm = null;
ServiceUtils.setTransactionManager(null);
super.tearDown(); super.tearDown();
} }
@ -331,4 +331,5 @@ public class JMSTestBase extends ServiceTestBase
throw new JMSRuntimeException(cause.getMessage(), cause.getErrorCode(), cause); throw new JMSRuntimeException(cause.getMessage(), cause.getErrorCode(), cause);
} }
} }
} }