mirror of https://github.com/apache/activemq.git
remove some of the dependencies on port 61616 in current tests. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1153649 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a6b85cc9f3
commit
42e51a3368
|
@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionConsumer;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageListener;
|
||||
|
@ -76,8 +77,13 @@ public class OnePrefetchAsyncConsumerTest extends EmbeddedBrokerTestSupport {
|
|||
assertTrue("Attempted to retrieve more than one ServerSession at a time", testMutex.testSuccessful);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bindAddress = "tcp://localhost:61616";
|
||||
bindAddress = "tcp://localhost:0";
|
||||
super.setUp();
|
||||
|
||||
testMutex = new TestMutex();
|
||||
|
|
|
@ -17,18 +17,14 @@
|
|||
package org.apache.activemq;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.InvalidClientIDException;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ReconnectWithSameClientIDTest.class);
|
||||
|
||||
|
@ -59,8 +55,13 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
|
|||
useConnection(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bindAddress = "tcp://localhost:61616";
|
||||
bindAddress = "tcp://localhost:0";
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
@ -75,9 +76,5 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
|
|||
protected void useConnection(Connection connection) throws JMSException {
|
||||
connection.setClientID("foo");
|
||||
connection.start();
|
||||
/**
|
||||
* Session session = connection.createSession(transacted, authMode);
|
||||
* return session;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,19 +29,15 @@ import org.apache.activemq.ActiveMQSession;
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.region.Queue;
|
||||
import org.apache.activemq.broker.region.RegionBroker;
|
||||
import org.apache.activemq.broker.region.policy.DispatchPolicy;
|
||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class MasterSlaveTempQueueMemoryTest extends TempQueueMemoryTest {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(MasterSlaveTempQueueMemoryTest.class);
|
||||
|
||||
String masterBindAddress = "tcp://localhost:61616";
|
||||
String slaveBindAddress = "tcp://localhost:62616";
|
||||
BrokerService slave;
|
||||
|
||||
/*
|
||||
|
@ -51,17 +47,16 @@ public class MasterSlaveTempQueueMemoryTest extends TempQueueMemoryTest {
|
|||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
// bindAddress is used by super.createBroker
|
||||
bindAddress = masterBindAddress;
|
||||
bindAddress = "tcp://localhost:0";
|
||||
BrokerService master = super.createBroker();
|
||||
master.setBrokerName("master");
|
||||
configureBroker(master);
|
||||
bindAddress = slaveBindAddress;
|
||||
slave = super.createBroker();
|
||||
slave.setBrokerName("slave");
|
||||
slave.setMasterConnectorURI(masterBindAddress);
|
||||
slave.setMasterConnectorURI(master.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
|
||||
configureBroker(slave);
|
||||
bindAddress = masterBindAddress;
|
||||
bindAddress = master.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
return master;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Map;
|
|||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
|
@ -48,7 +49,6 @@ import org.apache.activemq.broker.region.BaseDestination;
|
|||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||
import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy;
|
||||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTempQueue;
|
||||
|
@ -90,8 +90,9 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
public void testConnectors() throws Exception{
|
||||
ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Broker,BrokerName=localhost");
|
||||
BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true);
|
||||
assertEquals("openwire URL port doesn't equal bind Address", new URI(broker.getOpenWireURL()).getPort(), new URI(this.bindAddress).getPort());
|
||||
|
||||
assertEquals("openwire URL port doesn't equal bind Address",
|
||||
new URI(broker.getOpenWireURL()).getPort(),
|
||||
new URI(this.broker.getTransportConnectors().get(0).getPublishableConnectString()).getPort());
|
||||
}
|
||||
|
||||
public void testMBeans() throws Exception {
|
||||
|
@ -317,10 +318,9 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
|
||||
String newDestination = getSecondDestinationString();
|
||||
long queueSize = queue.getQueueSize();
|
||||
assertTrue(queueSize > 0);
|
||||
queue.copyMatchingMessagesTo("counter > 2", newDestination);
|
||||
|
||||
|
||||
|
||||
queueViewMBeanName = assertRegisteredObjectName(domain + ":Type=Queue,Destination=" + newDestination + ",BrokerName=localhost");
|
||||
|
||||
queue = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true);
|
||||
|
@ -334,6 +334,7 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
assertEquals("dest has no memory usage", 0, queue.getMemoryPercentUsage());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void assertSendViaMBean() throws Exception {
|
||||
String queueName = getDestinationString() + ".SendMBBean";
|
||||
|
||||
|
@ -353,7 +354,7 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
for (int i = 0; i < count; i++) {
|
||||
String body = "message:" + i;
|
||||
|
||||
Map headers = new HashMap();
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
headers.put("JMSCorrelationID", "MyCorrId");
|
||||
headers.put("JMSDeliveryMode", Boolean.FALSE);
|
||||
headers.put("JMSXGroupID", "MyGroupID");
|
||||
|
@ -370,7 +371,6 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
if (compdatalist.length == 0) {
|
||||
fail("There is no message in the queue:");
|
||||
}
|
||||
String[] messageIDs = new String[compdatalist.length];
|
||||
|
||||
for (int i = 0; i < compdatalist.length; i++) {
|
||||
CompositeData cdata = compdatalist[i];
|
||||
|
@ -407,7 +407,6 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
assertComplexData(i, cdata, "JMSXGroupSeq", 1234);
|
||||
assertComplexData(i, cdata, "JMSXGroupID", "MyGroupID");
|
||||
assertComplexData(i, cdata, "Text", "message:" + i);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -632,7 +631,7 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bindAddress = "tcp://localhost:61616";
|
||||
bindAddress = "tcp://localhost:0";
|
||||
useTopic = false;
|
||||
super.setUp();
|
||||
mbeanServer = broker.getManagementContext().getMBeanServer();
|
||||
|
@ -656,6 +655,11 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
}
|
||||
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService answer = new BrokerService();
|
||||
answer.setPersistent(false);
|
||||
|
@ -691,7 +695,6 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
protected void useConnectionWithBlobMessage(Connection connection) throws Exception {
|
||||
connection.setClientID(clientID);
|
||||
connection.start();
|
||||
|
@ -733,7 +736,6 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
LOG.info(text);
|
||||
}
|
||||
|
||||
|
||||
protected String getSecondDestinationString() {
|
||||
return "test.new.destination." + getClass() + "." + getName();
|
||||
}
|
||||
|
@ -815,7 +817,6 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
} catch (Exception e) {
|
||||
// expected!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test for AMQ-3029
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.management.ObjectName;
|
|||
import junit.framework.Test;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.store.PersistenceAdapter;
|
||||
|
@ -36,8 +37,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* A specific test of Queue.purge() functionality
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PurgeTest extends EmbeddedBrokerTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PurgeTest.class);
|
||||
|
@ -118,7 +117,6 @@ public class PurgeTest extends EmbeddedBrokerTestSupport {
|
|||
Message message = session.createTextMessage("Test Message");
|
||||
producer.send(message);
|
||||
|
||||
|
||||
MessageConsumer consumer = session.createConsumer(destination);
|
||||
|
||||
Message received = consumer.receive(1000);
|
||||
|
@ -128,16 +126,12 @@ public class PurgeTest extends EmbeddedBrokerTestSupport {
|
|||
BrokerViewMBean brokerProxy = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerViewMBeanName, BrokerViewMBean.class, true);
|
||||
|
||||
brokerProxy.removeQueue(getDestinationString());
|
||||
|
||||
|
||||
producer.send(message);
|
||||
|
||||
received = consumer.receive(1000);
|
||||
|
||||
assertNotNull("Message not received", received);
|
||||
assertEquals(message, received);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testDelete() throws Exception {
|
||||
|
@ -209,7 +203,7 @@ public class PurgeTest extends EmbeddedBrokerTestSupport {
|
|||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bindAddress = "tcp://localhost:61616";
|
||||
bindAddress = "tcp://localhost:0";
|
||||
useTopic = false;
|
||||
super.setUp();
|
||||
mbeanServer = broker.getManagementContext().getMBeanServer();
|
||||
|
@ -233,6 +227,11 @@ public class PurgeTest extends EmbeddedBrokerTestSupport {
|
|||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
}
|
||||
|
||||
protected void echo(String text) {
|
||||
LOG.info(text);
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ public class AMQ1687Test extends EmbeddedBrokerTestSupport {
|
|||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
//prefetch change is not required, but test will not fail w/o it, only spew errors in the AMQ log.
|
||||
return new ActiveMQConnectionFactory(this.bindAddress+"?jms.prefetchPolicy.all=5");
|
||||
//return super.createConnectionFactory();
|
||||
//return new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
}
|
||||
|
||||
public void testVirtualTopicCreation() throws Exception {
|
||||
|
@ -80,12 +78,10 @@ public class AMQ1687Test extends EmbeddedBrokerTestSupport {
|
|||
messageList.assertMessagesArrived(total*2);
|
||||
}
|
||||
|
||||
|
||||
protected String getVirtualTopicName() {
|
||||
return "VirtualTopic.TEST";
|
||||
}
|
||||
|
||||
|
||||
protected String getVirtualTopicConsumerName() {
|
||||
return "Consumer.A.VirtualTopic.TEST";
|
||||
}
|
||||
|
@ -94,7 +90,6 @@ public class AMQ1687Test extends EmbeddedBrokerTestSupport {
|
|||
return "Consumer.B.VirtualTopic.TEST";
|
||||
}
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
this.bindAddress="tcp://localhost:61616";
|
||||
super.setUp();
|
||||
|
|
|
@ -51,8 +51,8 @@ public class AMQ1866 extends TestCase {
|
|||
private BrokerService brokerService;
|
||||
private ArrayList<Thread> threads = new ArrayList<Thread>();
|
||||
|
||||
String ACTIVEMQ_BROKER_BIND = "tcp://localhost:61616";
|
||||
String ACTIVEMQ_BROKER_URI = "tcp://localhost:61616";
|
||||
private final String ACTIVEMQ_BROKER_BIND = "tcp://localhost:0";
|
||||
private String ACTIVEMQ_BROKER_URI;
|
||||
|
||||
AtomicBoolean shutdown = new AtomicBoolean();
|
||||
private ActiveMQQueue destination;
|
||||
|
@ -75,6 +75,8 @@ public class AMQ1866 extends TestCase {
|
|||
|
||||
brokerService.addConnector(ACTIVEMQ_BROKER_BIND);
|
||||
brokerService.start();
|
||||
|
||||
ACTIVEMQ_BROKER_URI = brokerService.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
destination = new ActiveMQQueue(getName());
|
||||
}
|
||||
|
||||
|
@ -90,17 +92,16 @@ public class AMQ1866 extends TestCase {
|
|||
}
|
||||
|
||||
public void testConsumerSlowDownPrefetch0() throws Exception {
|
||||
ACTIVEMQ_BROKER_URI = "tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=0";
|
||||
ACTIVEMQ_BROKER_URI = ACTIVEMQ_BROKER_URI + "?jms.prefetchPolicy.queuePrefetch=0";
|
||||
doTestConsumerSlowDown();
|
||||
}
|
||||
|
||||
public void testConsumerSlowDownPrefetch10() throws Exception {
|
||||
ACTIVEMQ_BROKER_URI = "tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=10";
|
||||
ACTIVEMQ_BROKER_URI = ACTIVEMQ_BROKER_URI + "?jms.prefetchPolicy.queuePrefetch=10";
|
||||
doTestConsumerSlowDown();
|
||||
}
|
||||
|
||||
public void testConsumerSlowDownDefaultPrefetch() throws Exception {
|
||||
ACTIVEMQ_BROKER_URI = "tcp://localhost:61616";
|
||||
doTestConsumerSlowDown();
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,7 @@ public class AMQ1866 extends TestCase {
|
|||
Thread.sleep(1000);
|
||||
long c1Counter = c1.counter.getAndSet(0);
|
||||
long c2Counter = c2.counter.getAndSet(0);
|
||||
System.out.println("c1: "+c1Counter+", c2: "+c2Counter);
|
||||
log.debug("c1: "+c1Counter+", c2: "+c2Counter);
|
||||
totalReceived += c1Counter;
|
||||
totalReceived += c2Counter;
|
||||
|
||||
|
|
|
@ -43,19 +43,20 @@ public class AMQ1917Test extends TestCase {
|
|||
|
||||
private static final int NUM_MESSAGES = 4000;
|
||||
private static final int NUM_THREADS = 10;
|
||||
public static final String REQUEST_QUEUE = "mock.in.queue";
|
||||
public static final String REPLY_QUEUE = "mock.out.queue";
|
||||
private static final String REQUEST_QUEUE = "mock.in.queue";
|
||||
private static final String REPLY_QUEUE = "mock.out.queue";
|
||||
|
||||
Destination requestDestination = ActiveMQDestination.createDestination(
|
||||
private Destination requestDestination = ActiveMQDestination.createDestination(
|
||||
REQUEST_QUEUE, ActiveMQDestination.QUEUE_TYPE);
|
||||
Destination replyDestination = ActiveMQDestination.createDestination(
|
||||
private Destination replyDestination = ActiveMQDestination.createDestination(
|
||||
REPLY_QUEUE, ActiveMQDestination.QUEUE_TYPE);
|
||||
|
||||
CountDownLatch roundTripLatch = new CountDownLatch(NUM_MESSAGES);
|
||||
CountDownLatch errorLatch = new CountDownLatch(1);
|
||||
ThreadPoolExecutor tpe;
|
||||
final String BROKER_URL = "tcp://localhost:61616";
|
||||
BrokerService broker = null;
|
||||
private CountDownLatch roundTripLatch = new CountDownLatch(NUM_MESSAGES);
|
||||
private CountDownLatch errorLatch = new CountDownLatch(1);
|
||||
private ThreadPoolExecutor tpe;
|
||||
private final String BROKER_URL = "tcp://localhost:61616";
|
||||
private String connectionUri;
|
||||
private BrokerService broker = null;
|
||||
private boolean working = true;
|
||||
|
||||
// trival session/producer pool
|
||||
|
@ -68,6 +69,8 @@ public class AMQ1917Test extends TestCase {
|
|||
broker.addConnector(BROKER_URL);
|
||||
broker.start();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
|
||||
BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(10000);
|
||||
tpe = new ThreadPoolExecutor(NUM_THREADS, NUM_THREADS, 60000,
|
||||
TimeUnit.MILLISECONDS, queue);
|
||||
|
@ -83,7 +86,7 @@ public class AMQ1917Test extends TestCase {
|
|||
public void testLoadedSendRecieveWithCorrelationId() throws Exception {
|
||||
|
||||
ActiveMQConnectionFactory connectionFactory = new org.apache.activemq.ActiveMQConnectionFactory();
|
||||
connectionFactory.setBrokerURL(BROKER_URL);
|
||||
connectionFactory.setBrokerURL(connectionUri);
|
||||
Connection connection = connectionFactory.createConnection();
|
||||
setupReceiver(connection);
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.apache.activemq.util.Wait;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class AMQ2314Test extends CombinationTestSupport {
|
||||
|
||||
public boolean consumeAll = false;
|
||||
|
@ -48,8 +47,9 @@ public class AMQ2314Test extends CombinationTestSupport {
|
|||
private static final int MESSAGES_COUNT = 30000;
|
||||
private static byte[] buf = new byte[1024];
|
||||
private BrokerService broker;
|
||||
private String connectionUri;
|
||||
|
||||
protected long messageReceiveTimeout = 500L;
|
||||
private static final long messageReceiveTimeout = 500L;
|
||||
|
||||
Destination destination = new ActiveMQTopic("FooTwo");
|
||||
|
||||
|
@ -64,7 +64,6 @@ public class AMQ2314Test extends CombinationTestSupport {
|
|||
runProducerWithHungConsumer();
|
||||
}
|
||||
|
||||
|
||||
public void runProducerWithHungConsumer() throws Exception {
|
||||
|
||||
final CountDownLatch consumerContinue = new CountDownLatch(1);
|
||||
|
@ -72,7 +71,7 @@ public class AMQ2314Test extends CombinationTestSupport {
|
|||
|
||||
final long origTempUsage = broker.getSystemUsage().getTempUsage().getUsage();
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
factory.setAlwaysSyncSend(true);
|
||||
|
||||
// ensure messages are spooled to disk for this consumer
|
||||
|
@ -159,17 +158,17 @@ public class AMQ2314Test extends CombinationTestSupport {
|
|||
broker.setAdvisorySupport(false);
|
||||
broker.setDeleteAllMessagesOnStartup(true);
|
||||
|
||||
broker.addConnector("tcp://localhost:61616").setName("Default");
|
||||
broker.addConnector("tcp://localhost:0").setName("Default");
|
||||
broker.start();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
broker.stop();
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return suite(AMQ2314Test.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,14 +37,15 @@ import org.apache.activemq.broker.jmx.ManagementContext;
|
|||
*/
|
||||
public class AMQ2513Test extends TestCase {
|
||||
|
||||
BrokerService broker;
|
||||
private BrokerService broker;
|
||||
private String connectionUri;
|
||||
|
||||
void createBroker(boolean deleteAllMessagesOnStartup) throws Exception {
|
||||
broker = new BrokerService();
|
||||
broker.setBrokerName("localhost");
|
||||
broker.setUseJmx(true);
|
||||
broker.setDeleteAllMessagesOnStartup(deleteAllMessagesOnStartup);
|
||||
broker.addConnector("tcp://localhost:61616");
|
||||
broker.addConnector("tcp://localhost:0");
|
||||
|
||||
ManagementContext ctx = new ManagementContext();
|
||||
//if createConnector == true everything is fine
|
||||
|
@ -52,14 +53,15 @@ public class AMQ2513Test extends TestCase {
|
|||
broker.setManagementContext(ctx);
|
||||
|
||||
broker.start();
|
||||
|
||||
broker.waitUntilStarted();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
}
|
||||
|
||||
public void testJmx() throws Exception{
|
||||
createBroker(true);
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
Connection connection = factory.createConnection();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer producer = session.createProducer(session.createQueue("test"));
|
||||
|
@ -77,7 +79,7 @@ public class AMQ2513Test extends TestCase {
|
|||
broker.waitUntilStopped();
|
||||
|
||||
createBroker(false);
|
||||
factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
connection = factory.createConnection();
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
producer = session.createProducer(session.createQueue("test"));
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
|
@ -39,16 +38,17 @@ public class AMQ2616Test extends TestCase {
|
|||
private static final int NUMBER = 2000;
|
||||
private BrokerService brokerService;
|
||||
private final ArrayList<Thread> threads = new ArrayList<Thread>();
|
||||
String ACTIVEMQ_BROKER_BIND = "tcp://0.0.0.0:61616";
|
||||
AtomicBoolean shutdown = new AtomicBoolean();
|
||||
private final String ACTIVEMQ_BROKER_BIND = "tcp://0.0.0.0:0";
|
||||
private final AtomicBoolean shutdown = new AtomicBoolean();
|
||||
|
||||
private String connectionUri;
|
||||
|
||||
public void testQueueResourcesReleased() throws Exception{
|
||||
ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(ACTIVEMQ_BROKER_BIND);
|
||||
ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(connectionUri);
|
||||
Connection tempConnection = fac.createConnection();
|
||||
tempConnection.start();
|
||||
Session tempSession = tempConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Queue tempQueue = tempSession.createTemporaryQueue();
|
||||
final MessageConsumer tempConsumer = tempSession.createConsumer(tempQueue);
|
||||
|
||||
Connection testConnection = fac.createConnection();
|
||||
long startUsage = brokerService.getSystemUsage().getMemoryUsage().getUsage();
|
||||
|
@ -95,6 +95,10 @@ public class AMQ2616Test extends TestCase {
|
|||
brokerService.getSystemUsage().getTempUsage().setLimit(200 * 1024 * 1024);
|
||||
brokerService.addConnector(ACTIVEMQ_BROKER_BIND);
|
||||
brokerService.start();
|
||||
brokerService.waitUntilStarted();
|
||||
|
||||
connectionUri = brokerService.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
|
||||
new ActiveMQQueue(getName());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.activemq.bugs;
|
|||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.Session;
|
||||
|
||||
|
@ -26,13 +25,12 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CraigsBugTest extends EmbeddedBrokerTestSupport {
|
||||
|
||||
private String connectionUri;
|
||||
|
||||
public void testConnectionFactory() throws Exception {
|
||||
final ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
final ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectionUri);
|
||||
final ActiveMQQueue queue = new ActiveMQQueue("testqueue");
|
||||
final Connection conn = cf.createConnection();
|
||||
|
||||
|
@ -60,8 +58,10 @@ public class CraigsBugTest extends EmbeddedBrokerTestSupport {
|
|||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bindAddress = "tcp://localhost:61616";
|
||||
bindAddress = "tcp://localhost:0";
|
||||
super.setUp();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,13 +41,14 @@ public class DataFileNotDeletedTest extends TestCase {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(DataFileNotDeletedTest.class);
|
||||
|
||||
private final CountDownLatch latch = new CountDownLatch(max_messages);
|
||||
private static int max_messages = 600;
|
||||
private final static int max_messages = 600;
|
||||
private static int messageCounter;
|
||||
private final String destinationName = getName()+"_Queue";
|
||||
private BrokerService broker;
|
||||
private Connection receiverConnection;
|
||||
private Connection producerConnection;
|
||||
final boolean useTopic = false;
|
||||
private final boolean useTopic = false;
|
||||
private String connectionUri;
|
||||
|
||||
AMQPersistenceAdapter persistentAdapter;
|
||||
protected static final String payload = new String(new byte[512]);
|
||||
|
@ -111,7 +112,7 @@ public class DataFileNotDeletedTest extends TestCase {
|
|||
}
|
||||
|
||||
private Connection createConnection() throws JMSException {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
return factory.createConnection();
|
||||
}
|
||||
|
||||
|
@ -120,7 +121,7 @@ public class DataFileNotDeletedTest extends TestCase {
|
|||
broker.setDeleteAllMessagesOnStartup(true);
|
||||
broker.setPersistent(true);
|
||||
broker.setUseJmx(true);
|
||||
broker.addConnector("tcp://localhost:61616").setName("Default");
|
||||
broker.addConnector("tcp://localhost:0").setName("Default");
|
||||
broker.setPersistenceFactory(new AMQPersistenceAdapterFactory());
|
||||
AMQPersistenceAdapterFactory factory = (AMQPersistenceAdapterFactory) broker.getPersistenceFactory();
|
||||
// ensure there are a bunch of data files but multiple entries in each
|
||||
|
@ -133,6 +134,9 @@ public class DataFileNotDeletedTest extends TestCase {
|
|||
persistentAdapter = (AMQPersistenceAdapter) broker.getPersistenceAdapter();
|
||||
broker.start();
|
||||
LOG.info("Starting broker..");
|
||||
broker.waitUntilStarted();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
}
|
||||
|
||||
private void buildReceiver(Connection connection, final String queueName, boolean transacted, final Receiver receiver, boolean isTopic) throws Exception {
|
||||
|
|
|
@ -16,10 +16,9 @@
|
|||
*/
|
||||
package org.apache.activemq.bugs;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageProducer;
|
||||
|
@ -28,19 +27,19 @@ import javax.jms.Session;
|
|||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.transport.RequestTimedOutIOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class JmsTimeoutTest extends EmbeddedBrokerTestSupport {
|
||||
|
||||
static final Logger LOG = LoggerFactory.getLogger(JmsTimeoutTest.class);
|
||||
|
||||
private int messageSize=1024*64;
|
||||
private int messageCount=10000;
|
||||
private final int messageSize=1024*64;
|
||||
private final int messageCount=10000;
|
||||
private final AtomicInteger exceptionCount = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
|
@ -88,7 +87,6 @@ public class JmsTimeoutTest extends EmbeddedBrokerTestSupport {
|
|||
assertTrue("No exception from the broker", exceptionCount.get() > 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the case where the broker is blocked due to a memory limit
|
||||
* with a fail timeout
|
||||
|
@ -120,7 +118,6 @@ public class JmsTimeoutTest extends EmbeddedBrokerTestSupport {
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
cx.start();
|
||||
|
@ -134,7 +131,7 @@ public class JmsTimeoutTest extends EmbeddedBrokerTestSupport {
|
|||
|
||||
protected void setUp() throws Exception {
|
||||
exceptionCount.set(0);
|
||||
bindAddress = "tcp://localhost:61616";
|
||||
bindAddress = "tcp://localhost:0";
|
||||
broker = createBroker();
|
||||
broker.setDeleteAllMessagesOnStartup(true);
|
||||
broker.getSystemUsage().getMemoryUsage().setLimit(5*1024*1024);
|
||||
|
@ -142,6 +139,12 @@ public class JmsTimeoutTest extends EmbeddedBrokerTestSupport {
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory(
|
||||
broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
}
|
||||
|
||||
private String createMessageText() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("<filler>");
|
||||
|
|
|
@ -39,23 +39,23 @@ import javax.management.ObjectName;
|
|||
/**
|
||||
* Test to determine if expired messages are being reaped if there is
|
||||
* no active consumer connected to the broker.
|
||||
*
|
||||
* @author bsnyder
|
||||
*
|
||||
*/
|
||||
public class MessageExpirationReaperTest {
|
||||
|
||||
protected BrokerService broker;
|
||||
protected ConnectionFactory factory;
|
||||
protected ActiveMQConnection connection;
|
||||
protected String destinationName = "TEST.Q";
|
||||
protected String brokerUrl = "tcp://localhost:61616";
|
||||
protected String brokerName = "testBroker";
|
||||
private BrokerService broker;
|
||||
private ConnectionFactory factory;
|
||||
private ActiveMQConnection connection;
|
||||
private final String destinationName = "TEST.Q";
|
||||
private final String brokerUrl = "tcp://localhost:0";
|
||||
private final String brokerName = "testBroker";
|
||||
private String connectionUri;
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
createBroker();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
|
||||
factory = createConnectionFactory();
|
||||
connection = (ActiveMQConnection) factory.createConnection();
|
||||
connection.start();
|
||||
|
@ -83,7 +83,7 @@ public class MessageExpirationReaperTest {
|
|||
}
|
||||
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory(brokerUrl);
|
||||
return new ActiveMQConnectionFactory(connectionUri);
|
||||
}
|
||||
|
||||
protected Session createSession() throws Exception {
|
||||
|
|
|
@ -38,18 +38,18 @@ public class OutOfOrderTestCase extends TestCase {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(OutOfOrderTestCase.class);
|
||||
|
||||
public static final String BROKER_URL = "tcp://localhost:61616";
|
||||
private static final String BROKER_URL = "tcp://localhost:0";
|
||||
private static final int PREFETCH = 10;
|
||||
private static final String CONNECTION_URL = BROKER_URL + "?jms.prefetchPolicy.all=" + PREFETCH;
|
||||
private static final String CONNECTION_URL_OPTIONS = "?jms.prefetchPolicy.all=" + PREFETCH;
|
||||
|
||||
public static final String QUEUE_NAME = "QUEUE";
|
||||
private static final String DESTINATION = "QUEUE?consumer.exclusive=true";
|
||||
|
||||
BrokerService brokerService;
|
||||
Session session;
|
||||
Connection connection;
|
||||
private BrokerService brokerService;
|
||||
private Session session;
|
||||
private Connection connection;
|
||||
private String connectionUri;
|
||||
|
||||
int seq = 0;
|
||||
private int seq = 0;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
brokerService = new BrokerService();
|
||||
|
@ -57,23 +57,22 @@ public class OutOfOrderTestCase extends TestCase {
|
|||
brokerService.addConnector(BROKER_URL);
|
||||
brokerService.deleteAllMessages();
|
||||
brokerService.start();
|
||||
brokerService.waitUntilStarted();
|
||||
|
||||
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(CONNECTION_URL);
|
||||
connectionUri = brokerService.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
|
||||
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri + CONNECTION_URL_OPTIONS);
|
||||
connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
session.close();
|
||||
connection.close();
|
||||
brokerService.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testOrder() throws Exception {
|
||||
|
||||
log.info("Producing messages 0-29 . . .");
|
||||
|
|
|
@ -41,21 +41,28 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Test case demonstrating situation where messages are not delivered to consumers.
|
||||
* Test case demonstrating situation where messages are not delivered to
|
||||
* consumers.
|
||||
*/
|
||||
public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
||||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(QueueWorkerPrefetchTest.class);
|
||||
public class QueueWorkerPrefetchTest extends TestCase implements
|
||||
MessageListener {
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(QueueWorkerPrefetchTest.class);
|
||||
private static final int BATCH_SIZE = 10;
|
||||
private static final long WAIT_TIMEOUT = 1000 * 10;
|
||||
|
||||
/** The connection URL. */
|
||||
private static final String CONNECTION_URL = "tcp://localhost:61616";
|
||||
private static final String BROKER_BIND_ADDRESS = "tcp://localhost:0";
|
||||
|
||||
/** The queue prefetch size to use. A value greater than 1 seems to make things work. */
|
||||
/**
|
||||
* The queue prefetch size to use. A value greater than 1 seems to make
|
||||
* things work.
|
||||
*/
|
||||
private static final int QUEUE_PREFETCH_SIZE = 1;
|
||||
|
||||
/** The number of workers to use. A single worker with a prefetch of 1 works. */
|
||||
/**
|
||||
* The number of workers to use. A single worker with a prefetch of 1 works.
|
||||
*/
|
||||
private static final int NUM_WORKERS = 2;
|
||||
|
||||
/** Embedded JMS broker. */
|
||||
|
@ -68,17 +75,21 @@ public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
|||
private MessageConsumer masterItemConsumer;
|
||||
|
||||
/** The number of acks received by the master. */
|
||||
private AtomicLong acksReceived = new AtomicLong(0);
|
||||
private final AtomicLong acksReceived = new AtomicLong(0);
|
||||
|
||||
private AtomicReference<CountDownLatch> latch = new AtomicReference<CountDownLatch>();
|
||||
private final AtomicReference<CountDownLatch> latch = new AtomicReference<CountDownLatch>();
|
||||
|
||||
private String connectionUri;
|
||||
|
||||
/** Messages sent to the work-item queue. */
|
||||
private static class WorkMessage implements Serializable
|
||||
{
|
||||
private static class WorkMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final int id;
|
||||
|
||||
public WorkMessage(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Work: " + id;
|
||||
|
@ -86,14 +97,15 @@ public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
|||
}
|
||||
|
||||
/**
|
||||
* The worker process. Consume messages from the work-item queue, possibly creating
|
||||
* more messages to submit to the work-item queue. For each work item, send an ack
|
||||
* to the master.
|
||||
* The worker process. Consume messages from the work-item queue, possibly
|
||||
* creating more messages to submit to the work-item queue. For each work
|
||||
* item, send an ack to the master.
|
||||
*/
|
||||
private static class Worker implements MessageListener {
|
||||
/**
|
||||
* Counter shared between workers to decided when new work-item messages
|
||||
* are created.
|
||||
*/
|
||||
private static class Worker implements MessageListener
|
||||
{
|
||||
|
||||
/** Counter shared between workers to decided when new work-item messages are created. */
|
||||
private static AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
/** Session to use. */
|
||||
|
@ -105,45 +117,40 @@ public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
|||
/** Producer for sending new work items to the work-items queue. */
|
||||
private MessageProducer workItemProducer;
|
||||
|
||||
public Worker(Session session)
|
||||
throws JMSException
|
||||
{
|
||||
public Worker(Session session) throws JMSException {
|
||||
this.session = session;
|
||||
masterItemProducer = session.createProducer(session.createQueue("master-item"));
|
||||
masterItemProducer = session.createProducer(session
|
||||
.createQueue("master-item"));
|
||||
Queue workItemQueue = session.createQueue("work-item");
|
||||
workItemProducer = session.createProducer(workItemQueue);
|
||||
MessageConsumer workItemConsumer = session.createConsumer(workItemQueue);
|
||||
MessageConsumer workItemConsumer = session
|
||||
.createConsumer(workItemQueue);
|
||||
workItemConsumer.setMessageListener(this);
|
||||
}
|
||||
|
||||
public void onMessage(javax.jms.Message message)
|
||||
{
|
||||
try
|
||||
{
|
||||
WorkMessage work = (WorkMessage)((ObjectMessage)message).getObject();
|
||||
public void onMessage(javax.jms.Message message) {
|
||||
try {
|
||||
WorkMessage work = (WorkMessage) ((ObjectMessage) message)
|
||||
.getObject();
|
||||
|
||||
long c = counter.incrementAndGet();
|
||||
|
||||
// Don't create a new work item for every BATCH_SIZE message. */
|
||||
if (c % BATCH_SIZE != 0)
|
||||
{
|
||||
if (c % BATCH_SIZE != 0) {
|
||||
// Send new work item to work-item queue.
|
||||
workItemProducer.send(session.createObjectMessage(
|
||||
new WorkMessage(work.id+1)));
|
||||
workItemProducer.send(session
|
||||
.createObjectMessage(new WorkMessage(work.id + 1)));
|
||||
}
|
||||
|
||||
// Send ack to master.
|
||||
masterItemProducer.send(session.createObjectMessage(work));
|
||||
}
|
||||
catch (JMSException e)
|
||||
{
|
||||
} catch (JMSException e) {
|
||||
throw new IllegalStateException("Something has gone wrong", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Close of JMS resources used by worker. */
|
||||
public void close() throws JMSException
|
||||
{
|
||||
public void close() throws JMSException {
|
||||
masterItemProducer.close();
|
||||
workItemProducer.close();
|
||||
session.close();
|
||||
|
@ -151,8 +158,7 @@ public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
|||
}
|
||||
|
||||
/** Master message handler. Process ack messages. */
|
||||
public void onMessage(javax.jms.Message message)
|
||||
{
|
||||
public void onMessage(javax.jms.Message message) {
|
||||
long acks = acksReceived.incrementAndGet();
|
||||
latch.get().countDown();
|
||||
if (acks % 1 == 0) {
|
||||
|
@ -160,53 +166,56 @@ public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
|||
}
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
protected void setUp() throws Exception {
|
||||
// Create the message broker.
|
||||
super.setUp();
|
||||
broker = new BrokerService();
|
||||
broker.setPersistent(false);
|
||||
broker.setUseJmx(true);
|
||||
broker.addConnector(CONNECTION_URL);
|
||||
broker.addConnector(BROKER_BIND_ADDRESS);
|
||||
broker.start();
|
||||
broker.waitUntilStarted();
|
||||
|
||||
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
protected void tearDown() throws Exception {
|
||||
// Shut down the message broker.
|
||||
broker.deleteAllMessages();
|
||||
broker.stop();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testActiveMQ()
|
||||
throws Exception
|
||||
{
|
||||
public void testActiveMQ() throws Exception {
|
||||
// Create the connection to the broker.
|
||||
ActiveMQConnectionFactory connectionFactory =
|
||||
new ActiveMQConnectionFactory(CONNECTION_URL);
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri);
|
||||
ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
|
||||
prefetchPolicy.setQueuePrefetch(QUEUE_PREFETCH_SIZE);
|
||||
connectionFactory.setPrefetchPolicy(prefetchPolicy);
|
||||
Connection connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
|
||||
Session masterSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
workItemProducer = masterSession.createProducer(masterSession.createQueue("work-item"));
|
||||
masterItemConsumer = masterSession.createConsumer(masterSession.createQueue("master-item"));
|
||||
Session masterSession = connection.createSession(false,
|
||||
Session.AUTO_ACKNOWLEDGE);
|
||||
workItemProducer = masterSession.createProducer(masterSession
|
||||
.createQueue("work-item"));
|
||||
masterItemConsumer = masterSession.createConsumer(masterSession
|
||||
.createQueue("master-item"));
|
||||
masterItemConsumer.setMessageListener(this);
|
||||
|
||||
// Create the workers.
|
||||
Worker[] workers = new Worker[NUM_WORKERS];
|
||||
for (int i = 0; i < NUM_WORKERS; i++)
|
||||
{
|
||||
workers[i] = new Worker(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
|
||||
for (int i = 0; i < NUM_WORKERS; i++) {
|
||||
workers[i] = new Worker(connection.createSession(false,
|
||||
Session.AUTO_ACKNOWLEDGE));
|
||||
}
|
||||
|
||||
// Send a message to the work queue, and wait for the BATCH_SIZE acks from the workers.
|
||||
// Send a message to the work queue, and wait for the BATCH_SIZE acks
|
||||
// from the workers.
|
||||
acksReceived.set(0);
|
||||
latch.set(new CountDownLatch(BATCH_SIZE));
|
||||
workItemProducer.send(masterSession.createObjectMessage(new WorkMessage(1)));
|
||||
workItemProducer.send(masterSession
|
||||
.createObjectMessage(new WorkMessage(1)));
|
||||
|
||||
if (!latch.get().await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
fail("First batch only received " + acksReceived + " messages");
|
||||
|
@ -220,7 +229,8 @@ public class QueueWorkerPrefetchTest extends TestCase implements MessageListener
|
|||
// receive this new message.
|
||||
acksReceived.set(0);
|
||||
latch.set(new CountDownLatch(BATCH_SIZE));
|
||||
workItemProducer.send(masterSession.createObjectMessage(new WorkMessage(1)));
|
||||
workItemProducer.send(masterSession
|
||||
.createObjectMessage(new WorkMessage(1)));
|
||||
|
||||
if (!latch.get().await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
fail("Second batch only received " + acksReceived + " messages");
|
||||
|
|
|
@ -41,8 +41,8 @@ public class SlowConsumerTest extends TestCase {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(SlowConsumerTest.class);
|
||||
private static final int MESSAGES_COUNT = 10000;
|
||||
|
||||
protected int messageLogFrequency = 2500;
|
||||
protected long messageReceiveTimeout = 10000L;
|
||||
private final int messageLogFrequency = 2500;
|
||||
private final long messageReceiveTimeout = 10000L;
|
||||
|
||||
private Socket stompSocket;
|
||||
private ByteArrayOutputStream inputBuffer;
|
||||
|
@ -58,9 +58,10 @@ public class SlowConsumerTest extends TestCase {
|
|||
broker.setUseJmx(true);
|
||||
broker.setDeleteAllMessagesOnStartup(true);
|
||||
|
||||
broker.addConnector("tcp://localhost:61616").setName("Default");
|
||||
broker.addConnector("tcp://localhost:0").setName("Default");
|
||||
broker.start();
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
|
||||
broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
final Connection connection = factory.createConnection();
|
||||
connection.start();
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TransactionNotStartedErrorTest extends TestCase {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TransactionNotStartedErrorTest.class);
|
||||
|
||||
private static int counter = 500;
|
||||
private static final int counter = 500;
|
||||
|
||||
private static int hectorToHaloCtr;
|
||||
private static int xenaToHaloCtr;
|
||||
|
@ -54,14 +54,13 @@ public class TransactionNotStartedErrorTest extends TestCase {
|
|||
private static int haloToXenaCtr;
|
||||
private static int haloToTroyCtr;
|
||||
|
||||
private String hectorToHalo = "hectorToHalo";
|
||||
private String xenaToHalo = "xenaToHalo";
|
||||
private String troyToHalo = "troyToHalo";
|
||||
|
||||
private String haloToHector = "haloToHector";
|
||||
private String haloToXena = "haloToXena";
|
||||
private String haloToTroy = "haloToTroy";
|
||||
private final String hectorToHalo = "hectorToHalo";
|
||||
private final String xenaToHalo = "xenaToHalo";
|
||||
private final String troyToHalo = "troyToHalo";
|
||||
|
||||
private final String haloToHector = "haloToHector";
|
||||
private final String haloToXena = "haloToXena";
|
||||
private final String haloToTroy = "haloToTroy";
|
||||
|
||||
private BrokerService broker;
|
||||
|
||||
|
@ -72,8 +71,9 @@ public class TransactionNotStartedErrorTest extends TestCase {
|
|||
|
||||
private final Object lock = new Object();
|
||||
|
||||
public Connection createConnection() throws JMSException {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
public Connection createConnection() throws Exception {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
|
||||
broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
return factory.createConnection();
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class TransactionNotStartedErrorTest extends TestCase {
|
|||
broker.setDeleteAllMessagesOnStartup(true);
|
||||
broker.setPersistent(true);
|
||||
broker.setUseJmx(true);
|
||||
broker.addConnector("tcp://localhost:61616").setName("Default");
|
||||
broker.addConnector("tcp://localhost:0").setName("Default");
|
||||
broker.start();
|
||||
LOG.info("Starting broker..");
|
||||
}
|
||||
|
@ -234,12 +234,10 @@ public class TransactionNotStartedErrorTest extends TestCase {
|
|||
}
|
||||
|
||||
public MessageSender buildTransactionalProducer(String queueName, Connection connection) throws Exception {
|
||||
|
||||
return new MessageSender(queueName, connection, true, false);
|
||||
}
|
||||
|
||||
public Thread buildProducer(Connection connection, final String queueName) throws Exception {
|
||||
|
||||
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final MessageSender producer = new MessageSender(queueName, connection, false, false);
|
||||
Thread thread = new Thread() {
|
||||
|
|
|
@ -326,7 +326,7 @@ public class ConcurrentProducerDurableConsumerTest extends TestSupport {
|
|||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService brokerService = new BrokerService();
|
||||
brokerService.setEnableStatistics(false);
|
||||
brokerService.addConnector("tcp://0.0.0.0:61616");
|
||||
brokerService.addConnector("tcp://0.0.0.0:0");
|
||||
brokerService.setDeleteAllMessagesOnStartup(true);
|
||||
|
||||
PolicyEntry policy = new PolicyEntry();
|
||||
|
@ -343,9 +343,9 @@ public class ConcurrentProducerDurableConsumerTest extends TestSupport {
|
|||
policyMap.setDefaultEntry(policy);
|
||||
brokerService.setDestinationPolicy(policyMap);
|
||||
|
||||
if (false) {
|
||||
// external mysql works a lot faster
|
||||
//
|
||||
// if (false) {
|
||||
// // external mysql works a lot faster
|
||||
// //
|
||||
// JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
|
||||
// BasicDataSource ds = new BasicDataSource();
|
||||
// com.mysql.jdbc.Driver d = new com.mysql.jdbc.Driver();
|
||||
|
@ -372,14 +372,15 @@ public class ConcurrentProducerDurableConsumerTest extends TestSupport {
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
*/
|
||||
} else {
|
||||
// } else {
|
||||
setDefaultPersistenceAdapter(brokerService);
|
||||
}
|
||||
// }
|
||||
return brokerService;
|
||||
}
|
||||
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
|
||||
broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
|
||||
prefetchPolicy.setAll(1);
|
||||
factory.setPrefetchPolicy(prefetchPolicy);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
@ -16,6 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.jms.Connection;
|
||||
|
@ -32,10 +32,8 @@ import org.apache.activemq.command.ActiveMQQueue;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author Rajani Chennamaneni
|
||||
*
|
||||
*/
|
||||
public class DispatchMultipleConsumersTest extends TestCase {
|
||||
private final static Logger logger = LoggerFactory.getLogger(DispatchMultipleConsumersTest.class);
|
||||
|
@ -50,7 +48,7 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
AtomicInteger consumedCount;
|
||||
CountDownLatch producerLatch;
|
||||
CountDownLatch consumerLatch;
|
||||
String brokerURL = "tcp://localhost:61616";
|
||||
String brokerURL;
|
||||
String userName = "";
|
||||
String password = "";
|
||||
|
||||
|
@ -61,15 +59,18 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
broker.setPersistent(true);
|
||||
broker.setUseJmx(true);
|
||||
broker.deleteAllMessages();
|
||||
broker.addConnector("tcp://localhost:61616");
|
||||
broker.addConnector("tcp://localhost:0");
|
||||
broker.start();
|
||||
broker.waitUntilStarted();
|
||||
dest = new ActiveMQQueue(destinationName);
|
||||
resetCounters();
|
||||
brokerURL = broker.getTransportConnectors().get(0).getPublishableConnectString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
// broker.stop();
|
||||
broker.stop();
|
||||
broker.waitUntilStopped();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
@ -84,15 +85,6 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
for (int i = 1; i <= 5; i++) {
|
||||
resetCounters();
|
||||
dispatch();
|
||||
/*try {
|
||||
System.out.print("Press Enter to continue/finish:");
|
||||
//pause to check the counts on JConsole
|
||||
System.in.read();
|
||||
System.in.read();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
//check for consumed messages count
|
||||
assertEquals("Incorrect messages in Iteration " + i, sentCount.get(), consumedCount.get());
|
||||
}
|
||||
}
|
||||
|
@ -130,15 +122,13 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
}
|
||||
|
||||
private class ConsumerThread extends Thread {
|
||||
Connection conn;
|
||||
Session session;
|
||||
MessageConsumer consumer;
|
||||
|
||||
public ConsumerThread(Connection conn, String name) {
|
||||
super();
|
||||
this.conn = conn;
|
||||
this.setName(name);
|
||||
logger.info("Created new consumer thread:" + name);
|
||||
logger.trace("Created new consumer thread:" + name);
|
||||
try {
|
||||
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
consumer = session.createConsumer(dest);
|
||||
|
@ -170,7 +160,9 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
nullCount = 0;
|
||||
}
|
||||
Thread.sleep(100);
|
||||
logger.info("Message received:" + msg.getJMSMessageID());
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Message received:" + msg.getJMSMessageID());
|
||||
}
|
||||
msgCount++;
|
||||
} catch (JMSException e) {
|
||||
logger.error("Failed to consume:", e);
|
||||
|
@ -185,9 +177,8 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
}
|
||||
consumedCount.addAndGet(msgCount);
|
||||
consumerLatch.countDown();
|
||||
logger.info("Consumed " + msgCount + " messages using thread " + getName());
|
||||
logger.trace("Consumed " + msgCount + " messages using thread " + getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ProducerThread extends Thread {
|
||||
|
@ -200,7 +191,7 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
super();
|
||||
this.count = count;
|
||||
this.setName(name);
|
||||
logger.info("Created new producer thread:" + name);
|
||||
logger.trace("Created new producer thread:" + name);
|
||||
try {
|
||||
conn = connFactory.createConnection();
|
||||
conn.start();
|
||||
|
@ -228,8 +219,9 @@ public class DispatchMultipleConsumersTest extends TestCase {
|
|||
}
|
||||
sentCount.addAndGet(i);
|
||||
producerLatch.countDown();
|
||||
logger.info("Sent " + i + " messages from thread " + getName());
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Sent " + i + " messages from thread " + getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ public class MessageGroupCloseTest extends TestCase {
|
|||
private HashSet<String> closedGroups2 = new HashSet<String>();
|
||||
// with the prefetch too high, this bug is not realized
|
||||
private static final String connStr =
|
||||
//"tcp://localhost:61616";
|
||||
"vm://localhost?broker.persistent=false&broker.useJmx=false&jms.prefetchPolicy.all=1";
|
||||
|
||||
public void testNewConsumer() throws JMSException, InterruptedException {
|
||||
|
|
Loading…
Reference in New Issue