mirror of https://github.com/apache/activemq.git
Fix a bunch of warnings covering deprecated asserts and such.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1443600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c7d559fbcd
commit
4743a20be3
|
@ -18,10 +18,13 @@ package org.apache.activemq.perf;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -30,7 +33,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ConnectionChurnTest extends TestCase {
|
||||
protected static final int CONNECTION_COUNT = 200;
|
||||
|
@ -41,7 +44,7 @@ public class ConnectionChurnTest extends TestCase {
|
|||
|
||||
public void testPerformance() throws Exception {
|
||||
ConnectionFactory factory = createConnectionFactory();
|
||||
List<Connection> list = new ArrayList();
|
||||
List<Connection> list = new ArrayList<Connection>();
|
||||
for (int i = 0; i < CONNECTION_COUNT; i++) {
|
||||
Connection connection = factory.createConnection();
|
||||
connection.start();
|
||||
|
@ -64,6 +67,7 @@ public class ConnectionChurnTest extends TestCase {
|
|||
list.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
if (broker == null) {
|
||||
broker = createBroker();
|
||||
|
@ -71,6 +75,7 @@ public class ConnectionChurnTest extends TestCase {
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
if (broker != null) {
|
||||
|
|
|
@ -24,16 +24,17 @@ import javax.jms.MessageProducer;
|
|||
import javax.jms.Session;
|
||||
import javax.jms.Topic;
|
||||
import javax.jms.TopicSubscriber;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class InactiveDurableTopicTest extends TestCase {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(InactiveDurableTopicTest.class);
|
||||
|
@ -137,7 +138,7 @@ public class InactiveDurableTopicTest extends TestCase {
|
|||
LOG.info("Sent " + loop + " messages");
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(loop, MESSAGE_COUNT);
|
||||
assertEquals(loop, MESSAGE_COUNT);
|
||||
publisher.close();
|
||||
session.close();
|
||||
connection.stop();
|
||||
|
@ -169,12 +170,12 @@ public class InactiveDurableTopicTest extends TestCase {
|
|||
assertNotNull(subscriber);
|
||||
int loop;
|
||||
for (loop = 0; loop < MESSAGE_COUNT; loop++) {
|
||||
Message msg = subscriber.receive();
|
||||
subscriber.receive();
|
||||
if (loop % 500 == 0) {
|
||||
LOG.debug("Received " + loop + " messages");
|
||||
}
|
||||
}
|
||||
this.assertEquals(loop, MESSAGE_COUNT);
|
||||
assertEquals(loop, MESSAGE_COUNT);
|
||||
subscriber.close();
|
||||
session.close();
|
||||
connection.close();
|
||||
|
|
|
@ -22,16 +22,16 @@ import javax.jms.MapMessage;
|
|||
import javax.jms.Message;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TopicSubscriber;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class InactiveQueueTest extends TestCase {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(InactiveQueueTest.class);
|
||||
|
@ -39,20 +39,19 @@ public class InactiveQueueTest extends TestCase {
|
|||
private static final int MESSAGE_COUNT = 0;
|
||||
private static final String DEFAULT_PASSWORD = "";
|
||||
private static final String USERNAME = "testuser";
|
||||
private static final String CLIENTID = "mytestclient";
|
||||
private static final String QUEUE_NAME = "testevent";
|
||||
private static final int DELIVERY_MODE = javax.jms.DeliveryMode.PERSISTENT;
|
||||
private static final int DELIVERY_PRIORITY = javax.jms.Message.DEFAULT_PRIORITY;
|
||||
|
||||
|
||||
ActiveMQConnectionFactory connectionFactory;
|
||||
BrokerService broker;
|
||||
|
||||
private Connection connection;
|
||||
private MessageProducer publisher;
|
||||
private TopicSubscriber subscriber;
|
||||
private Destination destination;
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
broker = new BrokerService();
|
||||
|
@ -77,6 +76,7 @@ public class InactiveQueueTest extends TestCase {
|
|||
connectionFactory.setUseAsyncSend(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
broker.stop();
|
||||
|
@ -104,7 +104,7 @@ public class InactiveQueueTest extends TestCase {
|
|||
}
|
||||
}
|
||||
Thread.sleep(1000000);
|
||||
this.assertEquals(loop, MESSAGE_COUNT);
|
||||
assertEquals(loop, MESSAGE_COUNT);
|
||||
publisher.close();
|
||||
session.close();
|
||||
connection.stop();
|
||||
|
|
|
@ -21,7 +21,6 @@ import javax.jms.ConnectionFactory;
|
|||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TemporaryQueue;
|
||||
|
@ -35,7 +34,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MemoryAllocationTest extends TestCase {
|
||||
|
||||
|
@ -81,6 +80,7 @@ public class MemoryAllocationTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
if (broker == null) {
|
||||
broker = createBroker();
|
||||
|
@ -88,6 +88,7 @@ public class MemoryAllocationTest extends TestCase {
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.network.NetworkConnector;
|
||||
import org.apache.activemq.xbean.BrokerFactoryBean;
|
||||
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class NetworkedSyncTest extends TestCase {
|
|||
super(name);
|
||||
LOG.info("Testcase started.");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
TestRunner.run(NetworkedSyncTest.class);
|
||||
}
|
||||
|
@ -67,10 +67,12 @@ public class NetworkedSyncTest extends TestCase {
|
|||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
LOG.info("setUp() called.");
|
||||
ClassPathXmlApplicationContext context1 = null;
|
||||
BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(config));
|
||||
assertNotNull(brokerFactory);
|
||||
|
||||
/* start up first broker instance */
|
||||
try {
|
||||
|
@ -125,6 +127,7 @@ public class NetworkedSyncTest extends TestCase {
|
|||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
LOG.info("tearDown() called.");
|
||||
|
@ -148,7 +151,7 @@ public class NetworkedSyncTest extends TestCase {
|
|||
LOG.info("testMessageExchange() called.");
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
|
||||
// create producer and consumer threads
|
||||
Thread producer = new Thread(new Producer());
|
||||
Thread consumer = new Thread(new Consumer());
|
||||
|
@ -156,22 +159,22 @@ public class NetworkedSyncTest extends TestCase {
|
|||
consumer.start();
|
||||
Thread.sleep(2000);
|
||||
producer.start();
|
||||
|
||||
|
||||
|
||||
// wait for threads to finish
|
||||
producer.join();
|
||||
consumer.join();
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
|
||||
System.out.println("Duration: "+(end-start));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Message producer running as a separate thread, connecting to broker1
|
||||
*
|
||||
*
|
||||
* @author tmielke
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Producer implements Runnable {
|
||||
|
||||
|
@ -180,6 +183,7 @@ class Producer implements Runnable {
|
|||
/**
|
||||
* connect to broker and constantly send messages
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Connection connection = null;
|
||||
|
@ -192,6 +196,7 @@ class Producer implements Runnable {
|
|||
connection = amq.createConnection();
|
||||
|
||||
connection.setExceptionListener(new javax.jms.ExceptionListener() {
|
||||
@Override
|
||||
public void onException(javax.jms.JMSException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -241,16 +246,17 @@ class Producer implements Runnable {
|
|||
/*
|
||||
* * Message consumer running as a separate thread, connecting to broker2
|
||||
* @author tmielke
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Consumer implements Runnable {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Consumer.class);;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* connect to broker and receive messages
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
Connection connection = null;
|
||||
Session session = null;
|
||||
|
@ -264,6 +270,7 @@ class Consumer implements Runnable {
|
|||
connection.setClientID("tmielke");
|
||||
|
||||
connection.setExceptionListener(new javax.jms.ExceptionListener() {
|
||||
@Override
|
||||
public void onException(javax.jms.JMSException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -276,11 +283,11 @@ class Consumer implements Runnable {
|
|||
|
||||
long counter = 0;
|
||||
// Wait for a message
|
||||
for (int i = 0; i < NetworkedSyncTest.MESSAGE_COUNT; i++) {
|
||||
for (int i = 0; i < NetworkedSyncTest.MESSAGE_COUNT; i++) {
|
||||
Message message2 = consumer.receive();
|
||||
if (message2 instanceof TextMessage) {
|
||||
TextMessage textMessage = (TextMessage) message2;
|
||||
String text = textMessage.getText();
|
||||
textMessage.getText();
|
||||
// logger.info("Received: " + text);
|
||||
} else {
|
||||
LOG.error("Received message of unsupported type. Expecting TextMessage. "+ message2);
|
||||
|
@ -289,7 +296,7 @@ class Consumer implements Runnable {
|
|||
if ((counter % 1000) == 0)
|
||||
LOG.info("received " + counter + " messages");
|
||||
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error in Consumer: " + e);
|
||||
|
|
|
@ -19,34 +19,39 @@ package org.apache.activemq.perf;
|
|||
import javax.jms.Connection;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class QueueConnectionMemoryTest extends SimpleQueueTest {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(QueueConnectionMemoryTest.class);
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Destination createDestination(Session s, String destinationName) throws JMSException {
|
||||
return s.createTemporaryQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testPerformance() throws JMSException {
|
||||
// just cancel super class test
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureBroker(BrokerService answer,String uri) throws Exception {
|
||||
KahaPersistenceAdapter adaptor = new KahaPersistenceAdapter();
|
||||
answer.setPersistenceAdapter(adaptor);
|
||||
|
@ -61,14 +66,14 @@ public class QueueConnectionMemoryTest extends SimpleQueueTest {
|
|||
factory = createConnectionFactory(bindAddress);
|
||||
Connection con = factory.createConnection();
|
||||
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Destination destination = createDestination(session, destinationName);
|
||||
createDestination(session, destinationName);
|
||||
con.close();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Connection connection = factory.createConnection();
|
||||
connection.start();
|
||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Destination dest = s.createTemporaryQueue();
|
||||
MessageConsumer consumer = s.createConsumer(dest);
|
||||
s.createConsumer(dest);
|
||||
LOG.debug("Created connnection: " + i);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.activemq.perf;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
|
||||
import org.apache.activemq.util.IOHelper;
|
||||
|
@ -29,7 +30,6 @@ public class RunBroker {
|
|||
KahaDBPersistenceAdapter kahaDB = new KahaDBPersistenceAdapter();
|
||||
File dataFileDir = new File("target/test-amq-data/perfTest/kahadb");
|
||||
IOHelper.deleteChildren(dataFileDir);
|
||||
File archiveDir = new File(dataFileDir, "archive");
|
||||
kahaDB.setDirectory(dataFileDir);
|
||||
|
||||
// The setEnableJournalDiskSyncs(false) setting is a little
|
||||
|
|
|
@ -21,32 +21,34 @@ import javax.jms.ConnectionFactory;
|
|||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SimpleTopicTest extends TestCase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SimpleTopicTest.class);
|
||||
|
||||
|
||||
protected BrokerService broker;
|
||||
protected String clientURI="tcp://localhost:61616?wireFormat.cacheEnabled=true&wireFormat.tightEncodingEnabled=true&jms.useAsyncSend=false&wireFormat.maxInactivityDuration=0";
|
||||
//protected String clientURI="tcp://localhost:61616";
|
||||
protected String bindAddress="tcp://localhost:61616?wireFormat.maxInactivityDuration=0";
|
||||
//protected String bindAddress = "tcp://localhost:61616";
|
||||
//protected String bindAddress="vm://localhost?marshal=true";
|
||||
//protected String bindAddress="vm://localhost";
|
||||
protected String clientURI = "tcp://localhost:61616?wireFormat.cacheEnabled=true&wireFormat.tightEncodingEnabled=true&jms.useAsyncSend=false&wireFormat.maxInactivityDuration=0";
|
||||
// protected String clientURI="tcp://localhost:61616";
|
||||
protected String bindAddress = "tcp://localhost:61616?wireFormat.maxInactivityDuration=0";
|
||||
// protected String bindAddress = "tcp://localhost:61616";
|
||||
// protected String bindAddress="vm://localhost?marshal=true";
|
||||
// protected String bindAddress="vm://localhost";
|
||||
protected PerfProducer[] producers;
|
||||
protected PerfConsumer[] consumers;
|
||||
protected String destinationName = getClass().getName();
|
||||
protected int sampleCount = 20;
|
||||
protected long sampleInternal = 10000;
|
||||
protected int numberOfDestinations=1;
|
||||
protected int numberOfDestinations = 1;
|
||||
protected int numberOfConsumers = 1;
|
||||
protected int numberofProducers = 1;
|
||||
protected int totalNumberOfProducers;
|
||||
|
@ -54,12 +56,13 @@ public class SimpleTopicTest extends TestCase {
|
|||
protected int playloadSize = 12;
|
||||
protected byte[] array;
|
||||
protected ConnectionFactory factory;
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Sets up a test where the producer and consumer have their own connection.
|
||||
*
|
||||
*
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
if (broker == null) {
|
||||
broker = createBroker(bindAddress);
|
||||
|
@ -67,18 +70,17 @@ public class SimpleTopicTest extends TestCase {
|
|||
factory = createConnectionFactory(clientURI);
|
||||
Connection con = factory.createConnection();
|
||||
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
|
||||
|
||||
LOG.info("Running " + numberofProducers + " producer(s) and " + numberOfConsumers + " consumer(s) per " + numberOfDestinations + " Destination(s)");
|
||||
|
||||
totalNumberOfConsumers=numberOfConsumers*numberOfDestinations;
|
||||
totalNumberOfProducers=numberofProducers*numberOfDestinations;
|
||||
|
||||
totalNumberOfConsumers = numberOfConsumers * numberOfDestinations;
|
||||
totalNumberOfProducers = numberofProducers * numberOfDestinations;
|
||||
producers = new PerfProducer[totalNumberOfProducers];
|
||||
consumers = new PerfConsumer[totalNumberOfConsumers];
|
||||
int consumerCount = 0;
|
||||
int producerCount = 0;
|
||||
for (int k =0; k < numberOfDestinations;k++) {
|
||||
Destination destination = createDestination(session, destinationName+":"+k);
|
||||
for (int k = 0; k < numberOfDestinations; k++) {
|
||||
Destination destination = createDestination(session, destinationName + ":" + k);
|
||||
LOG.info("Testing against destination: " + destination);
|
||||
for (int i = 0; i < numberOfConsumers; i++) {
|
||||
consumers[consumerCount] = createConsumer(factory, destination, consumerCount);
|
||||
|
@ -87,7 +89,7 @@ public class SimpleTopicTest extends TestCase {
|
|||
for (int i = 0; i < numberofProducers; i++) {
|
||||
array = new byte[playloadSize];
|
||||
for (int j = i; j < array.length; j++) {
|
||||
array[j] = (byte)j;
|
||||
array[j] = (byte) j;
|
||||
}
|
||||
producers[producerCount] = createProducer(factory, destination, i, array);
|
||||
producerCount++;
|
||||
|
@ -97,6 +99,7 @@ public class SimpleTopicTest extends TestCase {
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
for (int i = 0; i < numberOfConsumers; i++) {
|
||||
|
@ -117,12 +120,12 @@ public class SimpleTopicTest extends TestCase {
|
|||
|
||||
/**
|
||||
* Factory method to create a new broker
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected BrokerService createBroker(String uri) throws Exception {
|
||||
BrokerService answer = new BrokerService();
|
||||
configureBroker(answer,uri);
|
||||
configureBroker(answer, uri);
|
||||
answer.start();
|
||||
return answer;
|
||||
}
|
||||
|
@ -134,9 +137,8 @@ public class SimpleTopicTest extends TestCase {
|
|||
protected PerfConsumer createConsumer(ConnectionFactory fac, Destination dest, int number) throws JMSException {
|
||||
return new PerfConsumer(fac, dest);
|
||||
}
|
||||
|
||||
|
||||
protected void configureBroker(BrokerService answer,String uri) throws Exception {
|
||||
|
||||
protected void configureBroker(BrokerService answer, String uri) throws Exception {
|
||||
answer.setDeleteAllMessagesOnStartup(true);
|
||||
answer.addConnector(uri);
|
||||
answer.setUseShutdownHook(false);
|
||||
|
@ -167,34 +169,33 @@ public class SimpleTopicTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void dumpProducerRate() {
|
||||
int totalRate = 0;
|
||||
int totalCount = 0;
|
||||
String producerString="Producers:";
|
||||
String producerString = "Producers:";
|
||||
for (int i = 0; i < producers.length; i++) {
|
||||
PerfRate rate = producers[i].getRate().cloneAndReset();
|
||||
totalRate += rate.getRate();
|
||||
totalCount += rate.getTotalCount();
|
||||
producerString+="["+i+":"+rate.getRate() + ","+rate.getTotalCount()+"];";
|
||||
producerString += "[" + i + ":" + rate.getRate() + "," + rate.getTotalCount() + "];";
|
||||
}
|
||||
if (producers != null && producers.length > 0) {
|
||||
int avgRate = totalRate / producers.length;
|
||||
System.out.println("Avg producer rate = " + avgRate
|
||||
+ " msg/sec | Total rate = " + totalRate + ", sent = "
|
||||
+ totalCount);
|
||||
// System.out.println(producerString);
|
||||
System.out.println("Avg producer rate = " + avgRate + " msg/sec | Total rate = " + totalRate + ", sent = " + totalCount);
|
||||
// System.out.println(producerString);
|
||||
}
|
||||
}
|
||||
|
||||
protected void dumpConsumerRate() {
|
||||
int totalRate = 0;
|
||||
int totalCount = 0;
|
||||
String consumerString="Consumers:";
|
||||
String consumerString = "Consumers:";
|
||||
for (int i = 0; i < consumers.length; i++) {
|
||||
PerfRate rate = consumers[i].getRate().cloneAndReset();
|
||||
totalRate += rate.getRate();
|
||||
totalCount += rate.getTotalCount();
|
||||
consumerString+="["+i+":"+rate.getRate() + ","+rate.getTotalCount()+"];";
|
||||
consumerString += "[" + i + ":" + rate.getRate() + "," + rate.getTotalCount() + "];";
|
||||
}
|
||||
if (consumers != null && consumers.length > 0) {
|
||||
int avgRate = totalRate / consumers.length;
|
||||
|
|
|
@ -16,6 +16,24 @@
|
|||
*/
|
||||
package org.apache.activemq.security;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.apache.activemq.jaas.GroupPrincipal;
|
||||
|
@ -32,39 +50,21 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends AbstractLdapTestUnit {
|
||||
|
||||
static final GroupPrincipal GUESTS = new GroupPrincipal("guests");
|
||||
static final GroupPrincipal USERS = new GroupPrincipal("users");
|
||||
static final GroupPrincipal ADMINS = new GroupPrincipal("admins");
|
||||
|
||||
|
||||
protected LdapConnection connection;
|
||||
protected SimpleCachedLDAPAuthorizationMap map;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
connection = getLdapConnection();
|
||||
map = createMap();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
if (connection != null) {
|
||||
|
@ -74,7 +74,7 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (map != null) {
|
||||
map.destroy();
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
|
||||
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSynchronousUpdate() throws Exception {
|
||||
map.setRefreshInterval(1);
|
||||
|
@ -103,16 +103,18 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
|
||||
Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
|
||||
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
|
||||
|
||||
|
||||
LdifReader reader = new LdifReader(getRemoveLdif());
|
||||
|
||||
for (LdifEntry entry : reader) {
|
||||
connection.delete(entry.getDn());
|
||||
}
|
||||
|
||||
|
||||
reader.close();
|
||||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
|
||||
|
||||
|
||||
assertNull(map.getTempDestinationReadACLs());
|
||||
assertNull(map.getTempDestinationWriteACLs());
|
||||
assertNull(map.getTempDestinationAdminACLs());
|
||||
|
@ -144,7 +146,7 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
@Test
|
||||
public void testTemporary() throws Exception {
|
||||
map.query();
|
||||
|
||||
|
||||
Thread.sleep(1000);
|
||||
Set<?> readACLs = map.getTempDestinationReadACLs();
|
||||
assertEquals("set size: " + readACLs, 2, readACLs.size());
|
||||
|
@ -165,6 +167,8 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
connection.add(entry.getEntry());
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
|
||||
|
@ -184,16 +188,17 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
connection.delete(entry.getDn());
|
||||
}
|
||||
|
||||
reader.close();
|
||||
Thread.sleep(2000);
|
||||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
|
||||
|
||||
|
||||
assertTrue(map.getTempDestinationReadACLs() == null || map.getTempDestinationReadACLs().isEmpty());
|
||||
assertTrue(map.getTempDestinationWriteACLs() == null || map.getTempDestinationWriteACLs().isEmpty());
|
||||
assertTrue(map.getTempDestinationAdminACLs() == null || map.getTempDestinationAdminACLs().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRenameDestination() throws Exception {
|
||||
map.query();
|
||||
|
@ -214,30 +219,30 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.BAR"));
|
||||
assertEquals("set size: " + failedACLs, 2, failedACLs.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRenamePermission() throws Exception {
|
||||
map.query();
|
||||
|
||||
|
||||
// Test for a permission rename
|
||||
connection.delete(new Dn("cn=Read,cn=TEST.FOO," + getQueueBaseDn()));
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
|
||||
|
||||
|
||||
failedACLs = map.getWriteACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 2, failedACLs.size());
|
||||
|
||||
|
||||
connection.rename(new Dn("cn=Write,cn=TEST.FOO," + getQueueBaseDn()),
|
||||
new Rdn("cn=Read"));
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 2, failedACLs.size());
|
||||
|
||||
|
||||
failedACLs = map.getWriteACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
|
||||
}
|
||||
|
@ -262,16 +267,16 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 1, failedACLs.size());
|
||||
|
||||
|
||||
// Change destination entry
|
||||
request = new ModifyRequestImpl();
|
||||
request.setName(new Dn("cn=TEST.FOO," + getQueueBaseDn()));
|
||||
request.add("description", "This is a description! In fact, it is a very good description.");
|
||||
|
||||
|
||||
connection.modify(request);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
|
||||
assertEquals("set size: " + failedACLs, 1, failedACLs.size());
|
||||
}
|
||||
|
@ -304,6 +309,7 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
// wait for the context to be closed
|
||||
// as we can't rely on ldar server isStarted()
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
if (sync) {
|
||||
return !map.isContextAlive();
|
||||
|
@ -328,40 +334,41 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
connection.add(entry.getEntry());
|
||||
}
|
||||
|
||||
reader.close();
|
||||
Thread.sleep(2000);
|
||||
|
||||
failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
|
||||
assertEquals("set size: " + failedACLs, 2, failedACLs.size());
|
||||
}
|
||||
|
||||
|
||||
protected SimpleCachedLDAPAuthorizationMap createMap() {
|
||||
return new SimpleCachedLDAPAuthorizationMap();
|
||||
}
|
||||
|
||||
|
||||
protected abstract InputStream getAddLdif();
|
||||
|
||||
|
||||
protected abstract InputStream getRemoveLdif();
|
||||
|
||||
|
||||
protected void setupModifyRequest(ModifyRequest request) {
|
||||
request.remove("member", "cn=users");
|
||||
}
|
||||
|
||||
|
||||
protected abstract String getQueueBaseDn();
|
||||
|
||||
|
||||
protected abstract LdapConnection getLdapConnection() throws Exception;
|
||||
|
||||
|
||||
public static void cleanAndLoad(String deleteFromDn, String ldifResourcePath,
|
||||
String ldapHost, int ldapPort, String ldapUser, String ldapPass,
|
||||
DirContext context) throws Exception {
|
||||
// Cleanup everything used for testing.
|
||||
List<String> dns = new LinkedList<String>();
|
||||
dns.add(deleteFromDn);
|
||||
|
||||
|
||||
while (!dns.isEmpty()) {
|
||||
String name = dns.get(dns.size() - 1);
|
||||
Context currentContext = (Context) context.lookup(name);
|
||||
NamingEnumeration<NameClassPair> namingEnum = currentContext.list("");
|
||||
|
||||
|
||||
if (namingEnum.hasMore()) {
|
||||
while (namingEnum.hasMore()) {
|
||||
dns.add(namingEnum.next().getNameInNamespace());
|
||||
|
@ -371,13 +378,14 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
dns.remove(dns.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// A bit of a hacked approach to loading an LDIF into OpenLDAP since there isn't an easy way to do it
|
||||
// otherwise. This approach invokes the command line tool programmatically but has
|
||||
// to short-circuit the call to System.exit that the command line tool makes when it finishes.
|
||||
// We are assuming that there isn't already a security manager in place.
|
||||
final SecurityManager securityManager = new SecurityManager() {
|
||||
|
||||
@Override
|
||||
public void checkPermission(java.security.Permission permission) {
|
||||
if (permission.getName().contains("exitVM")) {
|
||||
throw new SecurityException("System.exit calls disabled for the moment.");
|
||||
|
@ -387,13 +395,13 @@ public abstract class AbstractCachedLDAPAuthorizationMapLegacyTest extends Abstr
|
|||
|
||||
System.setSecurityManager(securityManager);
|
||||
|
||||
|
||||
|
||||
File file = new File(AbstractCachedLDAPAuthorizationMapLegacyTest.class.getClassLoader().getResource(
|
||||
ldifResourcePath).toURI());
|
||||
|
||||
|
||||
Class<?> clazz = Class.forName("LDAPModify");
|
||||
Method mainMethod = clazz.getMethod("main", String[].class);
|
||||
|
||||
|
||||
try {
|
||||
mainMethod.invoke(null, new Object[] {
|
||||
new String[] {
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.security.auth.login.AppConfigurationEntry;
|
|||
import javax.security.auth.login.Configuration;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.broker.ConnectionContext;
|
||||
import org.apache.activemq.broker.StubBroker;
|
||||
import org.apache.activemq.command.ConnectionInfo;
|
||||
|
@ -42,6 +43,7 @@ public class JaasCertificateAuthenticationBrokerTest extends TestCase {
|
|||
ConnectionContext connectionContext;
|
||||
ConnectionInfo connectionInfo;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
receiveBroker = new StubBroker();
|
||||
|
||||
|
@ -53,6 +55,7 @@ public class JaasCertificateAuthenticationBrokerTest extends TestCase {
|
|||
connectionInfo.setTransportContext(new StubX509Certificate[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
@ -110,14 +113,14 @@ public class JaasCertificateAuthenticationBrokerTest extends TestCase {
|
|||
|
||||
assertEquals("Number of addConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.addConnectionData.size());
|
||||
|
||||
ConnectionContext receivedContext = ((StubBroker.AddConnectionData)receiveBroker.addConnectionData.getFirst()).connectionContext;
|
||||
ConnectionContext receivedContext = receiveBroker.addConnectionData.getFirst().connectionContext;
|
||||
|
||||
assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.", dnUserName, receivedContext.getSecurityContext().getUserName());
|
||||
|
||||
Set receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
|
||||
Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
|
||||
|
||||
for (Iterator iter = receivedPrincipals.iterator(); iter.hasNext();) {
|
||||
Principal currentPrincipal = (Principal)iter.next();
|
||||
for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext();) {
|
||||
Principal currentPrincipal = iter.next();
|
||||
|
||||
if (currentPrincipal instanceof UserPrincipal) {
|
||||
if (userNames.remove(currentPrincipal.getName())) {
|
||||
|
|
|
@ -17,7 +17,18 @@
|
|||
|
||||
package org.apache.activemq.security;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.security.auth.login.AppConfigurationEntry;
|
||||
import javax.security.auth.login.Configuration;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.broker.ConnectionContext;
|
||||
import org.apache.activemq.broker.Connector;
|
||||
import org.apache.activemq.broker.StubBroker;
|
||||
|
@ -25,17 +36,11 @@ import org.apache.activemq.broker.TransportConnector;
|
|||
import org.apache.activemq.command.ConnectionInfo;
|
||||
import org.apache.activemq.jaas.GroupPrincipal;
|
||||
import org.apache.activemq.jaas.UserPrincipal;
|
||||
import org.apache.activemq.transport.tcp.*;
|
||||
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.security.auth.login.AppConfigurationEntry;
|
||||
import javax.security.auth.login.Configuration;
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import org.apache.activemq.transport.tcp.SslTransportServer;
|
||||
import org.apache.activemq.transport.tcp.StubSSLServerSocket;
|
||||
import org.apache.activemq.transport.tcp.StubSSLSocketFactory;
|
||||
import org.apache.activemq.transport.tcp.StubX509Certificate;
|
||||
import org.apache.activemq.transport.tcp.TcpTransportServer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -81,6 +86,7 @@ public class JaasDualAuthenticationBrokerTest extends TestCase {
|
|||
Configuration.setConfiguration(jaasConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
receiveBroker = new StubBroker();
|
||||
|
||||
|
@ -101,7 +107,7 @@ public class JaasDualAuthenticationBrokerTest extends TestCase {
|
|||
sslTransportServer.bind();
|
||||
|
||||
try {
|
||||
nonSslTransportServer = new TcpTransportServer(null, new URI("tcp://localhost:61613"), socketFactory);
|
||||
nonSslTransportServer = new TcpTransportServer(null, new URI("tcp://localhost:61613"), socketFactory);
|
||||
} catch (Exception e) {
|
||||
fail("Unable to create TcpTransportServer.");
|
||||
}
|
||||
|
@ -112,6 +118,7 @@ public class JaasDualAuthenticationBrokerTest extends TestCase {
|
|||
createLoginConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
@ -136,13 +143,13 @@ public class JaasDualAuthenticationBrokerTest extends TestCase {
|
|||
assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.",
|
||||
DN_USERNAME, receivedContext.getSecurityContext().getUserName());
|
||||
|
||||
Set receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
|
||||
Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
|
||||
|
||||
|
||||
assertEquals("2 Principals received", 2, receivedPrincipals.size());
|
||||
|
||||
for (Iterator iter = receivedPrincipals.iterator(); iter.hasNext();) {
|
||||
Principal currentPrincipal = (Principal)iter.next();
|
||||
|
||||
for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext();) {
|
||||
Principal currentPrincipal = iter.next();
|
||||
|
||||
if (currentPrincipal instanceof UserPrincipal) {
|
||||
assertEquals("UserPrincipal is '" + DN_USERNAME + "'", DN_USERNAME, currentPrincipal.getName());
|
||||
|
@ -166,7 +173,7 @@ public class JaasDualAuthenticationBrokerTest extends TestCase {
|
|||
Connector connector = new TransportConnector(nonSslTransportServer);
|
||||
connectionContext.setConnector(connector);
|
||||
connectionInfo.setUserName(INSECURE_USERNAME);
|
||||
|
||||
|
||||
try {
|
||||
authBroker.addConnection(connectionContext, connectionInfo);
|
||||
} catch (Exception e) {
|
||||
|
@ -181,11 +188,11 @@ public class JaasDualAuthenticationBrokerTest extends TestCase {
|
|||
assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.",
|
||||
INSECURE_USERNAME, receivedContext.getSecurityContext().getUserName());
|
||||
|
||||
Set receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
|
||||
Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
|
||||
|
||||
assertEquals("2 Principals received", 2, receivedPrincipals.size());
|
||||
for (Iterator iter = receivedPrincipals.iterator(); iter.hasNext();) {
|
||||
Principal currentPrincipal = (Principal)iter.next();
|
||||
for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext();) {
|
||||
Principal currentPrincipal = iter.next();
|
||||
|
||||
if (currentPrincipal instanceof UserPrincipal) {
|
||||
assertEquals("UserPrincipal is '" + INSECURE_USERNAME + "'",
|
||||
|
|
|
@ -16,6 +16,17 @@
|
|||
*/
|
||||
package org.apache.activemq.security;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.apache.activemq.advisory.AdvisorySupport;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
|
@ -31,29 +42,16 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* This test assumes setup like in file 'AMQauth.ldif'. Contents of this file is
|
||||
* attached below in comments.
|
||||
*
|
||||
* This test assumes setup like in file 'AMQauth.ldif'. Contents of this file is attached below in comments.
|
||||
*
|
||||
* @author ngcutura
|
||||
*
|
||||
*
|
||||
*/
|
||||
@RunWith( FrameworkRunner.class )
|
||||
@CreateLdapServer(transports = {@CreateTransport(protocol = "LDAP")})
|
||||
@ApplyLdifFiles(
|
||||
"org/apache/activemq/security/AMQauth.ldif"
|
||||
)
|
||||
@RunWith(FrameworkRunner.class)
|
||||
@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP") })
|
||||
@ApplyLdifFiles("org/apache/activemq/security/AMQauth.ldif")
|
||||
public class LDAPAuthorizationMapTest extends AbstractLdapTestUnit {
|
||||
private static LDAPAuthorizationMap authMap;
|
||||
|
||||
|
@ -73,9 +71,9 @@ public class LDAPAuthorizationMapTest extends AbstractLdapTestUnit {
|
|||
public void testOpen() throws Exception {
|
||||
DirContext ctx = authMap.open();
|
||||
HashSet<String> set = new HashSet<String>();
|
||||
NamingEnumeration list = ctx.list("ou=destinations,o=ActiveMQ,ou=system");
|
||||
NamingEnumeration<NameClassPair> list = ctx.list("ou=destinations,o=ActiveMQ,ou=system");
|
||||
while (list.hasMore()) {
|
||||
NameClassPair ncp = (NameClassPair) list.next();
|
||||
NameClassPair ncp = list.next();
|
||||
set.add(ncp.getName());
|
||||
}
|
||||
assertTrue(set.contains("ou=topics"));
|
||||
|
@ -83,80 +81,76 @@ public class LDAPAuthorizationMapTest extends AbstractLdapTestUnit {
|
|||
}
|
||||
|
||||
/*
|
||||
* Test method for
|
||||
* 'org.apache.activemq.security.LDAPAuthorizationMap.getAdminACLs(ActiveMQDestination)'
|
||||
* Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getAdminACLs(ActiveMQDestination)'
|
||||
*/
|
||||
@Test
|
||||
public void testGetAdminACLs() {
|
||||
ActiveMQDestination q1 = new ActiveMQQueue("queue1");
|
||||
Set aclsq1 = authMap.getAdminACLs(q1);
|
||||
Set<GroupPrincipal> aclsq1 = authMap.getAdminACLs(q1);
|
||||
assertEquals(1, aclsq1.size());
|
||||
assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
|
||||
|
||||
ActiveMQDestination t1 = new ActiveMQTopic("topic1");
|
||||
Set aclst1 = authMap.getAdminACLs(t1);
|
||||
Set<GroupPrincipal> aclst1 = authMap.getAdminACLs(t1);
|
||||
assertEquals(1, aclst1.size());
|
||||
assertTrue(aclst1.contains(new GroupPrincipal("role1")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test method for
|
||||
* 'org.apache.activemq.security.LDAPAuthorizationMap.getReadACLs(ActiveMQDestination)'
|
||||
* Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getReadACLs(ActiveMQDestination)'
|
||||
*/
|
||||
@Test
|
||||
public void testGetReadACLs() {
|
||||
ActiveMQDestination q1 = new ActiveMQQueue("queue1");
|
||||
Set aclsq1 = authMap.getReadACLs(q1);
|
||||
Set<GroupPrincipal> aclsq1 = authMap.getReadACLs(q1);
|
||||
assertEquals(1, aclsq1.size());
|
||||
assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
|
||||
|
||||
ActiveMQDestination t1 = new ActiveMQTopic("topic1");
|
||||
Set aclst1 = authMap.getReadACLs(t1);
|
||||
Set<GroupPrincipal> aclst1 = authMap.getReadACLs(t1);
|
||||
assertEquals(1, aclst1.size());
|
||||
assertTrue(aclst1.contains(new GroupPrincipal("role2")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test method for
|
||||
* 'org.apache.activemq.security.LDAPAuthorizationMap.getWriteACLs(ActiveMQDestination)'
|
||||
* Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getWriteACLs(ActiveMQDestination)'
|
||||
*/
|
||||
@Test
|
||||
public void testGetWriteACLs() {
|
||||
ActiveMQDestination q1 = new ActiveMQQueue("queue1");
|
||||
Set aclsq1 = authMap.getWriteACLs(q1);
|
||||
Set<GroupPrincipal> aclsq1 = authMap.getWriteACLs(q1);
|
||||
assertEquals(2, aclsq1.size());
|
||||
assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
|
||||
assertTrue(aclsq1.contains(new GroupPrincipal("role2")));
|
||||
|
||||
ActiveMQDestination t1 = new ActiveMQTopic("topic1");
|
||||
Set aclst1 = authMap.getWriteACLs(t1);
|
||||
Set<GroupPrincipal> aclst1 = authMap.getWriteACLs(t1);
|
||||
assertEquals(1, aclst1.size());
|
||||
assertTrue(aclst1.contains(new GroupPrincipal("role3")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComposite() {
|
||||
ActiveMQDestination q1 = new ActiveMQQueue("queue1,topic://topic1");
|
||||
Set aclsq1 = authMap.getWriteACLs(q1);
|
||||
assertEquals(0, aclsq1.size());
|
||||
ActiveMQDestination q1 = new ActiveMQQueue("queue1,topic://topic1");
|
||||
Set<GroupPrincipal> aclsq1 = authMap.getWriteACLs(q1);
|
||||
assertEquals(0, aclsq1.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvisory() {
|
||||
ActiveMQDestination dest = AdvisorySupport.getConnectionAdvisoryTopic();
|
||||
Set acls = authMap.getWriteACLs(dest);
|
||||
Set<GroupPrincipal> acls = authMap.getWriteACLs(dest);
|
||||
|
||||
assertEquals(1, acls.size());
|
||||
assertTrue(acls.contains(new GroupPrincipal("role3")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void testTemp() {
|
||||
Set acls = authMap.getTempDestinationAdminACLs();
|
||||
Set<GroupPrincipal> acls = authMap.getTempDestinationAdminACLs();
|
||||
|
||||
assertEquals(1, acls.size());
|
||||
assertTrue(acls.contains(new GroupPrincipal("role1")));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,20 @@
|
|||
*/
|
||||
package org.apache.activemq.security;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.directory.server.annotations.CreateLdapServer;
|
||||
import org.apache.directory.server.annotations.CreateTransport;
|
||||
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
|
||||
|
@ -31,11 +41,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import javax.jms.*;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
@RunWith( FrameworkRunner.class )
|
||||
@CreateLdapServer(transports = {@CreateTransport(protocol = "LDAP")})
|
||||
|
@ -51,7 +56,7 @@ public class LDAPSecurityTest extends AbstractLdapTestUnit {
|
|||
@Before
|
||||
public void setup() throws Exception {
|
||||
System.setProperty("ldapPort", String.valueOf(getLdapServer().getPort()));
|
||||
|
||||
|
||||
broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-ldap.xml");
|
||||
broker.start();
|
||||
broker.waitUntilStarted();
|
||||
|
|
|
@ -25,13 +25,9 @@ import org.apache.activemq.CombinationTestSupport;
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SimpleAnonymousPluginTest.class);
|
||||
|
||||
public static Test suite() {
|
||||
return suite(SimpleAnonymousPluginTest.class);
|
||||
}
|
||||
|
@ -40,10 +36,12 @@ public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
|||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
return createBroker("org/apache/activemq/security/simple-anonymous-broker.xml");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testInvalidAuthentication() throws JMSException {
|
||||
|
||||
try {
|
||||
|
@ -64,8 +62,8 @@ public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
|||
} catch (JMSException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void testAnonymousReceiveSucceeds() throws JMSException {
|
||||
doReceive(false);
|
||||
}
|
||||
|
@ -73,7 +71,7 @@ public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
|||
public void testAnonymousReceiveFails() throws JMSException {
|
||||
doReceive(true);
|
||||
}
|
||||
|
||||
|
||||
public void testAnonymousSendFails() throws JMSException {
|
||||
doSend(true);
|
||||
}
|
||||
|
@ -81,7 +79,7 @@ public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
|||
public void testAnonymousSendSucceeds() throws JMSException {
|
||||
doSend(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see {@link CombinationTestSupport}
|
||||
*/
|
||||
|
@ -99,7 +97,7 @@ public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
|||
addCombinationValues("password", new Object[] {});
|
||||
addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO") });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see {@link CombinationTestSupport}
|
||||
*/
|
||||
|
@ -117,5 +115,5 @@ public class SimpleAnonymousPluginTest extends SimpleAuthenticationPluginTest {
|
|||
addCombinationValues("password", new Object[] {});
|
||||
addCombinationValues("destination", new Object[] {new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR")});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ public class StubLoginModule implements LoginModule {
|
|||
private String groupNames[];
|
||||
private boolean allowLogin;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {
|
||||
String allowLoginString = (String)(options.get(ALLOW_LOGIN_PROPERTY));
|
||||
String usersString = (String)(options.get(USERS_PROPERTY));
|
||||
|
@ -51,6 +53,7 @@ public class StubLoginModule implements LoginModule {
|
|||
groupNames = groupsString.split(",");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean login() throws LoginException {
|
||||
if (!allowLogin) {
|
||||
throw new FailedLoginException("Login was not allowed (as specified in configuration).");
|
||||
|
@ -59,6 +62,7 @@ public class StubLoginModule implements LoginModule {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commit() throws LoginException {
|
||||
if (!allowLogin) {
|
||||
throw new FailedLoginException("Login was not allowed (as specified in configuration).");
|
||||
|
@ -79,10 +83,12 @@ public class StubLoginModule implements LoginModule {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean abort() throws LoginException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean logout() throws LoginException {
|
||||
subject.getPrincipals().clear();
|
||||
|
||||
|
|
|
@ -17,18 +17,18 @@
|
|||
package org.apache.activemq.selector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.filter.BooleanExpression;
|
||||
import org.apache.activemq.filter.ComparisonExpression;
|
||||
import org.apache.activemq.filter.Expression;
|
||||
import org.apache.activemq.filter.LogicExpression;
|
||||
import org.apache.activemq.filter.PropertyExpression;
|
||||
import org.apache.activemq.filter.XPathExpression;
|
||||
import org.apache.activemq.spring.ConsumerBean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SelectorParserTest extends TestCase {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SelectorParserTest.class);
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.jms.JMSException;
|
|||
import javax.jms.Message;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQMessage;
|
||||
import org.apache.activemq.command.ActiveMQTextMessage;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
|
@ -28,7 +29,7 @@ import org.apache.activemq.filter.BooleanExpression;
|
|||
import org.apache.activemq.filter.MessageEvaluationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SelectorTest extends TestCase {
|
||||
|
||||
|
@ -54,33 +55,33 @@ public class SelectorTest extends TestCase {
|
|||
assertSelector(message, "XPATH '//root/b=\"b\"'", true);
|
||||
assertSelector(message, "XPATH '//root/b=\"c\"'", false);
|
||||
assertSelector(message, "XPATH '//root/b!=\"c\"'", true);
|
||||
|
||||
|
||||
assertSelector(message, "XPATH '//root/*[@key=''second'']'", true);
|
||||
assertSelector(message, "XPATH '//root/*[@key=''third'']'", false);
|
||||
assertSelector(message, "XPATH '//root/a[@key=''first'']'", true);
|
||||
assertSelector(message, "XPATH '//root/a[@num=1]'", true);
|
||||
assertSelector(message, "XPATH '//root/a[@key=''second'']'", false);
|
||||
|
||||
|
||||
assertSelector(message, "XPATH '/root/*[@key=''first'' or @key=''third'']'", true);
|
||||
assertSelector(message, "XPATH '//root/*[@key=''third'' or @key=''forth'']'", false);
|
||||
|
||||
assertSelector(message, "XPATH '/root/b=''b'' and /root/b[@key=''second'']'", true);
|
||||
assertSelector(message, "XPATH '/root/b=''b'' and /root/b[@key=''first'']'", false);
|
||||
|
||||
|
||||
assertSelector(message, "XPATH 'not(//root/a)'", false);
|
||||
assertSelector(message, "XPATH 'not(//root/c)'", true);
|
||||
assertSelector(message, "XPATH '//root/a[not(@key=''first'')]'", false);
|
||||
assertSelector(message, "XPATH '//root/a[not(not(@key=''first''))]'", true);
|
||||
|
||||
|
||||
assertSelector(message, "XPATH 'string(//root/b)'", true);
|
||||
assertSelector(message, "XPATH 'string(//root/a)'", false);
|
||||
|
||||
|
||||
assertSelector(message, "XPATH 'sum(//@num) < 10'", true);
|
||||
assertSelector(message, "XPATH 'sum(//@num) > 10'", false);
|
||||
|
||||
|
||||
assertSelector(message, "XPATH '//root/a[@num > 1]'", false);
|
||||
assertSelector(message, "XPATH '//root/b[@num > 1]'", true);
|
||||
|
||||
assertSelector(message, "XPATH '//root/b[@num > 1]'", true);
|
||||
|
||||
}
|
||||
|
||||
public void testJMSPropertySelectors() throws Exception {
|
||||
|
@ -272,44 +273,21 @@ public class SelectorTest extends TestCase {
|
|||
public void testFloatComparisons() throws Exception {
|
||||
Message message = createMessage();
|
||||
|
||||
// JMS 1.1 Section 3.8.1.1 : Approximate literals use the Java
|
||||
// floating-point literal syntax.
|
||||
// We will use the java varible x to demo valid floating point syntaxs.
|
||||
double x;
|
||||
|
||||
// test decimals like x.x
|
||||
x = 1.0;
|
||||
x = -1.1;
|
||||
x = 1.0E1;
|
||||
x = 1.1E1;
|
||||
x = -1.1E1;
|
||||
assertSelector(message, "1.0 < 1.1", true);
|
||||
assertSelector(message, "-1.1 < 1.0", true);
|
||||
assertSelector(message, "1.0E1 < 1.1E1", true);
|
||||
assertSelector(message, "-1.1E1 < 1.0E1", true);
|
||||
|
||||
// test decimals like x.
|
||||
x = 1.;
|
||||
x = 1.E1;
|
||||
assertSelector(message, "1. < 1.1", true);
|
||||
assertSelector(message, "-1.1 < 1.", true);
|
||||
assertSelector(message, "1.E1 < 1.1E1", true);
|
||||
assertSelector(message, "-1.1E1 < 1.E1", true);
|
||||
|
||||
// test decimals like .x
|
||||
x = .5;
|
||||
x = -.5;
|
||||
x = .5E1;
|
||||
assertSelector(message, ".1 < .5", true);
|
||||
assertSelector(message, "-.5 < .1", true);
|
||||
assertSelector(message, ".1E1 < .5E1", true);
|
||||
assertSelector(message, "-.5E1 < .1E1", true);
|
||||
|
||||
// test exponents
|
||||
x = 4E10;
|
||||
x = -4E10;
|
||||
x = 5E+10;
|
||||
x = 5E-10;
|
||||
assertSelector(message, "4E10 < 5E10", true);
|
||||
assertSelector(message, "5E8 < 5E10", true);
|
||||
assertSelector(message, "-4E10 < 2E10", true);
|
||||
|
@ -361,10 +339,10 @@ public class SelectorTest extends TestCase {
|
|||
message.setByteProperty("byteProp", (byte)123);
|
||||
message.setByteProperty("byteProp2", (byte)33);
|
||||
message.setShortProperty("shortProp", (short)123);
|
||||
message.setIntProperty("intProp", (int)123);
|
||||
message.setLongProperty("longProp", (long)123);
|
||||
message.setFloatProperty("floatProp", (float)123);
|
||||
message.setDoubleProperty("doubleProp", (double)123);
|
||||
message.setIntProperty("intProp", 123);
|
||||
message.setLongProperty("longProp", 123);
|
||||
message.setFloatProperty("floatProp", 123);
|
||||
message.setDoubleProperty("doubleProp", 123);
|
||||
|
||||
message.setIntProperty("rank", 123);
|
||||
message.setIntProperty("version", 2);
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||
import javax.jms.Message;
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Assert;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -37,7 +37,6 @@ public class ConsumerBean extends Assert implements MessageListener {
|
|||
public ConsumerBean() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return all the messages on the list so far, clearing the buffer
|
||||
*/
|
||||
|
@ -55,6 +54,7 @@ public class ConsumerBean extends Assert implements MessageListener {
|
|||
*
|
||||
* @param message
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
synchronized (messages) {
|
||||
messages.add(message);
|
||||
|
|
|
@ -19,15 +19,17 @@ package org.apache.activemq.spring;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.Message;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.activemq.test.JmsTopicSendReceiveTest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SpringTestSupport extends TestCase {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SpringTest.class);
|
||||
|
@ -64,9 +66,9 @@ public class SpringTestSupport extends TestCase {
|
|||
consumer.waitForMessagesToArrive(producer.getMessageCount());
|
||||
|
||||
// now lets check that the consumer has received some messages
|
||||
List messages = consumer.flushMessages();
|
||||
List<Message> messages = consumer.flushMessages();
|
||||
LOG.info("Consumer has received messages....");
|
||||
for (Iterator iter = messages.iterator(); iter.hasNext();) {
|
||||
for (Iterator<Message> iter = messages.iterator(); iter.hasNext();) {
|
||||
Object message = iter.next();
|
||||
LOG.info("Received: " + message);
|
||||
}
|
||||
|
@ -79,6 +81,7 @@ public class SpringTestSupport extends TestCase {
|
|||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (consumer != null) {
|
||||
consumer.stop();
|
||||
|
|
|
@ -43,16 +43,16 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
abstract public class MessagePriorityTest extends CombinationTestSupport {
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MessagePriorityTest.class);
|
||||
|
||||
BrokerService broker;
|
||||
PersistenceAdapter adapter;
|
||||
|
||||
|
||||
protected ActiveMQConnectionFactory factory;
|
||||
protected Connection conn;
|
||||
protected Session sess;
|
||||
|
||||
|
||||
public boolean useCache = true;
|
||||
public int deliveryMode = Message.DEFAULT_DELIVERY_MODE;
|
||||
public boolean dispatchAsync = true;
|
||||
|
@ -64,9 +64,10 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
public int MSG_NUM = 600;
|
||||
public int HIGH_PRI = 7;
|
||||
public int LOW_PRI = 3;
|
||||
|
||||
|
||||
abstract protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws Exception;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
broker = new BrokerService();
|
||||
broker.setBrokerName("priorityTest");
|
||||
|
@ -96,7 +97,7 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
broker.setDestinationPolicy(policyMap);
|
||||
broker.start();
|
||||
broker.waitUntilStarted();
|
||||
|
||||
|
||||
factory = new ActiveMQConnectionFactory("vm://priorityTest");
|
||||
ActiveMQPrefetchPolicy prefetch = new ActiveMQPrefetchPolicy();
|
||||
prefetch.setAll(prefetchVal);
|
||||
|
@ -108,7 +109,8 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
conn.start();
|
||||
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
sess.close();
|
||||
|
@ -119,11 +121,11 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
broker.waitUntilStopped();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testStoreConfigured() throws Exception {
|
||||
final Queue queue = sess.createQueue("TEST");
|
||||
final Topic topic = sess.createTopic("TEST");
|
||||
|
||||
|
||||
MessageProducer queueProducer = sess.createProducer(queue);
|
||||
MessageProducer topicProducer = sess.createProducer(topic);
|
||||
|
||||
|
@ -142,24 +144,25 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
}
|
||||
});
|
||||
assertTrue(broker.getRegionBroker().getDestinationMap().get(topic).getMessageStore().isPrioritizedMessages());
|
||||
|
||||
|
||||
queueProducer.close();
|
||||
topicProducer.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected class ProducerThread extends Thread {
|
||||
|
||||
int priority;
|
||||
int messageCount;
|
||||
ActiveMQDestination dest;
|
||||
|
||||
|
||||
public ProducerThread(ActiveMQDestination dest, int messageCount, int priority) {
|
||||
this.messageCount = messageCount;
|
||||
this.priority = priority;
|
||||
this.dest = dest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
MessageProducer producer = sess.createProducer(dest);
|
||||
|
@ -178,28 +181,28 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
}
|
||||
|
||||
public void setMessageCount(int messageCount) {
|
||||
this.messageCount = messageCount;
|
||||
this.messageCount = messageCount;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initCombosForTestQueues() {
|
||||
addCombinationValues("useCache", new Object[] {new Boolean(true), new Boolean(false)});
|
||||
addCombinationValues("deliveryMode", new Object[] {new Integer(DeliveryMode.NON_PERSISTENT), new Integer(DeliveryMode.PERSISTENT)});
|
||||
}
|
||||
|
||||
|
||||
public void testQueues() throws Exception {
|
||||
ActiveMQQueue queue = (ActiveMQQueue)sess.createQueue("TEST");
|
||||
|
||||
ProducerThread lowPri = new ProducerThread(queue, MSG_NUM, LOW_PRI);
|
||||
ProducerThread highPri = new ProducerThread(queue, MSG_NUM, HIGH_PRI);
|
||||
|
||||
|
||||
lowPri.start();
|
||||
highPri.start();
|
||||
|
||||
|
||||
lowPri.join();
|
||||
highPri.join();
|
||||
|
||||
|
||||
MessageConsumer queueConsumer = sess.createConsumer(queue);
|
||||
for (int i = 0; i < MSG_NUM * 2; i++) {
|
||||
Message msg = queueConsumer.receive(5000);
|
||||
|
@ -219,21 +222,21 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
public void initCombosForTestDurableSubs() {
|
||||
addCombinationValues("prefetchVal", new Object[] {new Integer(1000), new Integer(MSG_NUM/4)});
|
||||
}
|
||||
|
||||
|
||||
public void testDurableSubs() throws Exception {
|
||||
ActiveMQTopic topic = (ActiveMQTopic)sess.createTopic("TEST");
|
||||
TopicSubscriber sub = sess.createDurableSubscriber(topic, "priority");
|
||||
sub.close();
|
||||
|
||||
|
||||
ProducerThread lowPri = new ProducerThread(topic, MSG_NUM, LOW_PRI);
|
||||
ProducerThread highPri = new ProducerThread(topic, MSG_NUM, HIGH_PRI);
|
||||
|
||||
|
||||
lowPri.start();
|
||||
highPri.start();
|
||||
|
||||
|
||||
lowPri.join();
|
||||
highPri.join();
|
||||
|
||||
|
||||
sub = sess.createDurableSubscriber(topic, "priority");
|
||||
for (int i = 0; i < MSG_NUM * 2; i++) {
|
||||
Message msg = sub.receive(5000);
|
||||
|
@ -271,7 +274,7 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
addCombinationValues("dispatchAsync", new Object[] {Boolean.FALSE});
|
||||
addCombinationValues("useCache", new Object[] {Boolean.TRUE, Boolean.FALSE});
|
||||
}
|
||||
|
||||
|
||||
public void testDurableSubsReconnect() throws Exception {
|
||||
ActiveMQTopic topic = (ActiveMQTopic)sess.createTopic("TEST");
|
||||
final String subName = "priorityDisconnect";
|
||||
|
@ -362,7 +365,7 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
assertNotNull("Message was null", msg);
|
||||
LOG.info("received hi? : " + msg);
|
||||
assertEquals("high priority", HIGH_PRI, msg.getJMSPriority());
|
||||
|
||||
|
||||
if (i % batchSize*2 == 0) {
|
||||
msg = sub.receive(15000);
|
||||
assertNotNull("Message was null", msg);
|
||||
|
@ -414,7 +417,6 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
|
|||
LOG.info("Ordered priority messages sent");
|
||||
|
||||
sub = sess.createDurableSubscriber(topic, subName);
|
||||
int count = 0;
|
||||
|
||||
Message msg = sub.receive(15000);
|
||||
assertNotNull("Message was null", msg);
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.apache.activemq.store.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.apache.activemq.broker.AbstractLocker;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
public class DatabaseLockerConfigTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashMap;
|
|||
import java.util.Vector;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Message;
|
||||
|
@ -32,15 +33,17 @@ import javax.jms.MessageProducer;
|
|||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
import javax.jms.TopicSubscriber;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQMessage;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.apache.activemq.store.MessagePriorityTest;
|
||||
import org.apache.activemq.store.PersistenceAdapter;
|
||||
import org.apache.activemq.util.Wait;
|
||||
import org.apache.derby.jdbc.EmbeddedDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.derby.jdbc.EmbeddedDataSource;
|
||||
|
||||
public class JDBCMessagePriorityTest extends MessagePriorityTest {
|
||||
|
||||
|
@ -62,6 +65,7 @@ public class JDBCMessagePriorityTest extends MessagePriorityTest {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
try {
|
||||
|
@ -154,7 +158,7 @@ public class JDBCMessagePriorityTest extends MessagePriorityTest {
|
|||
}
|
||||
|
||||
final int closeFrequency = MSG_NUM / 2;
|
||||
HashMap dups = new HashMap();
|
||||
HashMap<String, String> dups = new HashMap<String, String>();
|
||||
sub = consumerSession.createDurableSubscriber(topic, subName);
|
||||
for (int i = 0; i < MSG_NUM * maxPriority; i++) {
|
||||
Message msg = sub.receive(10000);
|
||||
|
@ -228,6 +232,7 @@ public class JDBCMessagePriorityTest extends MessagePriorityTest {
|
|||
sub = consumerSession.createDurableSubscriber(topic, subName);
|
||||
final AtomicInteger count = new AtomicInteger();
|
||||
sub.setMessageListener(new MessageListener() {
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
try {
|
||||
count.incrementAndGet();
|
||||
|
@ -273,6 +278,7 @@ public class JDBCMessagePriorityTest extends MessagePriorityTest {
|
|||
assertTrue("max X times as slow with consumer:" + withConsumerAve + " , noConsumerMax:" + noConsumerAve,
|
||||
withConsumerAve < noConsumerAve * reasonableMultiplier);
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.info("count: " + count.get());
|
||||
return TO_SEND * 2 == count.get();
|
||||
|
@ -422,6 +428,7 @@ public class JDBCMessagePriorityTest extends MessagePriorityTest {
|
|||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private int messageTableDump() throws Exception {
|
||||
int count = -1;
|
||||
java.sql.Connection c = dataSource.getConnection();
|
||||
|
|
|
@ -20,16 +20,10 @@ package org.apache.activemq.store.jdbc;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.XAConnection;
|
||||
import javax.jms.XASession;
|
||||
import javax.transaction.xa.XAException;
|
||||
|
@ -40,8 +34,6 @@ import org.apache.activemq.ActiveMQXAConnectionFactory;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
// https://issues.apache.org/activemq/browse/AMQ-2880
|
||||
public class JDBCXACommitExceptionTest extends JDBCCommitExceptionTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JDBCXACommitExceptionTest.class);
|
||||
|
@ -49,7 +41,7 @@ public class JDBCXACommitExceptionTest extends JDBCCommitExceptionTest {
|
|||
private long txGenerator = System.currentTimeMillis();
|
||||
|
||||
protected ActiveMQXAConnectionFactory factory = new ActiveMQXAConnectionFactory(
|
||||
"tcp://localhost:61616?jms.prefetchPolicy.all=0&jms.redeliveryPolicy.maximumRedeliveries="+messagesExpected);
|
||||
"tcp://localhost:61616?jms.prefetchPolicy.all=0&jms.redeliveryPolicy.maximumRedeliveries="+messagesExpected);
|
||||
|
||||
boolean onePhase = true;
|
||||
|
||||
|
@ -130,7 +122,7 @@ public class JDBCXACommitExceptionTest extends JDBCCommitExceptionTest {
|
|||
}
|
||||
|
||||
public Xid createXid() throws IOException {
|
||||
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream os = new DataOutputStream(baos);
|
||||
os.writeLong(++txGenerator);
|
||||
|
@ -138,14 +130,17 @@ public class JDBCXACommitExceptionTest extends JDBCCommitExceptionTest {
|
|||
final byte[] bs = baos.toByteArray();
|
||||
|
||||
return new Xid() {
|
||||
@Override
|
||||
public int getFormatId() {
|
||||
return 86;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getGlobalTransactionId() {
|
||||
return bs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBranchQualifier() {
|
||||
return bs;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.store.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.HashSet;
|
||||
|
@ -24,6 +28,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.activemq.broker.AbstractLocker;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter;
|
||||
|
@ -33,10 +38,6 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
|
||||
|
||||
public class LeaseDatabaseLockerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LeaseDatabaseLockerTest.class);
|
||||
|
@ -190,6 +191,6 @@ public class LeaseDatabaseLockerTest {
|
|||
}
|
||||
|
||||
private void printLockTable(Connection connection) throws Exception {
|
||||
((DefaultJDBCAdapter)jdbc.getAdapter()).printQuery(connection, "SELECT * from ACTIVEMQ_LOCK", System.err);
|
||||
DefaultJDBCAdapter.printQuery(connection, "SELECT * from ACTIVEMQ_LOCK", System.err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,17 @@
|
|||
*/
|
||||
package org.apache.activemq.store.kahadb;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Destination;
|
||||
|
@ -28,6 +34,7 @@ import javax.jms.Message;
|
|||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -41,19 +48,16 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
|
||||
public class KahaDBFastEnqueueTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(KahaDBFastEnqueueTest.class);
|
||||
private BrokerService broker;
|
||||
private ActiveMQConnectionFactory connectionFactory;
|
||||
KahaDBPersistenceAdapter kahaDBPersistenceAdapter;
|
||||
private Destination destination = new ActiveMQQueue("Test");
|
||||
private String payloadString = new String(new byte[6*1024]);
|
||||
private boolean useBytesMessage= true;
|
||||
private final Destination destination = new ActiveMQQueue("Test");
|
||||
private final String payloadString = new String(new byte[6*1024]);
|
||||
private final boolean useBytesMessage= true;
|
||||
private final int parallelProducer = 20;
|
||||
private Vector<Exception> exceptions = new Vector<Exception>();
|
||||
private final Vector<Exception> exceptions = new Vector<Exception>();
|
||||
long toSend = 10000;
|
||||
|
||||
// use with:
|
||||
|
|
|
@ -16,27 +16,36 @@
|
|||
*/
|
||||
package org.apache.activemq.store.kahadb;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.RecoveryBrokerTest;
|
||||
import org.apache.activemq.broker.StubConnection;
|
||||
import org.apache.activemq.command.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.RecoveryBrokerTest;
|
||||
import org.apache.activemq.broker.StubConnection;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ConnectionInfo;
|
||||
import org.apache.activemq.command.ConsumerInfo;
|
||||
import org.apache.activemq.command.Message;
|
||||
import org.apache.activemq.command.MessageAck;
|
||||
import org.apache.activemq.command.ProducerInfo;
|
||||
import org.apache.activemq.command.SessionInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Used to verify that recovery works correctly against
|
||||
*
|
||||
*
|
||||
* Used to verify that recovery works correctly against
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class KahaDBStoreRecoveryBrokerTest extends RecoveryBrokerTest {
|
||||
|
||||
enum CorruptionType { None, FailToLoad, LoadInvalid, LoadCorrupt };
|
||||
public CorruptionType failTest = CorruptionType.None;
|
||||
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService broker = new BrokerService();
|
||||
KahaDBStore kaha = new KahaDBStore();
|
||||
|
@ -45,7 +54,9 @@ public class KahaDBStoreRecoveryBrokerTest extends RecoveryBrokerTest {
|
|||
broker.setPersistenceAdapter(kaha);
|
||||
return broker;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
protected BrokerService createRestartedBroker() throws Exception {
|
||||
|
||||
// corrupting index
|
||||
|
@ -82,11 +93,11 @@ public class KahaDBStoreRecoveryBrokerTest extends RecoveryBrokerTest {
|
|||
broker.setPersistenceAdapter(kaha);
|
||||
return broker;
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return suite(KahaDBStoreRecoveryBrokerTest.class);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
@ -107,9 +118,9 @@ public class KahaDBStoreRecoveryBrokerTest extends RecoveryBrokerTest {
|
|||
connection.send(connectionInfo);
|
||||
connection.send(sessionInfo);
|
||||
connection.send(producerInfo);
|
||||
|
||||
|
||||
ArrayList<String> expected = new ArrayList<String>();
|
||||
|
||||
|
||||
int MESSAGE_COUNT = 10000;
|
||||
for(int i=0; i < MESSAGE_COUNT; i++) {
|
||||
Message message = createMessage(producerInfo, destination);
|
||||
|
@ -140,9 +151,9 @@ public class KahaDBStoreRecoveryBrokerTest extends RecoveryBrokerTest {
|
|||
MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
|
||||
connection.send(ack);
|
||||
}
|
||||
|
||||
|
||||
connection.request(closeConnectionInfo(connectionInfo));
|
||||
|
||||
|
||||
// restart the broker.
|
||||
restartBroker();
|
||||
|
||||
|
@ -161,10 +172,10 @@ public class KahaDBStoreRecoveryBrokerTest extends RecoveryBrokerTest {
|
|||
assertEquals(expected.get(i), m.getMessageId().toString());
|
||||
MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
|
||||
connection.send(ack);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
connection.request(closeConnectionInfo(connectionInfo));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,18 @@
|
|||
*/
|
||||
package org.apache.activemq.store.kahadb;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -35,15 +40,11 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
|
||||
public class KahaDBStoreRecoveryExpiryTest {
|
||||
|
||||
private BrokerService broker;
|
||||
private ActiveMQConnection connection;
|
||||
private Destination destination = new ActiveMQQueue("Test");
|
||||
private final Destination destination = new ActiveMQQueue("Test");
|
||||
private Session session;
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,16 +16,21 @@
|
|||
*/
|
||||
package org.apache.activemq.store.kahadb;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
|
||||
import javax.jms.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
|
||||
/**
|
||||
* @author chirino
|
||||
|
@ -39,7 +44,6 @@ public class KahaDBTest extends TestCase {
|
|||
broker.setPersistenceAdapter(kaha);
|
||||
broker.start();
|
||||
return broker;
|
||||
|
||||
}
|
||||
|
||||
private KahaDBStore createStore(boolean delete) throws IOException {
|
||||
|
@ -95,7 +99,7 @@ public class KahaDBTest extends TestCase {
|
|||
|
||||
// We know we won't get all the messages but we should get most of them.
|
||||
int count = receiveMessages();
|
||||
assertTrue( count > 800 );
|
||||
assertTrue( count > 800 );
|
||||
assertTrue( count < 1000 );
|
||||
|
||||
broker.stop();
|
||||
|
|
|
@ -23,33 +23,34 @@ import junit.framework.TestCase;
|
|||
import org.apache.activemq.protobuf.Buffer;
|
||||
import org.apache.activemq.store.kahadb.data.KahaAddMessageCommand;
|
||||
import org.apache.activemq.store.kahadb.data.KahaDestination;
|
||||
import org.apache.activemq.store.kahadb.data.KahaEntryType;
|
||||
import org.apache.activemq.store.kahadb.data.KahaDestination.DestinationType;
|
||||
import org.apache.activemq.store.kahadb.data.KahaEntryType;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.DataByteArrayInputStream;
|
||||
import org.apache.activemq.util.DataByteArrayOutputStream;
|
||||
|
||||
public class PBMesssagesTest extends TestCase {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testKahaAddMessageCommand() throws IOException {
|
||||
|
||||
KahaAddMessageCommand expected = new KahaAddMessageCommand();
|
||||
expected.setDestination(new KahaDestination().setName("Foo").setType(DestinationType.QUEUE));
|
||||
expected.setMessage(new Buffer(new byte[] {1,2,3,4,5,6} ));
|
||||
expected.setMessageId("Hello World");
|
||||
|
||||
|
||||
int size = expected.serializedSizeFramed();
|
||||
DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1);
|
||||
os.writeByte(expected.type().getNumber());
|
||||
expected.writeFramed(os);
|
||||
ByteSequence seq = os.toByteSequence();
|
||||
|
||||
|
||||
DataByteArrayInputStream is = new DataByteArrayInputStream(seq);
|
||||
KahaEntryType type = KahaEntryType.valueOf(is.readByte());
|
||||
JournalCommand message = (JournalCommand)type.createMessage();
|
||||
message.mergeFramed(is);
|
||||
|
||||
|
||||
assertEquals(expected, message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
@ -35,18 +33,16 @@ import junit.framework.Test;
|
|||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.JmsTestSupport;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.ProgressPrinter;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.store.kahadb.KahaDBStore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.activemq.store.kahadb.KahaDBStore;
|
||||
|
||||
/**
|
||||
* This tests bulk loading and unloading of messages to a Queue.s
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class KahaBulkLoadingTest extends JmsTestSupport {
|
||||
|
||||
|
@ -54,6 +50,7 @@ public class KahaBulkLoadingTest extends JmsTestSupport {
|
|||
|
||||
protected int messageSize = 1024 * 4;
|
||||
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService broker = new BrokerService();
|
||||
KahaDBStore kaha = new KahaDBStore();
|
||||
|
@ -64,8 +61,9 @@ public class KahaBulkLoadingTest extends JmsTestSupport {
|
|||
return broker;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getServer().getConnectURI());
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI());
|
||||
factory.setUseAsyncSend(true);
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -30,13 +30,14 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* Tests that a Message can have nested Map and List properties attached.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NestedMapAndListPropertyTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NestedMapAndListPropertyTest.class);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void assertMessageValid(int index, Message message) throws JMSException {
|
||||
Object value = message.getObjectProperty("textField");
|
||||
assertEquals("textField", data[index], value);
|
||||
|
@ -69,6 +70,7 @@ public class NestedMapAndListPropertyTest extends JmsTopicSendReceiveWithTwoConn
|
|||
assertEquals("JohnDoe", message.getStringProperty("JMSXUserID"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Message createMessage(int index) throws JMSException {
|
||||
Message answer = session.createMessage();
|
||||
|
||||
|
@ -90,5 +92,4 @@ public class NestedMapAndListPropertyTest extends JmsTopicSendReceiveWithTwoConn
|
|||
|
||||
return answer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,12 +30,14 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NestedMapMessageTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NestedMapMessageTest.class);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void assertMessageValid(int index, Message message) throws JMSException {
|
||||
assertTrue("Should be a MapMessage: " + message, message instanceof MapMessage);
|
||||
|
||||
|
@ -71,6 +73,7 @@ public class NestedMapMessageTest extends JmsTopicSendReceiveWithTwoConnectionsA
|
|||
assertEquals("listField[2]", "c", list.get(2));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Message createMessage(int index) throws JMSException {
|
||||
MapMessage answer = session.createMapMessage();
|
||||
|
||||
|
|
|
@ -31,13 +31,12 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.test.TemporaryDestinationToFromNameTest;
|
||||
import org.apache.activemq.util.MessageIdList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class RetroactiveConsumerTestWithSimpleMessageListTest extends EmbeddedBrokerTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RetroactiveConsumerTestWithSimpleMessageListTest.class);
|
||||
|
@ -72,12 +71,14 @@ public class RetroactiveConsumerTestWithSimpleMessageListTest extends EmbeddedBr
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
useTopic = true;
|
||||
bindAddress = "vm://localhost";
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
|
@ -89,18 +90,21 @@ public class RetroactiveConsumerTestWithSimpleMessageListTest extends EmbeddedBr
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory(bindAddress);
|
||||
answer.setUseRetroactiveConsumer(true);
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
String uri = getBrokerXml();
|
||||
LOG.info("Loading broker configuration from the classpath with URI: " + uri);
|
||||
return BrokerFactory.createBroker(new URI("xbean:" + uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startBroker() throws Exception {
|
||||
// broker already started by XBean
|
||||
}
|
||||
|
|
|
@ -30,17 +30,16 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.usecases.CreateLotsOfTemporaryQueuesTest;
|
||||
import org.apache.activemq.util.MessageIdList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class RetroactiveConsumerWithMessageQueryTest extends EmbeddedBrokerTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RetroactiveConsumerWithMessageQueryTest.class);
|
||||
|
||||
|
||||
protected int messageCount = 20;
|
||||
protected Connection connection;
|
||||
protected Session session;
|
||||
|
@ -69,12 +68,14 @@ public class RetroactiveConsumerWithMessageQueryTest extends EmbeddedBrokerTestS
|
|||
listener.assertMessagesReceived(messageCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
useTopic = true;
|
||||
bindAddress = "vm://localhost";
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
|
@ -86,6 +87,7 @@ public class RetroactiveConsumerWithMessageQueryTest extends EmbeddedBrokerTestS
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||
ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory(bindAddress);
|
||||
// answer.setUseRetroactiveConsumer(true);
|
||||
|
@ -93,12 +95,14 @@ public class RetroactiveConsumerWithMessageQueryTest extends EmbeddedBrokerTestS
|
|||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
String uri = getBrokerXml();
|
||||
LOG.info("Loading broker configuration from the classpath with URI: " + uri);
|
||||
return BrokerFactory.createBroker(new URI("xbean:" + uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startBroker() throws Exception {
|
||||
// broker already started by XBean
|
||||
}
|
||||
|
|
|
@ -21,33 +21,37 @@ import java.util.Queue;
|
|||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class StubTransportListener implements TransportListener {
|
||||
|
||||
private Queue commands = new ConcurrentLinkedQueue();
|
||||
private Queue exceptions = new ConcurrentLinkedQueue();
|
||||
private final Queue<Object> commands = new ConcurrentLinkedQueue<Object>();
|
||||
private final Queue<Object> exceptions = new ConcurrentLinkedQueue<Object>();
|
||||
|
||||
public Queue getCommands() {
|
||||
public Queue<Object> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public Queue getExceptions() {
|
||||
public Queue<Object> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Object command) {
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(IOException error) {
|
||||
exceptions.add(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportInterupted() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportResumed() {
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
|
@ -30,6 +31,7 @@ import javax.jms.MessageProducer;
|
|||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.TestSupport;
|
||||
import org.apache.activemq.broker.BrokerPlugin;
|
||||
|
@ -49,7 +51,7 @@ public class FailoverDuplicateTest extends TestSupport {
|
|||
private String url;
|
||||
BrokerService broker;
|
||||
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
stopBroker();
|
||||
}
|
||||
|
@ -60,10 +62,6 @@ public class FailoverDuplicateTest extends TestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
private void startCleanBroker() throws Exception {
|
||||
startBroker(true);
|
||||
}
|
||||
|
||||
public void startBroker(boolean deleteAllMessagesOnStartup) throws Exception {
|
||||
broker = createBroker(deleteAllMessagesOnStartup);
|
||||
broker.start();
|
||||
|
@ -115,6 +113,7 @@ public class FailoverDuplicateTest extends TestSupport {
|
|||
if (first.compareAndSet(false, true)) {
|
||||
producerExchange.getConnectionContext().setDontSendReponse(true);
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOG.info("Waiting for recepit");
|
||||
|
@ -160,6 +159,7 @@ public class FailoverDuplicateTest extends TestSupport {
|
|||
final CountDownLatch sendDoneLatch = new CountDownLatch(1);
|
||||
// broker will die on send reply so this will hang till restart
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.info("doing async send...");
|
||||
try {
|
||||
|
|
|
@ -40,8 +40,6 @@ public class FailoverTransportBackupsTest {
|
|||
|
||||
protected Transport transport;
|
||||
protected FailoverTransport failoverTransport;
|
||||
private int commandsReceived;
|
||||
private int exceptionReceived;
|
||||
private int transportInterruptions;
|
||||
private int transportResumptions;
|
||||
|
||||
|
@ -64,8 +62,6 @@ public class FailoverTransportBackupsTest {
|
|||
broker3.waitUntilStarted();
|
||||
|
||||
// Reset stats
|
||||
commandsReceived = 0;
|
||||
exceptionReceived = 0;
|
||||
transportInterruptions = 0;
|
||||
transportResumptions = 0;
|
||||
}
|
||||
|
@ -92,6 +88,7 @@ public class FailoverTransportBackupsTest {
|
|||
assertEquals(2, failoverTransport.getBackupPoolSize());
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 2;
|
||||
|
@ -107,6 +104,7 @@ public class FailoverTransportBackupsTest {
|
|||
assertEquals(2, failoverTransport.getBackupPoolSize());
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 2;
|
||||
|
@ -116,6 +114,7 @@ public class FailoverTransportBackupsTest {
|
|||
broker1.stop();
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 1;
|
||||
|
@ -128,6 +127,7 @@ public class FailoverTransportBackupsTest {
|
|||
broker2.stop();
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 0;
|
||||
|
@ -146,6 +146,7 @@ public class FailoverTransportBackupsTest {
|
|||
assertEquals(1, failoverTransport.getBackupPoolSize());
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 1;
|
||||
|
@ -155,6 +156,7 @@ public class FailoverTransportBackupsTest {
|
|||
broker1.stop();
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 1;
|
||||
|
@ -164,6 +166,7 @@ public class FailoverTransportBackupsTest {
|
|||
broker2.stop();
|
||||
|
||||
assertTrue("Timed out waiting for Backups to connect.", Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Current Backup Count = " + failoverTransport.getCurrentBackups());
|
||||
return failoverTransport.getCurrentBackups() == 0;
|
||||
|
@ -193,21 +196,23 @@ public class FailoverTransportBackupsTest {
|
|||
Transport transport = TransportFactory.connect(new URI(connectionUri));
|
||||
transport.setTransportListener(new TransportListener() {
|
||||
|
||||
@Override
|
||||
public void onCommand(Object command) {
|
||||
LOG.debug("Test Transport Listener received Command: " + command);
|
||||
commandsReceived++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(IOException error) {
|
||||
LOG.debug("Test Transport Listener received Exception: " + error);
|
||||
exceptionReceived++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportInterupted() {
|
||||
transportInterruptions++;
|
||||
LOG.debug("Test Transport Listener records transport Interrupted: " + transportInterruptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportResumed() {
|
||||
transportResumptions++;
|
||||
LOG.debug("Test Transport Listener records transport Resumed: " + transportResumptions);
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.jms.DeliveryMode;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.broker.StubConnection;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
|
@ -152,15 +153,16 @@ public class FailoverTransportBrokerTest extends NetworkTestSupport {
|
|||
assertNull("no peer brokers present", info[0].getPeerBrokerInfos());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocalURI() {
|
||||
return "tcp://localhost:0?wireFormat.tcpNoDelayEnabled=true";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRemoteURI() {
|
||||
return "tcp://localhost:0?wireFormat.tcpNoDelayEnabled=true";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected StubConnection createFailoverConnection(TransportListener listener) throws Exception {
|
||||
URI failoverURI = new URI("failover://" + connector.getServer().getConnectURI() + "," + remoteConnector.getServer().getConnectURI() + "");
|
||||
Transport transport = TransportFactory.connect(failoverURI);
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.jms.Session;
|
|||
import javax.jms.TextMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.advisory.AdvisorySupport;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
|
@ -40,13 +41,13 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PeerTransportTest extends TestCase {
|
||||
protected static final int MESSAGE_COUNT = 50;
|
||||
protected static final int NUMBER_IN_CLUSTER = 3;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PeerTransportTest.class);
|
||||
|
||||
|
||||
protected ActiveMQDestination destination;
|
||||
protected boolean topic = true;
|
||||
protected int deliveryMode = DeliveryMode.NON_PERSISTENT;
|
||||
|
@ -54,6 +55,7 @@ public class PeerTransportTest extends TestCase {
|
|||
protected Connection[] connections;
|
||||
protected MessageIdList messageIdList[];
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
connections = new Connection[NUMBER_IN_CLUSTER];
|
||||
|
@ -61,8 +63,6 @@ public class PeerTransportTest extends TestCase {
|
|||
messageIdList = new MessageIdList[NUMBER_IN_CLUSTER];
|
||||
ActiveMQDestination destination = createDestination();
|
||||
|
||||
String root = System.getProperty("activemq.store.dir");
|
||||
|
||||
for (int i = 0; i < NUMBER_IN_CLUSTER; i++) {
|
||||
connections[i] = createConnection(i);
|
||||
connections[i].setClientID("ClusterTest" + i);
|
||||
|
@ -102,6 +102,7 @@ public class PeerTransportTest extends TestCase {
|
|||
LOG.info("Cluster is online.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (connections != null) {
|
||||
for (int i = 0; i < connections.length; i++) {
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.net.SocketAddress;
|
|||
import java.net.URI;
|
||||
|
||||
import org.apache.activemq.openwire.OpenWireFormat;
|
||||
import org.apache.activemq.test.JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest;
|
||||
import org.apache.activemq.transport.CommandJoiner;
|
||||
import org.apache.activemq.transport.Transport;
|
||||
import org.apache.activemq.transport.udp.ResponseRedirectInterceptor;
|
||||
|
@ -30,14 +29,15 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class UnreliableUdpTransportTest extends UdpTransportTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UnreliableUdpTransportTest.class);
|
||||
|
||||
protected DropCommandStrategy dropStrategy = new DropCommandStrategy() {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldDropCommand(int commandId, SocketAddress address, boolean redelivery) {
|
||||
if (redelivery) {
|
||||
return false;
|
||||
|
@ -46,6 +46,7 @@ public class UnreliableUdpTransportTest extends UdpTransportTest {
|
|||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Transport createProducer() throws Exception {
|
||||
LOG.info("Producer using URI: " + producerURI);
|
||||
|
||||
|
@ -60,6 +61,7 @@ public class UnreliableUdpTransportTest extends UdpTransportTest {
|
|||
return new CommandJoiner(reliableTransport, wireFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transport createConsumer() throws Exception {
|
||||
LOG.info("Consumer on port: " + consumerPort);
|
||||
OpenWireFormat wireFormat = createWireFormat();
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.transport.tcp;
|
|||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class QualityOfServiceUtilsTest extends TestCase {
|
||||
|
@ -33,6 +34,7 @@ public class QualityOfServiceUtilsTest extends TestCase {
|
|||
protected void setUp() throws Exception {
|
||||
Socket socket = new Socket();
|
||||
ECN = socket.getTrafficClass() & Integer.parseInt("00000011", 2);
|
||||
socket.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,13 +106,13 @@ public class QualityOfServiceUtilsTest extends TestCase {
|
|||
|
||||
private void testInvalidDiffServName(String name) {
|
||||
try {
|
||||
int dscp = QualityOfServiceUtils.getDSCP(name);
|
||||
QualityOfServiceUtils.getDSCP(name);
|
||||
fail("No IllegalArgumentException thrown for invalid Differentiated"
|
||||
+ " Services value: " + name + ".");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void testValidDiffServIntegerValue(int val) {
|
||||
try {
|
||||
int dscp = QualityOfServiceUtils.getDSCP(Integer.toString(val));
|
||||
|
@ -125,7 +127,7 @@ public class QualityOfServiceUtilsTest extends TestCase {
|
|||
|
||||
private void testInvalidDiffServIntegerValue(int val) {
|
||||
try {
|
||||
int dscp = QualityOfServiceUtils.getDSCP(Integer.toString(val));
|
||||
QualityOfServiceUtils.getDSCP(Integer.toString(val));
|
||||
fail("No IllegalArgumentException thrown for invalid "
|
||||
+ "Differentiated Services value " + val + ".");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
|
@ -159,7 +161,7 @@ public class QualityOfServiceUtilsTest extends TestCase {
|
|||
|
||||
private void testInvalidTypeOfServiceValue(int val) {
|
||||
try {
|
||||
int typeOfService = QualityOfServiceUtils.getToS(val);
|
||||
QualityOfServiceUtils.getToS(val);
|
||||
fail("No IllegalArgumentException thrown for invalid "
|
||||
+ "Type of Service value " + val + ".");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
|
|
|
@ -22,152 +22,157 @@ import java.net.Socket;
|
|||
import java.net.UnknownHostException;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* Automatically generated socket.close() calls to simulate network faults
|
||||
*/
|
||||
public class SocketTstFactory extends SocketFactory {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SocketTstFactory.class);
|
||||
|
||||
private static final ConcurrentHashMap<InetAddress, Integer> closeIter = new ConcurrentHashMap<InetAddress, Integer>();
|
||||
private static final ConcurrentHashMap<InetAddress, Integer> closeIter = new ConcurrentHashMap<InetAddress, Integer>();
|
||||
|
||||
private class SocketTst {
|
||||
|
||||
private class Bagot implements Runnable {
|
||||
private Thread processus;
|
||||
private Random rnd;
|
||||
private Socket socket;
|
||||
private final InetAddress address;
|
||||
private class Bagot implements Runnable {
|
||||
private final Thread processus;
|
||||
private final Socket socket;
|
||||
private final InetAddress address;
|
||||
|
||||
public Bagot(Random rnd, Socket socket, InetAddress address) {
|
||||
this.processus = new Thread(this, "Network Faults maker : undefined");
|
||||
this.rnd = rnd;
|
||||
this.socket = socket;
|
||||
this.address = address;
|
||||
}
|
||||
public Bagot(Random rnd, Socket socket, InetAddress address) {
|
||||
this.processus = new Thread(this, "Network Faults maker : undefined");
|
||||
this.socket = socket;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.processus.setName("Network Faults maker : " + this.socket.toString());
|
||||
this.processus.start();
|
||||
}
|
||||
public void start() {
|
||||
this.processus.setName("Network Faults maker : " + this.socket.toString());
|
||||
this.processus.start();
|
||||
}
|
||||
|
||||
public void run () {
|
||||
int lastDelayVal;
|
||||
Integer lastDelay;
|
||||
while (!this.processus.isInterrupted()) {
|
||||
if (!this.socket.isClosed()) {
|
||||
try {
|
||||
lastDelay = closeIter.get(this.address);
|
||||
if (lastDelay == null) {
|
||||
lastDelayVal = 0;
|
||||
}
|
||||
else {
|
||||
lastDelayVal = lastDelay.intValue();
|
||||
if (lastDelayVal > 10)
|
||||
lastDelayVal += 20;
|
||||
else lastDelayVal += 1;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
int lastDelayVal;
|
||||
Integer lastDelay;
|
||||
while (!this.processus.isInterrupted()) {
|
||||
if (!this.socket.isClosed()) {
|
||||
try {
|
||||
lastDelay = closeIter.get(this.address);
|
||||
if (lastDelay == null) {
|
||||
lastDelayVal = 0;
|
||||
} else {
|
||||
lastDelayVal = lastDelay.intValue();
|
||||
if (lastDelayVal > 10)
|
||||
lastDelayVal += 20;
|
||||
else
|
||||
lastDelayVal += 1;
|
||||
}
|
||||
|
||||
lastDelay = new Integer(lastDelayVal);
|
||||
lastDelay = new Integer(lastDelayVal);
|
||||
|
||||
LOG.info("Trying to close client socket " + socket.toString() + " in " + lastDelayVal + " milliseconds");
|
||||
LOG.info("Trying to close client socket " + socket.toString() + " in " + lastDelayVal + " milliseconds");
|
||||
|
||||
try {
|
||||
Thread.sleep(lastDelayVal);
|
||||
} catch (InterruptedException e) {
|
||||
this.processus.interrupt();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
this.socket.close();
|
||||
closeIter.put(this.address, lastDelay);
|
||||
LOG.info("Client socket " + this.socket.toString() + " is closed.");
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(lastDelayVal);
|
||||
} catch (InterruptedException e) {
|
||||
this.processus.interrupt();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
this.processus.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.socket.close();
|
||||
closeIter.put(this.address, lastDelay);
|
||||
LOG.info("Client socket " + this.socket.toString() + " is closed.");
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private final Bagot bagot;
|
||||
private final Socket socket;
|
||||
this.processus.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SocketTst(InetAddress address, int port, Random rnd) throws IOException {
|
||||
this.socket = new Socket(address, port);
|
||||
bagot = new Bagot(rnd, this.socket, address);
|
||||
}
|
||||
private final Bagot bagot;
|
||||
private final Socket socket;
|
||||
|
||||
public SocketTst(InetAddress address, int port, InetAddress localAddr, int localPort, Random rnd) throws IOException {
|
||||
this.socket = new Socket(address, port, localAddr, localPort);
|
||||
bagot = new Bagot(rnd, this.socket, address);
|
||||
}
|
||||
public SocketTst(InetAddress address, int port, Random rnd) throws IOException {
|
||||
this.socket = new Socket(address, port);
|
||||
bagot = new Bagot(rnd, this.socket, address);
|
||||
}
|
||||
|
||||
public SocketTst(String address, int port, Random rnd) throws UnknownHostException, IOException {
|
||||
this.socket = new Socket(address, port);
|
||||
bagot = new Bagot(rnd, this.socket, InetAddress.getByName(address));
|
||||
}
|
||||
public SocketTst(InetAddress address, int port, InetAddress localAddr, int localPort, Random rnd) throws IOException {
|
||||
this.socket = new Socket(address, port, localAddr, localPort);
|
||||
bagot = new Bagot(rnd, this.socket, address);
|
||||
}
|
||||
|
||||
public SocketTst(String address, int port, InetAddress localAddr, int localPort, Random rnd) throws IOException {
|
||||
this.socket = new Socket(address, port, localAddr, localPort);
|
||||
bagot = new Bagot(rnd, this.socket, InetAddress.getByName(address));
|
||||
}
|
||||
public SocketTst(String address, int port, Random rnd) throws UnknownHostException, IOException {
|
||||
this.socket = new Socket(address, port);
|
||||
bagot = new Bagot(rnd, this.socket, InetAddress.getByName(address));
|
||||
}
|
||||
|
||||
public Socket getSocket() {
|
||||
return this.socket;
|
||||
}
|
||||
public SocketTst(String address, int port, InetAddress localAddr, int localPort, Random rnd) throws IOException {
|
||||
this.socket = new Socket(address, port, localAddr, localPort);
|
||||
bagot = new Bagot(rnd, this.socket, InetAddress.getByName(address));
|
||||
}
|
||||
|
||||
public void startBagot() {
|
||||
bagot.start();
|
||||
}
|
||||
public Socket getSocket() {
|
||||
return this.socket;
|
||||
}
|
||||
|
||||
public void startBagot() {
|
||||
bagot.start();
|
||||
}
|
||||
};
|
||||
|
||||
private final Random rnd;
|
||||
private final Random rnd;
|
||||
|
||||
public SocketTstFactory() {
|
||||
super();
|
||||
LOG.info("Creating a new SocketTstFactory");
|
||||
this.rnd = new Random();
|
||||
super();
|
||||
LOG.info("Creating a new SocketTstFactory");
|
||||
this.rnd = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress host, int port) throws IOException {
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress host, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, localAddress, localPort, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, localAddress, localPort, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException {
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, localAddress, localPort, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
SocketTst sockTst;
|
||||
sockTst = new SocketTst(host, port, localAddress, localPort, this.rnd);
|
||||
sockTst.startBagot();
|
||||
return sockTst.getSocket();
|
||||
}
|
||||
|
||||
private final static SocketTstFactory client = new SocketTstFactory();
|
||||
|
||||
public static SocketFactory getDefault() {
|
||||
return client;
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,46 +20,43 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.activemq.transport.TransportBrokerTestSupport;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SslContextBrokerServiceTest extends TestCase {
|
||||
|
||||
|
||||
private ClassPathXmlApplicationContext context;
|
||||
private BrokerService broker;
|
||||
private TransportConnector connector;
|
||||
|
||||
|
||||
public void testConfiguration() throws URISyntaxException {
|
||||
|
||||
assertNotNull(broker);
|
||||
assertNotNull(connector);
|
||||
|
||||
|
||||
assertEquals(new URI("ssl://localhost:61616"), connector.getUri());
|
||||
|
||||
|
||||
assertNotNull(broker.getSslContext());
|
||||
assertFalse(broker.getSslContext().getKeyManagers().isEmpty());
|
||||
assertFalse(broker.getSslContext().getTrustManagers().isEmpty());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
Thread.currentThread().setContextClassLoader(SslContextBrokerServiceTest.class.getClassLoader());
|
||||
context = new ClassPathXmlApplicationContext("org/apache/activemq/transport/tcp/activemq-ssl.xml");
|
||||
Map beansOfType = context.getBeansOfType(BrokerService.class);
|
||||
broker = (BrokerService)beansOfType.values().iterator().next();
|
||||
connector = broker.getTransportConnectors().get(0);
|
||||
Map<String, BrokerService> beansOfType = context.getBeansOfType(BrokerService.class);
|
||||
broker = beansOfType.values().iterator().next();
|
||||
connector = broker.getTransportConnectors().get(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
|
|
|
@ -36,19 +36,18 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
public class SslContextNBrokerServiceTest extends TestCase {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(SslContextNBrokerServiceTest.class);
|
||||
|
||||
|
||||
private ClassPathXmlApplicationContext context;
|
||||
Map beansOfType;
|
||||
|
||||
Map<String, BrokerService> beansOfType;
|
||||
|
||||
public void testConfigurationIsolation() throws Exception {
|
||||
|
||||
|
||||
assertTrue("dummy bean has dummy cert", verifyCredentials("dummy"));
|
||||
assertTrue("good bean has amq cert", verifyCredentials("activemq.org"));
|
||||
}
|
||||
|
||||
|
||||
private boolean verifyCredentials(String name) throws Exception {
|
||||
boolean result = false;
|
||||
BrokerService broker = getBroker(name);
|
||||
|
@ -66,18 +65,17 @@ public class SslContextNBrokerServiceTest extends TestCase {
|
|||
TransportConnector connector = broker.getTransportConnectors().get(0);
|
||||
URI brokerUri = connector.getConnectUri();
|
||||
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
CertChainCatcher catcher = new CertChainCatcher();
|
||||
context.init(null, new TrustManager[] {catcher}, null);
|
||||
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
CertChainCatcher catcher = new CertChainCatcher();
|
||||
context.init(null, new TrustManager[] { catcher }, null);
|
||||
|
||||
SSLSocketFactory factory = context.getSocketFactory();
|
||||
LOG.info("Connecting to broker: " + broker.getBrokerName()
|
||||
+ " on: " + brokerUri.getHost() + ":" + brokerUri.getPort());
|
||||
SSLSocket socket = (SSLSocket)factory.createSocket(brokerUri.getHost(), brokerUri.getPort());
|
||||
LOG.info("Connecting to broker: " + broker.getBrokerName() + " on: " + brokerUri.getHost() + ":" + brokerUri.getPort());
|
||||
SSLSocket socket = (SSLSocket) factory.createSocket(brokerUri.getHost(), brokerUri.getPort());
|
||||
socket.setSoTimeout(5000);
|
||||
socket.startHandshake();
|
||||
socket.close();
|
||||
|
||||
|
||||
boolean matches = false;
|
||||
if (catcher.serverCerts != null) {
|
||||
for (int i = 0; i < catcher.serverCerts.length; i++) {
|
||||
|
@ -91,15 +89,14 @@ public class SslContextNBrokerServiceTest extends TestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
private BrokerService getBroker(String name) {
|
||||
BrokerService result = null;
|
||||
Iterator iterator = beansOfType.values().iterator();
|
||||
while(iterator.hasNext()) {
|
||||
BrokerService candidate = (BrokerService)iterator.next();
|
||||
Iterator<BrokerService> iterator = beansOfType.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
BrokerService candidate = iterator.next();
|
||||
if (candidate.getBrokerName().equals(name)) {
|
||||
result = candidate;
|
||||
break;
|
||||
|
@ -108,29 +105,32 @@ public class SslContextNBrokerServiceTest extends TestCase {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
//System.setProperty("javax.net.debug", "ssl");
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
// System.setProperty("javax.net.debug", "ssl");
|
||||
Thread.currentThread().setContextClassLoader(SslContextNBrokerServiceTest.class.getClassLoader());
|
||||
context = new ClassPathXmlApplicationContext("org/apache/activemq/transport/tcp/n-brokers-ssl.xml");
|
||||
beansOfType = context.getBeansOfType(BrokerService.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
context.destroy();
|
||||
}
|
||||
|
||||
|
||||
class CertChainCatcher implements X509TrustManager {
|
||||
class CertChainCatcher implements X509TrustManager {
|
||||
X509Certificate[] serverCerts;
|
||||
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
|
||||
serverCerts = arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ import javax.jms.Message;
|
|||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
|
@ -66,6 +66,7 @@ public class AMQStackOverFlowTest extends TestCase {
|
|||
|
||||
template1.send("test.q", new MessageCreator() {
|
||||
|
||||
@Override
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
return session.createTextMessage("test");
|
||||
}
|
||||
|
@ -80,14 +81,14 @@ public class AMQStackOverFlowTest extends TestCase {
|
|||
|
||||
final TextMessage tm = (TextMessage)m;
|
||||
|
||||
Assert.assertEquals("test", tm.getText());
|
||||
assertEquals("test", tm.getText());
|
||||
|
||||
template2.send("test2.q", new MessageCreator() {
|
||||
|
||||
@Override
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
return session.createTextMessage("test2");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
final Message m2 = template1.receive("test2.q");
|
||||
|
@ -96,17 +97,14 @@ public class AMQStackOverFlowTest extends TestCase {
|
|||
|
||||
final TextMessage tm2 = (TextMessage)m2;
|
||||
|
||||
Assert.assertEquals("test2", tm2.getText());
|
||||
assertEquals("test2", tm2.getText());
|
||||
|
||||
} finally {
|
||||
|
||||
brokerService1.stop();
|
||||
brokerService1 = null;
|
||||
brokerService2.stop();
|
||||
brokerService2 = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BrokerService createBrokerService(final String brokerName, final String uri1, final String uri2)
|
||||
|
@ -146,6 +144,5 @@ public class AMQStackOverFlowTest extends TestCase {
|
|||
}
|
||||
|
||||
return brokerService;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,32 +28,31 @@ import org.apache.activemq.broker.region.DestinationInterceptor;
|
|||
import org.apache.activemq.broker.region.virtual.VirtualDestination;
|
||||
import org.apache.activemq.broker.region.virtual.VirtualDestinationInterceptor;
|
||||
import org.apache.activemq.broker.region.virtual.VirtualTopic;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.network.NetworkConnector;
|
||||
import org.apache.activemq.store.kahadb.KahaDBStore;
|
||||
import org.apache.activemq.util.MessageIdList;
|
||||
|
||||
public abstract class AbstractTwoBrokerNetworkConnectorWildcardIncludedDestinationTestSupport extends JmsMultipleBrokersTestSupport {
|
||||
|
||||
|
||||
protected static final int MESSAGE_COUNT = 1;
|
||||
boolean dynamicOnly = true;
|
||||
int networkTTL = 1;
|
||||
boolean conduit = true;
|
||||
boolean suppressDuplicateQueueSubscriptions = true;
|
||||
boolean decreaseNetworkConsumerPriority = true;
|
||||
|
||||
|
||||
/**
|
||||
* simple nwob
|
||||
*/
|
||||
public void testSimpleNWOB() throws Exception {
|
||||
|
||||
|
||||
sendReceive("BrokerA", "local.test", false, "BrokerB", "local.test", false, 1, 0);
|
||||
sendReceive("BrokerA", "local.test", true, "BrokerB", "local.test", true, 1, 0);
|
||||
sendReceive("BrokerA", "global.test", false, "BrokerB", "global.test", false, 1, 1);
|
||||
sendReceive("BrokerA", "global.test", true, "BrokerB", "global.test", true, 1, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nwob with wild-card subscriptions
|
||||
*/
|
||||
|
@ -65,27 +64,27 @@ public abstract class AbstractTwoBrokerNetworkConnectorWildcardIncludedDestinati
|
|||
sendReceive("BrokerA", "global.test.2", true, "BrokerB", "global.test.>", true, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nwob with virtual destinations
|
||||
*/
|
||||
public void testSimpleNWOBWithVirtualDestinations() throws Exception {
|
||||
|
||||
|
||||
sendReceive("BrokerA", "local.test", true, "BrokerB", "Consumer.a.local.test", false, 1, 0);
|
||||
sendReceive("BrokerA", "global.test", true, "BrokerB", "Consumer.a.global.test", false, 1, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nwob with virtual destinations and wild-card subscriptions
|
||||
*/
|
||||
public void testSimpleNWOBWithVirtualDestinationsAndWildcardSubscriptions() throws Exception {
|
||||
|
||||
|
||||
sendReceive("BrokerA", "local.test.1", true, "BrokerB", "Consumer.a.local.test.>", false, 1, 0);
|
||||
sendReceive("BrokerA", "global.test.1", true, "BrokerB", "Consumer.a.global.test.>", false, 1, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void sendReceive(String broker1, String dest1, boolean topic1, String broker2, String dest2, boolean topic2, int send, int expected) throws Exception{
|
||||
MessageConsumer client = createConsumer(broker2, createDestination(dest2, topic2));
|
||||
Thread.sleep(1000);
|
||||
|
@ -100,35 +99,36 @@ public abstract class AbstractTwoBrokerNetworkConnectorWildcardIncludedDestinati
|
|||
|
||||
protected abstract void addIncludedDestination(NetworkConnector networkConnector);
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
String options = new String("?useJmx=false&deleteAllMessagesOnStartup=true");
|
||||
String options = new String("?useJmx=false&deleteAllMessagesOnStartup=true");
|
||||
createAndConfigureBroker(new URI("broker:(tcp://localhost:61616)/BrokerA" + options));
|
||||
createAndConfigureBroker(new URI("broker:(tcp://localhost:61617)/BrokerB" + options));
|
||||
|
||||
|
||||
// Setup broker networks
|
||||
NetworkConnector nc = bridgeBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduit);
|
||||
nc.setDecreaseNetworkConsumerPriority(decreaseNetworkConsumerPriority);
|
||||
nc.setSuppressDuplicateQueueSubscriptions(suppressDuplicateQueueSubscriptions);
|
||||
|
||||
|
||||
addIncludedDestination(nc);
|
||||
|
||||
|
||||
nc = bridgeBrokers("BrokerB", "BrokerA", dynamicOnly, networkTTL, conduit);
|
||||
nc.setDecreaseNetworkConsumerPriority(decreaseNetworkConsumerPriority);
|
||||
nc.setSuppressDuplicateQueueSubscriptions(suppressDuplicateQueueSubscriptions);
|
||||
|
||||
|
||||
addIncludedDestination(nc);
|
||||
|
||||
|
||||
startAllBrokers();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BrokerService createAndConfigureBroker(URI uri) throws Exception {
|
||||
BrokerService broker = createBroker(uri);
|
||||
|
||||
|
||||
configurePersistenceAdapter(broker);
|
||||
|
||||
|
||||
// make all topics virtual and consumers use the default prefix
|
||||
VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
|
||||
virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[]{new VirtualTopic()});
|
||||
|
@ -136,12 +136,12 @@ public abstract class AbstractTwoBrokerNetworkConnectorWildcardIncludedDestinati
|
|||
broker.setDestinationInterceptors(destinationInterceptors);
|
||||
return broker;
|
||||
}
|
||||
|
||||
|
||||
protected void configurePersistenceAdapter(BrokerService broker) throws IOException {
|
||||
File dataFileDir = new File("target/test-amq-data/kahadb/" + broker.getBrokerName());
|
||||
KahaDBStore kaha = new KahaDBStore();
|
||||
kaha.setDirectory(dataFileDir);
|
||||
broker.setPersistenceAdapter(kaha);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,11 @@ import javax.jms.MessageConsumer;
|
|||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.TestSupport;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.TestSupport;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -38,16 +37,19 @@ public class AdvisoryTopicDeletionTest extends TestSupport {
|
|||
private BrokerService broker;
|
||||
private Connection connection;
|
||||
|
||||
@Override
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory("vm://" + getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
createBroker();
|
||||
topic = false;
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
destroyBroker();
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.usecases;
|
|||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.TextMessage;
|
||||
|
@ -55,12 +56,11 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
private long inactiveDuration = 1000;
|
||||
private boolean useSocketProxy = true;
|
||||
|
||||
|
||||
public void initCombosForTestSendOnAReceiveOnBWithTransportDisconnect() {
|
||||
addCombinationValues( "useDuplexNetworkBridge", new Object[]{ Boolean.TRUE, Boolean.FALSE} );
|
||||
addCombinationValues( "simulateStalledNetwork", new Object[]{ Boolean.TRUE } );
|
||||
}
|
||||
|
||||
|
||||
public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception {
|
||||
bridgeBrokers(SPOKE, HUB);
|
||||
|
||||
|
@ -68,24 +68,25 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
|
||||
// Setup destination
|
||||
Destination dest = createDestination("TEST.FOO", false);
|
||||
|
||||
|
||||
// Setup consumers
|
||||
MessageConsumer client = createConsumer(HUB, dest);
|
||||
|
||||
|
||||
// allow subscription information to flow back to Spoke
|
||||
sleep(600);
|
||||
|
||||
|
||||
// Send messages
|
||||
sendMessages(SPOKE, dest, MESSAGE_COUNT);
|
||||
|
||||
MessageIdList msgs = getConsumerMessages(HUB, client);
|
||||
msgs.waitForMessagesToArrive(MESSAGE_COUNT);
|
||||
|
||||
assertTrue("At least message " + MESSAGE_COUNT +
|
||||
assertTrue("At least message " + MESSAGE_COUNT +
|
||||
" must be recieved, duplicates are expected, count=" + msgs.getMessageCount(),
|
||||
MESSAGE_COUNT <= msgs.getMessageCount());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNoStuckConnectionsWithTransportDisconnect() throws Exception {
|
||||
inactiveDuration=60000l;
|
||||
useDuplexNetworkBridge = true;
|
||||
|
@ -120,9 +121,10 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
socketProxy.halfClose();
|
||||
sleep(10000);
|
||||
}
|
||||
// wait for full reformation of bridge
|
||||
// wait for full reformation of bridge
|
||||
// verify no extra connections
|
||||
boolean allGood = Wait.waitFor(new Wait.Condition(){
|
||||
boolean allGood = Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
long numConnections = hub.broker.getTransportConnectors().get(0).getConnections().size();
|
||||
LOG.info("Num connetions:" + numConnections);
|
||||
|
@ -134,6 +136,7 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
assertTrue("should be only one transport connection for the single duplex network connector", allGood);
|
||||
|
||||
allGood = Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
long numVmConnections = VMTransportFactory.SERVERS.get(HUB).getConnectionCount();
|
||||
LOG.info("Num VM connetions:" + numVmConnections);
|
||||
|
@ -144,7 +147,7 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
}
|
||||
assertTrue("should be only 2 vm connections for the single network duplex network connector", allGood);
|
||||
}
|
||||
|
||||
|
||||
public void testTwoDuplexNCsAreAllowed() throws Exception {
|
||||
useDuplexNetworkBridge = true;
|
||||
useSocketProxy = false;
|
||||
|
@ -154,13 +157,13 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
connector = bridgeBrokers(SPOKE, HUB);
|
||||
connector.setName("SecondDuplex");
|
||||
|
||||
startAllBrokers();
|
||||
startAllBrokers();
|
||||
waitForBridgeFormation();
|
||||
|
||||
BrokerItem hub = brokers.get(HUB);
|
||||
assertEquals("Has two transport Connectors", 2, hub.broker.getTransportConnectors().get(0).getConnections().size());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void startAllBrokers() throws Exception {
|
||||
// Ensure HUB is started first so bridge will be active from the get go
|
||||
|
@ -171,6 +174,7 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
sleep(600);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
networkDownTimeStart = 0;
|
||||
inactiveDuration = 1000;
|
||||
|
@ -181,18 +185,19 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
createBroker(new URI("broker:(tcp://localhost:61617)/" + HUB + options));
|
||||
createBroker(new URI("broker:(tcp://localhost:61616)/" + SPOKE + options));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
if (socketProxy != null) {
|
||||
socketProxy.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return suite(BrokerQueueNetworkWithDisconnectTest.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSend(int i, TextMessage msg) {
|
||||
sleep(50);
|
||||
|
@ -224,7 +229,7 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
try {
|
||||
Thread.sleep(milliSecondTime);
|
||||
} catch (InterruptedException igonred) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,12 +237,12 @@ public class BrokerQueueNetworkWithDisconnectTest extends JmsMultipleBrokersTest
|
|||
List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
|
||||
URI remoteURI;
|
||||
if (!transportConnectors.isEmpty()) {
|
||||
remoteURI = ((TransportConnector)transportConnectors.get(0)).getConnectUri();
|
||||
remoteURI = transportConnectors.get(0).getConnectUri();
|
||||
if (useSocketProxy) {
|
||||
socketProxy = new SocketProxy(remoteURI);
|
||||
remoteURI = socketProxy.getUrl();
|
||||
}
|
||||
DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:(" + remoteURI
|
||||
DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:(" + remoteURI
|
||||
+ "?wireFormat.maxInactivityDuration=" + inactiveDuration + "&wireFormat.maxInactivityDurationInitalDelay=" + inactiveDuration + ")?useExponentialBackOff=false"));
|
||||
connector.setDynamicOnly(dynamicOnly);
|
||||
connector.setNetworkTTL(networkTTL);
|
||||
|
|
|
@ -110,6 +110,7 @@ public class BrowseOverNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
this.expect = expect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int retries = 0;
|
||||
while (retries++ < 20 && totalCount != expect) {
|
||||
|
@ -122,8 +123,8 @@ public class BrowseOverNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
totalCount += count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ActiveMQTextMessage message = (ActiveMQTextMessage)consumer.receive(1000);
|
||||
LOG.info(broker + " consumer: " + message.getText() + " " + message.getDestination() + " " + message.getMessageId() + " " + Arrays.toString(message.getBrokerPath()));
|
||||
if (message == null) break;
|
||||
LOG.info(broker + " consumer: " + message.getText() + " " + message.getDestination() + " " + message.getMessageId() + " " + Arrays.toString(message.getBrokerPath()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -216,13 +217,13 @@ public class BrowseOverNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
|
||||
LOG.info("broker-3A browsed " + browser1.getTotalCount());
|
||||
LOG.info("broker-3B browsed " + browser2.getTotalCount());
|
||||
|
||||
|
||||
assertEquals(MESSAGE_COUNT * 2, browser1.getTotalCount() + browser2.getTotalCount() );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected int browseMessages(QueueBrowser browser, String name) throws Exception {
|
||||
Enumeration msgs = browser.getEnumeration();
|
||||
Enumeration<?> msgs = browser.getEnumeration();
|
||||
int browsedMessage = 0;
|
||||
while (msgs.hasMoreElements()) {
|
||||
browsedMessage++;
|
||||
|
@ -240,6 +241,7 @@ public class BrowseOverNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
return browsedMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
|
@ -28,7 +29,7 @@ import javax.jms.Session;
|
|||
import org.apache.activemq.test.TestSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ChangeSentMessageTest extends TestSupport {
|
||||
private static final int COUNT = 200;
|
||||
|
@ -36,9 +37,10 @@ public class ChangeSentMessageTest extends TestSupport {
|
|||
|
||||
/**
|
||||
* test Object messages can be changed after sending with no side-affects
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testDoChangeSentMessage() throws Exception {
|
||||
Destination destination = createDestination("test-" + ChangeSentMessageTest.class.getName());
|
||||
Connection connection = createConnection();
|
||||
|
|
|
@ -29,7 +29,7 @@ import javax.jms.Session;
|
|||
import org.apache.activemq.test.TestSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ChangeSessionDeliveryModeTest extends TestSupport implements MessageListener {
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class ChangeSessionDeliveryModeTest extends TestSupport implements Messag
|
|||
* test following condition- which are defined by JMS Spec 1.1:
|
||||
* MessageConsumers cannot use a MessageListener and receive() from the same
|
||||
* session
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testDoChangeSessionDeliveryMode() throws Exception {
|
||||
|
@ -47,7 +47,6 @@ public class ChangeSessionDeliveryModeTest extends TestSupport implements Messag
|
|||
Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageConsumer consumer1 = consumerSession.createConsumer(destination);
|
||||
consumer1.setMessageListener(this);
|
||||
JMSException jmsEx = null;
|
||||
MessageConsumer consumer2 = consumerSession.createConsumer(destination);
|
||||
|
||||
try {
|
||||
|
@ -58,6 +57,7 @@ public class ChangeSessionDeliveryModeTest extends TestSupport implements Messag
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Message msg) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,11 @@ import javax.jms.Session;
|
|||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.apache.activemq.test.JmsSendReceiveTestSupport;
|
||||
import org.apache.activemq.test.retroactive.RetroactiveConsumerTestWithSimpleMessageListTest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class CompositePublishTest extends JmsSendReceiveTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CompositePublishTest.class);
|
||||
|
@ -43,8 +42,11 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport {
|
|||
protected Connection receiveConnection;
|
||||
protected Session receiveSession;
|
||||
protected MessageConsumer[] consumers;
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected List[] messageLists;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
@ -95,6 +97,7 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport {
|
|||
|
||||
protected MessageListener createMessageListener(int i, final List<Message> messageList) {
|
||||
return new MessageListener() {
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
consumeMessage(message, messageList);
|
||||
}
|
||||
|
@ -104,6 +107,7 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport {
|
|||
/**
|
||||
* Returns the subject on which we publish
|
||||
*/
|
||||
@Override
|
||||
protected String getSubject() {
|
||||
return getPrefix() + "FOO.BAR," + getPrefix() + "FOO.X.Y";
|
||||
}
|
||||
|
@ -119,6 +123,8 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport {
|
|||
return super.getSubject() + ".";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void assertMessagesAreReceived() throws JMSException {
|
||||
waitForMessagesToBeDelivered();
|
||||
int size = messageLists.length;
|
||||
|
@ -131,10 +137,12 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() {
|
||||
return new ActiveMQConnectionFactory("vm://localhost");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
session.close();
|
||||
receiveSession.close();
|
||||
|
|
|
@ -18,56 +18,47 @@ package org.apache.activemq.usecases;
|
|||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.JmsConnectionStartStopTest;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||
|
||||
/**
|
||||
* Test case intended to demonstrate delivery interruption to queue consumers when
|
||||
* a JMS selector leaves some messages on the queue (due to use of a JMS Selector)
|
||||
*
|
||||
* testNonDiscriminatingConsumer() demonstrates proper functionality for consumers that don't use
|
||||
* a selector to qualify their input.
|
||||
*
|
||||
* testDiscriminatingConsumer() demonstrates the failure condition in which delivery to the consumer
|
||||
* eventually halts.
|
||||
*
|
||||
* The expected behavior is for the delivery to the client to be maintained regardless of the depth
|
||||
* of the queue, particularly when the messages in the queue do not meet the selector criteria of the
|
||||
* client.
|
||||
* Test case intended to demonstrate delivery interruption to queue consumers when a JMS selector leaves some messages
|
||||
* on the queue (due to use of a JMS Selector)
|
||||
*
|
||||
* testNonDiscriminatingConsumer() demonstrates proper functionality for consumers that don't use a selector to qualify
|
||||
* their input.
|
||||
*
|
||||
* testDiscriminatingConsumer() demonstrates the failure condition in which delivery to the consumer eventually halts.
|
||||
*
|
||||
* The expected behavior is for the delivery to the client to be maintained regardless of the depth of the queue,
|
||||
* particularly when the messages in the queue do not meet the selector criteria of the client.
|
||||
*
|
||||
* https://issues.apache.org/activemq/browse/AMQ-2217
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DiscriminatingConsumerLoadTest extends TestSupport {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
|
||||
.getLog(DiscriminatingConsumerLoadTest.class);
|
||||
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(DiscriminatingConsumerLoadTest.class);
|
||||
|
||||
private Connection producerConnection;
|
||||
private Connection consumerConnection;
|
||||
private int counterSent = 0;
|
||||
private int counterReceived = 0;
|
||||
|
||||
public static final String JMSTYPE_EATME = "DiscriminatingLoadClient.EatMe";
|
||||
public static final String JMSTYPE_IGNOREME = "DiscriminatingLoadClient.IgnoreMe";
|
||||
private Connection producerConnection;
|
||||
private Connection consumerConnection;
|
||||
|
||||
private int testSize = 5000; // setting this to a small number will pass all tests
|
||||
public static final String JMSTYPE_EATME = "DiscriminatingLoadClient.EatMe";
|
||||
public static final String JMSTYPE_IGNOREME = "DiscriminatingLoadClient.IgnoreMe";
|
||||
|
||||
private final int testSize = 5000; // setting this to a small number will pass all tests
|
||||
|
||||
BrokerService broker;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
broker = new BrokerService();
|
||||
broker.setPersistent(false);
|
||||
|
||||
|
@ -79,258 +70,241 @@ public class DiscriminatingConsumerLoadTest extends TestSupport {
|
|||
broker.setDestinationPolicy(policyMap);
|
||||
broker.start();
|
||||
|
||||
super.setUp();
|
||||
this.producerConnection = this.createConnection();
|
||||
this.consumerConnection = this.createConnection();
|
||||
}
|
||||
super.setUp();
|
||||
this.producerConnection = this.createConnection();
|
||||
this.consumerConnection = this.createConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
protected void tearDown() throws Exception {
|
||||
if (producerConnection != null) {
|
||||
producerConnection.close();
|
||||
producerConnection = null;
|
||||
}
|
||||
if (consumerConnection != null) {
|
||||
consumerConnection.close();
|
||||
consumerConnection = null;
|
||||
}
|
||||
super.tearDown();
|
||||
broker.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check if a single consumer with no JMS selector will receive all intended messages
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void testNonDiscriminatingConsumer() throws Exception {
|
||||
|
||||
consumerConnection = createConnection();
|
||||
consumerConnection.start();
|
||||
LOG.info("consumerConnection = " +consumerConnection);
|
||||
|
||||
try {Thread.sleep(1000); } catch (Exception e) {}
|
||||
|
||||
// here we pass in null for the JMS selector
|
||||
Consumer consumer = new Consumer(consumerConnection, null);
|
||||
Thread consumerThread = new Thread(consumer);
|
||||
|
||||
consumerThread.start();
|
||||
|
||||
producerConnection = createConnection();
|
||||
producerConnection.start();
|
||||
LOG.info("producerConnection = " +producerConnection);
|
||||
|
||||
try {Thread.sleep(3000); } catch (Exception e) {}
|
||||
|
||||
Producer producer = new Producer(producerConnection);
|
||||
Thread producerThread = new Thread(producer);
|
||||
producerThread.start();
|
||||
|
||||
// now that everything is running, let's wait for the consumer thread to finish ...
|
||||
consumerThread.join();
|
||||
producer.stop = true;
|
||||
|
||||
if (consumer.getCount() == testSize )
|
||||
LOG.info("test complete .... all messsages consumed!!");
|
||||
else
|
||||
LOG.info("test failed .... Sent " + (testSize / 1) +
|
||||
" messages intended to be consumed ( " + testSize + " total), but only consumed " + consumer.getCount());
|
||||
|
||||
|
||||
assertTrue("Sent " + testSize + " messages intended to be consumed, but only consumed " + consumer.getCount(),
|
||||
(consumer.getCount() == testSize ));
|
||||
assertFalse("Delivery of messages to consumer was halted during this test", consumer.deliveryHalted());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check if a single consumer with a JMS selector will receive all intended messages
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void testDiscriminatingConsumer() throws Exception {
|
||||
|
||||
consumerConnection = createConnection();
|
||||
consumerConnection.start();
|
||||
LOG.info("consumerConnection = " +consumerConnection);
|
||||
|
||||
try {Thread.sleep(1000); } catch (Exception e) {}
|
||||
|
||||
// here we pass the JMS selector we intend to consume
|
||||
Consumer consumer = new Consumer(consumerConnection, JMSTYPE_EATME);
|
||||
Thread consumerThread = new Thread(consumer);
|
||||
|
||||
consumerThread.start();
|
||||
|
||||
producerConnection = createConnection();
|
||||
producerConnection.start();
|
||||
LOG.info("producerConnection = " +producerConnection);
|
||||
|
||||
try {Thread.sleep(3000); } catch (Exception e) {}
|
||||
|
||||
Producer producer = new Producer(producerConnection);
|
||||
Thread producerThread = new Thread(producer);
|
||||
producerThread.start();
|
||||
|
||||
// now that everything is running, let's wait for the consumer thread to finish ...
|
||||
consumerThread.join();
|
||||
producer.stop = true;
|
||||
|
||||
if (consumer.getCount() == (testSize / 2))
|
||||
{
|
||||
LOG.info("test complete .... all messsages consumed!!");
|
||||
/**
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (producerConnection != null) {
|
||||
producerConnection.close();
|
||||
producerConnection = null;
|
||||
}
|
||||
if (consumerConnection != null) {
|
||||
consumerConnection.close();
|
||||
consumerConnection = null;
|
||||
}
|
||||
super.tearDown();
|
||||
broker.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check if a single consumer with no JMS selector will receive all intended messages
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void testNonDiscriminatingConsumer() throws Exception {
|
||||
|
||||
consumerConnection = createConnection();
|
||||
consumerConnection.start();
|
||||
LOG.info("consumerConnection = " + consumerConnection);
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// here we pass in null for the JMS selector
|
||||
Consumer consumer = new Consumer(consumerConnection, null);
|
||||
Thread consumerThread = new Thread(consumer);
|
||||
|
||||
consumerThread.start();
|
||||
|
||||
producerConnection = createConnection();
|
||||
producerConnection.start();
|
||||
LOG.info("producerConnection = " + producerConnection);
|
||||
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
Producer producer = new Producer(producerConnection);
|
||||
Thread producerThread = new Thread(producer);
|
||||
producerThread.start();
|
||||
|
||||
// now that everything is running, let's wait for the consumer thread to finish ...
|
||||
consumerThread.join();
|
||||
producer.stop = true;
|
||||
|
||||
if (consumer.getCount() == testSize)
|
||||
LOG.info("test complete .... all messsages consumed!!");
|
||||
else
|
||||
{
|
||||
LOG.info("test failed .... Sent " + testSize + " original messages, only half of which (" + (testSize / 2) +
|
||||
") were intended to be consumed: consumer paused at: " + consumer.getCount());
|
||||
//System.out.println("test failed .... Sent " + testSize + " original messages, only half of which (" + (testSize / 2) +
|
||||
// ") were intended to be consumed: consumer paused at: " + consumer.getCount());
|
||||
|
||||
}
|
||||
|
||||
assertTrue("Sent " + testSize + " original messages, only half of which (" + (testSize / 2) +
|
||||
") were intended to be consumed: consumer paused at: " + consumer.getCount(),
|
||||
(consumer.getCount() == (testSize / 2)));
|
||||
assertTrue("Delivery of messages to consumer was halted during this test as it only wants half", consumer.deliveryHalted());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class that will publish 2 * testSize messages. The messages will be distributed evenly
|
||||
* between the following two JMS types:
|
||||
*
|
||||
* @see JMSTYPE_INTENDED_FOR_CONSUMPTION
|
||||
* @see JMSTYPE_NOT_INTENDED_FOR_CONSUMPTION
|
||||
*
|
||||
* @author jlyons
|
||||
*
|
||||
*/
|
||||
private class Producer extends Thread
|
||||
{
|
||||
private int counterSent = 0;
|
||||
private Connection connection = null;
|
||||
public boolean stop = false;
|
||||
LOG.info("test failed .... Sent " + (testSize / 1) + " messages intended to be consumed ( " + testSize + " total), but only consumed "
|
||||
+ consumer.getCount());
|
||||
|
||||
public Producer(Connection connection)
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
assertTrue("Sent " + testSize + " messages intended to be consumed, but only consumed " + consumer.getCount(), (consumer.getCount() == testSize));
|
||||
assertFalse("Delivery of messages to consumer was halted during this test", consumer.deliveryHalted());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final Queue queue = session.createQueue("test");
|
||||
/**
|
||||
* Test to check if a single consumer with a JMS selector will receive all intended messages
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void testDiscriminatingConsumer() throws Exception {
|
||||
|
||||
// wait for 10 seconds to allow consumer.receive to be run
|
||||
// first
|
||||
Thread.sleep(10000);
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
consumerConnection = createConnection();
|
||||
consumerConnection.start();
|
||||
LOG.info("consumerConnection = " + consumerConnection);
|
||||
|
||||
while (!stop && (counterSent < testSize))
|
||||
{
|
||||
// first send a message intended to be consumed ....
|
||||
TextMessage message = session.createTextMessage("*** Ill ....... Ini ***"); // alma mater ...
|
||||
message.setJMSType(JMSTYPE_EATME);
|
||||
//LOG.info("sending .... JMSType = " + message.getJMSType());
|
||||
producer.send(message,DeliveryMode.NON_PERSISTENT,0,1800000);
|
||||
|
||||
counterSent++;
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// now send a message intended to be consumed by some other consumer in the the future
|
||||
// ... we expect these messages to accrue in the queue
|
||||
message = session.createTextMessage("*** Ill ....... Ini ***"); // alma mater ...
|
||||
message.setJMSType(JMSTYPE_IGNOREME);
|
||||
//LOG.info("sending .... JMSType = " + message.getJMSType());
|
||||
producer.send(message,DeliveryMode.NON_PERSISTENT,0,1800000);
|
||||
// here we pass the JMS selector we intend to consume
|
||||
Consumer consumer = new Consumer(consumerConnection, JMSTYPE_EATME);
|
||||
Thread consumerThread = new Thread(consumer);
|
||||
|
||||
counterSent++;
|
||||
}
|
||||
consumerThread.start();
|
||||
|
||||
session.close();
|
||||
producerConnection = createConnection();
|
||||
producerConnection.start();
|
||||
LOG.info("producerConnection = " + producerConnection);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOG.info("producer thread complete ... " + counterSent + " messages sent to the queue");
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return this.counterSent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class that will consume messages from the queue based on the supplied JMS selector.
|
||||
* Thread will stop after the first receive(..) timeout, or once all expected messages have
|
||||
* been received (see testSize). If the thread stops due to a timeout, it is experiencing the
|
||||
* delivery pause that is symptomatic of a bug in the broker.
|
||||
*
|
||||
* @author jlyons
|
||||
*
|
||||
*/
|
||||
private class Consumer extends Thread
|
||||
{
|
||||
protected int counterReceived = 0;
|
||||
private Connection connection = null;
|
||||
private String jmsSelector = null;
|
||||
private boolean deliveryHalted = false;
|
||||
|
||||
public Consumer(Connection connection, String jmsSelector)
|
||||
{
|
||||
this.connection = connection;
|
||||
this.jmsSelector = jmsSelector;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
boolean testComplete = false;
|
||||
try {
|
||||
Session session = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final Queue queue = session.createQueue("test");
|
||||
MessageConsumer consumer = null;
|
||||
if (null != this.jmsSelector)
|
||||
{
|
||||
consumer = session.createConsumer(queue, "JMSType='" + this.jmsSelector + "'");
|
||||
}
|
||||
else
|
||||
{
|
||||
consumer = session.createConsumer(queue);
|
||||
}
|
||||
Producer producer = new Producer(producerConnection);
|
||||
Thread producerThread = new Thread(producer);
|
||||
producerThread.start();
|
||||
|
||||
while (!deliveryHalted && (counterReceived < testSize))
|
||||
{
|
||||
TextMessage result = (TextMessage) consumer.receive(30000);
|
||||
if (result != null) {
|
||||
counterReceived++;
|
||||
//System.out.println("consuming .... JMSType = " + result.getJMSType() + " received = " + counterReceived);
|
||||
LOG.info("consuming .... JMSType = " + result.getJMSType() + " received = " + counterReceived);
|
||||
} else
|
||||
{
|
||||
LOG.info("consuming .... timeout while waiting for a message ... broker must have stopped delivery ... received = " + counterReceived);
|
||||
deliveryHalted = true;
|
||||
}
|
||||
}
|
||||
session.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// now that everything is running, let's wait for the consumer thread to finish ...
|
||||
consumerThread.join();
|
||||
producer.stop = true;
|
||||
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return this.counterReceived;
|
||||
}
|
||||
|
||||
public boolean deliveryHalted()
|
||||
{
|
||||
return this.deliveryHalted;
|
||||
}
|
||||
}
|
||||
if (consumer.getCount() == (testSize / 2)) {
|
||||
LOG.info("test complete .... all messsages consumed!!");
|
||||
} else {
|
||||
LOG.info("test failed .... Sent " + testSize + " original messages, only half of which (" + (testSize / 2)
|
||||
+ ") were intended to be consumed: consumer paused at: " + consumer.getCount());
|
||||
// System.out.println("test failed .... Sent " + testSize + " original messages, only half of which (" +
|
||||
// (testSize / 2) +
|
||||
// ") were intended to be consumed: consumer paused at: " + consumer.getCount());
|
||||
|
||||
}
|
||||
|
||||
assertTrue("Sent " + testSize + " original messages, only half of which (" + (testSize / 2) + ") were intended to be consumed: consumer paused at: "
|
||||
+ consumer.getCount(), (consumer.getCount() == (testSize / 2)));
|
||||
assertTrue("Delivery of messages to consumer was halted during this test as it only wants half", consumer.deliveryHalted());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class that will publish 2 * testSize messages. The messages will be distributed evenly between the
|
||||
* following two JMS types:
|
||||
*
|
||||
* @see JMSTYPE_INTENDED_FOR_CONSUMPTION
|
||||
* @see JMSTYPE_NOT_INTENDED_FOR_CONSUMPTION
|
||||
*
|
||||
*/
|
||||
private class Producer extends Thread {
|
||||
private int counterSent = 0;
|
||||
private Connection connection = null;
|
||||
public boolean stop = false;
|
||||
|
||||
public Producer(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final Queue queue = session.createQueue("test");
|
||||
|
||||
// wait for 10 seconds to allow consumer.receive to be run
|
||||
// first
|
||||
Thread.sleep(10000);
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
|
||||
while (!stop && (counterSent < testSize)) {
|
||||
// first send a message intended to be consumed ....
|
||||
TextMessage message = session.createTextMessage("*** Ill ....... Ini ***"); // alma mater ...
|
||||
message.setJMSType(JMSTYPE_EATME);
|
||||
// LOG.info("sending .... JMSType = " + message.getJMSType());
|
||||
producer.send(message, DeliveryMode.NON_PERSISTENT, 0, 1800000);
|
||||
|
||||
counterSent++;
|
||||
|
||||
// now send a message intended to be consumed by some other consumer in the the future
|
||||
// ... we expect these messages to accrue in the queue
|
||||
message = session.createTextMessage("*** Ill ....... Ini ***"); // alma mater ...
|
||||
message.setJMSType(JMSTYPE_IGNOREME);
|
||||
// LOG.info("sending .... JMSType = " + message.getJMSType());
|
||||
producer.send(message, DeliveryMode.NON_PERSISTENT, 0, 1800000);
|
||||
|
||||
counterSent++;
|
||||
}
|
||||
|
||||
session.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOG.info("producer thread complete ... " + counterSent + " messages sent to the queue");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class that will consume messages from the queue based on the supplied JMS selector. Thread will stop after
|
||||
* the first receive(..) timeout, or once all expected messages have been received (see testSize). If the thread
|
||||
* stops due to a timeout, it is experiencing the delivery pause that is symptomatic of a bug in the broker.
|
||||
*
|
||||
*/
|
||||
private class Consumer extends Thread {
|
||||
protected int counterReceived = 0;
|
||||
private String jmsSelector = null;
|
||||
private boolean deliveryHalted = false;
|
||||
|
||||
public Consumer(Connection connection, String jmsSelector) {
|
||||
this.jmsSelector = jmsSelector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Session session = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final Queue queue = session.createQueue("test");
|
||||
MessageConsumer consumer = null;
|
||||
if (null != this.jmsSelector) {
|
||||
consumer = session.createConsumer(queue, "JMSType='" + this.jmsSelector + "'");
|
||||
} else {
|
||||
consumer = session.createConsumer(queue);
|
||||
}
|
||||
|
||||
while (!deliveryHalted && (counterReceived < testSize)) {
|
||||
TextMessage result = (TextMessage) consumer.receive(30000);
|
||||
if (result != null) {
|
||||
counterReceived++;
|
||||
// System.out.println("consuming .... JMSType = " + result.getJMSType() + " received = " +
|
||||
// counterReceived);
|
||||
LOG.info("consuming .... JMSType = " + result.getJMSType() + " received = " + counterReceived);
|
||||
} else {
|
||||
LOG.info("consuming .... timeout while waiting for a message ... broker must have stopped delivery ... received = " + counterReceived);
|
||||
deliveryHalted = true;
|
||||
}
|
||||
}
|
||||
session.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.counterReceived;
|
||||
}
|
||||
|
||||
public boolean deliveryHalted() {
|
||||
return this.deliveryHalted;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -27,6 +29,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
|
@ -53,9 +56,6 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DurableSubProcessConcurrentCommitActivateNoDuplicateTest.class);
|
||||
public static final long RUNTIME = 5 * 60 * 1000;
|
||||
|
@ -69,9 +69,9 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
public static final Random CLIENT_OFFLINE = new Random(1 * 1000, 10 * 1000);
|
||||
|
||||
public static final int CLIENT_OFFLINE_DURING_COMMIT = 2; // random(x) == x
|
||||
|
||||
|
||||
public static final Persistence PERSISTENT_ADAPTER = Persistence.KAHADB;
|
||||
|
||||
|
||||
public static final long BROKER_RESTART = -2 * 60 * 1000;
|
||||
|
||||
public static final boolean ALLOW_SUBSCRIPTION_ABANDONMENT = true;
|
||||
|
@ -126,10 +126,10 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
//allow the clients to unsubscribe before finishing
|
||||
clientManager.setEnd(true);
|
||||
try {
|
||||
Thread.sleep(60 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
exit("ProcessTest.testProcess failed.", e);
|
||||
}
|
||||
Thread.sleep(60 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
exit("ProcessTest.testProcess failed.", e);
|
||||
}
|
||||
|
||||
server.done = true;
|
||||
|
||||
|
@ -181,7 +181,7 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
|
||||
int transRover = 0;
|
||||
int messageRover = 0;
|
||||
public volatile int committingTransaction = -1;
|
||||
public volatile int committingTransaction = -1;
|
||||
public boolean done = false;
|
||||
public Server() {
|
||||
super("Server");
|
||||
|
@ -194,8 +194,8 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
try {
|
||||
while (!done) {
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
processLock.readLock().lock();
|
||||
try {
|
||||
send();
|
||||
|
@ -347,7 +347,7 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
|
||||
private final CopyOnWriteArrayList<Client> clients = new CopyOnWriteArrayList<Client>();
|
||||
|
||||
private boolean end;
|
||||
private boolean end;
|
||||
|
||||
public ClientManager() {
|
||||
super("ClientManager");
|
||||
|
@ -355,11 +355,11 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
}
|
||||
|
||||
public synchronized void setEnd(boolean end) {
|
||||
this.end = end;
|
||||
|
||||
}
|
||||
this.end = end;
|
||||
|
||||
@Override
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
|
@ -491,10 +491,10 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
offline.sleepRandom();
|
||||
else
|
||||
sleep = true;
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
|
||||
processLock.readLock().lock();
|
||||
onlineCount.incrementAndGet();
|
||||
try {
|
||||
|
@ -524,7 +524,7 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
|
||||
private void process(long millis) throws JMSException {
|
||||
//long end = System.currentTimeMillis() + millis;
|
||||
long end = System.currentTimeMillis() + 200;
|
||||
long end = System.currentTimeMillis() + 200;
|
||||
long hardEnd = end + 20000; // wait to finish the transaction.
|
||||
boolean inTransaction = false;
|
||||
int transCount = 0;
|
||||
|
@ -565,7 +565,7 @@ public class DurableSubProcessConcurrentCommitActivateNoDuplicateTest {
|
|||
|
||||
inTransaction = false;
|
||||
transCount = 0;
|
||||
|
||||
|
||||
int committing = server.committingTransaction;
|
||||
if (committing == trans) {
|
||||
LOG.info("Going offline during transaction commit. messageID=" + message.getIntProperty("ID"));
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -26,6 +29,7 @@ import java.util.Vector;
|
|||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
|
@ -33,6 +37,7 @@ import javax.jms.Message;
|
|||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -47,10 +52,6 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class DurableSubProcessWithRestartTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DurableSubProcessWithRestartTest.class);
|
||||
public static final long RUNTIME = 5 * 60 * 1000;
|
||||
|
@ -93,22 +94,18 @@ public class DurableSubProcessWithRestartTest {
|
|||
if (ALLOW_SUBSCRIPTION_ABANDONMENT)
|
||||
houseKeeper.start();
|
||||
|
||||
if (BROKER_RESTART <= 0)
|
||||
Thread.sleep(RUNTIME);
|
||||
else {
|
||||
long end = System.currentTimeMillis() + RUNTIME;
|
||||
long end = System.currentTimeMillis() + RUNTIME;
|
||||
|
||||
while (true) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now > end)
|
||||
break;
|
||||
while (true) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now > end)
|
||||
break;
|
||||
|
||||
now = end - now;
|
||||
now = now < BROKER_RESTART ? now : BROKER_RESTART;
|
||||
Thread.sleep(now);
|
||||
now = end - now;
|
||||
now = now < BROKER_RESTART ? now : BROKER_RESTART;
|
||||
Thread.sleep(now);
|
||||
|
||||
restartBroker();
|
||||
}
|
||||
restartBroker();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
exit("ProcessTest.testProcess failed.", e);
|
||||
|
@ -588,6 +585,7 @@ public class DurableSubProcessWithRestartTest {
|
|||
/**
|
||||
* Checks if the message was not delivered fast enough.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public void checkDeliveryTime(Message message) throws JMSException {
|
||||
long creation = message.getJMSTimestamp();
|
||||
long min = System.currentTimeMillis() - (offline.max + online.min)
|
||||
|
|
|
@ -736,9 +736,7 @@ public class DurableSubscriptionOfflineTest extends org.apache.activemq.TestSupp
|
|||
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer producer = session.createProducer(null);
|
||||
|
||||
int sent = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sent++;
|
||||
Message message = session.createMessage();
|
||||
message.setStringProperty("filter", "true");
|
||||
producer.send(topic, message);
|
||||
|
|
|
@ -25,9 +25,9 @@ import javax.jms.MessageProducer;
|
|||
import javax.jms.Session;
|
||||
import javax.jms.TopicSubscriber;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -74,7 +74,8 @@ public class DurableSubscriptionSelectorTest extends org.apache.activemq.TestSup
|
|||
|
||||
sendMessage(true);
|
||||
|
||||
Wait.waitFor(new Wait.Condition() { public boolean isSatisified() { return received >= 1;} }, 10000);
|
||||
Wait.waitFor(new Wait.Condition() { @Override
|
||||
public boolean isSatisified() { return received >= 1;} }, 10000);
|
||||
|
||||
assertEquals("Message is not received.", 1, received);
|
||||
|
||||
|
@ -92,6 +93,7 @@ public class DurableSubscriptionSelectorTest extends org.apache.activemq.TestSup
|
|||
TopicSubscriber subscriber = session.createDurableSubscriber(topic, "subName", "filter=true", false);
|
||||
|
||||
subscriber.setMessageListener(new MessageListener() {
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
received++;
|
||||
}
|
||||
|
@ -123,22 +125,10 @@ public class DurableSubscriptionSelectorTest extends org.apache.activemq.TestSup
|
|||
producerConnection = null;
|
||||
}
|
||||
|
||||
private int getPendingQueueSize() throws Exception {
|
||||
ObjectName[] subs = broker.getAdminView().getDurableTopicSubscribers();
|
||||
for (ObjectName sub: subs) {
|
||||
if ("cliID".equals(mbs.getAttribute(sub, "ClientId"))) {
|
||||
Integer size = (Integer) mbs.getAttribute(sub, "PendingQueueSize");
|
||||
return size != null ? size : 0;
|
||||
}
|
||||
}
|
||||
assertTrue(false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void startBroker(boolean deleteMessages) throws Exception {
|
||||
broker = new BrokerService();
|
||||
broker.setBrokerName("test-broker");
|
||||
|
||||
|
||||
if (deleteMessages) {
|
||||
broker.setDeleteAllMessagesOnStartup(true);
|
||||
}
|
||||
|
@ -163,7 +153,8 @@ public class DurableSubscriptionSelectorTest extends org.apache.activemq.TestSup
|
|||
broker.stop();
|
||||
broker = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory("vm://test-broker?jms.watchTopicAdvisories=false&waitForStart=5000&create=false");
|
||||
}
|
||||
|
|
|
@ -16,14 +16,21 @@
|
|||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Session;
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.TestSupport;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.ConnectionContext;
|
||||
import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
|
||||
import org.apache.activemq.broker.jmx.SubscriptionView;
|
||||
import org.apache.activemq.broker.jmx.SubscriptionViewMBean;
|
||||
import org.apache.activemq.broker.region.Destination;
|
||||
import org.apache.activemq.broker.region.DurableTopicSubscription;
|
||||
import org.apache.activemq.broker.region.Subscription;
|
||||
|
@ -31,14 +38,6 @@ import org.apache.activemq.command.ActiveMQTopic;
|
|||
import org.apache.activemq.command.RemoveSubscriptionInfo;
|
||||
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Session;
|
||||
import javax.management.*;
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class DurableSubscriptionUnsubscribeTest extends TestSupport {
|
||||
|
||||
BrokerService broker = null;
|
||||
|
@ -193,7 +192,7 @@ public class DurableSubscriptionUnsubscribeTest extends TestSupport {
|
|||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
session.createDurableSubscriber(topic, "SubsId" + i);
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,6 +282,7 @@ public class DurableSubscriptionUnsubscribeTest extends TestSupport {
|
|||
startBroker(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
return new ActiveMQConnectionFactory("vm://" + getName() + "?waitForStart=5000&create=false");
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import static org.apache.activemq.TestSupport.getDestination;
|
||||
import static org.apache.activemq.TestSupport.getDestinationStatistics;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
@ -42,9 +45,6 @@ import org.apache.activemq.store.amq.AMQPersistenceAdapter;
|
|||
import org.apache.activemq.util.Wait;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static org.apache.activemq.TestSupport.getDestination;
|
||||
import static org.apache.activemq.TestSupport.getDestinationStatistics;
|
||||
|
||||
|
||||
public class ExpiredMessagesTest extends CombinationTestSupport {
|
||||
|
||||
|
@ -69,6 +69,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
final boolean deleteAllMessages = true;
|
||||
broker = createBroker(deleteAllMessages, 100);
|
||||
|
@ -87,6 +88,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
final AtomicLong received = new AtomicLong();
|
||||
|
||||
Thread consumerThread = new Thread("Consumer Thread") {
|
||||
@Override
|
||||
public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
|
@ -109,6 +111,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
|
||||
final int numMessagesToSend = 10000;
|
||||
Thread producingThread = new Thread("Producing Thread") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int i = 0;
|
||||
|
@ -132,6 +135,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
|
||||
// wait for all to inflight to expire
|
||||
assertTrue("all inflight messages expired ", Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
return view.getInflight().getCount() == 0;
|
||||
}
|
||||
|
@ -143,6 +147,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
|
||||
// wait for all sent to get delivered and expire
|
||||
assertTrue("all sent messages expired ", Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
long oldEnqueues = view.getEnqueues().getCount();
|
||||
Thread.sleep(200);
|
||||
|
@ -159,6 +164,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
assertTrue("got at least what did not expire", received.get() >= view.getDequeues().getCount() - view.getExpired().getCount());
|
||||
|
||||
assertTrue("all messages expired - queue size gone to zero " + view.getMessages().getCount(), Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.info("Stats: received: " + received.get() + ", size= " + view.getMessages().getCount() + ", enqueues: " + view.getEnqueues().getCount() + ", dequeues: " + view.getDequeues().getCount()
|
||||
+ ", dispatched: " + view.getDispatched().getCount() + ", inflight: " + view.getInflight().getCount() + ", expiries: " + view.getExpired().getCount());
|
||||
|
@ -174,6 +180,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
+ ", dispatched: " + dlqView.getDispatched().getCount() + ", inflight: " + dlqView.getInflight().getCount() + ", expiries: " + dlqView.getExpired().getCount());
|
||||
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
return totalExpiredCount == dlqView.getMessages().getCount();
|
||||
}
|
||||
|
@ -190,6 +197,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
dlqConsumer.setMessageListener(dlqListener);
|
||||
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
return totalExpiredCount == dlqListener.count;
|
||||
}
|
||||
|
@ -202,6 +210,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
|
||||
int count = 0;
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
count++;
|
||||
}
|
||||
|
@ -228,6 +237,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
|
||||
|
||||
Thread producingThread = new Thread("Producing Thread") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int i = 0;
|
||||
|
@ -266,6 +276,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
broker = createBroker(deleteAllMessages, 5000);
|
||||
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
DestinationStatistics view = getDestinationStatistics(broker, destination);
|
||||
LOG.info("Stats: size: " + view.getMessages().getCount() + ", enqueues: "
|
||||
|
@ -311,6 +322,7 @@ public class ExpiredMessagesTest extends CombinationTestSupport {
|
|||
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
connection.stop();
|
||||
broker.stop();
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.JMSException;
|
||||
|
@ -31,20 +34,17 @@ import javax.jms.MessageProducer;
|
|||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
import javax.jms.Topic;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||
import org.apache.activemq.broker.region.policy.StorePendingDurableSubscriberMessageStoragePolicy;
|
||||
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JdbcDurableSubDupTest {
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class JdbcDurableSubDupTest {
|
|||
|
||||
final int TO_RECEIVE = 5000;
|
||||
BrokerService broker = null;
|
||||
Vector<Throwable> exceptions = new Vector();
|
||||
Vector<Throwable> exceptions = new Vector<Throwable>();
|
||||
final int MAX_MESSAGES = 100000;
|
||||
int[] dupChecker = new int[MAX_MESSAGES];
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class JdbcDurableSubDupTest {
|
|||
for (int i = 0; i < TO_RECEIVE; i++) {
|
||||
assertTrue("got message " + i, dupChecker[i] == 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class JmsConsumerDup implements MessageListener {
|
||||
|
@ -185,6 +185,7 @@ public class JdbcDurableSubDupTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
++count;
|
||||
|
||||
|
@ -229,6 +230,7 @@ public class JdbcDurableSubDupTest {
|
|||
|
||||
int priorityModulator = 10;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Connection connection;
|
||||
|
|
|
@ -77,7 +77,7 @@ public class MessageGroupCloseTest extends TestCase {
|
|||
if (i % 100 == 0) {
|
||||
LOG.info("Sent messages: group=" + i);
|
||||
}
|
||||
messageGroupCount++;
|
||||
setMessageGroupCount(getMessageGroupCount() + 1);
|
||||
}
|
||||
LOG.info(messagesSent+" messages sent");
|
||||
latchMessagesCreated.countDown();
|
||||
|
@ -218,4 +218,18 @@ public class MessageGroupCloseTest extends TestCase {
|
|||
messageGroups.put(groupId, count + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the messageGroupCount
|
||||
*/
|
||||
public int getMessageGroupCount() {
|
||||
return messageGroupCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param messageGroupCount the messageGroupCount to set
|
||||
*/
|
||||
public void setMessageGroupCount(int messageGroupCount) {
|
||||
this.messageGroupCount = messageGroupCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,208 +40,204 @@ import org.apache.activemq.command.ActiveMQQueue;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
public class MessageGroupDelayedTest extends JmsTestSupport {
|
||||
public static final Logger log = LoggerFactory.getLogger(MessageGroupDelayedTest.class);
|
||||
protected Connection connection;
|
||||
protected Session session;
|
||||
protected MessageProducer producer;
|
||||
protected Destination destination;
|
||||
|
||||
public int consumersBeforeDispatchStarts;
|
||||
public int timeBeforeDispatchStarts;
|
||||
|
||||
BrokerService broker;
|
||||
protected TransportConnector connector;
|
||||
|
||||
protected HashMap<String, Integer> messageCount = new HashMap<String, Integer>();
|
||||
protected HashMap<String, Set<String>> messageGroups = new HashMap<String, Set<String>>();
|
||||
|
||||
public static Test suite() {
|
||||
return suite(MessageGroupDelayedTest.class);
|
||||
}
|
||||
public static final Logger log = LoggerFactory.getLogger(MessageGroupDelayedTest.class);
|
||||
protected Connection connection;
|
||||
protected Session session;
|
||||
protected MessageProducer producer;
|
||||
protected Destination destination;
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
public int consumersBeforeDispatchStarts;
|
||||
public int timeBeforeDispatchStarts;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
broker = createBroker();
|
||||
broker.start();
|
||||
ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory(connector.getConnectUri() + "?jms.prefetchPolicy.all=1");
|
||||
connection = connFactory.createConnection();
|
||||
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||
destination = new ActiveMQQueue("test-queue2");
|
||||
producer = session.createProducer(destination);
|
||||
connection.start();
|
||||
}
|
||||
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService service = new BrokerService();
|
||||
service.setPersistent(false);
|
||||
service.setUseJmx(false);
|
||||
BrokerService broker;
|
||||
protected TransportConnector connector;
|
||||
|
||||
// Setup a destination policy where it takes only 1 message at a time.
|
||||
PolicyMap policyMap = new PolicyMap();
|
||||
PolicyEntry policy = new PolicyEntry();
|
||||
log.info("testing with consumersBeforeDispatchStarts=" + consumersBeforeDispatchStarts + " and timeBeforeDispatchStarts=" + timeBeforeDispatchStarts);
|
||||
policy.setConsumersBeforeDispatchStarts(consumersBeforeDispatchStarts);
|
||||
policy.setTimeBeforeDispatchStarts(timeBeforeDispatchStarts);
|
||||
policyMap.setDefaultEntry(policy);
|
||||
service.setDestinationPolicy(policyMap);
|
||||
protected HashMap<String, Integer> messageCount = new HashMap<String, Integer>();
|
||||
protected HashMap<String, Set<String>> messageGroups = new HashMap<String, Set<String>>();
|
||||
|
||||
connector = service.addConnector("tcp://localhost:0");
|
||||
return service;
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
producer.close();
|
||||
session.close();
|
||||
connection.close();
|
||||
broker.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void initCombosForTestDelayedDirectConnectionListener() {
|
||||
addCombinationValues("consumersBeforeDispatchStarts", new Object[] {0, 3, 5});
|
||||
addCombinationValues("timeBeforeDispatchStarts", new Object[] {0, 100});
|
||||
}
|
||||
|
||||
public void testDelayedDirectConnectionListener() throws Exception {
|
||||
|
||||
for(int i = 0; i < 10; i++) {
|
||||
Message msga = session.createTextMessage("hello a");
|
||||
msga.setStringProperty("JMSXGroupID", "A");
|
||||
producer.send(msga);
|
||||
Message msgb = session.createTextMessage("hello b");
|
||||
msgb.setStringProperty("JMSXGroupID", "B");
|
||||
producer.send(msgb);
|
||||
Message msgc = session.createTextMessage("hello c");
|
||||
msgc.setStringProperty("JMSXGroupID", "C");
|
||||
producer.send(msgc);
|
||||
public static Test suite() {
|
||||
return suite(MessageGroupDelayedTest.class);
|
||||
}
|
||||
log.info("30 messages sent to group A/B/C");
|
||||
|
||||
int[] counters = {10, 10, 10};
|
||||
|
||||
CountDownLatch startSignal = new CountDownLatch(1);
|
||||
CountDownLatch doneSignal = new CountDownLatch(1);
|
||||
|
||||
messageCount.put("worker1", 0);
|
||||
messageGroups.put("worker1", new HashSet<String>());
|
||||
Worker worker1 = new Worker(connection, destination, "worker1", startSignal, doneSignal, counters, messageCount, messageGroups);
|
||||
messageCount.put("worker2", 0);
|
||||
messageGroups.put("worker2", new HashSet<String>());
|
||||
Worker worker2 = new Worker(connection, destination, "worker2", startSignal, doneSignal, counters, messageCount, messageGroups);
|
||||
messageCount.put("worker3", 0);
|
||||
messageGroups.put("worker3", new HashSet<String>());
|
||||
Worker worker3 = new Worker(connection, destination, "worker3", startSignal, doneSignal, counters, messageCount, messageGroups);
|
||||
|
||||
|
||||
new Thread(worker1).start();
|
||||
new Thread(worker2).start();
|
||||
new Thread(worker3).start();
|
||||
|
||||
startSignal.countDown();
|
||||
doneSignal.await();
|
||||
|
||||
// check results
|
||||
if (consumersBeforeDispatchStarts == 0 && timeBeforeDispatchStarts == 0) {
|
||||
log.info("Ignoring results because both parameters are 0");
|
||||
return;
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
for (String worker: messageCount.keySet()) {
|
||||
log.info("worker " + worker + " received " + messageCount.get(worker) + " messages from groups " + messageGroups.get(worker));
|
||||
assertEquals("worker " + worker + " received " + messageCount.get(worker) + " messages from groups " + messageGroups.get(worker)
|
||||
, 10, messageCount.get(worker).intValue());
|
||||
assertEquals("worker " + worker + " received " + messageCount.get(worker) + " messages from groups " + messageGroups.get(worker)
|
||||
, 1, messageGroups.get(worker).size());
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
broker = createBroker();
|
||||
broker.start();
|
||||
ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory(connector.getConnectUri() + "?jms.prefetchPolicy.all=1");
|
||||
connection = connFactory.createConnection();
|
||||
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||
destination = new ActiveMQQueue("test-queue2");
|
||||
producer = session.createProducer(destination);
|
||||
connection.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class Worker implements Runnable {
|
||||
private Connection connection = null;
|
||||
private Destination queueName = null;
|
||||
private String workerName = null;
|
||||
private CountDownLatch startSignal = null;
|
||||
private CountDownLatch doneSignal = null;
|
||||
private int[] counters = null;
|
||||
private HashMap<String, Integer> messageCount;
|
||||
private HashMap<String, Set<String>>messageGroups;
|
||||
|
||||
|
||||
private Worker(Connection connection, Destination queueName, String workerName, CountDownLatch startSignal, CountDownLatch doneSignal, int[] counters, HashMap<String, Integer> messageCount, HashMap<String, Set<String>>messageGroups) {
|
||||
this.connection = connection;
|
||||
this.queueName = queueName;
|
||||
this.workerName = workerName;
|
||||
this.startSignal = startSignal;
|
||||
this.doneSignal = doneSignal;
|
||||
this.counters = counters;
|
||||
this.messageCount = messageCount;
|
||||
this.messageGroups = messageGroups;
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService service = new BrokerService();
|
||||
service.setPersistent(false);
|
||||
service.setUseJmx(false);
|
||||
|
||||
// Setup a destination policy where it takes only 1 message at a time.
|
||||
PolicyMap policyMap = new PolicyMap();
|
||||
PolicyEntry policy = new PolicyEntry();
|
||||
log.info("testing with consumersBeforeDispatchStarts=" + consumersBeforeDispatchStarts + " and timeBeforeDispatchStarts=" + timeBeforeDispatchStarts);
|
||||
policy.setConsumersBeforeDispatchStarts(consumersBeforeDispatchStarts);
|
||||
policy.setTimeBeforeDispatchStarts(timeBeforeDispatchStarts);
|
||||
policyMap.setDefaultEntry(policy);
|
||||
service.setDestinationPolicy(policyMap);
|
||||
|
||||
connector = service.addConnector("tcp://localhost:0");
|
||||
return service;
|
||||
}
|
||||
|
||||
private void update(String group) {
|
||||
int msgCount = messageCount.get(workerName);
|
||||
messageCount.put(workerName, msgCount + 1);
|
||||
Set<String> groups = messageGroups.get(workerName);
|
||||
groups.add(group);
|
||||
messageGroups.put(workerName, groups);
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
producer.close();
|
||||
session.close();
|
||||
connection.close();
|
||||
broker.stop();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
log.info(workerName);
|
||||
startSignal.await();
|
||||
Session sess = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||
MessageConsumer consumer = sess.createConsumer(queueName);
|
||||
public void initCombosForTestDelayedDirectConnectionListener() {
|
||||
addCombinationValues("consumersBeforeDispatchStarts", new Object[] { 0, 3, 5 });
|
||||
addCombinationValues("timeBeforeDispatchStarts", new Object[] { 0, 100 });
|
||||
}
|
||||
|
||||
while(true) {
|
||||
if(counters[0] == 0 && counters[1] == 0 && counters[2] == 0 ) {
|
||||
doneSignal.countDown();
|
||||
log.info(workerName + " done...");
|
||||
break;
|
||||
}
|
||||
|
||||
Message msg = consumer.receive(500);
|
||||
if(msg == null)
|
||||
continue;
|
||||
public void testDelayedDirectConnectionListener() throws Exception {
|
||||
|
||||
String group = msg.getStringProperty("JMSXGroupID");
|
||||
boolean first = msg.getBooleanProperty("JMSXGroupFirstForConsumer");
|
||||
|
||||
if("A".equals(group)){
|
||||
--counters[0];
|
||||
update(group);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
else if("B".equals(group)) {
|
||||
--counters[1];
|
||||
update(group);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
else if("C".equals(group)) {
|
||||
--counters[2];
|
||||
update(group);
|
||||
Thread.sleep(10);
|
||||
}
|
||||
else {
|
||||
log.warn("unknown group");
|
||||
}
|
||||
if (counters[0] != 0 || counters[1] != 0 || counters[2] != 0 ) {
|
||||
msg.acknowledge();
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Message msga = session.createTextMessage("hello a");
|
||||
msga.setStringProperty("JMSXGroupID", "A");
|
||||
producer.send(msga);
|
||||
Message msgb = session.createTextMessage("hello b");
|
||||
msgb.setStringProperty("JMSXGroupID", "B");
|
||||
producer.send(msgb);
|
||||
Message msgc = session.createTextMessage("hello c");
|
||||
msgc.setStringProperty("JMSXGroupID", "C");
|
||||
producer.send(msgc);
|
||||
}
|
||||
log.info("30 messages sent to group A/B/C");
|
||||
|
||||
int[] counters = { 10, 10, 10 };
|
||||
|
||||
CountDownLatch startSignal = new CountDownLatch(1);
|
||||
CountDownLatch doneSignal = new CountDownLatch(1);
|
||||
|
||||
messageCount.put("worker1", 0);
|
||||
messageGroups.put("worker1", new HashSet<String>());
|
||||
Worker worker1 = new Worker(connection, destination, "worker1", startSignal, doneSignal, counters, messageCount, messageGroups);
|
||||
messageCount.put("worker2", 0);
|
||||
messageGroups.put("worker2", new HashSet<String>());
|
||||
Worker worker2 = new Worker(connection, destination, "worker2", startSignal, doneSignal, counters, messageCount, messageGroups);
|
||||
messageCount.put("worker3", 0);
|
||||
messageGroups.put("worker3", new HashSet<String>());
|
||||
Worker worker3 = new Worker(connection, destination, "worker3", startSignal, doneSignal, counters, messageCount, messageGroups);
|
||||
|
||||
new Thread(worker1).start();
|
||||
new Thread(worker2).start();
|
||||
new Thread(worker3).start();
|
||||
|
||||
startSignal.countDown();
|
||||
doneSignal.await();
|
||||
|
||||
// check results
|
||||
if (consumersBeforeDispatchStarts == 0 && timeBeforeDispatchStarts == 0) {
|
||||
log.info("Ignoring results because both parameters are 0");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String worker : messageCount.keySet()) {
|
||||
log.info("worker " + worker + " received " + messageCount.get(worker) + " messages from groups " + messageGroups.get(worker));
|
||||
assertEquals("worker " + worker + " received " + messageCount.get(worker) + " messages from groups " + messageGroups.get(worker), 10, messageCount
|
||||
.get(worker).intValue());
|
||||
assertEquals("worker " + worker + " received " + messageCount.get(worker) + " messages from groups " + messageGroups.get(worker), 1, messageGroups
|
||||
.get(worker).size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class Worker implements Runnable {
|
||||
private Connection connection = null;
|
||||
private Destination queueName = null;
|
||||
private String workerName = null;
|
||||
private CountDownLatch startSignal = null;
|
||||
private CountDownLatch doneSignal = null;
|
||||
private int[] counters = null;
|
||||
private final HashMap<String, Integer> messageCount;
|
||||
private final HashMap<String, Set<String>> messageGroups;
|
||||
|
||||
private Worker(Connection connection, Destination queueName, String workerName, CountDownLatch startSignal, CountDownLatch doneSignal, int[] counters,
|
||||
HashMap<String, Integer> messageCount, HashMap<String, Set<String>> messageGroups) {
|
||||
this.connection = connection;
|
||||
this.queueName = queueName;
|
||||
this.workerName = workerName;
|
||||
this.startSignal = startSignal;
|
||||
this.doneSignal = doneSignal;
|
||||
this.counters = counters;
|
||||
this.messageCount = messageCount;
|
||||
this.messageGroups = messageGroups;
|
||||
}
|
||||
|
||||
private void update(String group) {
|
||||
int msgCount = messageCount.get(workerName);
|
||||
messageCount.put(workerName, msgCount + 1);
|
||||
Set<String> groups = messageGroups.get(workerName);
|
||||
groups.add(group);
|
||||
messageGroups.put(workerName, groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
log.info(workerName);
|
||||
startSignal.await();
|
||||
Session sess = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||
MessageConsumer consumer = sess.createConsumer(queueName);
|
||||
|
||||
while (true) {
|
||||
if (counters[0] == 0 && counters[1] == 0 && counters[2] == 0) {
|
||||
doneSignal.countDown();
|
||||
log.info(workerName + " done...");
|
||||
break;
|
||||
}
|
||||
|
||||
Message msg = consumer.receive(500);
|
||||
if (msg == null)
|
||||
continue;
|
||||
|
||||
String group = msg.getStringProperty("JMSXGroupID");
|
||||
msg.getBooleanProperty("JMSXGroupFirstForConsumer");
|
||||
|
||||
if ("A".equals(group)) {
|
||||
--counters[0];
|
||||
update(group);
|
||||
Thread.sleep(500);
|
||||
} else if ("B".equals(group)) {
|
||||
--counters[1];
|
||||
update(group);
|
||||
Thread.sleep(100);
|
||||
} else if ("C".equals(group)) {
|
||||
--counters[2];
|
||||
update(group);
|
||||
Thread.sleep(10);
|
||||
} else {
|
||||
log.warn("unknown group");
|
||||
}
|
||||
if (counters[0] != 0 || counters[1] != 0 || counters[2] != 0) {
|
||||
msg.acknowledge();
|
||||
}
|
||||
}
|
||||
consumer.close();
|
||||
sess.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
consumer.close();
|
||||
sess.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,19 +17,18 @@
|
|||
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class MyObject implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2505777188753549398L;
|
||||
|
||||
private String message;
|
||||
private AtomicInteger writeObjectCalled = new AtomicInteger(0);
|
||||
private AtomicInteger readObjectCalled = new AtomicInteger(0);
|
||||
private AtomicInteger readObjectNoDataCalled = new AtomicInteger(0);
|
||||
private final AtomicInteger writeObjectCalled = new AtomicInteger(0);
|
||||
private final AtomicInteger readObjectCalled = new AtomicInteger(0);
|
||||
private final AtomicInteger readObjectNoDataCalled = new AtomicInteger(0);
|
||||
|
||||
public MyObject(String message) {
|
||||
this.setMessage(message);
|
||||
|
@ -50,11 +49,7 @@ public class MyObject implements Serializable {
|
|||
|
||||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
readObjectCalled.incrementAndGet();
|
||||
}
|
||||
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
readObjectNoDataCalled.incrementAndGet();
|
||||
readObjectCalled.incrementAndGet();
|
||||
}
|
||||
|
||||
public int getWriteObjectCalled() {
|
||||
|
|
|
@ -28,14 +28,14 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NewConsumerCreatesDestinationTest extends EmbeddedBrokerAndConnectionTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NewConsumerCreatesDestinationTest.class);
|
||||
|
||||
private ActiveMQQueue wildcard;
|
||||
|
||||
|
||||
public void testNewConsumerCausesNewDestinationToBeAutoCreated() throws Exception {
|
||||
|
||||
// lets create a wildcard thats kinda like those used by Virtual Topics
|
||||
|
@ -44,10 +44,10 @@ public class NewConsumerCreatesDestinationTest extends EmbeddedBrokerAndConnecti
|
|||
|
||||
LOG.info("Using wildcard: " + wildcard);
|
||||
LOG.info("on destination: " + destination);
|
||||
|
||||
|
||||
assertDestinationCreated(destination, false);
|
||||
assertDestinationCreated(wildcard, false);
|
||||
|
||||
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
session.createConsumer(destination);
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class NewConsumerCreatesDestinationTest extends EmbeddedBrokerAndConnecti
|
|||
}
|
||||
|
||||
protected void assertDestinationCreated(Destination destination, boolean expected) throws Exception {
|
||||
Set answer = broker.getBroker().getDestinations((ActiveMQDestination) destination);
|
||||
Set<?> answer = broker.getBroker().getDestinations((ActiveMQDestination) destination);
|
||||
int size = expected ? 1 : 0;
|
||||
assertEquals("Size of found destinations: " + answer, size, answer.size());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,19 @@
|
|||
*/
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.QueueBrowser;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
|
@ -26,13 +39,6 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.jms.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class QueueBrowsingTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(QueueBrowsingTest.class);
|
||||
|
@ -80,11 +86,12 @@ public class QueueBrowsingTest {
|
|||
}
|
||||
|
||||
QueueBrowser browser = session.createBrowser(queue);
|
||||
Enumeration enumeration = browser.getEnumeration();
|
||||
Enumeration<?> enumeration = browser.getEnumeration();
|
||||
int received = 0;
|
||||
while (enumeration.hasMoreElements()) {
|
||||
Message m = (Message) enumeration.nextElement();
|
||||
received++;
|
||||
LOG.info("Browsed message " + received + ": " + m.getJMSMessageID());
|
||||
}
|
||||
|
||||
browser.close();
|
||||
|
@ -117,11 +124,12 @@ public class QueueBrowsingTest {
|
|||
public void run() {
|
||||
try {
|
||||
QueueBrowser browser = session.createBrowser(queue);
|
||||
Enumeration enumeration = browser.getEnumeration();
|
||||
Enumeration<?> enumeration = browser.getEnumeration();
|
||||
int received = 0;
|
||||
while (enumeration.hasMoreElements()) {
|
||||
Message m = (Message) enumeration.nextElement();
|
||||
received++;
|
||||
LOG.info("Browsed message " + received + ": " + m.getJMSMessageID());
|
||||
}
|
||||
assertEquals("Browsed all messages", messageToSend, received);
|
||||
} catch (Exception e) {
|
||||
|
@ -139,7 +147,7 @@ public class QueueBrowsingTest {
|
|||
MessageConsumer consumer = session.createConsumer(queue);
|
||||
int received = 0;
|
||||
while (true) {
|
||||
Message m = (Message) consumer.receive(1000);
|
||||
Message m = consumer.receive(1000);
|
||||
if (m == null)
|
||||
break;
|
||||
received++;
|
||||
|
@ -155,7 +163,6 @@ public class QueueBrowsingTest {
|
|||
|
||||
browserThread.join();
|
||||
consumerThread.join();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -180,7 +187,7 @@ public class QueueBrowsingTest {
|
|||
}
|
||||
|
||||
QueueBrowser browser = session.createBrowser(queue);
|
||||
Enumeration enumeration = browser.getEnumeration();
|
||||
Enumeration<?> enumeration = browser.getEnumeration();
|
||||
int received = 0;
|
||||
while (enumeration.hasMoreElements()) {
|
||||
Message m = (Message) enumeration.nextElement();
|
||||
|
@ -189,10 +196,6 @@ public class QueueBrowsingTest {
|
|||
}
|
||||
|
||||
browser.close();
|
||||
|
||||
assertEquals(3, received);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@ import java.net.URLStreamHandler;
|
|||
import java.net.URLStreamHandlerFactory;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.ActiveMQSession;
|
||||
|
@ -56,7 +58,7 @@ public class RequestReplyNoAdvisoryNetworkTest extends JmsMultipleBrokersTestSup
|
|||
ActiveMQQueue sendQ = new ActiveMQQueue("sendQ");
|
||||
static final String connectionIdMarker = "ID:marker.";
|
||||
ActiveMQTempQueue replyQWildcard = new ActiveMQTempQueue(connectionIdMarker + ">");
|
||||
private long receiveTimeout = 30000;
|
||||
private final long receiveTimeout = 30000;
|
||||
|
||||
public void testNonAdvisoryNetworkRequestReplyXmlConfig() throws Exception {
|
||||
final String xmlConfigString = new String(
|
||||
|
@ -197,9 +199,9 @@ public class RequestReplyNoAdvisoryNetworkTest extends JmsMultipleBrokersTestSup
|
|||
assertTrue("all temps are gone on " + regionBroker.getBrokerName(), Wait.waitFor(new Wait.Condition(){
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
Map tempTopics = regionBroker.getTempTopicRegion().getDestinationMap();
|
||||
Map<?,?> tempTopics = regionBroker.getTempTopicRegion().getDestinationMap();
|
||||
LOG.info("temp topics on " + regionBroker.getBrokerName() + ", " + tempTopics);
|
||||
Map tempQ = regionBroker.getTempQueueRegion().getDestinationMap();
|
||||
Map<?,?> tempQ = regionBroker.getTempQueueRegion().getDestinationMap();
|
||||
LOG.info("temp queues on " + regionBroker.getBrokerName() + ", " + tempQ);
|
||||
return tempQ.isEmpty() && tempTopics.isEmpty();
|
||||
}
|
||||
|
@ -236,6 +238,7 @@ public class RequestReplyNoAdvisoryNetworkTest extends JmsMultipleBrokersTestSup
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
for (BrokerService broker: brokers) {
|
||||
broker.stop();
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.apache.activemq.usecases;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -25,6 +27,7 @@ import java.util.concurrent.ArrayBlockingQueue;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
|
@ -33,6 +36,7 @@ import javax.jms.MessageConsumer;
|
|||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQSession;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -43,9 +47,6 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
||||
protected static final int CONCURRENT_CLIENT_COUNT = 5;
|
||||
protected static final int CONCURRENT_SERVER_COUNT = 5;
|
||||
|
@ -60,7 +61,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
protected boolean testError = false;
|
||||
protected boolean fatalTestError = false;
|
||||
|
||||
protected int echoResponseFill = 0; // Number of "filler" response messages per request
|
||||
protected int echoResponseFill = 0; // Number of "filler" response messages per request
|
||||
|
||||
protected static Log LOG;
|
||||
public boolean duplex = true;
|
||||
|
@ -69,8 +70,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
LOG = LogFactory.getLog(RequestReplyToTopicViaThreeNetworkHopsTest.class);
|
||||
}
|
||||
|
||||
public RequestReplyToTopicViaThreeNetworkHopsTest()
|
||||
throws Exception {
|
||||
public RequestReplyToTopicViaThreeNetworkHopsTest() throws Exception {
|
||||
edge1 = new EmbeddedTcpBroker("edge", 1);
|
||||
edge2 = new EmbeddedTcpBroker("edge", 2);
|
||||
core1 = new EmbeddedTcpBroker("core", 1);
|
||||
|
@ -80,7 +80,6 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
edge1.coreConnectTo(core1, duplex);
|
||||
edge2.coreConnectTo(core2, duplex);
|
||||
core1.coreConnectTo(core2, duplex);
|
||||
|
||||
}
|
||||
|
||||
public void logMessage(String msg) {
|
||||
|
@ -88,8 +87,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
System.out.flush();
|
||||
}
|
||||
|
||||
public void testMessages(Session sess, MessageProducer req_prod, Destination resp_dest, int num_msg)
|
||||
throws Exception {
|
||||
public void testMessages(Session sess, MessageProducer req_prod, Destination resp_dest, int num_msg) throws Exception {
|
||||
MessageConsumer resp_cons;
|
||||
TextMessage msg;
|
||||
MessageClient cons_client;
|
||||
|
@ -130,7 +128,6 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
else
|
||||
LOG.debug("Consumer client shutdown incomplete!!!");
|
||||
|
||||
|
||||
//
|
||||
// Check that the correct number of messages was received.
|
||||
//
|
||||
|
@ -144,15 +141,13 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
if (cons_client.getNumMsgReceived() == 0)
|
||||
fatalTestError = true;
|
||||
|
||||
LOG.error("Have " + cons_client.getNumMsgReceived() + " messages; expected " + tot_expected +
|
||||
" on destination " + resp_dest);
|
||||
LOG.error("Have " + cons_client.getNumMsgReceived() + " messages; expected " + tot_expected + " on destination " + resp_dest);
|
||||
}
|
||||
|
||||
resp_cons.close();
|
||||
}
|
||||
|
||||
protected void sendWithRetryOnDeletedDest(MessageProducer prod, Message msg)
|
||||
throws JMSException {
|
||||
protected void sendWithRetryOnDeletedDest(MessageProducer prod, Message msg) throws JMSException {
|
||||
try {
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("SENDING REQUEST message " + msg);
|
||||
|
@ -167,12 +162,10 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
/**
|
||||
* Test one destination between the given "producer broker" and "consumer broker" specified.
|
||||
*/
|
||||
public void testOneDest(Connection conn, Session sess, Destination cons_dest, int num_msg)
|
||||
throws Exception {
|
||||
public void testOneDest(Connection conn, Session sess, Destination cons_dest, int num_msg) throws Exception {
|
||||
Destination prod_dest;
|
||||
MessageProducer msg_prod;
|
||||
|
||||
|
||||
//
|
||||
// Create the Producer to the echo request Queue
|
||||
//
|
||||
|
@ -180,7 +173,6 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
prod_dest = sess.createQueue("echo");
|
||||
msg_prod = sess.createProducer(prod_dest);
|
||||
|
||||
|
||||
//
|
||||
// Pass messages around.
|
||||
//
|
||||
|
@ -189,57 +181,45 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
msg_prod.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TEST TEMPORARY TOPICS
|
||||
*/
|
||||
public void testTempTopic(String prod_broker_url, String cons_broker_url)
|
||||
throws Exception {
|
||||
public void testTempTopic(String prod_broker_url, String cons_broker_url) throws Exception {
|
||||
Connection conn;
|
||||
Session sess;
|
||||
Destination cons_dest;
|
||||
int echo_id;
|
||||
int num_msg;
|
||||
|
||||
num_msg = 5;
|
||||
|
||||
LOG.debug("TESTING TEMP TOPICS " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg +
|
||||
" messages)");
|
||||
|
||||
LOG.debug("TESTING TEMP TOPICS " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg + " messages)");
|
||||
|
||||
//
|
||||
// Connect to the bus.
|
||||
//
|
||||
|
||||
conn = createConnection(cons_broker_url);
|
||||
conn.start();
|
||||
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
|
||||
//
|
||||
// Create the destination on which messages are being tested.
|
||||
//
|
||||
|
||||
LOG.trace("Creating destination");
|
||||
cons_dest = sess.createTemporaryTopic();
|
||||
|
||||
testOneDest(conn, sess, cons_dest, num_msg);
|
||||
|
||||
|
||||
//
|
||||
// Cleanup
|
||||
//
|
||||
|
||||
sess.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TEST TOPICS
|
||||
*/
|
||||
public void testTopic(String prod_broker_url, String cons_broker_url)
|
||||
throws Exception {
|
||||
public void testTopic(String prod_broker_url, String cons_broker_url) throws Exception {
|
||||
int num_msg;
|
||||
|
||||
Connection conn;
|
||||
|
@ -250,19 +230,15 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
num_msg = 5;
|
||||
|
||||
LOG.info("TESTING TOPICS " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg +
|
||||
" messages)");
|
||||
|
||||
LOG.info("TESTING TOPICS " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg + " messages)");
|
||||
|
||||
conn = createConnection(cons_broker_url);
|
||||
conn.start();
|
||||
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
|
||||
//
|
||||
// Create the destination on which messages are being tested.
|
||||
//
|
||||
|
||||
topic_name = "topotest2.perm.topic";
|
||||
LOG.trace("Removing existing Topic");
|
||||
removeTopic(conn, topic_name);
|
||||
|
@ -271,23 +247,18 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
testOneDest(conn, sess, cons_dest, num_msg);
|
||||
|
||||
|
||||
//
|
||||
// Cleanup
|
||||
//
|
||||
|
||||
removeTopic(conn, topic_name);
|
||||
sess.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TEST TEMPORARY QUEUES
|
||||
*/
|
||||
public void testTempQueue(String prod_broker_url, String cons_broker_url)
|
||||
throws Exception {
|
||||
int echo_id;
|
||||
public void testTempQueue(String prod_broker_url, String cons_broker_url) throws Exception {
|
||||
int num_msg;
|
||||
|
||||
Connection conn;
|
||||
|
@ -297,43 +268,34 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
num_msg = 5;
|
||||
|
||||
LOG.info("TESTING TEMP QUEUES " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg +
|
||||
" messages)");
|
||||
|
||||
LOG.info("TESTING TEMP QUEUES " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg + " messages)");
|
||||
|
||||
//
|
||||
// Connect to the bus.
|
||||
//
|
||||
|
||||
conn = createConnection(cons_broker_url);
|
||||
conn.start();
|
||||
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
|
||||
//
|
||||
// Create the destination on which messages are being tested.
|
||||
//
|
||||
|
||||
LOG.trace("Creating destination");
|
||||
cons_dest = sess.createTemporaryQueue();
|
||||
|
||||
testOneDest(conn, sess, cons_dest, num_msg);
|
||||
|
||||
|
||||
//
|
||||
// Cleanup
|
||||
//
|
||||
|
||||
sess.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TEST QUEUES
|
||||
*/
|
||||
public void testQueue(String prod_broker_url, String cons_broker_url)
|
||||
throws Exception {
|
||||
public void testQueue(String prod_broker_url, String cons_broker_url) throws Exception {
|
||||
int num_msg;
|
||||
|
||||
Connection conn;
|
||||
|
@ -344,15 +306,12 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
num_msg = 5;
|
||||
|
||||
LOG.info("TESTING QUEUES " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg +
|
||||
" messages)");
|
||||
|
||||
LOG.info("TESTING QUEUES " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg + " messages)");
|
||||
|
||||
conn = createConnection(cons_broker_url);
|
||||
conn.start();
|
||||
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
|
||||
//
|
||||
// Create the destination on which messages are being tested.
|
||||
//
|
||||
|
@ -364,15 +323,13 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
testOneDest(conn, sess, cons_dest, num_msg);
|
||||
|
||||
|
||||
removeQueue(conn, queue_name);
|
||||
sess.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithTempTopicReplyTo()
|
||||
throws Exception {
|
||||
public void runWithTempTopicReplyTo() throws Exception {
|
||||
EchoService echo_svc;
|
||||
TopicTrafficGenerator traffic_gen;
|
||||
Thread start1;
|
||||
|
@ -390,16 +347,15 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
// Execute up to 20 clients at a time to simulate that load.
|
||||
//
|
||||
|
||||
clientExecPool = new ThreadPoolExecutor(CONCURRENT_CLIENT_COUNT, CONCURRENT_CLIENT_COUNT,
|
||||
0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10000));
|
||||
clientExecPool = new ThreadPoolExecutor(CONCURRENT_CLIENT_COUNT, CONCURRENT_CLIENT_COUNT, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10000));
|
||||
clientCompletionLatch = new CountDownLatch(TOTAL_CLIENT_ITER);
|
||||
|
||||
|
||||
// Use threads to avoid startup deadlock since the first broker started waits until
|
||||
// it knows the name of the remote broker before finishing its startup, which means
|
||||
// the remote must already be running.
|
||||
// it knows the name of the remote broker before finishing its startup, which means
|
||||
// the remote must already be running.
|
||||
|
||||
start1 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
edge1.start();
|
||||
|
@ -410,6 +366,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
};
|
||||
|
||||
start2 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
edge2.start();
|
||||
|
@ -420,6 +377,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
};
|
||||
|
||||
start3 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
core1.start();
|
||||
|
@ -430,6 +388,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
};
|
||||
|
||||
start4 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
core2.start();
|
||||
|
@ -452,14 +411,12 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
traffic_gen = new TopicTrafficGenerator(edge1.getConnectionUrl(), edge2.getConnectionUrl());
|
||||
traffic_gen.start();
|
||||
|
||||
|
||||
//
|
||||
// Now start the echo service with that queue.
|
||||
//
|
||||
echo_svc = new EchoService("echo", edge1.getConnectionUrl());
|
||||
echo_svc.start();
|
||||
|
||||
|
||||
//
|
||||
// Run the tests on Temp Topics.
|
||||
//
|
||||
|
@ -468,10 +425,10 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
iter = 0;
|
||||
while ((iter < TOTAL_CLIENT_ITER) && (!fatalTestError)) {
|
||||
clientExecPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
RequestReplyToTopicViaThreeNetworkHopsTest.this.testTempTopic(edge1.getConnectionUrl(),
|
||||
edge2.getConnectionUrl());
|
||||
RequestReplyToTopicViaThreeNetworkHopsTest.this.testTempTopic(edge1.getConnectionUrl(), edge2.getConnectionUrl());
|
||||
} catch (Exception exc) {
|
||||
LOG.error("test exception", exc);
|
||||
fatalTestError = true;
|
||||
|
@ -487,7 +444,8 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
boolean allDoneOnTime = clientCompletionLatch.await(20, TimeUnit.MINUTES);
|
||||
|
||||
LOG.info("** FINISHED TEMP TOPIC TESTS AFTER " + iter + " ITERATIONS, testError:" + testError + ", fatal: " + fatalTestError + ", onTime:" + allDoneOnTime);
|
||||
LOG.info("** FINISHED TEMP TOPIC TESTS AFTER " + iter + " ITERATIONS, testError:" + testError + ", fatal: " + fatalTestError + ", onTime:"
|
||||
+ allDoneOnTime);
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
|
@ -500,46 +458,39 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
assertTrue("no errors", !testError);
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
throws Exception {
|
||||
public void shutdown() throws Exception {
|
||||
edge1.stop();
|
||||
edge2.stop();
|
||||
core1.stop();
|
||||
core2.stop();
|
||||
}
|
||||
|
||||
protected Connection createConnection(String url)
|
||||
throws Exception {
|
||||
protected Connection createConnection(String url) throws Exception {
|
||||
return org.apache.activemq.ActiveMQConnection.makeConnection(url);
|
||||
}
|
||||
|
||||
protected static void removeQueue(Connection conn, String dest_name)
|
||||
throws java.lang.Exception {
|
||||
protected static void removeQueue(Connection conn, String dest_name) throws java.lang.Exception {
|
||||
org.apache.activemq.command.ActiveMQDestination dest;
|
||||
|
||||
if (conn instanceof org.apache.activemq.ActiveMQConnection) {
|
||||
dest = org.apache.activemq.command.ActiveMQDestination.
|
||||
createDestination(dest_name, (byte) org.apache.activemq.command.ActiveMQDestination.QUEUE_TYPE);
|
||||
dest = org.apache.activemq.command.ActiveMQDestination.createDestination(dest_name, org.apache.activemq.command.ActiveMQDestination.QUEUE_TYPE);
|
||||
((org.apache.activemq.ActiveMQConnection) conn).destroyDestination(dest);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void removeTopic(Connection conn, String dest_name)
|
||||
throws java.lang.Exception {
|
||||
protected static void removeTopic(Connection conn, String dest_name) throws java.lang.Exception {
|
||||
org.apache.activemq.command.ActiveMQDestination dest;
|
||||
|
||||
if (conn instanceof org.apache.activemq.ActiveMQConnection) {
|
||||
dest = org.apache.activemq.command.ActiveMQDestination.
|
||||
createDestination(dest_name, (byte) org.apache.activemq.command.ActiveMQDestination.TOPIC_TYPE);
|
||||
dest = org.apache.activemq.command.ActiveMQDestination.createDestination(dest_name, org.apache.activemq.command.ActiveMQDestination.TOPIC_TYPE);
|
||||
((org.apache.activemq.ActiveMQConnection) conn).destroyDestination(dest);
|
||||
}
|
||||
}
|
||||
|
||||
public static String fmtMsgInfo(Message msg)
|
||||
throws Exception {
|
||||
public static String fmtMsgInfo(Message msg) throws Exception {
|
||||
StringBuilder msg_desc;
|
||||
String prop;
|
||||
Enumeration prop_enum;
|
||||
Enumeration<?> prop_enum;
|
||||
|
||||
msg_desc = new StringBuilder();
|
||||
msg_desc = new StringBuilder();
|
||||
|
@ -573,8 +524,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
protected String tcpUrl;
|
||||
protected String fullUrl;
|
||||
|
||||
public EmbeddedTcpBroker(String name, int number)
|
||||
throws Exception {
|
||||
public EmbeddedTcpBroker(String name, int number) throws Exception {
|
||||
brokerSvc = new BrokerService();
|
||||
|
||||
synchronized (this.getClass()) {
|
||||
|
@ -599,8 +549,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
brokerSvc.addConnector(tcpUrl);
|
||||
}
|
||||
|
||||
public Connection createConnection()
|
||||
throws URISyntaxException, JMSException {
|
||||
public Connection createConnection() throws URISyntaxException, JMSException {
|
||||
Connection result;
|
||||
|
||||
result = org.apache.activemq.ActiveMQConnection.makeConnection(this.fullUrl);
|
||||
|
@ -612,9 +561,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
return this.fullUrl;
|
||||
}
|
||||
|
||||
|
||||
public void coreConnectTo(EmbeddedTcpBroker other, boolean duplex_f)
|
||||
throws Exception {
|
||||
public void coreConnectTo(EmbeddedTcpBroker other, boolean duplex_f) throws Exception {
|
||||
this.makeConnectionTo(other, duplex_f, true);
|
||||
this.makeConnectionTo(other, duplex_f, false);
|
||||
if (!duplex_f) {
|
||||
|
@ -623,24 +570,20 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void start()
|
||||
throws Exception {
|
||||
public void start() throws Exception {
|
||||
brokerSvc.start();
|
||||
brokerSvc.waitUntilStarted();
|
||||
}
|
||||
|
||||
public void stop()
|
||||
throws Exception {
|
||||
public void stop() throws Exception {
|
||||
brokerSvc.stop();
|
||||
}
|
||||
|
||||
|
||||
protected void makeConnectionTo(EmbeddedTcpBroker other, boolean duplex_f, boolean queue_f)
|
||||
throws Exception {
|
||||
protected void makeConnectionTo(EmbeddedTcpBroker other, boolean duplex_f, boolean queue_f) throws Exception {
|
||||
NetworkConnector nw_conn;
|
||||
String prefix;
|
||||
ActiveMQDestination excl_dest;
|
||||
ArrayList excludes;
|
||||
ArrayList<ActiveMQDestination> excludes;
|
||||
|
||||
nw_conn = new DiscoveryNetworkConnector(new URI("static:(" + other.tcpUrl + ")"));
|
||||
nw_conn.setDuplex(duplex_f);
|
||||
|
@ -663,7 +606,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
excl_dest = ActiveMQDestination.createDestination(">", ActiveMQDestination.QUEUE_TYPE);
|
||||
}
|
||||
|
||||
excludes = new ArrayList();
|
||||
excludes = new ArrayList<ActiveMQDestination>();
|
||||
excludes.add(excl_dest);
|
||||
nw_conn.setExcludedDestinations(excludes);
|
||||
|
||||
|
@ -691,6 +634,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
shutdownLatch = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
CountDownLatch latch;
|
||||
|
||||
|
@ -748,8 +692,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
return msgCount;
|
||||
}
|
||||
|
||||
protected void processMessages()
|
||||
throws Exception {
|
||||
protected void processMessages() throws Exception {
|
||||
Message in_msg;
|
||||
|
||||
haveFirstSeq = false;
|
||||
|
@ -770,8 +713,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
msgCons.close();
|
||||
}
|
||||
|
||||
protected void checkMessage(Message in_msg)
|
||||
throws Exception {
|
||||
protected void checkMessage(Message in_msg) throws Exception {
|
||||
int seq;
|
||||
|
||||
LOG.debug("received message " + fmtMsgInfo(in_msg) + " from " + in_msg.getJMSDestination());
|
||||
|
@ -784,9 +726,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
seq = in_msg.getIntProperty("SEQ");
|
||||
|
||||
if ((haveFirstSeq) && (seq != (lastSeq + 1))) {
|
||||
LOG.error("***ERROR*** incorrect sequence number; expected " +
|
||||
Integer.toString(lastSeq + 1) + " but have " +
|
||||
Integer.toString(seq));
|
||||
LOG.error("***ERROR*** incorrect sequence number; expected " + Integer.toString(lastSeq + 1) + " but have " + Integer.toString(seq));
|
||||
|
||||
testError = true;
|
||||
}
|
||||
|
@ -794,8 +734,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
lastSeq = seq;
|
||||
|
||||
if (msgCount > expectedCount) {
|
||||
LOG.error("*** have more messages than expected; have " + msgCount +
|
||||
"; expect " + expectedCount);
|
||||
LOG.error("*** have more messages than expected; have " + msgCount + "; expect " + expectedCount);
|
||||
|
||||
testError = true;
|
||||
}
|
||||
|
@ -823,8 +762,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
protected ThreadPoolExecutor processorPool;
|
||||
|
||||
public EchoService(String dest, Connection broker_conn)
|
||||
throws Exception {
|
||||
public EchoService(String dest, Connection broker_conn) throws Exception {
|
||||
destName = dest;
|
||||
jmsConn = broker_conn;
|
||||
|
||||
|
@ -838,16 +776,15 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
waitShutdown = new CountDownLatch(1);
|
||||
|
||||
processorPool = new ThreadPoolExecutor(CONCURRENT_SERVER_COUNT, CONCURRENT_SERVER_COUNT,
|
||||
0, TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<Runnable>(10000));
|
||||
processorPool = new ThreadPoolExecutor(CONCURRENT_SERVER_COUNT, CONCURRENT_SERVER_COUNT, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(
|
||||
10000));
|
||||
}
|
||||
|
||||
public EchoService(String dest, String broker_url)
|
||||
throws Exception {
|
||||
public EchoService(String dest, String broker_url) throws Exception {
|
||||
this(dest, ActiveMQConnection.makeConnection(broker_url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Message req;
|
||||
|
||||
|
@ -877,7 +814,6 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shut down the service, waiting up to 3 seconds for the service to terminate.
|
||||
*/
|
||||
|
@ -916,8 +852,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
|
||||
protected Message request;
|
||||
|
||||
public EchoRequestProcessor(Session sess, Message req)
|
||||
throws Exception {
|
||||
public EchoRequestProcessor(Session sess, Message req) throws Exception {
|
||||
this.session = sess;
|
||||
this.request = req;
|
||||
|
||||
|
@ -930,6 +865,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
this.msg_prod = session.createProducer(this.resp_dest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
this.processRequest(this.request);
|
||||
|
@ -941,8 +877,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
/**
|
||||
* Process one request for the Echo Service.
|
||||
*/
|
||||
protected void processRequest(Message req)
|
||||
throws Exception {
|
||||
protected void processRequest(Message req) throws Exception {
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("ECHO request message " + req.toString());
|
||||
|
||||
|
@ -975,8 +910,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
protected boolean Shutdown_ind;
|
||||
protected int send_count;
|
||||
|
||||
public TopicTrafficGenerator(String url1, String url2)
|
||||
throws Exception {
|
||||
public TopicTrafficGenerator(String url1, String url2) throws Exception {
|
||||
conn1 = createConnection(url1);
|
||||
conn2 = createConnection(url2);
|
||||
|
||||
|
@ -997,6 +931,7 @@ public class RequestReplyToTopicViaThreeNetworkHopsTest {
|
|||
Shutdown_ind = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Message msg;
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
|
||||
import org.apache.activemq.JmsMultipleBrokersTestSupport;
|
||||
|
@ -29,9 +28,6 @@ import org.apache.activemq.broker.region.DestinationInterceptor;
|
|||
import org.apache.activemq.broker.region.virtual.VirtualDestination;
|
||||
import org.apache.activemq.broker.region.virtual.VirtualDestinationInterceptor;
|
||||
import org.apache.activemq.broker.region.virtual.VirtualTopic;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.network.NetworkConnector;
|
||||
import org.apache.activemq.store.kahadb.KahaDBStore;
|
||||
import org.apache.activemq.util.MessageIdList;
|
||||
|
||||
|
@ -100,6 +96,7 @@ public class SingleBrokerVirtualDestinationsWithWildcardTest extends JmsMultiple
|
|||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
|
|
|
@ -36,139 +36,136 @@ import org.apache.activemq.broker.BrokerFactory;
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
|
||||
public class TestBrokerConnectionDuplexExcludedDestinations extends TestCase {
|
||||
|
||||
BrokerService receiverBroker;
|
||||
BrokerService senderBroker;
|
||||
|
||||
Connection hubConnection;
|
||||
Session hubSession;
|
||||
|
||||
Connection spokeConnection;
|
||||
Session spokeSession;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
// Hub broker
|
||||
String configFileName = "org/apache/activemq/usecases/receiver-duplex.xml";
|
||||
URI uri = new URI("xbean:" + configFileName);
|
||||
receiverBroker = BrokerFactory.createBroker(uri);
|
||||
receiverBroker.setPersistent(false);
|
||||
receiverBroker.setBrokerName("Hub");
|
||||
|
||||
// Spoke broker
|
||||
configFileName = "org/apache/activemq/usecases/sender-duplex.xml";
|
||||
uri = new URI("xbean:" + configFileName);
|
||||
senderBroker = BrokerFactory.createBroker(uri);
|
||||
senderBroker.setPersistent(false);
|
||||
senderBroker.setBrokerName("Spoke");
|
||||
BrokerService receiverBroker;
|
||||
BrokerService senderBroker;
|
||||
|
||||
// Start both Hub and Spoke broker
|
||||
receiverBroker.start();
|
||||
senderBroker.start();
|
||||
|
||||
// create hub session
|
||||
ConnectionFactory cfHub = new ActiveMQConnectionFactory("tcp://localhost:62002");
|
||||
Connection hubConnection;
|
||||
Session hubSession;
|
||||
|
||||
hubConnection = cfHub.createConnection();
|
||||
hubConnection.start();
|
||||
hubSession = hubConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Connection spokeConnection;
|
||||
Session spokeSession;
|
||||
|
||||
// create spoke session
|
||||
ConnectionFactory cfSpoke = new ActiveMQConnectionFactory("tcp://localhost:62001");
|
||||
spokeConnection = cfSpoke.createConnection();
|
||||
spokeConnection.start();
|
||||
spokeSession = spokeConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
hubSession.close();
|
||||
hubConnection.stop();
|
||||
hubConnection.close();
|
||||
|
||||
spokeSession.close();
|
||||
spokeConnection.stop();
|
||||
spokeConnection.close();
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
// Hub broker
|
||||
String configFileName = "org/apache/activemq/usecases/receiver-duplex.xml";
|
||||
URI uri = new URI("xbean:" + configFileName);
|
||||
receiverBroker = BrokerFactory.createBroker(uri);
|
||||
receiverBroker.setPersistent(false);
|
||||
receiverBroker.setBrokerName("Hub");
|
||||
|
||||
senderBroker.stop();
|
||||
receiverBroker.stop();
|
||||
}
|
||||
// Spoke broker
|
||||
configFileName = "org/apache/activemq/usecases/sender-duplex.xml";
|
||||
uri = new URI("xbean:" + configFileName);
|
||||
senderBroker = BrokerFactory.createBroker(uri);
|
||||
senderBroker.setPersistent(false);
|
||||
senderBroker.setBrokerName("Spoke");
|
||||
|
||||
public void testDuplexSendFromHubToSpoke()
|
||||
throws Exception {
|
||||
// Start both Hub and Spoke broker
|
||||
receiverBroker.start();
|
||||
senderBroker.start();
|
||||
|
||||
//create hub producer
|
||||
MessageProducer hubProducer = hubSession.createProducer(null);
|
||||
hubProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||
hubProducer.setDisableMessageID(true);
|
||||
hubProducer.setDisableMessageTimestamp(true);
|
||||
// create hub session
|
||||
ConnectionFactory cfHub = new ActiveMQConnectionFactory("tcp://localhost:62002");
|
||||
|
||||
//create spoke producer
|
||||
MessageProducer spokeProducer = hubSession.createProducer(null);
|
||||
spokeProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||
spokeProducer.setDisableMessageID(true);
|
||||
spokeProducer.setDisableMessageTimestamp(true);
|
||||
hubConnection = cfHub.createConnection();
|
||||
hubConnection.start();
|
||||
hubSession = hubConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
Queue excludedQueueHub = hubSession.createQueue("exclude.test.foo");
|
||||
TextMessage excludedMsgHub = hubSession.createTextMessage();
|
||||
excludedMsgHub.setText(excludedQueueHub.toString());
|
||||
|
||||
Queue includedQueueHub = hubSession.createQueue("include.test.foo");
|
||||
// create spoke session
|
||||
ConnectionFactory cfSpoke = new ActiveMQConnectionFactory("tcp://localhost:62001");
|
||||
spokeConnection = cfSpoke.createConnection();
|
||||
spokeConnection.start();
|
||||
spokeSession = spokeConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
}
|
||||
|
||||
TextMessage includedMsgHub = hubSession.createTextMessage();
|
||||
includedMsgHub.setText(includedQueueHub.toString());
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
hubSession.close();
|
||||
hubConnection.stop();
|
||||
hubConnection.close();
|
||||
|
||||
Queue alwaysIncludedQueueHub = hubSession.createQueue("always.include.test.foo");
|
||||
spokeSession.close();
|
||||
spokeConnection.stop();
|
||||
spokeConnection.close();
|
||||
|
||||
TextMessage alwaysIncludedMsgHub = hubSession.createTextMessage();
|
||||
alwaysIncludedMsgHub.setText(alwaysIncludedQueueHub.toString());
|
||||
senderBroker.stop();
|
||||
receiverBroker.stop();
|
||||
}
|
||||
|
||||
// Sending from Hub queue
|
||||
hubProducer.send(excludedQueueHub, excludedMsgHub);
|
||||
hubProducer.send(includedQueueHub, includedMsgHub);
|
||||
public void testDuplexSendFromHubToSpoke() throws Exception {
|
||||
|
||||
//create hub producer
|
||||
MessageProducer hubProducer = hubSession.createProducer(null);
|
||||
hubProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||
hubProducer.setDisableMessageID(true);
|
||||
hubProducer.setDisableMessageTimestamp(true);
|
||||
|
||||
//create spoke producer
|
||||
MessageProducer spokeProducer = hubSession.createProducer(null);
|
||||
spokeProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||
spokeProducer.setDisableMessageID(true);
|
||||
spokeProducer.setDisableMessageTimestamp(true);
|
||||
|
||||
Queue excludedQueueHub = hubSession.createQueue("exclude.test.foo");
|
||||
TextMessage excludedMsgHub = hubSession.createTextMessage();
|
||||
excludedMsgHub.setText(excludedQueueHub.toString());
|
||||
|
||||
Queue includedQueueHub = hubSession.createQueue("include.test.foo");
|
||||
|
||||
TextMessage includedMsgHub = hubSession.createTextMessage();
|
||||
includedMsgHub.setText(includedQueueHub.toString());
|
||||
|
||||
Queue alwaysIncludedQueueHub = hubSession.createQueue("always.include.test.foo");
|
||||
|
||||
TextMessage alwaysIncludedMsgHub = hubSession.createTextMessage();
|
||||
alwaysIncludedMsgHub.setText(alwaysIncludedQueueHub.toString());
|
||||
|
||||
// Sending from Hub queue
|
||||
hubProducer.send(excludedQueueHub, excludedMsgHub);
|
||||
hubProducer.send(includedQueueHub, includedMsgHub);
|
||||
hubProducer.send(alwaysIncludedQueueHub, alwaysIncludedMsgHub);
|
||||
|
||||
Queue excludedQueueSpoke = spokeSession.createQueue("exclude.test.foo");
|
||||
MessageConsumer excludedConsumerSpoke = spokeSession.createConsumer(excludedQueueSpoke);
|
||||
|
||||
Queue excludedQueueSpoke = spokeSession.createQueue("exclude.test.foo");
|
||||
MessageConsumer excludedConsumerSpoke = spokeSession.createConsumer(excludedQueueSpoke);
|
||||
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(100);
|
||||
|
||||
Queue includedQueueSpoke = spokeSession.createQueue("include.test.foo");
|
||||
MessageConsumer includedConsumerSpoke = spokeSession.createConsumer(includedQueueSpoke);
|
||||
Queue includedQueueSpoke = spokeSession.createQueue("include.test.foo");
|
||||
MessageConsumer includedConsumerSpoke = spokeSession.createConsumer(includedQueueSpoke);
|
||||
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(100);
|
||||
|
||||
Queue alwaysIncludedQueueSpoke = spokeSession.createQueue("always.include.test.foo");
|
||||
MessageConsumer alwaysIncludedConsumerSpoke = spokeSession.createConsumer(alwaysIncludedQueueHub);
|
||||
Queue alwaysIncludedQueueSpoke = spokeSession.createQueue("always.include.test.foo");
|
||||
MessageConsumer alwaysIncludedConsumerSpoke = spokeSession.createConsumer(alwaysIncludedQueueHub);
|
||||
|
||||
Thread.sleep(100);
|
||||
TextMessage alwaysIncludedMsgSpoke = spokeSession.createTextMessage();
|
||||
alwaysIncludedMsgSpoke.setText(alwaysIncludedQueueSpoke.toString());
|
||||
alwaysIncludedMsgSpoke.setText(alwaysIncludedQueueSpoke.toString());
|
||||
spokeProducer.send(alwaysIncludedQueueSpoke, alwaysIncludedMsgSpoke);
|
||||
|
||||
MessageConsumer alwaysIncludedConsumerHub = spokeSession.createConsumer(alwaysIncludedQueueHub);
|
||||
assertNotNull(alwaysIncludedConsumerHub);
|
||||
|
||||
MessageConsumer alwaysIncludedConsumerHub = spokeSession.createConsumer(alwaysIncludedQueueHub);
|
||||
// Receiving from excluded Spoke queue
|
||||
Message msg = excludedConsumerSpoke.receive(200);
|
||||
assertNull(msg);
|
||||
|
||||
|
||||
// Receiving from excluded Spoke queue
|
||||
Message msg = excludedConsumerSpoke.receive(200);
|
||||
assertNull(msg);
|
||||
|
||||
// Receiving from included Spoke queue
|
||||
msg = includedConsumerSpoke.receive(200);
|
||||
assertEquals(includedMsgHub, msg);
|
||||
// Receiving from included Spoke queue
|
||||
msg = includedConsumerSpoke.receive(200);
|
||||
assertEquals(includedMsgHub, msg);
|
||||
|
||||
// Receiving from included Spoke queue
|
||||
msg = alwaysIncludedConsumerSpoke.receive(200);
|
||||
assertEquals(alwaysIncludedMsgHub, msg);
|
||||
|
||||
// we should be able to receive excluded queue message on Hub
|
||||
MessageConsumer excludedConsumerHub = hubSession.createConsumer(excludedQueueHub);
|
||||
msg = excludedConsumerHub.receive(200);;
|
||||
assertEquals(excludedMsgHub, msg);
|
||||
// Receiving from included Spoke queue
|
||||
msg = alwaysIncludedConsumerSpoke.receive(200);
|
||||
assertEquals(alwaysIncludedMsgHub, msg);
|
||||
|
||||
hubProducer.close();
|
||||
excludedConsumerSpoke.close();
|
||||
// we should be able to receive excluded queue message on Hub
|
||||
MessageConsumer excludedConsumerHub = hubSession.createConsumer(excludedQueueHub);
|
||||
msg = excludedConsumerHub.receive(200);;
|
||||
assertEquals(excludedMsgHub, msg);
|
||||
|
||||
}
|
||||
|
||||
hubProducer.close();
|
||||
excludedConsumerSpoke.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,22 +23,17 @@ import javax.jms.Message;
|
|||
import javax.jms.TextMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQMessage;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Useful base class for unit test cases
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TestSupport extends TestCase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestSupport.class);
|
||||
|
||||
|
||||
protected ActiveMQConnectionFactory connectionFactory;
|
||||
protected boolean topic = true;
|
||||
|
||||
|
|
|
@ -27,20 +27,20 @@ import org.apache.activemq.network.NetworkBridgeConfiguration;
|
|||
import org.apache.activemq.transport.TransportFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ThreeBrokerQueueNetworkUsingTcpTest extends ThreeBrokerQueueNetworkTest {
|
||||
protected List<DemandForwardingBridge> bridges;
|
||||
|
||||
protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
|
||||
List remoteTransports = remoteBroker.getTransportConnectors();
|
||||
List localTransports = localBroker.getTransportConnectors();
|
||||
List<TransportConnector> remoteTransports = remoteBroker.getTransportConnectors();
|
||||
List<TransportConnector> localTransports = localBroker.getTransportConnectors();
|
||||
|
||||
URI remoteURI;
|
||||
URI localURI;
|
||||
if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
|
||||
remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri();
|
||||
localURI = ((TransportConnector)localTransports.get(0)).getConnectUri();
|
||||
remoteURI = remoteTransports.get(0).getConnectUri();
|
||||
localURI = localTransports.get(0).getConnectUri();
|
||||
|
||||
// Ensure that we are connecting using tcp
|
||||
if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
|
||||
|
@ -61,6 +61,7 @@ public class ThreeBrokerQueueNetworkUsingTcpTest extends ThreeBrokerQueueNetwork
|
|||
maxSetupTime = 2000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ public class ThreeBrokerStompTemporaryQueueTest extends JmsMultipleBrokersTestSu
|
|||
private static final Logger LOG = LoggerFactory.getLogger(ThreeBrokerStompTemporaryQueueTest.class);
|
||||
private StompConnection stompConnection;
|
||||
|
||||
@Override
|
||||
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean dynamicOnly, int networkTTL, boolean conduit, boolean failover) throws Exception {
|
||||
List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
|
||||
URI remoteURI;
|
||||
|
@ -108,7 +109,6 @@ public class ThreeBrokerStompTemporaryQueueTest extends JmsMultipleBrokersTestSu
|
|||
advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID");
|
||||
assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
|
||||
|
||||
|
||||
LOG.info("Restarting brokerA");
|
||||
BrokerItem brokerItem = brokers.remove("BrokerA");
|
||||
if (brokerItem != null) {
|
||||
|
@ -133,7 +133,6 @@ public class ThreeBrokerStompTemporaryQueueTest extends JmsMultipleBrokersTestSu
|
|||
assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
|
||||
advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID");
|
||||
assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
|
||||
|
||||
}
|
||||
|
||||
private int countTopicsByName(String broker, String name)
|
||||
|
@ -147,11 +146,12 @@ public class ThreeBrokerStompTemporaryQueueTest extends JmsMultipleBrokersTestSu
|
|||
return advisoryTopicsForTempQueues;
|
||||
}
|
||||
|
||||
|
||||
private void bridgeAndConfigureBrokers(String local, String remote) throws Exception {
|
||||
NetworkConnector bridge = bridgeBrokers(local, remote);
|
||||
assertNotNull(bridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
|
@ -159,14 +159,11 @@ public class ThreeBrokerStompTemporaryQueueTest extends JmsMultipleBrokersTestSu
|
|||
createAndConfigureBroker(new URI("broker:(tcp://localhost:61616,stomp://localhost:61613)/BrokerA" + options));
|
||||
createAndConfigureBroker(new URI("broker:(tcp://localhost:61617,stomp://localhost:61614)/BrokerB" + options));
|
||||
createAndConfigureBroker(new URI("broker:(tcp://localhost:61618,stomp://localhost:61615)/BrokerC" + options));
|
||||
|
||||
}
|
||||
|
||||
private BrokerService createAndConfigureBroker(URI uri) throws Exception {
|
||||
BrokerService broker = createBroker(uri);
|
||||
|
||||
configurePersistenceAdapter(broker);
|
||||
|
||||
return broker;
|
||||
}
|
||||
|
||||
|
@ -176,5 +173,4 @@ public class ThreeBrokerStompTemporaryQueueTest extends JmsMultipleBrokersTestSu
|
|||
kaha.setDirectory(dataFileDir);
|
||||
broker.setPersistenceAdapter(kaha);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.activemq.JmsMultipleBrokersTestSupport;
|
|||
import org.apache.activemq.network.NetworkConnector;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ThreeBrokerTempQueueNetworkTest extends JmsMultipleBrokersTestSupport {
|
||||
protected static final int MESSAGE_COUNT = 100;
|
||||
|
@ -41,20 +41,20 @@ public class ThreeBrokerTempQueueNetworkTest extends JmsMultipleBrokersTestSuppo
|
|||
bridgeBrokers("BrokerA", "BrokerB", false, 2);
|
||||
bridgeBrokers("BrokerB", "BrokerC", false, 2);
|
||||
startAllBrokers();
|
||||
BrokerItem brokerItem = (BrokerItem)brokers.get("BrokerC");
|
||||
BrokerItem brokerItem = brokers.get("BrokerC");
|
||||
Connection conn = brokerItem.createConnection();
|
||||
conn.start();
|
||||
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
TemporaryQueue tempQ = sess.createTemporaryQueue();
|
||||
Thread.sleep(5000);
|
||||
for (Iterator i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = (BrokerItem)i.next();
|
||||
for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = i.next();
|
||||
assertEquals("No queues on broker " + bi.broker.getBrokerName(), 1, bi.broker.getAdminView().getTemporaryQueues().length);
|
||||
}
|
||||
tempQ.delete();
|
||||
Thread.sleep(2000);
|
||||
for (Iterator i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = (BrokerItem)i.next();
|
||||
for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = i.next();
|
||||
assertEquals("Temp queue left behind on broker " + bi.broker.getBrokerName(), 0, bi.broker.getAdminView().getTemporaryQueues().length);
|
||||
}
|
||||
}
|
||||
|
@ -65,26 +65,26 @@ public class ThreeBrokerTempQueueNetworkTest extends JmsMultipleBrokersTestSuppo
|
|||
bridgeBrokers("BrokerA", "BrokerB", false, 3);
|
||||
bridgeBrokers("BrokerB", "BrokerC", false, 3);
|
||||
startAllBrokers();
|
||||
BrokerItem brokerItem = (BrokerItem)brokers.get("BrokerC");
|
||||
BrokerItem brokerItem = brokers.get("BrokerC");
|
||||
Connection conn = brokerItem.createConnection();
|
||||
conn.start();
|
||||
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
TemporaryQueue tempQ = sess.createTemporaryQueue();
|
||||
Thread.sleep(5000);
|
||||
for (Iterator i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = (BrokerItem)i.next();
|
||||
for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = i.next();
|
||||
assertEquals("No queues on broker " + bi.broker.getBrokerName(), 1, bi.broker.getAdminView().getTemporaryQueues().length);
|
||||
}
|
||||
createBroker(new URI("broker:(tcp://localhost:61619)/BrokerD?persistent=false&useJmx=true"));
|
||||
bridgeBrokers("BrokerD", "BrokerA", false, 3);
|
||||
BrokerItem newBroker = (BrokerItem)brokers.get("BrokerD");
|
||||
BrokerItem newBroker = brokers.get("BrokerD");
|
||||
newBroker.broker.start();
|
||||
Thread.sleep(1000);
|
||||
assertEquals("No queues on broker D", 1, newBroker.broker.getAdminView().getTemporaryQueues().length);
|
||||
tempQ.delete();
|
||||
Thread.sleep(2000);
|
||||
for (Iterator i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = (BrokerItem)i.next();
|
||||
for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext();) {
|
||||
BrokerItem bi = i.next();
|
||||
assertEquals("Temp queue left behind on broker " + bi.broker.getBrokerName(), 0, bi.broker.getAdminView().getTemporaryQueues().length);
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,7 @@ public class ThreeBrokerTempQueueNetworkTest extends JmsMultipleBrokersTestSuppo
|
|||
fail("Test should have failed since temp queues are disabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
|
|
|
@ -28,14 +28,13 @@ import javax.jms.Topic;
|
|||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.JmsMultipleBrokersTestSupport;
|
||||
import org.apache.activemq.JmsMultipleBrokersTestSupport.BrokerItem;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||
import org.apache.activemq.util.MessageIdList;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
||||
protected static final int MESSAGE_COUNT = 100;
|
||||
|
@ -79,11 +78,11 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
assertEquals(MESSAGE_COUNT * 2, msgsB.getMessageCount());
|
||||
assertEquals(MESSAGE_COUNT * 2, msgsC.getMessageCount());
|
||||
}
|
||||
|
||||
|
||||
public void initCombosForTestABandBCbrokerNetworkWithSelectors() {
|
||||
addCombinationValues("dynamicOnly", new Object[] {true, false});
|
||||
addCombinationValues("dynamicOnly", new Object[] {true, false});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BrokerA -> BrokerB -> BrokerC
|
||||
*/
|
||||
|
@ -185,7 +184,7 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
|
||||
// let consumers propogate around the network
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
// Send messages
|
||||
sendMessages("BrokerA", dest, MESSAGE_COUNT);
|
||||
sendMessages("BrokerB", dest, MESSAGE_COUNT);
|
||||
|
@ -249,7 +248,7 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
}
|
||||
|
||||
public void testAllConnectedBrokerNetworkSingleProducerTTL() throws Exception {
|
||||
|
||||
|
||||
// duplicates are expected with ttl of 2 as each broker is connected to the next
|
||||
// but the dups are suppressed by the store and now also by the topic sub when enableAudit
|
||||
// default (true) is present in a matching destination policy entry
|
||||
|
@ -287,7 +286,7 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
|
||||
// Send messages
|
||||
sendMessages("BrokerA", dest, 1);
|
||||
|
||||
|
||||
// Get message count
|
||||
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
|
||||
MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
|
||||
|
@ -299,7 +298,7 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
|
||||
// ensure we don't get any more messages
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
assertEquals(1, msgsA.getMessageCount());
|
||||
assertEquals(1, msgsB.getMessageCount());
|
||||
assertEquals(1, msgsC.getMessageCount());
|
||||
|
@ -342,12 +341,12 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
|
||||
// ensure we don't get any more messages
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
assertEquals(1, msgsA.getMessageCount());
|
||||
assertEquals(1, msgsB.getMessageCount());
|
||||
assertEquals(1, msgsC.getMessageCount());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BrokerA <-> BrokerB <-> BrokerC
|
||||
*/
|
||||
|
@ -364,7 +363,7 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
MessageConsumer clientA = createConsumer("BrokerA", dest);
|
||||
MessageConsumer clientB = createConsumer("BrokerB", dest);
|
||||
MessageConsumer clientC = createConsumer("BrokerC", dest);
|
||||
|
||||
|
||||
//let consumers propogate around the network
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
@ -387,16 +386,17 @@ public class ThreeBrokerTopicNetworkTest extends JmsMultipleBrokersTestSupport {
|
|||
assertEquals(MESSAGE_COUNT * 3, msgsC.getMessageCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
String options = new String("?persistent=false&useJmx=false");
|
||||
String options = new String("?persistent=false&useJmx=false");
|
||||
createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA" + options));
|
||||
createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB" + options));
|
||||
createBroker(new URI("broker:(tcp://localhost:61618)/BrokerC" + options));
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return suite(ThreeBrokerTopicNetworkTest.class);
|
||||
return suite(ThreeBrokerTopicNetworkTest.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,20 +27,20 @@ import org.apache.activemq.network.NetworkBridgeConfiguration;
|
|||
import org.apache.activemq.transport.TransportFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ThreeBrokerTopicNetworkUsingTcpTest extends ThreeBrokerTopicNetworkTest {
|
||||
protected List<DemandForwardingBridge> bridges;
|
||||
|
||||
protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
|
||||
List remoteTransports = remoteBroker.getTransportConnectors();
|
||||
List localTransports = localBroker.getTransportConnectors();
|
||||
List<TransportConnector> remoteTransports = remoteBroker.getTransportConnectors();
|
||||
List<TransportConnector> localTransports = localBroker.getTransportConnectors();
|
||||
|
||||
URI remoteURI;
|
||||
URI localURI;
|
||||
if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
|
||||
remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri();
|
||||
localURI = ((TransportConnector)localTransports.get(0)).getConnectUri();
|
||||
remoteURI = remoteTransports.get(0).getConnectUri();
|
||||
localURI = localTransports.get(0).getConnectUri();
|
||||
|
||||
// Ensure that we are connecting using tcp
|
||||
if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
|
||||
|
@ -61,6 +61,7 @@ public class ThreeBrokerTopicNetworkUsingTcpTest extends ThreeBrokerTopicNetwork
|
|||
maxSetupTime = 2000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
|
|
@ -34,7 +34,9 @@ import javax.management.MBeanServerConnection;
|
|||
import javax.management.MBeanServerInvocationHandler;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.ActiveMQPrefetchPolicy;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
|
@ -50,8 +52,8 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
private static final Logger LOG = LoggerFactory.getLogger(TopicDurableConnectStatsTest.class);
|
||||
private BrokerService broker;
|
||||
private ActiveMQTopic topic;
|
||||
private Vector<Throwable> exceptions = new Vector<Throwable>();
|
||||
private int messageSize = 4000;
|
||||
private final Vector<Throwable> exceptions = new Vector<Throwable>();
|
||||
private final int messageSize = 4000;
|
||||
protected MBeanServerConnection mbeanServer;
|
||||
protected String domain = "org.apache.activemq";
|
||||
private ActiveMQConnectionFactory connectionFactory = null;
|
||||
|
@ -59,6 +61,7 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
|
||||
private static Session session2 = null;
|
||||
|
||||
@Override
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
|
||||
connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));
|
||||
|
@ -87,6 +90,7 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
return suite(TopicDurableConnectStatsTest.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
exceptions.clear();
|
||||
topic = (ActiveMQTopic) createDestination();
|
||||
|
@ -96,6 +100,7 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
destroyBroker();
|
||||
|
@ -143,6 +148,7 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
Connection consumerCon = createConnection("cliId1");
|
||||
Session consumerSession = consumerCon.createSession(true, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageConsumer consumer1 = consumerSession.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
|
||||
assertNotNull(consumer1);
|
||||
|
||||
DurableSubscriptionViewMBean subscriber1 = null;
|
||||
|
||||
|
@ -201,6 +207,7 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
consumer2.setMessageListener(listener);
|
||||
|
||||
assertTrue("received all sent", Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
return numMessages == listener.count;
|
||||
}
|
||||
|
@ -238,6 +245,7 @@ public class TopicDurableConnectStatsTest extends org.apache.activemq.TestSuppor
|
|||
Listener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
count++;
|
||||
try {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.activemq.usecases;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -32,6 +31,7 @@ import javax.jms.Session;
|
|||
import javax.jms.TextMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* @author pragmasoft
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class TransactionTest extends TestCase {
|
||||
|
||||
|
@ -54,7 +54,7 @@ public final class TransactionTest extends TestCase {
|
|||
private MessageProducer producer;
|
||||
private MessageConsumer consumer;
|
||||
private Connection connection;
|
||||
private CountDownLatch latch = new CountDownLatch(1);
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
public void testTransaction() throws Exception {
|
||||
|
||||
|
@ -70,6 +70,7 @@ public final class TransactionTest extends TestCase {
|
|||
consumer = consumerSession.createConsumer(queue);
|
||||
consumer.setMessageListener(new MessageListener() {
|
||||
|
||||
@Override
|
||||
public void onMessage(Message m) {
|
||||
try {
|
||||
TextMessage tm = (TextMessage)m;
|
||||
|
@ -111,6 +112,7 @@ public final class TransactionTest extends TestCase {
|
|||
LOG.info("test completed, destination=" + receivedText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSupport {
|
||||
protected static final int MESSAGE_COUNT = 100; // Best if a factor of 100
|
||||
|
@ -366,6 +366,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
assertEquals("Client for " + broker2 + " should have received 50% of the messages.", (int)(MESSAGE_COUNT * 0.50), msgsClient2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDuplicateSend() throws Exception {
|
||||
broker1 = "BrokerA";
|
||||
broker2 = "BrokerB";
|
||||
|
@ -391,6 +392,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
if (first.compareAndSet(false, true)) {
|
||||
producerExchange.getConnectionContext().setDontSendReponse(true);
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOG.info("Waiting for recepit");
|
||||
|
@ -441,6 +443,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDuplicateSendWithNoAuditEnqueueCountStat() throws Exception {
|
||||
broker1 = "BrokerA";
|
||||
broker2 = "BrokerB";
|
||||
|
@ -463,6 +466,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
if (first.compareAndSet(false, true)) {
|
||||
producerExchange.getConnectionContext().setDontSendReponse(true);
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOG.info("Waiting for recepit");
|
||||
|
@ -547,6 +551,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
return msgsReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageConsumer createConsumer(String brokerName, Destination dest) throws Exception {
|
||||
Connection conn = createConnection(brokerName);
|
||||
conn.start();
|
||||
|
@ -554,6 +559,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
return sess.createConsumer(dest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureBroker(BrokerService broker) {
|
||||
PolicyMap policyMap = new PolicyMap();
|
||||
PolicyEntry defaultEntry = new PolicyEntry();
|
||||
|
@ -562,6 +568,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
broker.setDestinationPolicy(policyMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean dynamicOnly, int networkTTL, boolean conduit, boolean failover) throws Exception {
|
||||
NetworkConnector nc = super.bridgeBrokers(localBroker,remoteBroker, dynamicOnly, networkTTL, conduit, failover);
|
||||
nc.setPrefetchSize(NETWORK_PREFETCH);
|
||||
|
@ -569,6 +576,7 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu
|
|||
return nc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setAutoFail(true);
|
||||
super.setUp();
|
||||
|
|
|
@ -32,15 +32,16 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoConnectionsTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TwoBrokerTopicSendReceiveTest.class);
|
||||
|
||||
protected ActiveMQConnectionFactory sendFactory;
|
||||
protected ActiveMQConnectionFactory receiveFactory;
|
||||
protected HashMap brokers = new HashMap();
|
||||
protected HashMap<String, BrokerService> brokers = new HashMap<String, BrokerService>();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
sendFactory = createSenderConnectionFactory();
|
||||
receiveFactory = createReceiverConnectionFactory();
|
||||
|
@ -63,19 +64,22 @@ public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoCon
|
|||
return createConnectionFactory("org/apache/activemq/usecases/sender.xml", "sender", "vm://sender");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
for (Iterator iter = brokers.values().iterator(); iter.hasNext();) {
|
||||
BrokerService broker = (BrokerService)iter.next();
|
||||
for (Iterator<BrokerService> iter = brokers.values().iterator(); iter.hasNext();) {
|
||||
BrokerService broker = iter.next();
|
||||
ServiceSupport.dispose(broker);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Connection createReceiveConnection() throws JMSException {
|
||||
return receiveFactory.createConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Connection createSendConnection() throws JMSException {
|
||||
return sendFactory.createConnection();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@ import javax.jms.JMSException;
|
|||
import javax.jms.Message;
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -37,15 +36,15 @@ import org.slf4j.LoggerFactory;
|
|||
* chain these instances together with the {@link #setParent(MessageListener)}
|
||||
* method so that you can aggregate the total number of messages consumed across
|
||||
* a number of consumers.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MessageIdList extends Assert implements MessageListener {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MessageIdList.class);
|
||||
|
||||
private List<String> messageIds = new ArrayList<String>();
|
||||
private Object semaphore;
|
||||
private final List<String> messageIds = new ArrayList<String>();
|
||||
private final Object semaphore;
|
||||
private boolean verbose;
|
||||
private MessageListener parent;
|
||||
private long maximumDuration = 15000L;
|
||||
|
@ -61,6 +60,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
this.semaphore = semaphore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof MessageIdList) {
|
||||
MessageIdList thatList = (MessageIdList)that;
|
||||
|
@ -69,12 +69,14 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
synchronized (semaphore) {
|
||||
return messageIds.hashCode() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
synchronized (semaphore) {
|
||||
return messageIds.toString();
|
||||
|
@ -98,6 +100,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
String id = null;
|
||||
try {
|
||||
|
@ -161,7 +164,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
/**
|
||||
* Performs a testing assertion that the correct number of messages have
|
||||
* been received without waiting
|
||||
*
|
||||
*
|
||||
* @param messageCount
|
||||
*/
|
||||
public void assertMessagesReceivedNoWait(int messageCount) {
|
||||
|
@ -172,7 +175,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
* Performs a testing assertion that the correct number of messages have
|
||||
* been received waiting for the messages to arrive up to a fixed amount of
|
||||
* time.
|
||||
*
|
||||
*
|
||||
* @param messageCount
|
||||
*/
|
||||
public void assertMessagesReceived(int messageCount) {
|
||||
|
@ -193,7 +196,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
/**
|
||||
* Asserts that there are at most the number of messages received without
|
||||
* waiting
|
||||
*
|
||||
*
|
||||
* @param messageCount
|
||||
*/
|
||||
public void assertAtMostMessagesReceived(int messageCount) {
|
||||
|
@ -250,7 +253,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
/**
|
||||
* Gets the amount of time the message listener will spend sleeping to
|
||||
* simulate a processing delay.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getProcessingDelay() {
|
||||
|
@ -260,7 +263,7 @@ public class MessageIdList extends Assert implements MessageListener {
|
|||
/**
|
||||
* Sets the amount of time the message listener will spend sleeping to
|
||||
* simulate a processing delay.
|
||||
*
|
||||
*
|
||||
* @param processingDelay
|
||||
*/
|
||||
public void setProcessingDelay(long processingDelay) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.apache.activemq.network.NetworkConnector;
|
||||
|
@ -39,7 +40,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ConnectorXBeanConfigTest extends TestCase {
|
||||
|
||||
|
@ -48,57 +49,57 @@ public class ConnectorXBeanConfigTest extends TestCase {
|
|||
|
||||
public void testConnectorConfiguredCorrectly() throws Exception {
|
||||
|
||||
TransportConnector connector = (TransportConnector)brokerService.getTransportConnectors().get(0);
|
||||
TransportConnector connector = brokerService.getTransportConnectors().get(0);
|
||||
|
||||
assertEquals(new URI("tcp://localhost:61636"), connector.getUri());
|
||||
assertTrue(connector.getTaskRunnerFactory() == brokerService.getTaskRunnerFactory());
|
||||
|
||||
NetworkConnector netConnector = (NetworkConnector)brokerService.getNetworkConnectors().get(0);
|
||||
List excludedDestinations = netConnector.getExcludedDestinations();
|
||||
NetworkConnector netConnector = brokerService.getNetworkConnectors().get(0);
|
||||
List<ActiveMQDestination> excludedDestinations = netConnector.getExcludedDestinations();
|
||||
assertEquals(new ActiveMQQueue("exclude.test.foo"), excludedDestinations.get(0));
|
||||
assertEquals(new ActiveMQTopic("exclude.test.bar"), excludedDestinations.get(1));
|
||||
|
||||
List dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
|
||||
List<ActiveMQDestination> dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
|
||||
assertEquals(new ActiveMQQueue("include.test.foo"), dynamicallyIncludedDestinations.get(0));
|
||||
assertEquals(new ActiveMQTopic("include.test.bar"), dynamicallyIncludedDestinations.get(1));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testBrokerRestartIsAllowed() throws Exception {
|
||||
brokerService.stop();
|
||||
brokerService.waitUntilStopped();
|
||||
|
||||
// redundant start is now ignored
|
||||
brokerService.start();
|
||||
brokerService.stop();
|
||||
brokerService.waitUntilStopped();
|
||||
|
||||
// redundant start is now ignored
|
||||
brokerService.start();
|
||||
}
|
||||
|
||||
|
||||
public void testForceBrokerRestart() throws Exception {
|
||||
brokerService.stop();
|
||||
brokerService.waitUntilStopped();
|
||||
|
||||
brokerService.start(true); // force restart
|
||||
brokerService.waitUntilStarted();
|
||||
|
||||
LOG.info("try and connect to restarted broker");
|
||||
//send and receive a message from a restarted broker
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61636");
|
||||
Connection conn = factory.createConnection();
|
||||
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
conn.start();
|
||||
Destination dest = new ActiveMQQueue("test");
|
||||
MessageProducer producer = sess.createProducer(dest);
|
||||
MessageConsumer consumer = sess.createConsumer(dest);
|
||||
producer.send(sess.createTextMessage("test"));
|
||||
TextMessage msg = (TextMessage)consumer.receive(1000);
|
||||
assertEquals("test", msg.getText());
|
||||
brokerService.stop();
|
||||
brokerService.waitUntilStopped();
|
||||
|
||||
brokerService.start(true); // force restart
|
||||
brokerService.waitUntilStarted();
|
||||
|
||||
LOG.info("try and connect to restarted broker");
|
||||
//send and receive a message from a restarted broker
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61636");
|
||||
Connection conn = factory.createConnection();
|
||||
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
conn.start();
|
||||
Destination dest = new ActiveMQQueue("test");
|
||||
MessageProducer producer = sess.createProducer(dest);
|
||||
MessageConsumer consumer = sess.createConsumer(dest);
|
||||
producer.send(sess.createTextMessage("test"));
|
||||
TextMessage msg = (TextMessage)consumer.receive(1000);
|
||||
assertEquals("test", msg.getText());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
brokerService = createBroker();
|
||||
brokerService.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (brokerService != null) {
|
||||
brokerService.stop();
|
||||
|
@ -109,5 +110,4 @@ public class ConnectorXBeanConfigTest extends TestCase {
|
|||
String uri = "org/apache/activemq/xbean/connector-test.xml";
|
||||
return BrokerFactory.createBroker(new URI("xbean:" + uri));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ import javax.management.ObjectName;
|
|||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.jmx.BrokerViewMBean;
|
||||
|
@ -36,7 +38,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ManagementContextXBeanConfigTest extends TestCase {
|
||||
|
||||
|
@ -57,7 +59,7 @@ public class ManagementContextXBeanConfigTest extends TestCase {
|
|||
|
||||
public void testSuccessAuthentication() throws Exception {
|
||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:2011/jmxrmi");
|
||||
Map env = new HashMap();
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
env.put(JMXConnector.CREDENTIALS, new String[]{"admin", "activemq"});
|
||||
JMXConnector connector = JMXConnectorFactory.connect(url, env);
|
||||
assertAuthentication(connector);
|
||||
|
@ -78,16 +80,18 @@ public class ManagementContextXBeanConfigTest extends TestCase {
|
|||
connector.connect();
|
||||
MBeanServerConnection connection = connector.getMBeanServerConnection();
|
||||
ObjectName name = new ObjectName("test.domain:type=Broker,brokerName=localhost");
|
||||
BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler
|
||||
BrokerViewMBean mbean = MBeanServerInvocationHandler
|
||||
.newProxyInstance(connection, name, BrokerViewMBean.class, true);
|
||||
LOG.info("Broker " + mbean.getBrokerId() + " - " + mbean.getBrokerName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
brokerService = createBroker();
|
||||
brokerService.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (brokerService != null) {
|
||||
brokerService.stop();
|
||||
|
|
|
@ -19,14 +19,11 @@ package org.apache.activemq.xbean;
|
|||
import javax.jms.Connection;
|
||||
|
||||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.test.retroactive.RetroactiveConsumerWithMessageQueryTest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Neil Clayton
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MultipleTestsWithEmbeddedBrokerTest extends EmbeddedBrokerTestSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MultipleTestsWithEmbeddedBrokerTest.class);
|
||||
|
@ -39,6 +36,7 @@ public class MultipleTestsWithEmbeddedBrokerTest extends EmbeddedBrokerTestSuppo
|
|||
public void test2() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
LOG.info("### starting up the test case: " + getName());
|
||||
|
||||
|
@ -48,6 +46,7 @@ public class MultipleTestsWithEmbeddedBrokerTest extends EmbeddedBrokerTestSuppo
|
|||
LOG.info("### started up the test case: " + getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
connection.close();
|
||||
|
||||
|
|
Loading…
Reference in New Issue