Fix a bunch of warnings covering deprecated asserts and such.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1443267 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-02-06 22:56:12 +00:00
parent 46e67a10cc
commit c7d559fbcd
66 changed files with 1065 additions and 993 deletions

View File

@ -22,7 +22,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
@ -142,7 +141,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception {
broker = new BrokerService();
broker.setPersistent(false);
TransportConnector connector = broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
broker.start();
// This should create the connection.
@ -185,6 +184,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
assertNull(connection.getExceptionListener());
ExceptionListener exListener = new ExceptionListener() {
@Override
public void onException(JMSException arg0) {
}
};
@ -211,6 +211,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
assertNull(connection.getClientInternalExceptionListener());
ClientInternalExceptionListener listener = new ClientInternalExceptionListener() {
@Override
public void onException(Throwable exception) {
}
};

View File

@ -20,25 +20,16 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.KeyStore;
import java.security.SecureRandom;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Session;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import org.apache.activemq.broker.BrokerRegistry;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.SslBrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -50,10 +41,10 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
private TransportConnector connector;
private ActiveMQConnection connection;
private BrokerService broker;
@Override
protected void tearDown() throws Exception {
// Try our best to close any previously opend connection.
try {
@ -195,7 +186,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
BrokerService service = new BrokerService();
service.setPersistent(false);
service.setUseJmx(false);
connector = service.addConnector(uri);
service.addConnector(uri);
service.start();
return service;
@ -212,7 +203,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
KeyManager[] km = getKeyManager();
TrustManager[] tm = getTrustManager();
connector = service.addSslConnector(uri, km, tm, null);
service.addSslConnector(uri, km, tm, null);
service.start();
return service;

View File

@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.JMSException;
import junit.framework.TestCase;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
@ -48,8 +49,9 @@ public class ClientTestSupport extends TestCase {
protected long idGenerator;
private ActiveMQConnectionFactory connFactory;
private String brokerURL = "vm://localhost?broker.persistent=false";
private final String brokerURL = "vm://localhost?broker.persistent=false";
@Override
public void setUp() throws Exception {
final AtomicBoolean connected = new AtomicBoolean(false);
TransportConnector connector;
@ -57,10 +59,11 @@ public class ClientTestSupport extends TestCase {
// Start up a broker with a tcp connector.
try {
broker = BrokerFactory.createBroker(new URI(this.brokerURL));
String brokerId = broker.getBrokerName();
broker.getBrokerName();
connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) {
// Hook into the connector so we can assert that the server
// accepted a connection.
@Override
protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException {
connected.set(true);
return super.createConnection(transport);
@ -82,6 +85,7 @@ public class ClientTestSupport extends TestCase {
connFactory = new ActiveMQConnectionFactory(connectURI);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
if (broker != null) {

View File

@ -65,12 +65,12 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(CombinationTestSupport.class);
private HashMap<String, ComboOption> comboOptions = new HashMap<String, ComboOption>();
private final HashMap<String, ComboOption> comboOptions = new HashMap<String, ComboOption>();
private boolean combosEvaluated;
private Map<String, Object> options;
protected File basedir;
static protected File basedir(Class clazz) {
static protected File basedir(Class<?> clazz) {
try {
ProtectionDomain protectionDomain = clazz.getProtectionDomain();
return new File(new File(protectionDomain.getCodeSource().getLocation().getPath()), "../..").getCanonicalFile();
@ -101,6 +101,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
}
}
@Override
public void runBare() throws Throwable {
if (combosEvaluated) {
super.runBare();
@ -253,6 +254,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE);
}
@Override
public String getName() {
return getName(false);
}

View File

@ -23,7 +23,7 @@ import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import junit.framework.Assert;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
@ -33,6 +33,7 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
private static final String VM_BROKER_URL = "vm://localhost";
@Override
protected BrokerService createBroker() throws Exception {
BrokerService answer = new BrokerService();
answer.setPersistent(false);
@ -87,15 +88,13 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
senderSession.close();
conn.close();
}
}
public void testFailoverToAnotherExclusiveConsumerCreatedFirst() throws JMSException,
@ -132,9 +131,9 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer1.receive(100));
Assert.assertNull(exclusiveConsumer2.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer1.receive(100));
assertNull(exclusiveConsumer2.receive(100));
assertNull(fallbackConsumer.receive(100));
// Close the exclusive consumer to verify the non-exclusive consumer
// takes over
@ -143,8 +142,8 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
producer.send(msg);
producer.send(msg);
Assert.assertNotNull("Should have received a message", exclusiveConsumer2.receive(100));
Assert.assertNull("Should not have received a message", fallbackConsumer.receive(100));
assertNotNull("Should have received a message", exclusiveConsumer2.receive(100));
assertNull("Should not have received a message", fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
@ -184,8 +183,8 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
// Close the exclusive consumer to verify the non-exclusive consumer
// takes over
@ -193,14 +192,12 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
producer.send(msg);
Assert.assertNotNull(fallbackConsumer.receive(100));
assertNotNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
senderSession.close();
conn.close();
}
}
}

View File

@ -24,8 +24,8 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.activemq.command.ActiveMQQueue;
public class ExclusiveConsumerTest extends TestCase {
@ -36,10 +36,12 @@ public class ExclusiveConsumerTest extends TestCase {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
@ -83,8 +85,8 @@ public class ExclusiveConsumerTest extends TestCase {
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
@ -122,8 +124,8 @@ public class ExclusiveConsumerTest extends TestCase {
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
@ -167,9 +169,9 @@ public class ExclusiveConsumerTest extends TestCase {
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer1.receive(100));
Assert.assertNull(exclusiveConsumer2.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer1.receive(100));
assertNull(exclusiveConsumer2.receive(100));
assertNull(fallbackConsumer.receive(100));
// Close the exclusive consumer to verify the non-exclusive consumer
// takes over
@ -178,8 +180,8 @@ public class ExclusiveConsumerTest extends TestCase {
producer.send(msg);
producer.send(msg);
Assert.assertNotNull(exclusiveConsumer2.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer2.receive(100));
assertNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
@ -224,9 +226,9 @@ public class ExclusiveConsumerTest extends TestCase {
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer1.receive(100));
Assert.assertNull(exclusiveConsumer2.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer1.receive(100));
assertNull(exclusiveConsumer2.receive(100));
assertNull(fallbackConsumer.receive(100));
// Close the exclusive consumer to verify the non-exclusive consumer
// takes over
@ -235,8 +237,8 @@ public class ExclusiveConsumerTest extends TestCase {
producer.send(msg);
producer.send(msg);
Assert.assertNotNull(exclusiveConsumer2.receive(1000));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer2.receive(1000));
assertNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
@ -276,8 +278,8 @@ public class ExclusiveConsumerTest extends TestCase {
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
// Close the exclusive consumer to verify the non-exclusive consumer
// takes over
@ -285,7 +287,7 @@ public class ExclusiveConsumerTest extends TestCase {
producer.send(msg);
Assert.assertNotNull(fallbackConsumer.receive(100));
assertNotNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();
@ -325,8 +327,8 @@ public class ExclusiveConsumerTest extends TestCase {
Thread.sleep(100);
// Verify exclusive consumer receives the message.
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
// Close the exclusive consumer to verify the non-exclusive consumer
// takes over
@ -335,15 +337,15 @@ public class ExclusiveConsumerTest extends TestCase {
producer.send(msg);
// Verify other non-exclusive consumer receices the message.
Assert.assertNotNull(fallbackConsumer.receive(100));
assertNotNull(fallbackConsumer.receive(100));
// Create exclusive consumer to determine if it will start receiving
// the messages.
exclusiveConsumer = exclusiveSession.createConsumer(exclusiveQueue);
producer.send(msg);
Assert.assertNotNull(exclusiveConsumer.receive(100));
Assert.assertNull(fallbackConsumer.receive(100));
assertNotNull(exclusiveConsumer.receive(100));
assertNull(fallbackConsumer.receive(100));
} finally {
fallbackSession.close();

View File

@ -36,7 +36,9 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.management.ObjectName;
import junit.framework.Test;
import org.apache.activemq.broker.jmx.DestinationViewMBean;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
@ -85,6 +87,7 @@ public class JMSConsumerTest extends JmsTestSupport {
destination = createDestination(session, destinationType);
ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
counter.incrementAndGet();
if (counter.get() == 1) {
@ -135,6 +138,7 @@ public class JMSConsumerTest extends JmsTestSupport {
final Map<Thread, Throwable> exceptions =
Collections.synchronizedMap(new HashMap<Thread, Throwable>());
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
LOG.error("Uncaught exception:", e);
exceptions.put(t, e);
@ -142,12 +146,13 @@ public class JMSConsumerTest extends JmsTestSupport {
});
final class AckAndClose implements Runnable {
private Message message;
private final Message message;
public AckAndClose(Message m) {
this.message = m;
}
@Override
public void run() {
try {
int count = counter.incrementAndGet();
@ -170,6 +175,7 @@ public class JMSConsumerTest extends JmsTestSupport {
final ExecutorService executor = Executors.newCachedThreadPool();
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
// ack and close eventually in separate thread
executor.execute(new AckAndClose(m));
@ -310,6 +316,7 @@ public class JMSConsumerTest extends JmsTestSupport {
// See if the message get sent to the listener
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
counter.incrementAndGet();
if (counter.get() == 4) {
@ -339,6 +346,7 @@ public class JMSConsumerTest extends JmsTestSupport {
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination, new MessageListener() {
@Override
public void onMessage(Message m) {
counter.incrementAndGet();
if (counter.get() == 4) {
@ -346,6 +354,7 @@ public class JMSConsumerTest extends JmsTestSupport {
}
}
});
assertNotNull(consumer);
// Send the messages
sendMessages(session, destination, 4);
@ -383,6 +392,7 @@ public class JMSConsumerTest extends JmsTestSupport {
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
try {
TextMessage tm = (TextMessage)m;
@ -420,6 +430,7 @@ public class JMSConsumerTest extends JmsTestSupport {
session = connection.createSession(false, ackMode);
consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
try {
TextMessage tm = (TextMessage)m;
@ -469,6 +480,7 @@ public class JMSConsumerTest extends JmsTestSupport {
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
try {
TextMessage tm = (TextMessage)m;
@ -506,6 +518,7 @@ public class JMSConsumerTest extends JmsTestSupport {
session = connection.createSession(false, ackMode);
consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
try {
TextMessage tm = (TextMessage)m;
@ -547,6 +560,7 @@ public class JMSConsumerTest extends JmsTestSupport {
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
counter.incrementAndGet();
if (counter.get() == 4) {
@ -582,6 +596,7 @@ public class JMSConsumerTest extends JmsTestSupport {
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message m) {
counter.incrementAndGet();
if (counter.get() == 4) {

View File

@ -438,7 +438,7 @@ public class JMSMessageTest extends JmsTestSupport {
}
@Override
public Enumeration getPropertyNames() throws JMSException {
public Enumeration<?> getPropertyNames() throws JMSException {
return new Vector<String>(props.keySet()).elements();
}

View File

@ -37,9 +37,9 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import junit.framework.Test;
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.slf4j.Logger;
@ -76,12 +76,14 @@ public class JmsBenchmark extends JmsTestSupport {
addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST")});
}
@Override
protected BrokerService createBroker() throws Exception {
return BrokerFactory.createBroker(new URI("broker://(tcp://localhost:0)?persistent=false"));
}
@Override
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
return new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getServer().getConnectURI());
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI());
}
/**
@ -96,7 +98,8 @@ public class JmsBenchmark extends JmsTestSupport {
final AtomicInteger producedMessages = new AtomicInteger(0);
final AtomicInteger receivedMessages = new AtomicInteger(0);
final Callable producer = new Callable() {
final Callable<Object> producer = new Callable<Object>() {
@Override
public Object call() throws JMSException, InterruptedException {
Connection connection = factory.createConnection();
connections.add(connection);
@ -119,7 +122,8 @@ public class JmsBenchmark extends JmsTestSupport {
}
};
final Callable consumer = new Callable() {
final Callable<Object> consumer = new Callable<Object>() {
@Override
public Object call() throws JMSException, InterruptedException {
Connection connection = factory.createConnection();
connections.add(connection);
@ -127,6 +131,7 @@ public class JmsBenchmark extends JmsTestSupport {
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message msg) {
receivedMessages.incrementAndGet();
}
@ -145,6 +150,7 @@ public class JmsBenchmark extends JmsTestSupport {
final Throwable workerError[] = new Throwable[1];
for (int i = 0; i < PRODUCER_COUNT; i++) {
new Thread("Producer:" + i) {
@Override
public void run() {
try {
producer.call();
@ -158,6 +164,7 @@ public class JmsBenchmark extends JmsTestSupport {
for (int i = 0; i < CONSUMER_COUNT; i++) {
new Thread("Consumer:" + i) {
@Override
public void run() {
try {
consumer.call();
@ -198,7 +205,5 @@ public class JmsBenchmark extends JmsTestSupport {
if (workerError[0] != null) {
throw workerError[0];
}
}
}

View File

@ -18,13 +18,10 @@ package org.apache.activemq;
import java.util.Random;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
@ -48,6 +45,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
/**
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
LOG.info(getClass().getClassLoader().getResource("log4j.properties"));
@ -61,6 +59,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
/**
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
stoppedConnection.close();
startedConnection.close();
@ -123,6 +122,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
final Vector<Throwable> exceptions = new Vector<Throwable>();
final Random rand = new Random();
Runnable createSessionTask = new Runnable() {
@Override
public void run() {
try {
TimeUnit.MILLISECONDS.sleep(rand.nextInt(10));
@ -134,6 +134,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
};
Runnable startStopTask = new Runnable() {
@Override
public void run() {
try {
TimeUnit.MILLISECONDS.sleep(rand.nextInt(10));

View File

@ -19,18 +19,19 @@ package org.apache.activemq;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.jms.Connection;
import javax.jms.TextMessage;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
import junit.framework.Test;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.region.BaseDestination;
@ -80,16 +81,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
consumer.close();
//Thread.sleep(200);
QueueBrowser browser = session.createBrowser((Queue) destination);
Enumeration enumeration = browser.getEnumeration();
QueueBrowser browser = session.createBrowser(destination);
Enumeration<?> enumeration = browser.getEnumeration();
// browse the second
assertTrue("should have received the second message", enumeration.hasMoreElements());
assertEquals(outbound[1], (Message) enumeration.nextElement());
assertEquals(outbound[1], enumeration.nextElement());
// browse the third.
assertTrue("Should have received the third message", enumeration.hasMoreElements());
assertEquals(outbound[2], (Message) enumeration.nextElement());
assertEquals(outbound[2], enumeration.nextElement());
// There should be no more.
boolean tooMany = false;
@ -135,8 +136,8 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
producer.send(outbound[i]);
}
QueueBrowser browser = session.createBrowser((Queue) destination);
Enumeration enumeration = browser.getEnumeration();
QueueBrowser browser = session.createBrowser(destination);
Enumeration<?> enumeration = browser.getEnumeration();
for (int i=0; i<outbound.length; i++) {
assertTrue("should have a", enumeration.hasMoreElements());
@ -149,7 +150,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
}
// verify second batch is visible to browse
browser = session.createBrowser((Queue) destination);
browser = session.createBrowser(destination);
enumeration = browser.getEnumeration();
for (int j=0; j<2;j++) {
for (int i=0; i<outbound.length; i++) {
@ -290,12 +291,12 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
producer.send(outbound[0]);
// create browser first
QueueBrowser browser = session.createBrowser((Queue) destination);
Enumeration enumeration = browser.getEnumeration();
QueueBrowser browser = session.createBrowser(destination);
Enumeration<?> enumeration = browser.getEnumeration();
// browse the first message
assertTrue("should have received the first message", enumeration.hasMoreElements());
assertEquals(outbound[0], (Message) enumeration.nextElement());
assertEquals(outbound[0], enumeration.nextElement());
// Receive the first message.
assertEquals(outbound[0], consumer.receive(1000));
@ -317,7 +318,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
}
QueueBrowser browser = session.createBrowser(destination);
Enumeration enumeration = browser.getEnumeration();
Enumeration<?> enumeration = browser.getEnumeration();
assertTrue(enumeration.hasMoreElements());
@ -362,6 +363,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
}
QueueBrowser browser = session2.createBrowser(destinationPrefetch1);
@SuppressWarnings("unchecked")
Enumeration<Message> browserView = browser.getEnumeration();
List<Message> messages = new ArrayList<Message>();
@ -412,19 +414,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
// create browser first
QueueBrowser browser = session.createBrowser((Queue) destination);
Enumeration enumeration = browser.getEnumeration();
QueueBrowser browser = session.createBrowser(destination);
Enumeration<?> enumeration = browser.getEnumeration();
// browse some messages
assertEquals(outbound[0], (Message) enumeration.nextElement());
assertEquals(outbound[1], (Message) enumeration.nextElement());
assertEquals(outbound[0], enumeration.nextElement());
assertEquals(outbound[1], enumeration.nextElement());
//assertEquals(outbound[2], (Message) enumeration.nextElement());
browser.close();
// Receive the first message.
TextMessage msg = (TextMessage)consumer.receive(1000);
assertEquals("Expected " + outbound[0].getText() + " but received " + msg.getText(), outbound[0], msg);
@ -435,9 +434,9 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
consumer.close();
producer.close();
}
@Override
protected BrokerService createBroker() throws Exception {
BrokerService brokerService = super.createBroker();
PolicyMap policyMap = new PolicyMap();
@ -447,5 +446,4 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
brokerService.setDestinationPolicy(policyMap);
return brokerService;
}
}

View File

@ -17,8 +17,6 @@
package org.apache.activemq;
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
@ -30,6 +28,7 @@ public class JmsQueueSendReceiveTwoConnectionsTest extends JmsTopicSendReceiveWi
*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
topic = false;
super.setUp();

View File

@ -40,6 +40,7 @@ import javax.jms.TemporaryQueue;
import javax.jms.TextMessage;
import junit.framework.TestCase;
import org.apache.activemq.transport.TransportListener;
import org.apache.activemq.transport.vm.VMTransport;
import org.apache.activemq.util.Wait;
@ -56,6 +57,7 @@ public class JmsTempDestinationTest extends TestCase {
private ActiveMQConnectionFactory factory;
protected List<Connection> connections = Collections.synchronizedList(new ArrayList<Connection>());
@Override
protected void setUp() throws Exception {
factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
factory.setAlwaysSyncSend(true);
@ -66,9 +68,10 @@ public class JmsTempDestinationTest extends TestCase {
/**
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
for (Iterator iter = connections.iterator(); iter.hasNext();) {
Connection conn = (Connection)iter.next();
for (Iterator<Connection> iter = connections.iterator(); iter.hasNext();) {
Connection conn = iter.next();
try {
conn.close();
} catch (Throwable e) {
@ -173,7 +176,7 @@ public class JmsTempDestinationTest extends TestCase {
int count = 500;
int dataSize = 1024;
ArrayList list = new ArrayList(count);
ArrayList<BytesMessage> list = new ArrayList<BytesMessage>(count);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
MessageProducer producer = session.createProducer(queue);

View File

@ -42,8 +42,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.jms.Destination;
import javax.jms.Session;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -60,9 +60,9 @@ public final class LargeStreamletTest extends TestCase {
protected Exception writerException;
protected Exception readerException;
private AtomicInteger totalRead = new AtomicInteger();
private AtomicInteger totalWritten = new AtomicInteger();
private AtomicBoolean stopThreads = new AtomicBoolean(false);
private final AtomicInteger totalRead = new AtomicInteger();
private final AtomicInteger totalWritten = new AtomicInteger();
private final AtomicBoolean stopThreads = new AtomicBoolean(false);
public void testStreamlets() throws Exception {
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL);
@ -75,6 +75,7 @@ public final class LargeStreamletTest extends TestCase {
final Destination destination = session.createQueue("wibble");
final Thread readerThread = new Thread(new Runnable() {
@Override
public void run() {
totalRead.set(0);
try {
@ -100,6 +101,7 @@ public final class LargeStreamletTest extends TestCase {
final Thread writerThread = new Thread(new Runnable() {
private final Random random = new Random();
@Override
public void run() {
totalWritten.set(0);
int count = MESSAGE_COUNT;
@ -147,7 +149,7 @@ public final class LargeStreamletTest extends TestCase {
assertTrue("Should not have received a reader exception", readerException == null);
assertTrue("Should not have received a writer exception", writerException == null);
Assert.assertEquals("Not all messages accounted for", totalWritten.get(), totalRead.get());
assertEquals("Not all messages accounted for", totalWritten.get(), totalRead.get());
} finally {
session.close();

View File

@ -16,10 +16,10 @@
*/
package org.apache.activemq;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
@ -41,7 +41,6 @@ import javax.jms.Topic;
import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.broker.region.policy.ConstantPendingMessageLimitStrategy;
import org.apache.activemq.broker.region.policy.FilePendingSubscriberMessageStoragePolicy;
import org.apache.activemq.broker.region.policy.OldestMessageEvictionStrategy;
@ -53,10 +52,10 @@ import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.Wait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MessageEvictionTest {
static final Logger LOG = LoggerFactory.getLogger(MessageEvictionTest.class);
@ -107,6 +106,7 @@ public class MessageEvictionTest {
final CountDownLatch advisoryIsGood = new CountDownLatch(1);
executor.execute(new Runnable() {
@Override
public void run() {
try {
ActiveMQTopic discardedAdvisoryDestination =
@ -117,6 +117,7 @@ public class MessageEvictionTest {
final MessageConsumer consumer = advisorySession.createConsumer(discardedAdvisoryDestination);
consumer.setMessageListener(new MessageListener() {
int advisoriesReceived = 0;
@Override
public void onMessage(Message message) {
try {
LOG.info("advisory:" + message);
@ -156,10 +157,12 @@ public class MessageEvictionTest {
final CountDownLatch ackDone = new CountDownLatch(1);
final CountDownLatch consumerRegistered = new CountDownLatch(1);
executor.execute(new Runnable() {
@Override
public void run() {
try {
final MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
try {
// very slow, only ack once
@ -191,6 +194,7 @@ public class MessageEvictionTest {
final AtomicInteger sent = new AtomicInteger(0);
final CountDownLatch sendDone = new CountDownLatch(1);
executor.execute(new Runnable() {
@Override
public void run() {
MessageProducer producer;
try {
@ -218,6 +222,7 @@ public class MessageEvictionTest {
executor.awaitTermination(30, TimeUnit.SECONDS);
assertTrue("usage goes to 0 once consumer goes away", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 0 == TestSupport.getDestination(broker,
ActiveMQDestination.transform(destination)).getMemoryUsage().getPercentUsage();
@ -274,7 +279,7 @@ public class MessageEvictionTest {
}
ConnectionFactory createConnectionFactory() throws Exception {
String url = ((TransportConnector) broker.getTransportConnectors().get(0)).getServer().getConnectURI().toString();
String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString();
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
factory.setWatchTopicAdvisories(false);
return factory;

View File

@ -24,8 +24,8 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.activemq.command.ActiveMQQueue;
public class QueueConsumerPriorityTest extends TestCase {
@ -36,10 +36,12 @@ public class QueueConsumerPriorityTest extends TestCase {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
@ -64,6 +66,7 @@ public class QueueConsumerPriorityTest extends TestCase {
consumerLowPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumerHighPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(consumerHighPriority);
senderSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
String queueName = getClass().getName();
ActiveMQQueue low = new ActiveMQQueue(queueName+"?consumer.priority=1");
@ -79,17 +82,13 @@ public class QueueConsumerPriorityTest extends TestCase {
Message msg = senderSession.createTextMessage("test");
for (int i =0; i< 10000;i++) {
producer.send(msg);
Assert.assertNotNull("null on iteration: " + i, highConsumer.receive(500));
assertNotNull("null on iteration: " + i, highConsumer.receive(500));
}
Assert.assertNull(lowConsumer.receive(2000));
assertNull(lowConsumer.receive(2000));
} finally {
conn.close();
}
}
}
}

View File

@ -22,8 +22,7 @@ import java.util.HashSet;
import java.util.Set;
import junit.framework.TestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
/**
@ -35,12 +34,14 @@ public abstract class SpringTestSupport extends TestCase {
protected AbstractApplicationContext context;
@Override
protected void setUp() throws Exception {
context = createApplicationContext();
}
protected abstract AbstractApplicationContext createApplicationContext();;
@Override
protected void tearDown() throws Exception {
if (context != null) {
context.destroy();
@ -55,7 +56,7 @@ public abstract class SpringTestSupport extends TestCase {
return bean;
}
protected void assertSetEquals(String description, Object[] expected, Set actual) {
protected void assertSetEquals(String description, Object[] expected, Set<?> actual) {
Set<Object> expectedSet = new HashSet<Object>();
expectedSet.addAll(Arrays.asList(expected));
assertEquals(description, expectedSet, actual);

View File

@ -18,7 +18,6 @@ package org.apache.activemq;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import javax.jms.Connection;
@ -27,8 +26,6 @@ import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;
import junit.framework.TestCase;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.DestinationStatistics;
import org.apache.activemq.broker.region.RegionBroker;
@ -42,8 +39,6 @@ import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter;
import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Useful base class for unit test cases

View File

@ -33,7 +33,6 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ConsumerControl;
import org.apache.activemq.command.ConsumerInfo;
import org.apache.activemq.command.ExceptionResponse;
import org.apache.activemq.spring.SpringConsumer;
import org.slf4j.Logger;
@ -372,6 +371,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
return brokerService;
}
@Override
protected void setUp() throws Exception {
bindAddress = "tcp://localhost:0";
super.setUp();
@ -381,11 +381,13 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
queue = createQueue();
}
@Override
protected void startBroker() throws Exception {
super.startBroker();
bindAddress = broker.getTransportConnectors().get(0).getConnectUri().toString();
}
@Override
protected void tearDown() throws Exception {
connection.close();
super.tearDown();

View File

@ -16,7 +16,23 @@
*/
package org.apache.activemq.advisory;
import java.util.ArrayList;
import java.util.List;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TemporaryQueue;
import javax.jms.Topic;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
@ -26,10 +42,6 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import javax.jms.*;
import java.util.ArrayList;
import java.util.List;
public class AdvisoryTempDestinationTests extends TestCase {
protected static final int MESSAGE_COUNT = 2000;
@ -44,6 +56,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
TemporaryQueue queue = s.createTemporaryQueue();
MessageConsumer consumer = s.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
}
});
@ -66,6 +79,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = s.createTemporaryQueue();
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport
.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
@ -86,6 +100,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = s.createTemporaryQueue();
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
@ -130,6 +145,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = s.createQueue(getClass().getName());
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
@ -146,6 +162,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
assertNotNull(msg);
}
@Override
protected void setUp() throws Exception {
if (broker == null) {
broker = createBroker();
@ -156,6 +173,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
connection.close();

View File

@ -26,7 +26,9 @@ import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQPrefetchPolicy;
@ -53,6 +55,7 @@ public class AdvisoryTests extends TestCase {
Queue queue = s.createQueue(getClass().getName());
MessageConsumer consumer = s.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
}
});
@ -75,6 +78,7 @@ public class AdvisoryTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = s.createQueue(getClass().getName());
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport
.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
@ -95,6 +99,7 @@ public class AdvisoryTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = s.createQueue(getClass().getName());
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
@ -139,6 +144,7 @@ public class AdvisoryTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = s.createQueue(getClass().getName());
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
@ -159,6 +165,7 @@ public class AdvisoryTests extends TestCase {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = s.createTopic(getClass().getName());
MessageConsumer consumer = s.createConsumer(topic);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getMessageDiscardedAdvisoryTopic((ActiveMQDestination) topic);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
@ -174,7 +181,7 @@ public class AdvisoryTests extends TestCase {
assertNotNull(msg);
}
@Override
protected void setUp() throws Exception {
if (broker == null) {
broker = createBroker();
@ -185,6 +192,7 @@ public class AdvisoryTests extends TestCase {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
connection.close();

View File

@ -78,10 +78,12 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P
assertConsumerEvent(0, false);
}
@Override
public void onProducerEvent(ProducerEvent event) {
eventQueue.add(event);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -91,6 +93,7 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P
producerEventSource.setProducerListener(this);
}
@Override
protected void tearDown() throws Exception {
if (producerEventSource != null) {
producerEventSource.stop();
@ -119,6 +122,8 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P
Session answer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = answer.createProducer(destination);
assertNotNull(producer);
return answer;
}

View File

@ -24,8 +24,6 @@ import java.net.URL;
import javax.jms.JMSException;
import junit.framework.Assert;
import org.apache.activemq.command.ActiveMQBlobMessage;
public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
@ -59,8 +57,8 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
sb.append((char)i);
i = stream.read();
}
Assert.assertEquals("hello world", sb.toString().substring(0, "hello world".length()));
Assert.assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length());
assertEquals("hello world", sb.toString().substring(0, "hello world".length()));
assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length());
assertTrue(uploadFile.exists());
strategy.deleteFile(message);
@ -68,7 +66,7 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
} catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false);
assertTrue(false);
}
}
@ -79,15 +77,15 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/"));
strategy.getInputStream(message);
} catch(JMSException e) {
Assert.assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage());
assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage());
return;
} catch(Exception e) {
System.out.println(e);
Assert.assertTrue("Wrong Exception "+ e, false);
assertTrue("Wrong Exception "+ e, false);
return;
}
Assert.assertTrue("Expect Exception", false);
assertTrue("Expect Exception", false);
}
public void testWrongFTPPort() throws MalformedURLException {
@ -97,15 +95,14 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/"));
strategy.getInputStream(message);
} catch(JMSException e) {
Assert.assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage());
assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage());
return;
} catch(Exception e) {
e.printStackTrace();
Assert.assertTrue("Wrong Exception "+ e, false);
assertTrue("Wrong Exception "+ e, false);
return;
}
Assert.assertTrue("Expect Exception", false);
assertTrue("Expect Exception", false);
}
}

View File

@ -26,13 +26,10 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import junit.framework.Assert;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.BlobMessage;
import org.apache.activemq.command.ActiveMQBlobMessage;
public class FTPBlobTest extends FTPTestSupport {
public void testBlobFile() throws Exception {
@ -57,7 +54,7 @@ public class FTPBlobTest extends FTPTestSupport {
// check message send
Message msg = consumer.receive(1000);
Assert.assertTrue(msg instanceof ActiveMQBlobMessage);
assertTrue(msg instanceof ActiveMQBlobMessage);
assertEquals("name is correct", "fileName", ((ActiveMQBlobMessage)msg).getName());
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
@ -69,7 +66,7 @@ public class FTPBlobTest extends FTPTestSupport {
}
input.close();
File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_"));
Assert.assertEquals(content, b.toString());
assertEquals(content, b.toString());
assertTrue(uploaded.exists());
((ActiveMQBlobMessage)msg).deleteFile();
assertFalse(uploaded.exists());

View File

@ -23,8 +23,6 @@ import java.io.FileWriter;
import javax.jms.JMSException;
import javax.jms.Session;
import junit.framework.Assert;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.command.ActiveMQBlobMessage;
@ -47,7 +45,7 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport {
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
message.setMessageId(new MessageId("testmessage"));
message.onSend();
Assert.assertEquals(ftpUrl + "testmessage", message.getURL().toString());
assertEquals(ftpUrl + "testmessage", message.getURL().toString());
File uploaded = new File(ftpHomeDirFile, "testmessage");
assertTrue("File doesn't exists", uploaded.exists());
}

View File

@ -27,8 +27,6 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import junit.framework.Assert;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.BlobMessage;
import org.apache.activemq.EmbeddedBrokerTestSupport;
@ -42,7 +40,8 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(FilesystemBlobTest.class);
private Connection connection;
private String tmpDir = System.getProperty("user.dir") + "/target/FilesystemBlobTest";
private final String tmpDir = System.getProperty("user.dir") + "/target/FilesystemBlobTest";
@Override
public void setUp() throws Exception {
super.setUp();
// replace \ with / to let it work on windows too
@ -56,7 +55,6 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
connection.start();
}
public void testBlobFile() throws Exception {
// first create Message
File file = File.createTempFile("amq-data-file-", ".dat");
@ -77,7 +75,7 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
// check message send
Message msg = consumer.receive(1000);
Assert.assertTrue(msg instanceof ActiveMQBlobMessage);
assertTrue(msg instanceof ActiveMQBlobMessage);
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
StringBuilder b = new StringBuilder();
@ -88,12 +86,13 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
}
input.close();
File uploaded = new File(tmpDir, msg.getJMSMessageID().toString().replace(":", "_"));
Assert.assertEquals(content, b.toString());
assertEquals(content, b.toString());
assertTrue(uploaded.exists());
((ActiveMQBlobMessage)msg).deleteFile();
assertFalse(uploaded.exists());
}
@Override
protected void tearDown() throws Exception {
if (connection != null) {
connection.stop();

View File

@ -16,9 +16,13 @@
*/
package org.apache.activemq.broker.jmx;
import static org.junit.Assert.assertEquals;
import java.net.Socket;
import java.util.Set;
import javax.management.ObjectName;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
@ -28,9 +32,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TransportConnectorMBeanTest {
private static final Logger LOG = LoggerFactory.getLogger(TransportConnectorMBeanTest.class);
@ -73,7 +74,7 @@ public class TransportConnectorMBeanTest {
}
private String extractLocalPort(ActiveMQConnection connection) throws Exception {
Socket socket = (Socket) connection.getTransport().narrow(Socket.class);
Socket socket = connection.getTransport().narrow(Socket.class);
return String.valueOf(socket.getLocalPort());
}

View File

@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
public class IndividualDeadLetterTest extends DeadLetterTest {
private static final Logger LOG = LoggerFactory.getLogger(IndividualDeadLetterTest.class);
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker();
@ -56,6 +57,7 @@ public class IndividualDeadLetterTest extends DeadLetterTest {
return broker;
}
@Override
protected Destination createDlqDestination() {
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
return new ActiveMQQueue(prefix + getClass().getName() + "." + getName());
@ -99,7 +101,7 @@ public class IndividualDeadLetterTest extends DeadLetterTest {
}
protected void browseDlq() throws Exception {
Enumeration messages = dlqBrowser.getEnumeration();
Enumeration<?> messages = dlqBrowser.getEnumeration();
while (messages.hasMoreElements()) {
LOG.info("Browsing: " + messages.nextElement());
}

View File

@ -18,12 +18,10 @@ package org.apache.activemq.broker.policy;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.RedeliveryPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NoRetryDeadLetterTest extends DeadLetterTest {
private static final Logger LOG = LoggerFactory.getLogger(NoRetryDeadLetterTest.class);
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
ActiveMQConnectionFactory connectionFactory = super.createConnectionFactory();
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();

View File

@ -16,21 +16,13 @@
*/
package org.apache.activemq.broker.policy;
import java.util.Enumeration;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.DeadLetterStrategy;
import org.apache.activemq.broker.region.policy.IndividualDeadLetterStrategy;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* for durable subs, allow a dlq per subscriber such that poison messages are not duplicates
@ -38,10 +30,10 @@ import org.slf4j.LoggerFactory;
* https://issues.apache.org/jira/browse/AMQ-3003
*/
public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
private static final Logger LOG = LoggerFactory.getLogger(PerDurableConsumerDeadLetterTest.class);
private static final String CLIENT_ID = "george";
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker();
@ -59,10 +51,12 @@ public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
return broker;
}
@Override
protected String createClientId() {
return CLIENT_ID;
}
@Override
protected Destination createDlqDestination() {
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
String destinationName = prefix + getClass().getName() + "." + getName();

View File

@ -16,23 +16,26 @@
*/
package org.apache.activemq.broker.policy;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.broker.region.TopicSubscription;
import org.apache.activemq.broker.region.policy.PriorityNetworkDispatchPolicy;
import org.apache.activemq.command.*;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ConsumerId;
import org.apache.activemq.command.ConsumerInfo;
import org.apache.activemq.command.MessageId;
import org.apache.activemq.usage.SystemUsage;
import org.apache.derby.iapi.jdbc.BrokeredStatement;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class PriorityNetworkDispatchPolicyTest {
PriorityNetworkDispatchPolicy underTest = new PriorityNetworkDispatchPolicy();

View File

@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy;
import java.util.Iterator;
import javax.jms.MessageConsumer;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.QueueSubscriptionTest;
import org.apache.activemq.broker.region.policy.FixedCountSubscriptionRecoveryPolicy;
@ -28,6 +30,7 @@ import org.apache.activemq.util.MessageIdList;
public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker();
@ -42,6 +45,7 @@ public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
return broker;
}
@Override
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
@ -49,6 +53,7 @@ public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
// assertOneConsumerReceivedAllMessages(messageCount);
}
@Override
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
@ -58,8 +63,8 @@ public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
public void assertOneConsumerReceivedAllMessages(int messageCount) throws Exception {
boolean found = false;
for (Iterator i = consumers.keySet().iterator(); i.hasNext();) {
MessageIdList messageIdList = (MessageIdList)consumers.get(i.next());
for (Iterator<MessageConsumer> i = consumers.keySet().iterator(); i.hasNext();) {
MessageIdList messageIdList = consumers.get(i.next());
int count = messageIdList.getMessageCount();
if (count > 0) {
if (found) {

View File

@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy;
import java.util.Iterator;
import javax.jms.MessageConsumer;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TopicSubscriptionTest;
import org.apache.activemq.broker.region.policy.PolicyEntry;
@ -27,6 +29,7 @@ import org.apache.activemq.util.MessageIdList;
public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker();
@ -41,48 +44,56 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
return broker;
}
@Override
public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception {
super.testOneProducerTwoConsumersLargeMessagesOnePrefetch();
assertReceivedMessagesAreOrdered();
}
@Override
public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception {
super.testOneProducerTwoConsumersSmallMessagesOnePrefetch();
assertReceivedMessagesAreOrdered();
}
@Override
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
assertReceivedMessagesAreOrdered();
}
@Override
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
assertReceivedMessagesAreOrdered();
}
@Override
public void testOneProducerManyConsumersFewMessages() throws Exception {
super.testOneProducerManyConsumersFewMessages();
assertReceivedMessagesAreOrdered();
}
@Override
public void testOneProducerManyConsumersManyMessages() throws Exception {
super.testOneProducerManyConsumersManyMessages();
assertReceivedMessagesAreOrdered();
}
@Override
public void testManyProducersOneConsumer() throws Exception {
super.testManyProducersOneConsumer();
assertReceivedMessagesAreOrdered();
}
@Override
public void testManyProducersManyConsumers() throws Exception {
super.testManyProducersManyConsumers();
@ -96,7 +107,7 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
}
// Get basis of order
Iterator i = consumers.keySet().iterator();
Iterator<MessageConsumer> i = consumers.keySet().iterator();
MessageIdList messageOrder = (MessageIdList)consumers.get(i.next());
for (; i.hasNext();) {

View File

@ -34,10 +34,8 @@ import org.apache.activemq.JmsTestSupport;
import org.apache.activemq.broker.BrokerFactory;
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.memory.list.SimpleMessageList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -51,12 +49,14 @@ public class LoadTester extends JmsTestSupport {
protected int messageSize = 1024 * 64;
protected int produceCount = 10000;
@Override
protected BrokerService createBroker() throws Exception {
return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/store/loadtester.xml"));
}
@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;
}

View File

@ -17,7 +17,6 @@
package org.apache.activemq.bugs.amq1095;
import java.io.File;
import java.net.URI;
import java.util.Iterator;
import java.util.LinkedList;
@ -34,7 +33,6 @@ import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.activemq.broker.BrokerFactory;
@ -57,7 +55,7 @@ public class ActiveMQTestCase extends TestCase
private BrokerService broker;
protected Connection connection;
protected Destination destination;
private List<MessageConsumer> consumersToEmpty = new LinkedList<MessageConsumer>();
private final List<MessageConsumer> consumersToEmpty = new LinkedList<MessageConsumer>();
protected final long RECEIVE_TIMEOUT = 500;
@ -76,6 +74,7 @@ public class ActiveMQTestCase extends TestCase
/**
* <p>Sets up the JUnit testing environment.
*/
@Override
protected void setUp()
{
URI uri;
@ -84,7 +83,7 @@ public class ActiveMQTestCase extends TestCase
/* Copy all system properties starting with "java.naming." to the initial context. */
final Properties systemProperties = System.getProperties();
final Properties jndiProperties = new Properties();
for (final Iterator i = systemProperties.keySet().iterator(); i.hasNext();)
for (final Iterator<Object> i = systemProperties.keySet().iterator(); i.hasNext();)
{
final String key = (String) i.next();
if (key.startsWith("java.naming.") || key.startsWith("topic.") ||
@ -119,15 +118,15 @@ public class ActiveMQTestCase extends TestCase
catch (JMSException ex1)
{
ex1.printStackTrace();
Assert.fail(ex1.toString());
fail(ex1.toString());
}
catch (NamingException ex2) {
ex2.printStackTrace();
Assert.fail(ex2.toString());
fail(ex2.toString());
}
catch (Throwable ex3) {
ex3.printStackTrace();
Assert.fail(ex3.toString());
fail(ex3.toString());
}
}
@ -140,12 +139,13 @@ public class ActiveMQTestCase extends TestCase
* to be empty.
* </p>
*/
@Override
protected void tearDown() throws Exception {
TextMessage msg;
try {
for (final Iterator i = consumersToEmpty.iterator(); i.hasNext();)
for (final Iterator<MessageConsumer> i = consumersToEmpty.iterator(); i.hasNext();)
{
final MessageConsumer consumer = (MessageConsumer) i.next();
final MessageConsumer consumer = i.next();
if (consumer != null)
do
msg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT);

View File

@ -24,9 +24,6 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import junit.framework.Assert;
/**
* <p>
* Test cases for various ActiveMQ functionalities.
@ -223,7 +220,7 @@ public class MessageSelectorTest extends ActiveMQTestCase {
catch (JMSException ex)
{
ex.printStackTrace();
Assert.fail();
fail();
}
}

View File

@ -29,12 +29,13 @@ import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
*
*/
public class BrokerXmlConfigFromJNDITest extends JmsTopicSendReceiveWithTwoConnectionsTest {
@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
assertBaseDirectoryContainsSpaces();
// we could put these properties into a jndi.properties
// on the classpath instead
Hashtable properties = new Hashtable();
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
// configure the embedded broker using an XML config file

View File

@ -22,6 +22,7 @@ import javax.jms.JMSException;
import javax.jms.Session;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQMessageConsumer;
import org.apache.activemq.command.ActiveMQQueue;
@ -55,7 +56,7 @@ public class ConfigUsingDestinationOptions extends TestCase {
// JMS selector should be priority
try {
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
fail("Selector should be invalid");
fail("Selector should be invalid" + cons);
} catch (InvalidSelectorException e) {
}
@ -63,7 +64,7 @@ public class ConfigUsingDestinationOptions extends TestCase {
// Test setting using JMS destinations
try {
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
fail("Selector should be invalid");
fail("Selector should be invalid" + cons);
} catch (InvalidSelectorException e) {
}

View File

@ -92,6 +92,7 @@ public class TestPurgeCommand extends TestCase {
protected MessageProducer requestServerProducer;
protected Queue theQueue;
@Override
protected void setUp() throws Exception {
super.setUp();
@ -121,6 +122,7 @@ public class TestPurgeCommand extends TestCase {
return new ClassPathXmlApplicationContext("org/apache/activemq/console/command/activemq.xml");
}
@Override
protected void tearDown() throws Exception {
localConnection.close();
BrokerService broker = (BrokerService) context.getBean("localbroker");
@ -130,10 +132,8 @@ public class TestPurgeCommand extends TestCase {
super.tearDown();
}
@SuppressWarnings("unchecked")
public int getMessageCount(QueueBrowser browser, String prefix)
throws JMSException {
Enumeration e = browser.getEnumeration();
public int getMessageCount(QueueBrowser browser, String prefix) throws JMSException {
Enumeration<?> e = browser.getEnumeration();
int with = 0;
while (e.hasMoreElements()) {
Object o = e.nextElement();
@ -235,9 +235,9 @@ public class TestPurgeCommand extends TestCase {
+ token + ",*");
for (ObjectInstance queue : queueList) {
ObjectName queueName = ((ObjectInstance) queue)
ObjectName queueName = queue
.getObjectName();
QueueViewMBean proxy = (QueueViewMBean) MBeanServerInvocationHandler
QueueViewMBean proxy = MBeanServerInvocationHandler
.newProxyInstance(createJmxConnection(), queueName,
QueueViewMBean.class, true);
int removed = proxy

View File

@ -17,7 +17,9 @@
package org.apache.activemq.filter;
import java.util.Set;
import junit.framework.TestCase;
import org.apache.activemq.command.ActiveMQTempQueue;
import org.apache.activemq.command.ConnectionId;
import org.apache.activemq.util.IdGenerator;
@ -36,7 +38,7 @@ public class DestinationMapTempDestinationTest extends TestCase {
for (int i = 0; i < count; i++) {
ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
map.remove(queue, value);
Set set = map.get(queue);
Set<?> set = map.get(queue);
assertTrue(set.isEmpty());
}
}

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
@ -50,7 +51,6 @@ public class DestinationMapTest extends TestCase {
map.put(d1, d1);
map.put(d2, d2);
map.get(createDestination("TEST.BAR.D2,TEST.BAR.D3"));
}
public void testSimpleDestinations() throws Exception {
@ -131,7 +131,7 @@ public class DestinationMapTest extends TestCase {
map.put(d2, v2);
map.put(d3, v3);
List allValues = Arrays.asList(new Object[] {v1, v2, v3});
List<Object> allValues = Arrays.asList(new Object[] {v1, v2, v3});
assertMapValue(">", allValues);
assertMapValue("TEST.>", allValues);
@ -305,10 +305,9 @@ public class DestinationMapTest extends TestCase {
put("FOO.B", v2);
assertMapValue("FOO.>", v1, v2);
Set set = map.removeAll(createDestination("FOO.A"));
map.removeAll(createDestination("FOO.A"));
assertMapValue("FOO.>", v2);
}
protected void loadSample2() {
@ -371,7 +370,7 @@ public class DestinationMapTest extends TestCase {
assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5, expected6}));
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void assertMapValue(ActiveMQDestination destination, Object expected) {
List expectedList = null;
if (expected == null) {

View File

@ -25,10 +25,14 @@ import java.util.List;
*/
public class DummyPolicy extends DestinationMap {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Class getEntryClass() {
return DummyPolicyEntry.class;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void setEntries(List entries) {
super.setEntries(entries);
}

View File

@ -31,11 +31,12 @@ public class DummyPolicyTest extends SpringTestSupport {
public void testPolicy() throws Exception {
DummyPolicy policy = (DummyPolicy)getBean("policy");
Set set = policy.get(new ActiveMQTopic("FOO.BAR"));
Set<?> set = policy.get(new ActiveMQTopic("FOO.BAR"));
assertSetEquals("FOO.BAR set", new Object[] {"Edam", "Cheddar"}, set);
}
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/activemq/filter/dummyPolicy.xml");
}

View File

@ -27,6 +27,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
*/
public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFactoryTest {
@Override
public void testConnectionFactoriesArePresent() throws NamingException {
super.testConnectionFactoriesArePresent();
assertConnectionFactoryPresent("jms/Connection");
@ -41,10 +42,12 @@ public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFacto
assertEquals("testclient", factory2.getClientID());
}
@Override
protected String getConnectionFactoryLookupName() {
return "myConnectionFactory";
}
@Override
protected void configureEnvironment() {
super.configureEnvironment();
environment.put("connectionFactoryNames", " myConnectionFactory, jms/Connection, jms/DURABLE_SUB_CONNECTION_FACTORY");

View File

@ -28,6 +28,7 @@ public class DestinationNameWithSlashTest extends JNDITestSupport {
}
@Override
protected void configureEnvironment() {
super.configureEnvironment();
environment.put("queue.jms/Queue", "example.myqueue");

View File

@ -28,6 +28,7 @@ import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
/**
@ -38,7 +39,7 @@ public abstract class JNDITestSupport extends TestCase {
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
.getLog(JNDITestSupport.class);
protected Hashtable environment = new Hashtable();
protected Hashtable<String, String> environment = new Hashtable<String, String>();
protected Context context;
protected void assertConnectionFactoryPresent(String lookupName) throws NamingException {
@ -53,15 +54,16 @@ public abstract class JNDITestSupport extends TestCase {
assertTrue("Should have got a child context but got: " + object, object instanceof Context);
Context childContext = (Context) object;
NamingEnumeration iter = childContext.listBindings("");
NamingEnumeration<Binding> iter = childContext.listBindings("");
while (iter.hasMore()) {
Binding destinationBinding = (Binding) iter.next();
Binding destinationBinding = iter.next();
LOG.info("Found destination: " + destinationBinding.getName());
Object destination = destinationBinding.getObject();
assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination);
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -77,10 +79,11 @@ public abstract class JNDITestSupport extends TestCase {
*
* @throws javax.naming.NamingException
*/
@Override
protected void tearDown() throws NamingException, JMSException {
NamingEnumeration iter = context.listBindings("");
NamingEnumeration<Binding> iter = context.listBindings("");
while (iter.hasMore()) {
Binding binding = (Binding) iter.next();
Binding binding = iter.next();
Object connFactory = binding.getObject();
if (connFactory instanceof ActiveMQConnectionFactory) {
// ((ActiveMQConnectionFactory) connFactory).stop();

View File

@ -27,22 +27,23 @@ import javax.jms.JMSException;
*
*/
public class LoadController extends LoadClient{
private int numberOfBatches=1;
private int batchSize =1000;
private int count;
private final CountDownLatch stopped = new CountDownLatch(1);
public LoadController(String name,ConnectionFactory factory) {
super(name,factory);
}
public int awaitTestComplete() throws InterruptedException {
boolean complete = stopped.await(60*5,TimeUnit.SECONDS);
stopped.await(60*5,TimeUnit.SECONDS);
return count;
}
@Override
public void stop() throws JMSException, InterruptedException {
running = false;
stopped.countDown();
@ -51,6 +52,7 @@ public class LoadController extends LoadClient{
}
}
@Override
public void run() {
try {
for (int i = 0; i < numberOfBatches; i++) {
@ -73,33 +75,29 @@ public class LoadController extends LoadClient{
}
}
public int getNumberOfBatches() {
return numberOfBatches;
}
public void setNumberOfBatches(int numberOfBatches) {
this.numberOfBatches = numberOfBatches;
}
public int getBatchSize() {
return batchSize;
}
public void setBatchSize(int batchSize) {
this.batchSize = batchSize;
}
@Override
protected Destination getSendDestination() {
return startDestination;
}
@Override
protected Destination getConsumeDestination() {
return nextDestination;
}
}

View File

@ -16,18 +16,12 @@
*/
package org.apache.activemq.memory;
import java.io.File;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import junit.framework.TestCase;
public class MemoryPropertyTest extends TestCase {
@ -40,6 +34,7 @@ public class MemoryPropertyTest extends TestCase {
*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
// Create broker from resource
LOG.info("Creating broker... ");
@ -52,12 +47,12 @@ public class MemoryPropertyTest extends TestCase {
return BrokerFactory.createBroker(resource);
}
/*
* Stops the Broker
*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
LOG.info("Closing Broker");
if (broker != null) {
@ -66,8 +61,6 @@ public class MemoryPropertyTest extends TestCase {
LOG.info("Broker closed...");
}
public void testBrokerInitialized() {
assertTrue("We should have a broker", broker != null);
@ -79,5 +72,4 @@ public class MemoryPropertyTest extends TestCase {
// non persistent broker so no temp storage
assertNull(broker.getSystemUsage().getTempUsage().getStore());
}
}

View File

@ -16,9 +16,9 @@
*/
package org.apache.activemq.network;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.net.URI;
import java.util.Arrays;

View File

@ -19,6 +19,7 @@ package org.apache.activemq.network;
import javax.jms.DeliveryMode;
import junit.framework.Test;
import org.apache.activemq.broker.StubConnection;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ConnectionInfo;
@ -78,6 +79,7 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
// Make sure the message was delivered via the remote.
assertTrue("message was received", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return receiveMessage(connection2) != null;
}
@ -122,9 +124,10 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
// Send the message to the local boker.
connection1.request(createMessage(producerInfo, destination, deliveryMode));
// Make sure the message was delivered via the remote.
Message m = receiveMessage(connection2);
receiveMessage(connection2);
}
@Override
protected void setUp() throws Exception {
super.setUp();
NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
@ -135,6 +138,7 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
bridge.start();
}
@Override
protected void tearDown() throws Exception {
bridge.stop();
super.tearDown();

View File

@ -16,16 +16,16 @@
*/
package org.apache.activemq.network;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javax.jms.MessageProducer;
import javax.jms.TemporaryQueue;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.Wait;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
public class DuplexNetworkTest extends SimpleNetworkTest {
@Override

View File

@ -16,19 +16,20 @@
*/
package org.apache.activemq.network;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import java.lang.reflect.Field;
import javax.jms.MessageProducer;
import javax.jms.TemporaryQueue;
import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection;
import org.junit.Test;
import javax.jms.MessageProducer;
import javax.jms.TemporaryQueue;
import java.lang.reflect.Field;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
/**
* @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
*/

View File

@ -16,40 +16,22 @@
*/
package org.apache.activemq.network;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
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.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.TopicRequestor;
import javax.jms.TopicSession;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class NetworkConnectionsCleanedupTest extends TestCase {
protected static final int MESSAGE_COUNT = 10;
private static final Logger LOG = LoggerFactory.getLogger(NetworkConnectionsCleanedupTest.class);
protected AbstractApplicationContext context;
protected Connection localConnection;
@ -86,7 +68,4 @@ public class NetworkConnectionsCleanedupTest extends TestCase {
broker.start();
Thread.sleep(1000 * 3600);
}
}

View File

@ -37,7 +37,6 @@ import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.DestinationDoesNotExistException;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.AbstractDeadLetterStrategy;
import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.transport.TransportFilter;
@ -62,9 +61,9 @@ public class NetworkFailoverTest extends TestCase {
protected Session localSession;
protected Session remoteSession;
protected ActiveMQQueue included=new ActiveMQQueue("include.test.foo");
private AtomicInteger replyToNonExistDest = new AtomicInteger(0);
private AtomicInteger roundTripComplete = new AtomicInteger(0);
private AtomicInteger remoteDLQCount = new AtomicInteger(0);
private final AtomicInteger replyToNonExistDest = new AtomicInteger(0);
private final AtomicInteger roundTripComplete = new AtomicInteger(0);
private final AtomicInteger remoteDLQCount = new AtomicInteger(0);
public void testRequestReply() throws Exception {
final MessageProducer remoteProducer = remoteSession.createProducer(null);

View File

@ -109,6 +109,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase {
for (int i = 0; i < 100; i++) {
TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
assertNotNull(subscriber);
}
connection.close();
@ -148,6 +149,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase {
class DummyMessageListener implements MessageListener {
@Override
public void onMessage(Message arg0) {
// TODO Auto-generated method stub

View File

@ -36,7 +36,7 @@ import org.apache.activemq.usage.SystemUsage;
public class NetworkTestSupport extends BrokerTestSupport {
protected ArrayList connections = new ArrayList();
protected ArrayList<StubConnection> connections = new ArrayList<StubConnection>();
protected TransportConnector connector;
@ -46,6 +46,7 @@ public class NetworkTestSupport extends BrokerTestSupport {
protected TransportConnector remoteConnector;
protected boolean useJmx = false;
@Override
protected void setUp() throws Exception {
super.setUp();
@ -57,7 +58,7 @@ public class NetworkTestSupport extends BrokerTestSupport {
remoteBroker.start();
}
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = BrokerFactory.createBroker(new URI("broker:()/localhost?persistent=false&useJmx=false&"));
connector = createConnector();
@ -66,7 +67,6 @@ public class NetworkTestSupport extends BrokerTestSupport {
return broker;
}
/**
* @return
* @throws Exception
@ -111,6 +111,7 @@ public class NetworkTestSupport extends BrokerTestSupport {
return answer;
}
@Override
protected StubConnection createConnection() throws Exception {
Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
StubConnection connection = new StubConnection(transport);
@ -157,9 +158,10 @@ public class NetworkTestSupport extends BrokerTestSupport {
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
}
@Override
protected void tearDown() throws Exception {
for (Iterator iter = connections.iterator(); iter.hasNext();) {
StubConnection connection = (StubConnection)iter.next();
for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext();) {
StubConnection connection = iter.next();
connection.stop();
iter.remove();
}

View File

@ -20,45 +20,43 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test network reconnects over SSH tunnels. This case can be especially tricky
* since the SSH tunnels fool the TCP transport into thinking that they are
* initially connected.
*
* @author chirino
*/
public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
private static final transient Logger LOG = LoggerFactory.getLogger(SSHTunnelNetworkReconnectTest.class);
ArrayList processes = new ArrayList();
ArrayList<Process> processes = new ArrayList<Process>();
@Override
protected BrokerService createFirstBroker() throws Exception {
return BrokerFactory
.createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker1.xml"));
}
@Override
protected BrokerService createSecondBroker() throws Exception {
return BrokerFactory
.createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker2.xml"));
}
@Override
protected void setUp() throws Exception {
startProcess("ssh -Nn -L60006:localhost:61616 localhost");
startProcess("ssh -Nn -L60007:localhost:61617 localhost");
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
for (Iterator iter = processes.iterator(); iter.hasNext();) {
Process p = (Process)iter.next();
for (Process p : processes) {
p.destroy();
}
}
@ -67,6 +65,7 @@ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
final Process process = Runtime.getRuntime().exec(command);
processes.add(process);
new Thread("stdout: " + command) {
@Override
public void run() {
try {
InputStream is = process.getInputStream();
@ -79,6 +78,7 @@ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
}
}.start();
new Thread("stderr: " + command) {
@Override
public void run() {
try {
InputStream is = process.getErrorStream();

View File

@ -16,9 +16,9 @@
*/
package org.apache.activemq.network;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.net.URI;
import java.util.Arrays;
@ -103,6 +103,7 @@ public class SimpleNetworkTest {
final MessageProducer remoteProducer = remoteSession.createProducer(null);
MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
remoteConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message msg) {
try {
TextMessage textMsg = (TextMessage)msg;

View File

@ -16,7 +16,19 @@
*/
package org.apache.activemq.network.jms;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Iterator;
import javax.jms.Connection;
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.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
@ -25,17 +37,9 @@ import org.apache.activemq.util.Wait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jms.*;
import java.util.ArrayList;
import java.util.Iterator;
public class QueueBridgeStandaloneReconnectTest {
private static final Logger LOG = LoggerFactory.getLogger(QueueBridgeStandaloneReconnectTest.class);
private SimpleJmsQueueConnector jmsQueueConnector;
private BrokerService localBroker;
@ -47,7 +51,7 @@ public class QueueBridgeStandaloneReconnectTest {
private Destination outbound;
private Destination inbound;
private ArrayList<Connection> connections = new ArrayList<Connection>();
private final ArrayList<Connection> connections = new ArrayList<Connection>();
@Test
public void testSendAndReceiveOverConnectedBridges() throws Exception {

View File

@ -16,7 +16,23 @@
*/
package org.apache.activemq.network.jms;
import static org.junit.Assert.*;
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.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
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.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
@ -25,13 +41,6 @@ import org.apache.activemq.util.Wait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jms.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
/**
* These test cases are used to verify that queue outbound bridge connections get
@ -40,14 +49,12 @@ import java.util.concurrent.TimeUnit;
*/
public class QueueOutboundBridgeReconnectTest {
private static final Logger LOG = LoggerFactory.getLogger(QueueOutboundBridgeReconnectTest.class);
private BrokerService producerBroker;
private BrokerService consumerBroker;
private ActiveMQConnectionFactory producerConnectionFactory;
private ActiveMQConnectionFactory consumerConnectionFactory;
private Destination destination;
private ArrayList<Connection> connections = new ArrayList<Connection>();
private final ArrayList<Connection> connections = new ArrayList<Connection>();
@Test
public void testMultipleProducerBrokerRestarts() throws Exception {

View File

@ -16,7 +16,19 @@
*/
package org.apache.activemq.network.jms;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Iterator;
import javax.jms.Connection;
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.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
@ -25,17 +37,9 @@ import org.apache.activemq.util.Wait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jms.*;
import java.util.ArrayList;
import java.util.Iterator;
public class TopicBridgeStandaloneReconnectTest {
private static final Logger LOG = LoggerFactory.getLogger(TopicBridgeStandaloneReconnectTest.class);
private SimpleJmsTopicConnector jmsTopicConnector;
private BrokerService localBroker;
@ -47,7 +51,7 @@ public class TopicBridgeStandaloneReconnectTest {
private Destination outbound;
private Destination inbound;
private ArrayList<Connection> connections = new ArrayList<Connection>();
private final ArrayList<Connection> connections = new ArrayList<Connection>();
@Test
public void testSendAndReceiveOverConnectedBridges() throws Exception {

View File

@ -16,7 +16,23 @@
*/
package org.apache.activemq.network.jms;
import static org.junit.Assert.*;
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.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
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.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
@ -25,14 +41,6 @@ import org.apache.activemq.util.Wait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jms.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
/**
* These test cases are used to verify that queue outbound bridge connections get
@ -41,14 +49,12 @@ import java.util.concurrent.TimeUnit;
*/
public class TopicOutboundBridgeReconnectTest {
private static final Logger LOG = LoggerFactory.getLogger(TopicOutboundBridgeReconnectTest.class);
private BrokerService producerBroker;
private BrokerService consumerBroker;
private ActiveMQConnectionFactory producerConnectionFactory;
private ActiveMQConnectionFactory consumerConnectionFactory;
private Destination destination;
private ArrayList<Connection> connections = new ArrayList<Connection>();
private final ArrayList<Connection> connections = new ArrayList<Connection>();
@Test
public void testMultipleProducerBrokerRestarts() throws Exception {

View File

@ -40,6 +40,7 @@ public class BooleanStreamTest extends TestCase {
public void testBooleanMarshallingUsingAllTrue() throws Exception {
testBooleanStream(numberOfBytes, new BooleanValueSet() {
@Override
public boolean getBooleanValueFor(int index, int count) {
return true;
}
@ -48,6 +49,7 @@ public class BooleanStreamTest extends TestCase {
public void testBooleanMarshallingUsingAllFalse() throws Exception {
testBooleanStream(numberOfBytes, new BooleanValueSet() {
@Override
public boolean getBooleanValueFor(int index, int count) {
return false;
}
@ -56,6 +58,7 @@ public class BooleanStreamTest extends TestCase {
public void testBooleanMarshallingUsingOddAlternateTrueFalse() throws Exception {
testBooleanStream(numberOfBytes, new BooleanValueSet() {
@Override
public boolean getBooleanValueFor(int index, int count) {
return (index & 1) == 0;
}
@ -64,6 +67,7 @@ public class BooleanStreamTest extends TestCase {
public void testBooleanMarshallingUsingEvenAlternateTrueFalse() throws Exception {
testBooleanStream(numberOfBytes, new BooleanValueSet() {
@Override
public boolean getBooleanValueFor(int index, int count) {
return (index & 1) != 0;
}
@ -121,13 +125,14 @@ public class BooleanStreamTest extends TestCase {
// lets try read and we should get an exception
try {
byte value = dis.readByte();
dis.readByte();
fail("Should have reached the end of the stream");
} catch (IOException e) {
// worked!
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
openWireformat = createOpenWireFormat();

View File

@ -25,11 +25,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import junit.framework.Assert;
public abstract class DataFileGenerator extends Assert {
public abstract class DataFileGenerator extends org.junit.Assert {
static final File MODULE_BASE_DIR;
static final File CONTROL_DIR;
@ -52,16 +49,16 @@ public abstract class DataFileGenerator extends Assert {
* @throws InstantiationException
* @throws IllegalAccessException
*/
public static ArrayList getAllDataFileGenerators() throws Exception {
public static ArrayList<DataFileGenerator> getAllDataFileGenerators() throws Exception {
// System.out.println("Looking for generators in : "+classFileDir);
ArrayList l = new ArrayList();
ArrayList<DataFileGenerator> l = new ArrayList<DataFileGenerator>();
File[] files = CLASS_FILE_DIR.listFiles();
for (int i = 0; files != null && i < files.length; i++) {
File file = files[i];
if (file.getName().endsWith("Data.java")) {
String cn = file.getName();
cn = cn.substring(0, cn.length() - ".java".length());
Class clazz = DataFileGenerator.class.getClassLoader().loadClass("org.apache.activemq.openwire." + cn);
Class<?> clazz = DataFileGenerator.class.getClassLoader().loadClass("org.apache.activemq.openwire." + cn);
l.add((DataFileGenerator)clazz.newInstance());
}
}
@ -69,12 +66,11 @@ public abstract class DataFileGenerator extends Assert {
}
private static void generateControlFiles() throws Exception {
ArrayList generators = getAllDataFileGenerators();
for (Iterator iter = generators.iterator(); iter.hasNext();) {
DataFileGenerator object = (DataFileGenerator)iter.next();
ArrayList<DataFileGenerator> generators = getAllDataFileGenerators();
for (DataFileGenerator element : generators) {
try {
// System.out.println("Processing: "+object.getClass());
object.generateControlFile();
element.generateControlFile();
} catch (Exception e) {
// System.err.println("Error while processing:
// "+object.getClass() + ". Reason: " + e);
@ -112,11 +108,10 @@ public abstract class DataFileGenerator extends Assert {
}
public static void assertAllControlFileAreEqual() throws Exception {
ArrayList generators = getAllDataFileGenerators();
for (Iterator iter = generators.iterator(); iter.hasNext();) {
DataFileGenerator object = (DataFileGenerator)iter.next();
ArrayList<DataFileGenerator> generators = getAllDataFileGenerators();
for (DataFileGenerator element : generators) {
// System.out.println("Processing: "+object.getClass());
object.assertControlFileIsEqual();
element.assertControlFileIsEqual();
}
}

View File

@ -152,7 +152,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
} else if (expectedValue instanceof DataStructure) {
assertBeansEqual(message + name, comparedObjects, expectedValue, actualValue);
} else if (expectedValue instanceof Enumeration) {
assertEnumerationEqual(message + name, comparedObjects, (Enumeration)expectedValue, (Enumeration)actualValue);
assertEnumerationEqual(message + name, comparedObjects, (Enumeration<?>)expectedValue, (Enumeration<?>)actualValue);
} else {
assertEquals(message, expectedValue, actualValue);
}
@ -167,7 +167,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
}
}
protected void assertEnumerationEqual(String message, Set<Object> comparedObjects, Enumeration expected, Enumeration actual) throws Exception {
protected void assertEnumerationEqual(String message, Set<Object> comparedObjects, Enumeration<?> expected, Enumeration<?> actual) throws Exception {
while (expected.hasMoreElements()) {
Object expectedElem = expected.nextElement();
Object actualElem = actual.nextElement();
@ -204,6 +204,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
assertEquals(message, expected.getMessage(), actual.getMessage());
}
@Override
protected void setUp() throws Exception {
super.setUp();
openWireformat = createOpenWireFormat();

View File

@ -23,6 +23,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.SessionId;
import org.slf4j.Logger;
@ -87,7 +88,7 @@ public class NumberRangesWhileMarshallingTest extends TestCase {
// lets try read and we should get an exception
try {
byte value = dis.readByte();
fail("Should have reached the end of the stream");
fail("Should have reached the end of the stream: " + value);
} catch (IOException e) {
// worked!
}
@ -124,6 +125,7 @@ public class NumberRangesWhileMarshallingTest extends TestCase {
assertEquals(Long.MAX_VALUE, wf.getMaxFrameSize());
}
@Override
protected void setUp() throws Exception {
super.setUp();
openWireformat = createOpenWireFormat();