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

View File

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

View File

@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.JMSException; import javax.jms.JMSException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
@ -48,8 +49,9 @@ public class ClientTestSupport extends TestCase {
protected long idGenerator; protected long idGenerator;
private ActiveMQConnectionFactory connFactory; 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 { public void setUp() throws Exception {
final AtomicBoolean connected = new AtomicBoolean(false); final AtomicBoolean connected = new AtomicBoolean(false);
TransportConnector connector; TransportConnector connector;
@ -57,10 +59,11 @@ public class ClientTestSupport extends TestCase {
// Start up a broker with a tcp connector. // Start up a broker with a tcp connector.
try { try {
broker = BrokerFactory.createBroker(new URI(this.brokerURL)); broker = BrokerFactory.createBroker(new URI(this.brokerURL));
String brokerId = broker.getBrokerName(); broker.getBrokerName();
connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) { connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) {
// Hook into the connector so we can assert that the server // Hook into the connector so we can assert that the server
// accepted a connection. // accepted a connection.
@Override
protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException { protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException {
connected.set(true); connected.set(true);
return super.createConnection(transport); return super.createConnection(transport);
@ -82,6 +85,7 @@ public class ClientTestSupport extends TestCase {
connFactory = new ActiveMQConnectionFactory(connectURI); connFactory = new ActiveMQConnectionFactory(connectURI);
} }
@Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
if (broker != null) { 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 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 boolean combosEvaluated;
private Map<String, Object> options; private Map<String, Object> options;
protected File basedir; protected File basedir;
static protected File basedir(Class clazz) { static protected File basedir(Class<?> clazz) {
try { try {
ProtectionDomain protectionDomain = clazz.getProtectionDomain(); ProtectionDomain protectionDomain = clazz.getProtectionDomain();
return new File(new File(protectionDomain.getCodeSource().getLocation().getPath()), "../..").getCanonicalFile(); 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 { public void runBare() throws Throwable {
if (combosEvaluated) { if (combosEvaluated) {
super.runBare(); super.runBare();
@ -253,6 +254,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE); return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE);
} }
@Override
public String getName() { public String getName() {
return getName(false); return getName(false);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,8 +17,6 @@
package org.apache.activemq; package org.apache.activemq;
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest; 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() * @see junit.framework.TestCase#setUp()
*/ */
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
topic = false; topic = false;
super.setUp(); super.setUp();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,6 @@ package org.apache.activemq;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Enumeration;
import java.util.Map; import java.util.Map;
import javax.jms.Connection; import javax.jms.Connection;
@ -27,8 +26,6 @@ import javax.jms.JMSException;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import junit.framework.TestCase;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.DestinationStatistics; import org.apache.activemq.broker.region.DestinationStatistics;
import org.apache.activemq.broker.region.RegionBroker; 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.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter; import org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter;
import org.apache.activemq.store.memory.MemoryPersistenceAdapter; import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Useful base class for unit test cases * 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.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ConsumerControl; import org.apache.activemq.command.ConsumerControl;
import org.apache.activemq.command.ConsumerInfo;
import org.apache.activemq.command.ExceptionResponse; import org.apache.activemq.command.ExceptionResponse;
import org.apache.activemq.spring.SpringConsumer; import org.apache.activemq.spring.SpringConsumer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -372,6 +371,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
return brokerService; return brokerService;
} }
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
bindAddress = "tcp://localhost:0"; bindAddress = "tcp://localhost:0";
super.setUp(); super.setUp();
@ -381,11 +381,13 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
queue = createQueue(); queue = createQueue();
} }
@Override
protected void startBroker() throws Exception { protected void startBroker() throws Exception {
super.startBroker(); super.startBroker();
bindAddress = broker.getTransportConnectors().get(0).getConnectUri().toString(); bindAddress = broker.getTransportConnectors().get(0).getConnectUri().toString();
} }
@Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
connection.close(); connection.close();
super.tearDown(); super.tearDown();

View File

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

View File

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

View File

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

View File

@ -24,8 +24,6 @@ import java.net.URL;
import javax.jms.JMSException; import javax.jms.JMSException;
import junit.framework.Assert;
import org.apache.activemq.command.ActiveMQBlobMessage; import org.apache.activemq.command.ActiveMQBlobMessage;
public class FTPBlobDownloadStrategyTest extends FTPTestSupport { public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
@ -59,8 +57,8 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
sb.append((char)i); sb.append((char)i);
i = stream.read(); i = stream.read();
} }
Assert.assertEquals("hello world", sb.toString().substring(0, "hello world".length())); assertEquals("hello world", sb.toString().substring(0, "hello world".length()));
Assert.assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length()); assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length());
assertTrue(uploadFile.exists()); assertTrue(uploadFile.exists());
strategy.deleteFile(message); strategy.deleteFile(message);
@ -68,7 +66,7 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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/")); message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/"));
strategy.getInputStream(message); strategy.getInputStream(message);
} catch(JMSException e) { } 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; return;
} catch(Exception e) { } catch(Exception e) {
System.out.println(e); System.out.println(e);
Assert.assertTrue("Wrong Exception "+ e, false); assertTrue("Wrong Exception "+ e, false);
return; return;
} }
Assert.assertTrue("Expect Exception", false); assertTrue("Expect Exception", false);
} }
public void testWrongFTPPort() throws MalformedURLException { public void testWrongFTPPort() throws MalformedURLException {
@ -97,15 +95,14 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/")); message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/"));
strategy.getInputStream(message); strategy.getInputStream(message);
} catch(JMSException e) { } 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; return;
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
Assert.assertTrue("Wrong Exception "+ e, false); assertTrue("Wrong Exception "+ e, false);
return; 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.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import junit.framework.Assert;
import org.apache.activemq.ActiveMQSession; import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.BlobMessage; import org.apache.activemq.BlobMessage;
import org.apache.activemq.command.ActiveMQBlobMessage; import org.apache.activemq.command.ActiveMQBlobMessage;
public class FTPBlobTest extends FTPTestSupport { public class FTPBlobTest extends FTPTestSupport {
public void testBlobFile() throws Exception { public void testBlobFile() throws Exception {
@ -57,7 +54,7 @@ public class FTPBlobTest extends FTPTestSupport {
// check message send // check message send
Message msg = consumer.receive(1000); Message msg = consumer.receive(1000);
Assert.assertTrue(msg instanceof ActiveMQBlobMessage); assertTrue(msg instanceof ActiveMQBlobMessage);
assertEquals("name is correct", "fileName", ((ActiveMQBlobMessage)msg).getName()); assertEquals("name is correct", "fileName", ((ActiveMQBlobMessage)msg).getName());
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream(); InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
@ -69,7 +66,7 @@ public class FTPBlobTest extends FTPTestSupport {
} }
input.close(); input.close();
File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_")); File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_"));
Assert.assertEquals(content, b.toString()); assertEquals(content, b.toString());
assertTrue(uploaded.exists()); assertTrue(uploaded.exists());
((ActiveMQBlobMessage)msg).deleteFile(); ((ActiveMQBlobMessage)msg).deleteFile();
assertFalse(uploaded.exists()); assertFalse(uploaded.exists());

View File

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

View File

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

View File

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

View File

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

View File

@ -16,21 +16,13 @@
*/ */
package org.apache.activemq.broker.policy; package org.apache.activemq.broker.policy;
import java.util.Enumeration;
import javax.jms.DeliveryMode;
import javax.jms.Destination; 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.BrokerService;
import org.apache.activemq.broker.region.policy.DeadLetterStrategy;
import org.apache.activemq.broker.region.policy.IndividualDeadLetterStrategy; import org.apache.activemq.broker.region.policy.IndividualDeadLetterStrategy;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQQueue; 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 * 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 * https://issues.apache.org/jira/browse/AMQ-3003
*/ */
public class PerDurableConsumerDeadLetterTest extends DeadLetterTest { public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
private static final Logger LOG = LoggerFactory.getLogger(PerDurableConsumerDeadLetterTest.class);
private static final String CLIENT_ID = "george"; private static final String CLIENT_ID = "george";
@Override
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker(); BrokerService broker = super.createBroker();
@ -59,10 +51,12 @@ public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
return broker; return broker;
} }
@Override
protected String createClientId() { protected String createClientId() {
return CLIENT_ID; return CLIENT_ID;
} }
@Override
protected Destination createDlqDestination() { protected Destination createDlqDestination() {
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue."; String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
String destinationName = prefix + getClass().getName() + "." + getName(); String destinationName = prefix + getClass().getName() + "." + getName();

View File

@ -16,23 +16,26 @@
*/ */
package org.apache.activemq.broker.policy; package org.apache.activemq.broker.policy;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.region.Subscription; import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.broker.region.TopicSubscription; import org.apache.activemq.broker.region.TopicSubscription;
import org.apache.activemq.broker.region.policy.PriorityNetworkDispatchPolicy; 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.activemq.usage.SystemUsage;
import org.apache.derby.iapi.jdbc.BrokeredStatement;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class PriorityNetworkDispatchPolicyTest { public class PriorityNetworkDispatchPolicyTest {
PriorityNetworkDispatchPolicy underTest = new PriorityNetworkDispatchPolicy(); PriorityNetworkDispatchPolicy underTest = new PriorityNetworkDispatchPolicy();

View File

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

View File

@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy;
import java.util.Iterator; import java.util.Iterator;
import javax.jms.MessageConsumer;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TopicSubscriptionTest; import org.apache.activemq.broker.TopicSubscriptionTest;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
@ -27,6 +29,7 @@ import org.apache.activemq.util.MessageIdList;
public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest { public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
@Override
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker(); BrokerService broker = super.createBroker();
@ -41,48 +44,56 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
return broker; return broker;
} }
@Override
public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception { public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception {
super.testOneProducerTwoConsumersLargeMessagesOnePrefetch(); super.testOneProducerTwoConsumersLargeMessagesOnePrefetch();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception { public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception {
super.testOneProducerTwoConsumersSmallMessagesOnePrefetch(); super.testOneProducerTwoConsumersSmallMessagesOnePrefetch();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception { public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch(); super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception { public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch(); super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testOneProducerManyConsumersFewMessages() throws Exception { public void testOneProducerManyConsumersFewMessages() throws Exception {
super.testOneProducerManyConsumersFewMessages(); super.testOneProducerManyConsumersFewMessages();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testOneProducerManyConsumersManyMessages() throws Exception { public void testOneProducerManyConsumersManyMessages() throws Exception {
super.testOneProducerManyConsumersManyMessages(); super.testOneProducerManyConsumersManyMessages();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testManyProducersOneConsumer() throws Exception { public void testManyProducersOneConsumer() throws Exception {
super.testManyProducersOneConsumer(); super.testManyProducersOneConsumer();
assertReceivedMessagesAreOrdered(); assertReceivedMessagesAreOrdered();
} }
@Override
public void testManyProducersManyConsumers() throws Exception { public void testManyProducersManyConsumers() throws Exception {
super.testManyProducersManyConsumers(); super.testManyProducersManyConsumers();
@ -96,7 +107,7 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
} }
// Get basis of order // Get basis of order
Iterator i = consumers.keySet().iterator(); Iterator<MessageConsumer> i = consumers.keySet().iterator();
MessageIdList messageOrder = (MessageIdList)consumers.get(i.next()); MessageIdList messageOrder = (MessageIdList)consumers.get(i.next());
for (; i.hasNext();) { 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.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.ProgressPrinter; import org.apache.activemq.broker.ProgressPrinter;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.memory.list.SimpleMessageList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -51,12 +49,14 @@ public class LoadTester extends JmsTestSupport {
protected int messageSize = 1024 * 64; protected int messageSize = 1024 * 64;
protected int produceCount = 10000; protected int produceCount = 10000;
@Override
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/store/loadtester.xml")); return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/store/loadtester.xml"));
} }
@Override
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException { 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); factory.setUseAsyncSend(true);
return factory; return factory;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,11 +31,12 @@ public class DummyPolicyTest extends SpringTestSupport {
public void testPolicy() throws Exception { public void testPolicy() throws Exception {
DummyPolicy policy = (DummyPolicy)getBean("policy"); 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); assertSetEquals("FOO.BAR set", new Object[] {"Edam", "Cheddar"}, set);
} }
@Override
protected AbstractApplicationContext createApplicationContext() { protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/activemq/filter/dummyPolicy.xml"); 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 { public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFactoryTest {
@Override
public void testConnectionFactoriesArePresent() throws NamingException { public void testConnectionFactoriesArePresent() throws NamingException {
super.testConnectionFactoriesArePresent(); super.testConnectionFactoriesArePresent();
assertConnectionFactoryPresent("jms/Connection"); assertConnectionFactoryPresent("jms/Connection");
@ -41,10 +42,12 @@ public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFacto
assertEquals("testclient", factory2.getClientID()); assertEquals("testclient", factory2.getClientID());
} }
@Override
protected String getConnectionFactoryLookupName() { protected String getConnectionFactoryLookupName() {
return "myConnectionFactory"; return "myConnectionFactory";
} }
@Override
protected void configureEnvironment() { protected void configureEnvironment() {
super.configureEnvironment(); super.configureEnvironment();
environment.put("connectionFactoryNames", " myConnectionFactory, jms/Connection, jms/DURABLE_SUB_CONNECTION_FACTORY"); 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() { protected void configureEnvironment() {
super.configureEnvironment(); super.configureEnvironment();
environment.put("queue.jms/Queue", "example.myqueue"); environment.put("queue.jms/Queue", "example.myqueue");

View File

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

View File

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

View File

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

View File

@ -16,9 +16,9 @@
*/ */
package org.apache.activemq.network; 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.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;

View File

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

View File

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

View File

@ -16,19 +16,20 @@
*/ */
package org.apache.activemq.network; 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.advisory.AdvisorySupport;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection; import org.apache.activemq.broker.TransportConnection;
import org.junit.Test; 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> * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
*/ */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,23 @@
*/ */
package org.apache.activemq.network.jms; 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.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
@ -25,13 +41,6 @@ import org.apache.activemq.util.Wait;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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 * 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 { public class QueueOutboundBridgeReconnectTest {
private static final Logger LOG = LoggerFactory.getLogger(QueueOutboundBridgeReconnectTest.class);
private BrokerService producerBroker; private BrokerService producerBroker;
private BrokerService consumerBroker; private BrokerService consumerBroker;
private ActiveMQConnectionFactory producerConnectionFactory; private ActiveMQConnectionFactory producerConnectionFactory;
private ActiveMQConnectionFactory consumerConnectionFactory; private ActiveMQConnectionFactory consumerConnectionFactory;
private Destination destination; private Destination destination;
private ArrayList<Connection> connections = new ArrayList<Connection>(); private final ArrayList<Connection> connections = new ArrayList<Connection>();
@Test @Test
public void testMultipleProducerBrokerRestarts() throws Exception { public void testMultipleProducerBrokerRestarts() throws Exception {

View File

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

View File

@ -16,7 +16,23 @@
*/ */
package org.apache.activemq.network.jms; 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.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
@ -25,14 +41,6 @@ import org.apache.activemq.util.Wait;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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 * 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 { public class TopicOutboundBridgeReconnectTest {
private static final Logger LOG = LoggerFactory.getLogger(TopicOutboundBridgeReconnectTest.class);
private BrokerService producerBroker; private BrokerService producerBroker;
private BrokerService consumerBroker; private BrokerService consumerBroker;
private ActiveMQConnectionFactory producerConnectionFactory; private ActiveMQConnectionFactory producerConnectionFactory;
private ActiveMQConnectionFactory consumerConnectionFactory; private ActiveMQConnectionFactory consumerConnectionFactory;
private Destination destination; private Destination destination;
private ArrayList<Connection> connections = new ArrayList<Connection>(); private final ArrayList<Connection> connections = new ArrayList<Connection>();
@Test @Test
public void testMultipleProducerBrokerRestarts() throws Exception { public void testMultipleProducerBrokerRestarts() throws Exception {

View File

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

View File

@ -25,11 +25,8 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import junit.framework.Assert; public abstract class DataFileGenerator extends org.junit.Assert {
public abstract class DataFileGenerator extends Assert {
static final File MODULE_BASE_DIR; static final File MODULE_BASE_DIR;
static final File CONTROL_DIR; static final File CONTROL_DIR;
@ -52,16 +49,16 @@ public abstract class DataFileGenerator extends Assert {
* @throws InstantiationException * @throws InstantiationException
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public static ArrayList getAllDataFileGenerators() throws Exception { public static ArrayList<DataFileGenerator> getAllDataFileGenerators() throws Exception {
// System.out.println("Looking for generators in : "+classFileDir); // System.out.println("Looking for generators in : "+classFileDir);
ArrayList l = new ArrayList(); ArrayList<DataFileGenerator> l = new ArrayList<DataFileGenerator>();
File[] files = CLASS_FILE_DIR.listFiles(); File[] files = CLASS_FILE_DIR.listFiles();
for (int i = 0; files != null && i < files.length; i++) { for (int i = 0; files != null && i < files.length; i++) {
File file = files[i]; File file = files[i];
if (file.getName().endsWith("Data.java")) { if (file.getName().endsWith("Data.java")) {
String cn = file.getName(); String cn = file.getName();
cn = cn.substring(0, cn.length() - ".java".length()); 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()); l.add((DataFileGenerator)clazz.newInstance());
} }
} }
@ -69,12 +66,11 @@ public abstract class DataFileGenerator extends Assert {
} }
private static void generateControlFiles() throws Exception { private static void generateControlFiles() throws Exception {
ArrayList generators = getAllDataFileGenerators(); ArrayList<DataFileGenerator> generators = getAllDataFileGenerators();
for (Iterator iter = generators.iterator(); iter.hasNext();) { for (DataFileGenerator element : generators) {
DataFileGenerator object = (DataFileGenerator)iter.next();
try { try {
// System.out.println("Processing: "+object.getClass()); // System.out.println("Processing: "+object.getClass());
object.generateControlFile(); element.generateControlFile();
} catch (Exception e) { } catch (Exception e) {
// System.err.println("Error while processing: // System.err.println("Error while processing:
// "+object.getClass() + ". Reason: " + e); // "+object.getClass() + ". Reason: " + e);
@ -112,11 +108,10 @@ public abstract class DataFileGenerator extends Assert {
} }
public static void assertAllControlFileAreEqual() throws Exception { public static void assertAllControlFileAreEqual() throws Exception {
ArrayList generators = getAllDataFileGenerators(); ArrayList<DataFileGenerator> generators = getAllDataFileGenerators();
for (Iterator iter = generators.iterator(); iter.hasNext();) { for (DataFileGenerator element : generators) {
DataFileGenerator object = (DataFileGenerator)iter.next();
// System.out.println("Processing: "+object.getClass()); // 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) { } else if (expectedValue instanceof DataStructure) {
assertBeansEqual(message + name, comparedObjects, expectedValue, actualValue); assertBeansEqual(message + name, comparedObjects, expectedValue, actualValue);
} else if (expectedValue instanceof Enumeration) { } else if (expectedValue instanceof Enumeration) {
assertEnumerationEqual(message + name, comparedObjects, (Enumeration)expectedValue, (Enumeration)actualValue); assertEnumerationEqual(message + name, comparedObjects, (Enumeration<?>)expectedValue, (Enumeration<?>)actualValue);
} else { } else {
assertEquals(message, expectedValue, actualValue); 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()) { while (expected.hasMoreElements()) {
Object expectedElem = expected.nextElement(); Object expectedElem = expected.nextElement();
Object actualElem = actual.nextElement(); Object actualElem = actual.nextElement();
@ -204,6 +204,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
assertEquals(message, expected.getMessage(), actual.getMessage()); assertEquals(message, expected.getMessage(), actual.getMessage());
} }
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
openWireformat = createOpenWireFormat(); openWireformat = createOpenWireFormat();

View File

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