From c7d559fbcd5edd0be0b5079cceb7ba7df7e1ef5b Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 6 Feb 2013 22:56:12 +0000 Subject: [PATCH] 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 --- .../ActiveMQConnectionFactoryTest.java | 35 +- .../ActiveMQSslConnectionFactoryTest.java | 63 +- .../apache/activemq/ClientTestSupport.java | 8 +- .../activemq/CombinationTestSupport.java | 6 +- ...clusiveConsumerStartupDestinationTest.java | 29 +- .../activemq/ExclusiveConsumerTest.java | 48 +- .../org/apache/activemq/JMSConsumerTest.java | 125 ++-- .../org/apache/activemq/JMSMessageTest.java | 2 +- .../org/apache/activemq/JmsBenchmark.java | 21 +- .../activemq/JmsConnectionStartStopTest.java | 15 +- .../apache/activemq/JmsQueueBrowserTest.java | 66 +- ...JmsQueueSendReceiveTwoConnectionsTest.java | 7 +- .../activemq/JmsTempDestinationTest.java | 27 +- .../apache/activemq/LargeStreamletTest.java | 12 +- .../apache/activemq/MessageEvictionTest.java | 71 +- .../activemq/QueueConsumerPriorityTest.java | 15 +- .../apache/activemq/SpringTestSupport.java | 11 +- .../java/org/apache/activemq/TestSupport.java | 17 +- .../activemq/ZeroPrefetchConsumerTest.java | 38 +- .../AdvisoryTempDestinationTests.java | 26 +- .../activemq/advisory/AdvisoryTests.java | 52 +- .../advisory/ProducerListenerTest.java | 9 +- .../blob/FTPBlobDownloadStrategyTest.java | 27 +- .../org/apache/activemq/blob/FTPBlobTest.java | 9 +- .../blob/FTPBlobUploadStrategyTest.java | 18 +- .../activemq/blob/FilesystemBlobTest.java | 27 +- .../jmx/TransportConnectorMBeanTest.java | 9 +- .../policy/IndividualDeadLetterTest.java | 10 +- .../broker/policy/NoRetryDeadLetterTest.java | 6 +- .../PerDurableConsumerDeadLetterTest.java | 14 +- .../PriorityNetworkDispatchPolicyTest.java | 13 +- .../policy/SimpleDispatchPolicyTest.java | 13 +- .../policy/StrictOrderDispatchPolicyTest.java | 13 +- .../activemq/broker/store/LoadTester.java | 10 +- .../bugs/amq1095/ActiveMQTestCase.java | 42 +- .../bugs/amq1095/MessageSelectorTest.java | 13 +- .../config/BrokerXmlConfigFromJNDITest.java | 5 +- .../config/ConfigUsingDestinationOptions.java | 5 +- .../console/command/TestPurgeCommand.java | 700 +++++++++--------- .../DestinationMapTempDestinationTest.java | 6 +- .../activemq/filter/DestinationMapTest.java | 9 +- .../apache/activemq/filter/DummyPolicy.java | 10 +- .../activemq/filter/DummyPolicyTest.java | 3 +- .../jndi/CustomConnectionFactoryNameTest.java | 9 +- .../jndi/DestinationNameWithSlashTest.java | 3 +- .../apache/activemq/jndi/JNDITestSupport.java | 19 +- .../apache/activemq/load/LoadController.java | 24 +- .../activemq/memory/MemoryPropertyTest.java | 24 +- .../network/CompressionOverNetworkTest.java | 4 +- .../network/DemandForwardingBridgeTest.java | 8 +- .../activemq/network/DuplexNetworkTest.java | 8 +- ...IncludedDestinationsDuplexNetworkTest.java | 17 +- .../NetworkConnectionsCleanedupTest.java | 57 +- .../activemq/network/NetworkFailoverTest.java | 9 +- .../NetworkRemovesSubscriptionsTest.java | 6 +- .../activemq/network/NetworkTestSupport.java | 20 +- .../SSHTunnelNetworkReconnectTest.java | 18 +- .../activemq/network/SimpleNetworkTest.java | 7 +- .../QueueBridgeStandaloneReconnectTest.java | 24 +- .../jms/QueueOutboundBridgeReconnectTest.java | 29 +- .../TopicBridgeStandaloneReconnectTest.java | 24 +- .../jms/TopicOutboundBridgeReconnectTest.java | 30 +- .../activemq/openwire/BooleanStreamTest.java | 9 +- .../activemq/openwire/DataFileGenerator.java | 25 +- .../DataFileGeneratorTestSupport.java | 13 +- .../NumberRangesWhileMarshallingTest.java | 6 +- 66 files changed, 1065 insertions(+), 993 deletions(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java index e1e9ce8281..353f1d3262 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java @@ -22,7 +22,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.Map; import javax.jms.ExceptionListener; import javax.jms.JMSException; @@ -83,7 +82,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { assertTrue(cf.isUseAsyncSend()); // the broker url have been adjusted. assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL()); - + cf = new ActiveMQConnectionFactory("vm://localhost?jms.auditDepth=5000"); assertEquals(5000, cf.getAuditDepth()); } @@ -142,7 +141,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception { broker = new BrokerService(); broker.setPersistent(false); - TransportConnector connector = broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); + broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); broker.start(); // This should create the connection. @@ -178,56 +177,58 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { cf = (ActiveMQConnectionFactory)objectsIn.readObject(); assertEquals(cf.getClientID(), clientID); } - + public void testSetExceptionListener() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); connection = (ActiveMQConnection)cf.createConnection(); assertNull(connection.getExceptionListener()); - + ExceptionListener exListener = new ExceptionListener() { - public void onException(JMSException arg0) { - } + @Override + public void onException(JMSException arg0) { + } }; cf.setExceptionListener(exListener); connection.close(); - + connection = (ActiveMQConnection)cf.createConnection(); assertNotNull(connection.getExceptionListener()); assertEquals(exListener, connection.getExceptionListener()); connection.close(); - + connection = (ActiveMQConnection)cf.createConnection(); assertEquals(exListener, connection.getExceptionListener()); - + assertEquals(exListener, cf.getExceptionListener()); connection.close(); - + } - + public void testSetClientInternalExceptionListener() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); connection = (ActiveMQConnection)cf.createConnection(); assertNull(connection.getClientInternalExceptionListener()); - + ClientInternalExceptionListener listener = new ClientInternalExceptionListener() { + @Override public void onException(Throwable exception) { } }; connection.setClientInternalExceptionListener(listener); cf.setClientInternalExceptionListener(listener); connection.close(); - + connection = (ActiveMQConnection)cf.createConnection(); assertNotNull(connection.getClientInternalExceptionListener()); assertEquals(listener, connection.getClientInternalExceptionListener()); connection.close(); - + connection = (ActiveMQConnection)cf.createConnection(); - assertEquals(listener, connection.getClientInternalExceptionListener()); + assertEquals(listener, connection.getClientInternalExceptionListener()); assertEquals(listener, cf.getClientInternalExceptionListener()); connection.close(); - + } protected void assertCreateConnection(String uri) throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java index 77405f85a6..cbf4af3886 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java @@ -20,25 +20,16 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.URI; -import java.net.URISyntaxException; import java.security.KeyStore; import java.security.SecureRandom; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.Session; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; -import org.apache.activemq.broker.BrokerRegistry; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.SslBrokerService; -import org.apache.activemq.broker.TransportConnector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,10 +41,10 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore"; public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore"; - private TransportConnector connector; private ActiveMQConnection connection; private BrokerService broker; + @Override protected void tearDown() throws Exception { // Try our best to close any previously opend connection. try { @@ -77,7 +68,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { assertNotNull(connection); connection.start(); connection.stop(); - brokerStop(); + brokerStop(); } public void testCreateFailoverTcpConnectionUsingKnownPort() throws Exception { @@ -90,12 +81,12 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { assertNotNull(connection); connection.start(); connection.stop(); - brokerStop(); + brokerStop(); } public void testCreateSslConnection() throws Exception { // Create SSL/TLS connection with trusted cert from truststore. - String sslUri = "ssl://localhost:61611"; + String sslUri = "ssl://localhost:61611"; broker = createSslBroker(sslUri); assertNotNull(broker); @@ -113,7 +104,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { public void testFailoverSslConnection() throws Exception { // Create SSL/TLS connection with trusted cert from truststore. - String sslUri = "ssl://localhost:61611"; + String sslUri = "ssl://localhost:61611"; broker = createSslBroker(sslUri); assertNotNull(broker); @@ -148,7 +139,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { public void testNegativeCreateSslConnectionWithWrongPassword() throws Exception { // Create SSL/TLS connection with trusted cert from truststore. - String sslUri = "ssl://localhost:61611"; + String sslUri = "ssl://localhost:61611"; broker = createSslBroker(sslUri); assertNotNull(broker); @@ -160,8 +151,8 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { connection = (ActiveMQConnection)cf.createConnection(); } catch (javax.jms.JMSException ignore) { - // Expected exception - LOG.info("Expected java.io.Exception [" + ignore + "]"); + // Expected exception + LOG.info("Expected java.io.Exception [" + ignore + "]"); } assertNull(connection); @@ -170,7 +161,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { public void testNegativeCreateSslConnectionWithWrongCert() throws Exception { // Create SSL/TLS connection with trusted cert from truststore. - String sslUri = "ssl://localhost:61611"; + String sslUri = "ssl://localhost:61611"; broker = createSslBroker(sslUri); assertNotNull(broker); @@ -182,8 +173,8 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { connection = (ActiveMQConnection)cf.createConnection(); } catch (javax.jms.JMSException ignore) { - // Expected exception - LOG.info("Expected SSLHandshakeException [" + ignore + "]"); + // Expected exception + LOG.info("Expected SSLHandshakeException [" + ignore + "]"); } assertNull(connection); @@ -195,26 +186,26 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { BrokerService service = new BrokerService(); service.setPersistent(false); service.setUseJmx(false); - connector = service.addConnector(uri); + service.addConnector(uri); service.start(); return service; } protected BrokerService createSslBroker(String uri) throws Exception { - + // http://java.sun.com/javase/javaseforbusiness/docs/TLSReadme.html // work around: javax.net.ssl.SSLHandshakeException: renegotiation is not allowed //System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true"); - + SslBrokerService service = new SslBrokerService(); service.setPersistent(false); - + KeyManager[] km = getKeyManager(); TrustManager[] tm = getTrustManager(); - connector = service.addSslConnector(uri, km, tm, null); + service.addSslConnector(uri, km, tm, null); service.start(); - + return service; } @@ -225,32 +216,32 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { public static TrustManager[] getTrustManager() throws Exception { TrustManager[] trustStoreManagers = null; KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE); - + trustedCertStore.load(new FileInputStream(ActiveMQSslConnectionFactoryTest.TRUST_KEYSTORE), null); - TrustManagerFactory tmf = + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - + tmf.init(trustedCertStore); trustStoreManagers = tmf.getTrustManagers(); - return trustStoreManagers; + return trustStoreManagers; } public static KeyManager[] getKeyManager() throws Exception { - KeyManagerFactory kmf = - KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + KeyManagerFactory kmf = + KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); KeyStore ks = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE); KeyManager[] keystoreManagers = null; - + byte[] sslCert = loadClientCredential(ActiveMQSslConnectionFactoryTest.SERVER_KEYSTORE); - - + + if (sslCert != null && sslCert.length > 0) { ByteArrayInputStream bin = new ByteArrayInputStream(sslCert); ks.load(bin, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray()); kmf.init(ks, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray()); keystoreManagers = kmf.getKeyManagers(); } - return keystoreManagers; + return keystoreManagers; } private static byte[] loadClientCredential(String fileName) throws IOException { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ClientTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ClientTestSupport.java index 00a69382dd..eafe359540 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ClientTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ClientTestSupport.java @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.jms.JMSException; import junit.framework.TestCase; + import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; @@ -48,8 +49,9 @@ public class ClientTestSupport extends TestCase { protected long idGenerator; private ActiveMQConnectionFactory connFactory; - private String brokerURL = "vm://localhost?broker.persistent=false"; + private final String brokerURL = "vm://localhost?broker.persistent=false"; + @Override public void setUp() throws Exception { final AtomicBoolean connected = new AtomicBoolean(false); TransportConnector connector; @@ -57,10 +59,11 @@ public class ClientTestSupport extends TestCase { // Start up a broker with a tcp connector. try { broker = BrokerFactory.createBroker(new URI(this.brokerURL)); - String brokerId = broker.getBrokerName(); + broker.getBrokerName(); connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) { // Hook into the connector so we can assert that the server // accepted a connection. + @Override protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException { connected.set(true); return super.createConnection(transport); @@ -82,6 +85,7 @@ public class ClientTestSupport extends TestCase { connFactory = new ActiveMQConnectionFactory(connectURI); } + @Override protected void tearDown() throws Exception { super.tearDown(); if (broker != null) { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java index 7e53660c1a..fefab252d7 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java @@ -65,12 +65,12 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { private static final Logger LOG = LoggerFactory.getLogger(CombinationTestSupport.class); - private HashMap comboOptions = new HashMap(); + private final HashMap comboOptions = new HashMap(); private boolean combosEvaluated; private Map options; protected File basedir; - static protected File basedir(Class clazz) { + static protected File basedir(Class clazz) { try { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); return new File(new File(protectionDomain.getCodeSource().getLocation().getPath()), "../..").getCanonicalFile(); @@ -101,6 +101,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { } } + @Override public void runBare() throws Throwable { if (combosEvaluated) { super.runBare(); @@ -253,6 +254,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE); } + @Override public String getName() { return getName(false); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerStartupDestinationTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerStartupDestinationTest.java index 7c43dd729d..7aa22e36a2 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerStartupDestinationTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerStartupDestinationTest.java @@ -23,7 +23,7 @@ import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; -import junit.framework.Assert; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyMap; @@ -33,6 +33,7 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS private static final String VM_BROKER_URL = "vm://localhost"; + @Override protected BrokerService createBroker() throws Exception { BrokerService answer = new BrokerService(); answer.setPersistent(false); @@ -40,7 +41,7 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS PolicyEntry entry = new PolicyEntry(); entry.setAllConsumersExclusiveByDefault(true); map.setDefaultEntry(entry); - answer.setDestinationPolicy(map); + answer.setDestinationPolicy(map); return answer; } @@ -87,15 +88,13 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); - + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); senderSession.close(); conn.close(); } - } public void testFailoverToAnotherExclusiveConsumerCreatedFirst() throws JMSException, @@ -132,9 +131,9 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer1.receive(100)); - Assert.assertNull(exclusiveConsumer2.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer1.receive(100)); + assertNull(exclusiveConsumer2.receive(100)); + assertNull(fallbackConsumer.receive(100)); // Close the exclusive consumer to verify the non-exclusive consumer // takes over @@ -143,8 +142,8 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS producer.send(msg); producer.send(msg); - Assert.assertNotNull("Should have received a message", exclusiveConsumer2.receive(100)); - Assert.assertNull("Should not have received a message", fallbackConsumer.receive(100)); + assertNotNull("Should have received a message", exclusiveConsumer2.receive(100)); + assertNull("Should not have received a message", fallbackConsumer.receive(100)); } finally { fallbackSession.close(); @@ -184,8 +183,8 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); // Close the exclusive consumer to verify the non-exclusive consumer // takes over @@ -193,14 +192,12 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS producer.send(msg); - Assert.assertNotNull(fallbackConsumer.receive(100)); + assertNotNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); senderSession.close(); conn.close(); } - } - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerTest.java index 58ea18a3ca..757fceb678 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ExclusiveConsumerTest.java @@ -24,8 +24,8 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; -import junit.framework.Assert; import junit.framework.TestCase; + import org.apache.activemq.command.ActiveMQQueue; public class ExclusiveConsumerTest extends TestCase { @@ -36,10 +36,12 @@ public class ExclusiveConsumerTest extends TestCase { super(name); } + @Override protected void setUp() throws Exception { super.setUp(); } + @Override protected void tearDown() throws Exception { super.tearDown(); } @@ -83,8 +85,8 @@ public class ExclusiveConsumerTest extends TestCase { Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); @@ -122,8 +124,8 @@ public class ExclusiveConsumerTest extends TestCase { Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); @@ -167,9 +169,9 @@ public class ExclusiveConsumerTest extends TestCase { Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer1.receive(100)); - Assert.assertNull(exclusiveConsumer2.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer1.receive(100)); + assertNull(exclusiveConsumer2.receive(100)); + assertNull(fallbackConsumer.receive(100)); // Close the exclusive consumer to verify the non-exclusive consumer // takes over @@ -178,8 +180,8 @@ public class ExclusiveConsumerTest extends TestCase { producer.send(msg); producer.send(msg); - Assert.assertNotNull(exclusiveConsumer2.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer2.receive(100)); + assertNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); @@ -224,9 +226,9 @@ public class ExclusiveConsumerTest extends TestCase { Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer1.receive(100)); - Assert.assertNull(exclusiveConsumer2.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer1.receive(100)); + assertNull(exclusiveConsumer2.receive(100)); + assertNull(fallbackConsumer.receive(100)); // Close the exclusive consumer to verify the non-exclusive consumer // takes over @@ -235,8 +237,8 @@ public class ExclusiveConsumerTest extends TestCase { producer.send(msg); producer.send(msg); - Assert.assertNotNull(exclusiveConsumer2.receive(1000)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer2.receive(1000)); + assertNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); @@ -276,8 +278,8 @@ public class ExclusiveConsumerTest extends TestCase { Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); // Close the exclusive consumer to verify the non-exclusive consumer // takes over @@ -285,7 +287,7 @@ public class ExclusiveConsumerTest extends TestCase { producer.send(msg); - Assert.assertNotNull(fallbackConsumer.receive(100)); + assertNotNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); @@ -325,8 +327,8 @@ public class ExclusiveConsumerTest extends TestCase { Thread.sleep(100); // Verify exclusive consumer receives the message. - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); // Close the exclusive consumer to verify the non-exclusive consumer // takes over @@ -335,15 +337,15 @@ public class ExclusiveConsumerTest extends TestCase { producer.send(msg); // Verify other non-exclusive consumer receices the message. - Assert.assertNotNull(fallbackConsumer.receive(100)); + assertNotNull(fallbackConsumer.receive(100)); // Create exclusive consumer to determine if it will start receiving // the messages. exclusiveConsumer = exclusiveSession.createConsumer(exclusiveQueue); producer.send(msg); - Assert.assertNotNull(exclusiveConsumer.receive(100)); - Assert.assertNull(fallbackConsumer.receive(100)); + assertNotNull(exclusiveConsumer.receive(100)); + assertNull(fallbackConsumer.receive(100)); } finally { fallbackSession.close(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JMSConsumerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JMSConsumerTest.java index 39bd65584b..a6bc997ef7 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JMSConsumerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JMSConsumerTest.java @@ -36,7 +36,9 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import javax.management.ObjectName; + import junit.framework.Test; + import org.apache.activemq.broker.jmx.DestinationViewMBean; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; @@ -45,8 +47,8 @@ import org.slf4j.LoggerFactory; /** * Test cases used to test the JMS message consumer. - * - * + * + * */ public class JMSConsumerTest extends JmsTestSupport { @@ -85,6 +87,7 @@ public class JMSConsumerTest extends JmsTestSupport { destination = createDestination(session, destinationType); ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { counter.incrementAndGet(); if (counter.get() == 1) { @@ -121,35 +124,37 @@ public class JMSConsumerTest extends JmsTestSupport { final AtomicInteger counter = new AtomicInteger(0); final CountDownLatch closeDone = new CountDownLatch(1); - + connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); // preload the queue sendMessages(session, destination, 2000); - + final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination); - - final Map exceptions = + + final Map exceptions = Collections.synchronizedMap(new HashMap()); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { + @Override public void uncaughtException(Thread t, Throwable e) { LOG.error("Uncaught exception:", e); exceptions.put(t, e); } }); - - final class AckAndClose implements Runnable { - private Message message; + + final class AckAndClose implements Runnable { + private final Message message; public AckAndClose(Message m) { this.message = m; } + @Override public void run() { - try { + try { int count = counter.incrementAndGet(); if (count == 590) { // close in a separate thread is ok by jms @@ -161,16 +166,17 @@ public class JMSConsumerTest extends JmsTestSupport { // ack every 200 message.acknowledge(); } - } catch (Exception e) { + } catch (Exception e) { LOG.error("Exception on close or ack:", e); exceptions.put(Thread.currentThread(), e); - } - } + } + } }; - + final ExecutorService executor = Executors.newCachedThreadPool(); consumer.setMessageListener(new MessageListener() { - public void onMessage(Message m) { + @Override + public void onMessage(Message m) { // ack and close eventually in separate thread executor.execute(new AckAndClose(m)); } @@ -182,7 +188,7 @@ public class JMSConsumerTest extends JmsTestSupport { assertTrue("no exceptions: " + exceptions, exceptions.isEmpty()); } - + public void initCombosForTestMutiReceiveWithPrefetch1() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.AUTO_ACKNOWLEDGE), Integer.valueOf(Session.DUPS_OK_ACKNOWLEDGE), @@ -310,6 +316,7 @@ public class JMSConsumerTest extends JmsTestSupport { // See if the message get sent to the listener consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { counter.incrementAndGet(); if (counter.get() == 4) { @@ -339,6 +346,7 @@ public class JMSConsumerTest extends JmsTestSupport { ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination, new MessageListener() { + @Override public void onMessage(Message m) { counter.incrementAndGet(); if (counter.get() == 4) { @@ -346,6 +354,7 @@ public class JMSConsumerTest extends JmsTestSupport { } } }); + assertNotNull(consumer); // Send the messages sendMessages(session, destination, 4); @@ -357,14 +366,14 @@ public class JMSConsumerTest extends JmsTestSupport { assertEquals(4, counter.get()); } - public void initCombosForTestMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() { + public void initCombosForTestMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.CLIENT_ACKNOWLEDGE)}); addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE)}); } public void testMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() throws Exception { - + final AtomicInteger counter = new AtomicInteger(0); final CountDownLatch sendDone = new CountDownLatch(1); final CountDownLatch got2Done = new CountDownLatch(1); @@ -383,6 +392,7 @@ public class JMSConsumerTest extends JmsTestSupport { destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { try { TextMessage tm = (TextMessage)m; @@ -420,6 +430,7 @@ public class JMSConsumerTest extends JmsTestSupport { session = connection.createSession(false, ackMode); consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { try { TextMessage tm = (TextMessage)m; @@ -440,7 +451,7 @@ public class JMSConsumerTest extends JmsTestSupport { Thread.sleep(200); // assert msg 2 was redelivered as close() from onMessages() will only ack in auto_ack and dups_ok mode - assertEquals(5, counter.get()); + assertEquals(5, counter.get()); } public void initCombosForTestMessageListenerAutoAckOnCloseWithPrefetch1() { @@ -450,7 +461,7 @@ public class JMSConsumerTest extends JmsTestSupport { } public void testMessageListenerAutoAckOnCloseWithPrefetch1() throws Exception { - + final AtomicInteger counter = new AtomicInteger(0); final CountDownLatch sendDone = new CountDownLatch(1); final CountDownLatch got2Done = new CountDownLatch(1); @@ -469,6 +480,7 @@ public class JMSConsumerTest extends JmsTestSupport { destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { try { TextMessage tm = (TextMessage)m; @@ -506,6 +518,7 @@ public class JMSConsumerTest extends JmsTestSupport { session = connection.createSession(false, ackMode); consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { try { TextMessage tm = (TextMessage)m; @@ -547,6 +560,7 @@ public class JMSConsumerTest extends JmsTestSupport { destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { counter.incrementAndGet(); if (counter.get() == 4) { @@ -582,6 +596,7 @@ public class JMSConsumerTest extends JmsTestSupport { destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message m) { counter.incrementAndGet(); if (counter.get() == 4) { @@ -756,7 +771,7 @@ public class JMSConsumerTest extends JmsTestSupport { assertNull(consumer.receiveNoWait()); } - + public void testDupsOkConsumer() throws Exception { // Receive a message with the JMS API @@ -774,10 +789,10 @@ public class JMSConsumerTest extends JmsTestSupport { assertNotNull(m); } assertNull(consumer.receive(1000)); - + // Close out the consumer.. no other messages should be left on the queue. consumer.close(); - + consumer = session.createConsumer(destination); assertNull(consumer.receive(1000)); } @@ -787,55 +802,55 @@ public class JMSConsumerTest extends JmsTestSupport { connection.start(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); - + sendMessages(connection, destination, 2); - + MessageConsumer consumer = session.createConsumer(destination); assertNotNull(consumer.receive(1000)); assertNotNull(consumer.receive(1000)); - + // install another consumer while message dispatch is unacked/uncommitted Session redispatchSession = connection.createSession(true, Session.SESSION_TRANSACTED); MessageConsumer redispatchConsumer = redispatchSession.createConsumer(destination); // no commit so will auto rollback and get re-dispatched to redisptachConsumer session.close(); - + Message msg = redispatchConsumer.receive(1000); assertNotNull(msg); assertTrue("redelivered flag set", msg.getJMSRedelivered()); assertEquals(2, msg.getLongProperty("JMSXDeliveryCount")); - + msg = redispatchConsumer.receive(1000); assertNotNull(msg); assertTrue(msg.getJMSRedelivered()); assertEquals(2, msg.getLongProperty("JMSXDeliveryCount")); redispatchSession.commit(); - + assertNull(redispatchConsumer.receive(500)); redispatchSession.close(); } - + public void testRedispatchOfRolledbackTx() throws Exception { connection.start(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); - + sendMessages(connection, destination, 2); - + MessageConsumer consumer = session.createConsumer(destination); assertNotNull(consumer.receive(1000)); assertNotNull(consumer.receive(1000)); - + // install another consumer while message dispatch is unacked/uncommitted Session redispatchSession = connection.createSession(true, Session.SESSION_TRANSACTED); MessageConsumer redispatchConsumer = redispatchSession.createConsumer(destination); session.rollback(); session.close(); - + Message msg = redispatchConsumer.receive(1000); assertNotNull(msg); assertTrue(msg.getJMSRedelivered()); @@ -845,31 +860,31 @@ public class JMSConsumerTest extends JmsTestSupport { assertTrue(msg.getJMSRedelivered()); assertEquals(2, msg.getLongProperty("JMSXDeliveryCount")); redispatchSession.commit(); - + assertNull(redispatchConsumer.receive(500)); redispatchSession.close(); } - - + + public void initCombosForTestAckOfExpired() { - addCombinationValues("destinationType", + addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)}); } - + public void testAckOfExpired() throws Exception { - + ActiveMQConnectionFactory fact = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=4&jms.sendAcksAsync=false"); connection = fact.createActiveMQConnection(); - + connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = (ActiveMQDestination) (destinationType == ActiveMQDestination.QUEUE_TYPE ? session.createQueue("test") : session.createTopic("test")); - + MessageConsumer consumer = session.createConsumer(destination); connection.setStatsEnabled(true); - - Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sendSession.createProducer(destination); producer.setTimeToLive(1000); final int count = 4; @@ -877,37 +892,37 @@ public class JMSConsumerTest extends JmsTestSupport { TextMessage message = sendSession.createTextMessage("" + i); producer.send(message); } - + // let first bunch in queue expire Thread.sleep(2000); - + producer.setTimeToLive(0); for (int i = 0; i < count; i++) { TextMessage message = sendSession.createTextMessage("no expiry" + i); producer.send(message); } - + ActiveMQMessageConsumer amqConsumer = (ActiveMQMessageConsumer) consumer; - + for(int i=0; i getPropertyNames() throws JMSException { return new Vector(props.keySet()).elements(); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsBenchmark.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsBenchmark.java index 31178f7b7e..52a70a0791 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsBenchmark.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsBenchmark.java @@ -37,9 +37,9 @@ import javax.jms.MessageProducer; import javax.jms.Session; import junit.framework.Test; + import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.slf4j.Logger; @@ -50,8 +50,8 @@ import org.slf4j.LoggerFactory; * same destination. Make sure you run with jvm option -server (makes a big * difference). The tests simulate storing 1000 1k jms messages to see the rate * of processing msg/sec. - * - * + * + * */ public class JmsBenchmark extends JmsTestSupport { private static final transient Logger LOG = LoggerFactory.getLogger(JmsBenchmark.class); @@ -76,12 +76,14 @@ public class JmsBenchmark extends JmsTestSupport { addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST")}); } + @Override protected BrokerService createBroker() throws Exception { return BrokerFactory.createBroker(new URI("broker://(tcp://localhost:0)?persistent=false")); } + @Override protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException { - return new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getServer().getConnectURI()); + return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI()); } /** @@ -96,7 +98,8 @@ public class JmsBenchmark extends JmsTestSupport { final AtomicInteger producedMessages = new AtomicInteger(0); final AtomicInteger receivedMessages = new AtomicInteger(0); - final Callable producer = new Callable() { + final Callable producer = new Callable() { + @Override public Object call() throws JMSException, InterruptedException { Connection connection = factory.createConnection(); connections.add(connection); @@ -119,7 +122,8 @@ public class JmsBenchmark extends JmsTestSupport { } }; - final Callable consumer = new Callable() { + final Callable consumer = new Callable() { + @Override public Object call() throws JMSException, InterruptedException { Connection connection = factory.createConnection(); connections.add(connection); @@ -127,6 +131,7 @@ public class JmsBenchmark extends JmsTestSupport { MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message msg) { receivedMessages.incrementAndGet(); } @@ -145,6 +150,7 @@ public class JmsBenchmark extends JmsTestSupport { final Throwable workerError[] = new Throwable[1]; for (int i = 0; i < PRODUCER_COUNT; i++) { new Thread("Producer:" + i) { + @Override public void run() { try { producer.call(); @@ -158,6 +164,7 @@ public class JmsBenchmark extends JmsTestSupport { for (int i = 0; i < CONSUMER_COUNT; i++) { new Thread("Consumer:" + i) { + @Override public void run() { try { consumer.call(); @@ -198,7 +205,5 @@ public class JmsBenchmark extends JmsTestSupport { if (workerError[0] != null) { throw workerError[0]; } - } - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsConnectionStartStopTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsConnectionStartStopTest.java index 0a1a742625..c972b1e0d7 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsConnectionStartStopTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsConnectionStartStopTest.java @@ -18,13 +18,10 @@ package org.apache.activemq; import java.util.Random; import java.util.Vector; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; + import javax.jms.Connection; import javax.jms.JMSException; import javax.jms.Message; @@ -35,7 +32,7 @@ import javax.jms.TextMessage; import javax.jms.Topic; /** - * + * */ public class JmsConnectionStartStopTest extends TestSupport { @@ -48,6 +45,7 @@ public class JmsConnectionStartStopTest extends TestSupport { /** * @see junit.framework.TestCase#setUp() */ + @Override protected void setUp() throws Exception { LOG.info(getClass().getClassLoader().getResource("log4j.properties")); @@ -61,6 +59,7 @@ public class JmsConnectionStartStopTest extends TestSupport { /** * @see junit.framework.TestCase#tearDown() */ + @Override protected void tearDown() throws Exception { stoppedConnection.close(); startedConnection.close(); @@ -69,7 +68,7 @@ public class JmsConnectionStartStopTest extends TestSupport { /** * Tests if the consumer receives the messages that were sent before the * connection was started. - * + * * @throws JMSException */ public void testStoppedConsumerHoldsMessagesTillStarted() throws JMSException { @@ -104,7 +103,7 @@ public class JmsConnectionStartStopTest extends TestSupport { /** * Tests if the consumer is able to receive messages eveb when the * connecction restarts multiple times. - * + * * @throws Exception */ public void testMultipleConnectionStops() throws Exception { @@ -123,6 +122,7 @@ public class JmsConnectionStartStopTest extends TestSupport { final Vector exceptions = new Vector(); final Random rand = new Random(); Runnable createSessionTask = new Runnable() { + @Override public void run() { try { TimeUnit.MILLISECONDS.sleep(rand.nextInt(10)); @@ -134,6 +134,7 @@ public class JmsConnectionStartStopTest extends TestSupport { }; Runnable startStopTask = new Runnable() { + @Override public void run() { try { TimeUnit.MILLISECONDS.sleep(rand.nextInt(10)); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java index c262c7d687..f513bf0071 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java @@ -19,18 +19,19 @@ package org.apache.activemq; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; + import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; -import javax.jms.Queue; import javax.jms.QueueBrowser; import javax.jms.Session; -import javax.jms.Connection; import javax.jms.TextMessage; import javax.management.ObjectName; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; + import junit.framework.Test; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.jmx.QueueViewMBean; import org.apache.activemq.broker.region.BaseDestination; @@ -39,7 +40,7 @@ import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.command.ActiveMQQueue; /** - * + * */ public class JmsQueueBrowserTest extends JmsTestSupport { private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory @@ -80,16 +81,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport { consumer.close(); //Thread.sleep(200); - QueueBrowser browser = session.createBrowser((Queue) destination); - Enumeration enumeration = browser.getEnumeration(); + QueueBrowser browser = session.createBrowser(destination); + Enumeration enumeration = browser.getEnumeration(); // browse the second assertTrue("should have received the second message", enumeration.hasMoreElements()); - assertEquals(outbound[1], (Message) enumeration.nextElement()); + assertEquals(outbound[1], enumeration.nextElement()); // browse the third. assertTrue("Should have received the third message", enumeration.hasMoreElements()); - assertEquals(outbound[2], (Message) enumeration.nextElement()); + assertEquals(outbound[2], enumeration.nextElement()); // There should be no more. boolean tooMany = false; @@ -135,8 +136,8 @@ public class JmsQueueBrowserTest extends JmsTestSupport { producer.send(outbound[i]); } - QueueBrowser browser = session.createBrowser((Queue) destination); - Enumeration enumeration = browser.getEnumeration(); + QueueBrowser browser = session.createBrowser(destination); + Enumeration enumeration = browser.getEnumeration(); for (int i=0; i enumeration = browser.getEnumeration(); // browse the first message assertTrue("should have received the first message", enumeration.hasMoreElements()); - assertEquals(outbound[0], (Message) enumeration.nextElement()); - + assertEquals(outbound[0], enumeration.nextElement()); + // Receive the first message. assertEquals(outbound[0], consumer.receive(1000)); consumer.close(); @@ -317,7 +318,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport { } QueueBrowser browser = session.createBrowser(destination); - Enumeration enumeration = browser.getEnumeration(); + Enumeration enumeration = browser.getEnumeration(); assertTrue(enumeration.hasMoreElements()); @@ -334,14 +335,14 @@ public class JmsQueueBrowserTest extends JmsTestSupport { producer.close(); } - + public void testQueueBrowserWith2Consumers() throws Exception { final int numMessages = 1000; connection.setAlwaysSyncSend(false); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); ActiveMQQueue destination = new ActiveMQQueue("TEST"); ActiveMQQueue destinationPrefetch10 = new ActiveMQQueue("TEST?jms.prefetchSize=10"); - ActiveMQQueue destinationPrefetch1 = new ActiveMQQueue("TEST?jms.prefetchsize=1"); + ActiveMQQueue destinationPrefetch1 = new ActiveMQQueue("TEST?jms.prefetchsize=1"); connection.start(); ActiveMQConnection connection2 = (ActiveMQConnection)factory.createConnection(userName, password); @@ -355,15 +356,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport { // lets consume any outstanding messages from previous test runs while (consumer.receive(1000) != null) { } - + for (int i=0; i browserView = browser.getEnumeration(); - + List messages = new ArrayList(); for (int i = 0; i < numMessages; i++) { Message m1 = consumer.receive(5000); @@ -378,7 +380,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport { assertNotNull("m2 is null for index: " + i, m2); assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID()); } - + // currently browse max page size is ignored for a queue browser consumer // only guarantee is a page size - but a snapshot of pagedinpending is // used so it is most likely more @@ -412,19 +414,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport { // create browser first - QueueBrowser browser = session.createBrowser((Queue) destination); - Enumeration enumeration = browser.getEnumeration(); - + QueueBrowser browser = session.createBrowser(destination); + Enumeration enumeration = browser.getEnumeration(); // browse some messages - assertEquals(outbound[0], (Message) enumeration.nextElement()); - assertEquals(outbound[1], (Message) enumeration.nextElement()); + assertEquals(outbound[0], enumeration.nextElement()); + assertEquals(outbound[1], enumeration.nextElement()); //assertEquals(outbound[2], (Message) enumeration.nextElement()); - browser.close(); - // Receive the first message. TextMessage msg = (TextMessage)consumer.receive(1000); assertEquals("Expected " + outbound[0].getText() + " but received " + msg.getText(), outbound[0], msg); @@ -435,9 +434,9 @@ public class JmsQueueBrowserTest extends JmsTestSupport { consumer.close(); producer.close(); - } + @Override protected BrokerService createBroker() throws Exception { BrokerService brokerService = super.createBroker(); PolicyMap policyMap = new PolicyMap(); @@ -447,5 +446,4 @@ public class JmsQueueBrowserTest extends JmsTestSupport { brokerService.setDestinationPolicy(policyMap); return brokerService; } - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java index ea318dd498..f29cc09e6c 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java @@ -17,19 +17,18 @@ package org.apache.activemq; import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * + * */ public class JmsQueueSendReceiveTwoConnectionsTest extends JmsTopicSendReceiveWithTwoConnectionsTest { /** * Set up the test with a queue and using two connections. - * + * * @see junit.framework.TestCase#setUp() */ + @Override protected void setUp() throws Exception { topic = false; super.setUp(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTempDestinationTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTempDestinationTest.java index 3029f455f3..bd87b3daa8 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTempDestinationTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTempDestinationTest.java @@ -40,6 +40,7 @@ import javax.jms.TemporaryQueue; import javax.jms.TextMessage; import junit.framework.TestCase; + import org.apache.activemq.transport.TransportListener; import org.apache.activemq.transport.vm.VMTransport; import org.apache.activemq.util.Wait; @@ -56,6 +57,7 @@ public class JmsTempDestinationTest extends TestCase { private ActiveMQConnectionFactory factory; protected List connections = Collections.synchronizedList(new ArrayList()); + @Override protected void setUp() throws Exception { factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); factory.setAlwaysSyncSend(true); @@ -66,9 +68,10 @@ public class JmsTempDestinationTest extends TestCase { /** * @see junit.framework.TestCase#tearDown() */ + @Override protected void tearDown() throws Exception { - for (Iterator iter = connections.iterator(); iter.hasNext();) { - Connection conn = (Connection)iter.next(); + for (Iterator iter = connections.iterator(); iter.hasNext();) { + Connection conn = iter.next(); try { conn.close(); } catch (Throwable e) { @@ -79,7 +82,7 @@ public class JmsTempDestinationTest extends TestCase { /** * Make sure Temp destination can only be consumed by local connection - * + * * @throws JMSException */ public void testTempDestOnlyConsumedByLocalConn() throws JMSException { @@ -120,7 +123,7 @@ public class JmsTempDestinationTest extends TestCase { /** * Make sure that a temp queue does not drop message if there is an active * consumers. - * + * * @throws JMSException */ public void testTempQueueHoldsMessagesWithConsumers() throws JMSException { @@ -143,7 +146,7 @@ public class JmsTempDestinationTest extends TestCase { /** * Make sure that a temp queue does not drop message if there are no active * consumers. - * + * * @throws JMSException */ public void testTempQueueHoldsMessagesWithoutConsumers() throws JMSException { @@ -166,14 +169,14 @@ public class JmsTempDestinationTest extends TestCase { /** * Test temp queue works under load - * + * * @throws JMSException */ public void testTmpQueueWorksUnderLoad() throws JMSException { int count = 500; int dataSize = 1024; - ArrayList list = new ArrayList(count); + ArrayList list = new ArrayList(count); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); MessageProducer producer = session.createProducer(queue); @@ -201,13 +204,13 @@ public class JmsTempDestinationTest extends TestCase { /** * Make sure you cannot publish to a temp destination that does not exist * anymore. - * + * * @throws JMSException * @throws InterruptedException - * @throws URISyntaxException + * @throws URISyntaxException */ public void testPublishFailsForClosedConnection() throws Exception { - + Connection tempConnection = factory.createConnection(); connections.add(tempConnection); Session tempSession = tempConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -249,7 +252,7 @@ public class JmsTempDestinationTest extends TestCase { /** * Make sure you cannot publish to a temp destination that does not exist * anymore. - * + * * @throws JMSException * @throws InterruptedException */ @@ -295,7 +298,7 @@ public class JmsTempDestinationTest extends TestCase { /** * Test you can't delete a Destination with Active Subscribers - * + * * @throws JMSException */ public void testDeleteDestinationWithSubscribersFails() throws JMSException { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/LargeStreamletTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/LargeStreamletTest.java index 9a0ed483e8..d624d368c5 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/LargeStreamletTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/LargeStreamletTest.java @@ -42,8 +42,8 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.jms.Destination; import javax.jms.Session; -import junit.framework.Assert; import junit.framework.TestCase; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,9 +60,9 @@ public final class LargeStreamletTest extends TestCase { protected Exception writerException; protected Exception readerException; - private AtomicInteger totalRead = new AtomicInteger(); - private AtomicInteger totalWritten = new AtomicInteger(); - private AtomicBoolean stopThreads = new AtomicBoolean(false); + private final AtomicInteger totalRead = new AtomicInteger(); + private final AtomicInteger totalWritten = new AtomicInteger(); + private final AtomicBoolean stopThreads = new AtomicBoolean(false); public void testStreamlets() throws Exception { final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL); @@ -75,6 +75,7 @@ public final class LargeStreamletTest extends TestCase { final Destination destination = session.createQueue("wibble"); final Thread readerThread = new Thread(new Runnable() { + @Override public void run() { totalRead.set(0); try { @@ -100,6 +101,7 @@ public final class LargeStreamletTest extends TestCase { final Thread writerThread = new Thread(new Runnable() { private final Random random = new Random(); + @Override public void run() { totalWritten.set(0); int count = MESSAGE_COUNT; @@ -147,7 +149,7 @@ public final class LargeStreamletTest extends TestCase { assertTrue("Should not have received a reader exception", readerException == null); assertTrue("Should not have received a writer exception", writerException == null); - Assert.assertEquals("Not all messages accounted for", totalWritten.get(), totalRead.get()); + assertEquals("Not all messages accounted for", totalWritten.get(), totalRead.get()); } finally { session.close(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java index b4a6e196c8..b079070296 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java @@ -16,10 +16,10 @@ */ package org.apache.activemq; -import static junit.framework.Assert.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.List; @@ -41,7 +41,6 @@ import javax.jms.Topic; import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.region.policy.ConstantPendingMessageLimitStrategy; import org.apache.activemq.broker.region.policy.FilePendingSubscriberMessageStoragePolicy; import org.apache.activemq.broker.region.policy.OldestMessageEvictionStrategy; @@ -53,10 +52,10 @@ import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.util.Wait; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.junit.After; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MessageEvictionTest { static final Logger LOG = LoggerFactory.getLogger(MessageEvictionTest.class); @@ -78,45 +77,47 @@ public class MessageEvictionTest { session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); destination = session.createTopic(destinationName); } - + @After public void tearDown() throws Exception { connection.stop(); broker.stop(); } - + @Test public void testMessageEvictionMemoryUsageFileCursor() throws Exception { setUp(new FilePendingSubscriberMessageStoragePolicy()); doTestMessageEvictionMemoryUsage(); } - + @Test public void testMessageEvictionMemoryUsageVmCursor() throws Exception { setUp(new VMPendingSubscriberMessageStoragePolicy()); doTestMessageEvictionMemoryUsage(); } - + @Test public void testMessageEvictionDiscardedAdvisory() throws Exception { setUp(new VMPendingSubscriberMessageStoragePolicy()); - + ExecutorService executor = Executors.newSingleThreadExecutor(); final CountDownLatch consumerRegistered = new CountDownLatch(1); final CountDownLatch gotAdvisory = new CountDownLatch(1); final CountDownLatch advisoryIsGood = new CountDownLatch(1); - + executor.execute(new Runnable() { + @Override public void run() { try { - ActiveMQTopic discardedAdvisoryDestination = + ActiveMQTopic discardedAdvisoryDestination = AdvisorySupport.getMessageDiscardedAdvisoryTopic(destination); - // use separate session rather than asyncDispatch on consumer session + // use separate session rather than asyncDispatch on consumer session // as we want consumer session to block Session advisorySession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageConsumer consumer = advisorySession.createConsumer(discardedAdvisoryDestination); consumer.setMessageListener(new MessageListener() { int advisoriesReceived = 0; + @Override public void onMessage(Message message) { try { LOG.info("advisory:" + message); @@ -131,7 +132,7 @@ public class MessageEvictionTest { } finally { gotAdvisory.countDown(); } - } + } }); consumerRegistered.countDown(); gotAdvisory.await(120, TimeUnit.SECONDS); @@ -148,18 +149,20 @@ public class MessageEvictionTest { assertTrue("got an advisory for discarded", gotAdvisory.await(0, TimeUnit.SECONDS)); assertTrue("advisory is good",advisoryIsGood.await(0, TimeUnit.SECONDS)); } - + public void doTestMessageEvictionMemoryUsage() throws Exception { - + ExecutorService executor = Executors.newCachedThreadPool(); final CountDownLatch doAck = new CountDownLatch(1); final CountDownLatch ackDone = new CountDownLatch(1); final CountDownLatch consumerRegistered = new CountDownLatch(1); executor.execute(new Runnable() { + @Override public void run() { try { final MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message message) { try { // very slow, only ack once @@ -168,13 +171,13 @@ public class MessageEvictionTest { message.acknowledge(); ackDone.countDown(); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); fail(e.toString()); } finally { consumerRegistered.countDown(); ackDone.countDown(); } - } + } }); consumerRegistered.countDown(); ackDone.await(60, TimeUnit.SECONDS); @@ -185,12 +188,13 @@ public class MessageEvictionTest { } } }); - + assertTrue("we have a consumer", consumerRegistered.await(10, TimeUnit.SECONDS)); - + final AtomicInteger sent = new AtomicInteger(0); final CountDownLatch sendDone = new CountDownLatch(1); executor.execute(new Runnable() { + @Override public void run() { MessageProducer producer; try { @@ -209,17 +213,18 @@ public class MessageEvictionTest { } } }); - + assertTrue("messages sending done", sendDone.await(180, TimeUnit.SECONDS)); assertEquals("all message were sent", numMessages, sent.get()); - + doAck.countDown(); executor.shutdown(); executor.awaitTermination(30, TimeUnit.SECONDS); - + assertTrue("usage goes to 0 once consumer goes away", Wait.waitFor(new Wait.Condition() { + @Override public boolean isSatisified() throws Exception { - return 0 == TestSupport.getDestination(broker, + return 0 == TestSupport.getDestination(broker, ActiveMQDestination.transform(destination)).getMemoryUsage().getPercentUsage(); } })); @@ -230,22 +235,22 @@ public class MessageEvictionTest { brokerService.addConnector("tcp://localhost:0"); brokerService.setUseJmx(false); brokerService.setDeleteAllMessagesOnStartup(true); - + // spooling to disk early so topic memory limit is not reached brokerService.getSystemUsage().getMemoryUsage().setLimit(500*1024); - + final List policyEntries = new ArrayList(); final PolicyEntry entry = new PolicyEntry(); entry.setTopic(">"); - + entry.setAdvisoryForDiscardingMessages(true); - + // so consumer does not get over run while blocked limit the prefetch entry.setTopicPrefetch(50); - - + + entry.setPendingSubscriberPolicy(pendingSubscriberPolicy); - + // limit the number of outstanding messages, large enough to use the file store // or small enough not to blow memory limit int pendingMessageLimit = 50; @@ -261,7 +266,7 @@ public class MessageEvictionTest { // whether to check expiry before eviction, default limit 1000 is fine as no ttl set in this test //messageEvictionStrategy.setEvictExpiredMessagesHighWatermark(1000); entry.setMessageEvictionStrategy(messageEvictionStrategy); - + // let evicted messaged disappear entry.setDeadLetterStrategy(null); policyEntries.add(entry); @@ -269,12 +274,12 @@ public class MessageEvictionTest { final PolicyMap policyMap = new PolicyMap(); policyMap.setPolicyEntries(policyEntries); brokerService.setDestinationPolicy(policyMap); - + return brokerService; } ConnectionFactory createConnectionFactory() throws Exception { - String url = ((TransportConnector) broker.getTransportConnectors().get(0)).getServer().getConnectURI().toString(); + String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url); factory.setWatchTopicAdvisories(false); return factory; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/QueueConsumerPriorityTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/QueueConsumerPriorityTest.java index 0154f0ebe9..2a61820cc3 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/QueueConsumerPriorityTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/QueueConsumerPriorityTest.java @@ -24,8 +24,8 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; -import junit.framework.Assert; import junit.framework.TestCase; + import org.apache.activemq.command.ActiveMQQueue; public class QueueConsumerPriorityTest extends TestCase { @@ -36,10 +36,12 @@ public class QueueConsumerPriorityTest extends TestCase { super(name); } + @Override protected void setUp() throws Exception { super.setUp(); } + @Override protected void tearDown() throws Exception { super.tearDown(); } @@ -64,6 +66,7 @@ public class QueueConsumerPriorityTest extends TestCase { consumerLowPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); consumerHighPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + assertNotNull(consumerHighPriority); senderSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = getClass().getName(); ActiveMQQueue low = new ActiveMQQueue(queueName+"?consumer.priority=1"); @@ -79,17 +82,13 @@ public class QueueConsumerPriorityTest extends TestCase { Message msg = senderSession.createTextMessage("test"); for (int i =0; i< 10000;i++) { producer.send(msg); - Assert.assertNotNull("null on iteration: " + i, highConsumer.receive(500)); + assertNotNull("null on iteration: " + i, highConsumer.receive(500)); } - Assert.assertNull(lowConsumer.receive(2000)); - - + assertNull(lowConsumer.receive(2000)); + } finally { conn.close(); } - } - - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/SpringTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/SpringTestSupport.java index e57f2c0e55..f713120139 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/SpringTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/SpringTestSupport.java @@ -22,25 +22,26 @@ import java.util.HashSet; import java.util.Set; import junit.framework.TestCase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.context.support.AbstractApplicationContext; /** * A useful base class for spring based unit test cases - * - * + * + * */ public abstract class SpringTestSupport extends TestCase { protected AbstractApplicationContext context; + @Override protected void setUp() throws Exception { context = createApplicationContext(); } protected abstract AbstractApplicationContext createApplicationContext();; + @Override protected void tearDown() throws Exception { if (context != null) { context.destroy(); @@ -55,7 +56,7 @@ public abstract class SpringTestSupport extends TestCase { return bean; } - protected void assertSetEquals(String description, Object[] expected, Set actual) { + protected void assertSetEquals(String description, Object[] expected, Set actual) { Set expectedSet = new HashSet(); expectedSet.addAll(Arrays.asList(expected)); assertEquals(description, expectedSet, actual); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java index 44de37d268..0d9392c9a9 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java @@ -18,7 +18,6 @@ package org.apache.activemq; import java.io.File; import java.io.IOException; -import java.util.Enumeration; import java.util.Map; import javax.jms.Connection; @@ -27,8 +26,6 @@ import javax.jms.JMSException; import javax.jms.Message; import javax.jms.TextMessage; -import junit.framework.TestCase; - import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.region.DestinationStatistics; import org.apache.activemq.broker.region.RegionBroker; @@ -42,13 +39,11 @@ import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; import org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter; import org.apache.activemq.store.memory.MemoryPersistenceAdapter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Useful base class for unit test cases - * - * + * + * */ public abstract class TestSupport extends CombinationTestSupport { @@ -146,7 +141,7 @@ public abstract class TestSupport extends CombinationTestSupport { recursiveDelete(new File(System.getProperty("derby.system.home"))); } } - + public static DestinationStatistics getDestinationStatistics(BrokerService broker, ActiveMQDestination destination) { DestinationStatistics result = null; org.apache.activemq.broker.region.Destination dest = getDestination(broker, destination); @@ -155,7 +150,7 @@ public abstract class TestSupport extends CombinationTestSupport { } return result; } - + public static org.apache.activemq.broker.region.Destination getDestination(BrokerService target, ActiveMQDestination destination) { org.apache.activemq.broker.region.Destination result = null; for (org.apache.activemq.broker.region.Destination dest : getDestinationMap(target, destination).values()) { @@ -184,7 +179,7 @@ public abstract class TestSupport extends CombinationTestSupport { public PersistenceAdapter setDefaultPersistenceAdapter(BrokerService broker) throws IOException { return setPersistenceAdapter(broker, defaultPersistenceAdapter); } - + public PersistenceAdapter setPersistenceAdapter(BrokerService broker, PersistenceAdapterChoice choice) throws IOException { PersistenceAdapter adapter = null; switch (choice) { @@ -212,7 +207,7 @@ public abstract class TestSupport extends CombinationTestSupport { * Test if base directory contains spaces */ protected void assertBaseDirectoryContainsSpaces() { - assertFalse("Base directory cannot contain spaces.", new File(System.getProperty("basedir", ".")).getAbsoluteFile().toString().contains(" ")); + assertFalse("Base directory cannot contain spaces.", new File(System.getProperty("basedir", ".")).getAbsoluteFile().toString().contains(" ")); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java index fd0167313e..acf9c03285 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java @@ -33,14 +33,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ConsumerControl; -import org.apache.activemq.command.ConsumerInfo; import org.apache.activemq.command.ExceptionResponse; import org.apache.activemq.spring.SpringConsumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * + * */ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { @@ -99,7 +98,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { } // now lets receive it MessageConsumer consumer = session.createConsumer(queue); - + session.createConsumer(queue); TextMessage answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg1"); @@ -145,7 +144,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { answer = (TextMessage)consumer.receiveNoWait(); assertNull("Should have not received a message!", answer); } - + public void testTwoConsumers() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -164,7 +163,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { answer = (TextMessage)consumer2.receiveNoWait(); assertNull("Should have not received a message!", answer); } - + // https://issues.apache.org/activemq/browse/AMQ-2567 public void testManyMessageConsumer() throws Exception { doTestManyMessageConsumer(true); @@ -173,7 +172,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { public void testManyMessageConsumerNoTransaction() throws Exception { doTestManyMessageConsumer(false); } - + private void doTestManyMessageConsumer(boolean transacted) throws Exception { Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); @@ -191,7 +190,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { } // now lets receive it MessageConsumer consumer = session.createConsumer(queue); - + MessageConsumer consumer2 = session.createConsumer(queue); TextMessage answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg1"); @@ -214,26 +213,26 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { if (transacted) { session.commit(); } - // Now using other consumer + // Now using other consumer // this call should return the next message (Msg5) still left on the queue answer = (TextMessage)consumer2.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg5"); if (transacted) { session.commit(); } - // Now using other consumer + // Now using other consumer // this call should return the next message (Msg5) still left on the queue answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg6"); // read one more message without commit - // Now using other consumer + // Now using other consumer // this call should return the next message (Msg5) still left on the queue answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg7"); if (transacted) { session.commit(); } - // Now using other consumer + // Now using other consumer // this call should return the next message (Msg5) still left on the queue answer = (TextMessage)consumer2.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg8"); @@ -251,7 +250,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { public void testManyMessageConsumerWithSendNoTransaction() throws Exception { doTestManyMessageConsumerWithSend(false); } - + private void doTestManyMessageConsumerWithSend(boolean transacted) throws Exception { Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); @@ -269,7 +268,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { } // now lets receive it MessageConsumer consumer = session.createConsumer(queue); - + MessageConsumer consumer2 = session.createConsumer(queue); TextMessage answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg1"); @@ -297,23 +296,23 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { if (transacted) { session.commit(); } - + answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg6"); // read one more message without commit - // and using other consumer + // and using other consumer answer = (TextMessage)consumer2.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg7"); if (transacted) { session.commit(); } - + answer = (TextMessage)consumer2.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg8"); if (transacted) { session.commit(); } - + answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg9"); if (transacted) { @@ -372,6 +371,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { return brokerService; } + @Override protected void setUp() throws Exception { bindAddress = "tcp://localhost:0"; super.setUp(); @@ -380,12 +380,14 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { connection.start(); queue = createQueue(); } - + + @Override protected void startBroker() throws Exception { super.startBroker(); bindAddress = broker.getTransportConnectors().get(0).getConnectUri().toString(); } + @Override protected void tearDown() throws Exception { connection.close(); super.tearDown(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTempDestinationTests.java b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTempDestinationTests.java index 76af309d60..b0bfd8258f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTempDestinationTests.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTempDestinationTests.java @@ -16,7 +16,23 @@ */ package org.apache.activemq.advisory; +import java.util.ArrayList; +import java.util.List; + +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TemporaryQueue; +import javax.jms.Topic; + import junit.framework.TestCase; + import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; @@ -26,10 +42,6 @@ import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQMessage; -import javax.jms.*; -import java.util.ArrayList; -import java.util.List; - public class AdvisoryTempDestinationTests extends TestCase { protected static final int MESSAGE_COUNT = 2000; @@ -44,6 +56,7 @@ public class AdvisoryTempDestinationTests extends TestCase { TemporaryQueue queue = s.createTemporaryQueue(); MessageConsumer consumer = s.createConsumer(queue); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message message) { } }); @@ -66,6 +79,7 @@ public class AdvisoryTempDestinationTests extends TestCase { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue queue = s.createTemporaryQueue(); MessageConsumer consumer = s.createConsumer(queue); + assertNotNull(consumer); Topic advisoryTopic = AdvisorySupport .getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue); @@ -86,6 +100,7 @@ public class AdvisoryTempDestinationTests extends TestCase { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue queue = s.createTemporaryQueue(); MessageConsumer consumer = s.createConsumer(queue); + assertNotNull(consumer); Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); @@ -130,6 +145,7 @@ public class AdvisoryTempDestinationTests extends TestCase { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); + assertNotNull(consumer); Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); @@ -146,6 +162,7 @@ public class AdvisoryTempDestinationTests extends TestCase { assertNotNull(msg); } + @Override protected void setUp() throws Exception { if (broker == null) { broker = createBroker(); @@ -156,6 +173,7 @@ public class AdvisoryTempDestinationTests extends TestCase { super.setUp(); } + @Override protected void tearDown() throws Exception { super.tearDown(); connection.close(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java index b04871fc96..4bb90532f5 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java @@ -26,7 +26,9 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.Topic; + import junit.framework.TestCase; + import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQPrefetchPolicy; @@ -38,7 +40,7 @@ import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQMessage; /** - * + * */ public class AdvisoryTests extends TestCase { protected static final int MESSAGE_COUNT = 2000; @@ -46,13 +48,14 @@ public class AdvisoryTests extends TestCase { protected Connection connection; protected String bindAddress = ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL; protected int topicCount; - + public void testNoSlowConsumerAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); consumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message message) { } }); @@ -70,12 +73,13 @@ public class AdvisoryTests extends TestCase { Message msg = advisoryConsumer.receive(1000); assertNull(msg); } - + public void testSlowConsumerAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); - + assertNotNull(consumer); + Topic advisoryTopic = AdvisorySupport .getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue); s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -90,56 +94,58 @@ public class AdvisoryTests extends TestCase { Message msg = advisoryConsumer.receive(1000); assertNotNull(msg); } - - public void testMessageDeliveryAdvisory() throws Exception { + + public void testMessageDeliveryAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); - + assertNotNull(consumer); + Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); //start throwing messages at the consumer MessageProducer producer = s.createProducer(queue); - + BytesMessage m = s.createBytesMessage(); m.writeBytes(new byte[1024]); producer.send(m); - + Message msg = advisoryConsumer.receive(1000); assertNotNull(msg); } - - public void testMessageConsumedAdvisory() throws Exception { + + public void testMessageConsumedAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); - + Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); //start throwing messages at the consumer MessageProducer producer = s.createProducer(queue); - + BytesMessage m = s.createBytesMessage(); m.writeBytes(new byte[1024]); producer.send(m); String id = m.getJMSMessageID(); Message msg = consumer.receive(1000); assertNotNull(msg); - + msg = advisoryConsumer.receive(1000); assertNotNull(msg); - + ActiveMQMessage message = (ActiveMQMessage) msg; ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure(); String originalId = payload.getJMSMessageID(); assertEquals(originalId, id); } - + public void testMessageExpiredAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); - + assertNotNull(consumer); + Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); //start throwing messages at the consumer @@ -150,16 +156,17 @@ public class AdvisoryTests extends TestCase { m.writeBytes(new byte[1024]); producer.send(m); } - + Message msg = advisoryConsumer.receive(2000); assertNotNull(msg); } - + public void xtestMessageDiscardedAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = s.createTopic(getClass().getName()); MessageConsumer consumer = s.createConsumer(topic); - + assertNotNull(consumer); + Topic advisoryTopic = AdvisorySupport.getMessageDiscardedAdvisoryTopic((ActiveMQDestination) topic); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); //start throwing messages at the consumer @@ -169,12 +176,12 @@ public class AdvisoryTests extends TestCase { BytesMessage m = s.createBytesMessage(); producer.send(m); } - + Message msg = advisoryConsumer.receive(1000); assertNotNull(msg); } - + @Override protected void setUp() throws Exception { if (broker == null) { broker = createBroker(); @@ -185,6 +192,7 @@ public class AdvisoryTests extends TestCase { super.setUp(); } + @Override protected void tearDown() throws Exception { super.tearDown(); connection.close(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java index 9e26aac479..bc90cabb6c 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java @@ -30,8 +30,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * + * + * */ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements ProducerListener { private static final Logger LOG = LoggerFactory.getLogger(ProducerListenerTest.class); @@ -78,10 +78,12 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P assertConsumerEvent(0, false); } + @Override public void onProducerEvent(ProducerEvent event) { eventQueue.add(event); } + @Override protected void setUp() throws Exception { super.setUp(); @@ -91,6 +93,7 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P producerEventSource.setProducerListener(this); } + @Override protected void tearDown() throws Exception { if (producerEventSource != null) { producerEventSource.stop(); @@ -119,6 +122,8 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P Session answer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = answer.createProducer(destination); + assertNotNull(producer); + return answer; } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java index bc3ab76e7e..0875a5b3c8 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java @@ -24,8 +24,6 @@ import java.net.URL; import javax.jms.JMSException; -import junit.framework.Assert; - import org.apache.activemq.command.ActiveMQBlobMessage; public class FTPBlobDownloadStrategyTest extends FTPTestSupport { @@ -34,7 +32,7 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport { public void testDownload() throws Exception { setConnection(); - + // create file File uploadFile = new File(ftpHomeDirFile, "test.txt"); FileWriter wrt = new FileWriter(uploadFile); @@ -46,7 +44,7 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport { } wrt.close(); - + ActiveMQBlobMessage message = new ActiveMQBlobMessage(); BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy()); InputStream stream; @@ -59,16 +57,16 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport { sb.append((char)i); i = stream.read(); } - Assert.assertEquals("hello world", sb.toString().substring(0, "hello world".length())); - Assert.assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length()); + assertEquals("hello world", sb.toString().substring(0, "hello world".length())); + assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length()); assertTrue(uploadFile.exists()); strategy.deleteFile(message); assertFalse(uploadFile.exists()); - + } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(false); + assertTrue(false); } } @@ -79,15 +77,15 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport { message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/")); strategy.getInputStream(message); } catch(JMSException e) { - Assert.assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage()); + assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage()); return; } catch(Exception e) { System.out.println(e); - Assert.assertTrue("Wrong Exception "+ e, false); + assertTrue("Wrong Exception "+ e, false); return; } - Assert.assertTrue("Expect Exception", false); + assertTrue("Expect Exception", false); } public void testWrongFTPPort() throws MalformedURLException { @@ -97,15 +95,14 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport { message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/")); strategy.getInputStream(message); } catch(JMSException e) { - Assert.assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage()); + assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage()); return; } catch(Exception e) { e.printStackTrace(); - Assert.assertTrue("Wrong Exception "+ e, false); + assertTrue("Wrong Exception "+ e, false); return; } - Assert.assertTrue("Expect Exception", false); + assertTrue("Expect Exception", false); } - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobTest.java index 5eb52ae482..4aecc09529 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobTest.java @@ -26,13 +26,10 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; -import junit.framework.Assert; - import org.apache.activemq.ActiveMQSession; import org.apache.activemq.BlobMessage; import org.apache.activemq.command.ActiveMQBlobMessage; - public class FTPBlobTest extends FTPTestSupport { public void testBlobFile() throws Exception { @@ -57,7 +54,7 @@ public class FTPBlobTest extends FTPTestSupport { // check message send Message msg = consumer.receive(1000); - Assert.assertTrue(msg instanceof ActiveMQBlobMessage); + assertTrue(msg instanceof ActiveMQBlobMessage); assertEquals("name is correct", "fileName", ((ActiveMQBlobMessage)msg).getName()); InputStream input = ((ActiveMQBlobMessage) msg).getInputStream(); @@ -68,8 +65,8 @@ public class FTPBlobTest extends FTPTestSupport { i = input.read(); } input.close(); - File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_")); - Assert.assertEquals(content, b.toString()); + File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_")); + assertEquals(content, b.toString()); assertTrue(uploaded.exists()); ((ActiveMQBlobMessage)msg).deleteFile(); assertFalse(uploaded.exists()); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java index f8214fc6de..f76dbc39e4 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java @@ -23,8 +23,6 @@ import java.io.FileWriter; import javax.jms.JMSException; import javax.jms.Session; -import junit.framework.Assert; - import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQSession; import org.apache.activemq.command.ActiveMQBlobMessage; @@ -35,22 +33,22 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport { public void testFileUpload() throws Exception { setConnection(); - File file = File.createTempFile("amq-data-file-", ".dat"); + File file = File.createTempFile("amq-data-file-", ".dat"); // lets write some data BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.append("hello world"); writer.close(); - + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ((ActiveMQConnection)connection).setCopyMessageOnSend(false); - + ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file); message.setMessageId(new MessageId("testmessage")); message.onSend(); - Assert.assertEquals(ftpUrl + "testmessage", message.getURL().toString()); + assertEquals(ftpUrl + "testmessage", message.getURL().toString()); File uploaded = new File(ftpHomeDirFile, "testmessage"); assertTrue("File doesn't exists", uploaded.exists()); - } + } public void testWriteDenied() throws Exception { userNamePass = "guest"; @@ -60,10 +58,10 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.append("hello world"); writer.close(); - + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ((ActiveMQConnection)connection).setCopyMessageOnSend(false); - + ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file); message.setMessageId(new MessageId("testmessage")); try { @@ -74,5 +72,5 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport { } fail("Should have failed with permission denied exception!"); } - + } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FilesystemBlobTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FilesystemBlobTest.java index bcd4a9769c..1754689c71 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FilesystemBlobTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FilesystemBlobTest.java @@ -27,8 +27,6 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; -import junit.framework.Assert; - import org.apache.activemq.ActiveMQSession; import org.apache.activemq.BlobMessage; import org.apache.activemq.EmbeddedBrokerTestSupport; @@ -40,23 +38,23 @@ import org.slf4j.LoggerFactory; public class FilesystemBlobTest extends EmbeddedBrokerTestSupport { private static final Logger LOG = LoggerFactory.getLogger(FilesystemBlobTest.class); - + private Connection connection; - private String tmpDir = System.getProperty("user.dir") + "/target/FilesystemBlobTest"; - public void setUp() throws Exception { + private final String tmpDir = System.getProperty("user.dir") + "/target/FilesystemBlobTest"; + @Override + public void setUp() throws Exception { super.setUp(); // replace \ with / to let it work on windows too String fileUrl = "file:///" +tmpDir.replaceAll("\\\\", "/"); LOG.info("Using file: " + fileUrl); bindAddress = "vm://localhost?jms.blobTransferPolicy.defaultUploadUrl=" + fileUrl; - + connectionFactory = createConnectionFactory(); - + connection = createConnection(); - connection.start(); + connection.start(); } - - + public void testBlobFile() throws Exception { // first create Message File file = File.createTempFile("amq-data-file-", ".dat"); @@ -77,7 +75,7 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport { // check message send Message msg = consumer.receive(1000); - Assert.assertTrue(msg instanceof ActiveMQBlobMessage); + assertTrue(msg instanceof ActiveMQBlobMessage); InputStream input = ((ActiveMQBlobMessage) msg).getInputStream(); StringBuilder b = new StringBuilder(); @@ -87,19 +85,20 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport { i = input.read(); } input.close(); - File uploaded = new File(tmpDir, msg.getJMSMessageID().toString().replace(":", "_")); - Assert.assertEquals(content, b.toString()); + File uploaded = new File(tmpDir, msg.getJMSMessageID().toString().replace(":", "_")); + assertEquals(content, b.toString()); assertTrue(uploaded.exists()); ((ActiveMQBlobMessage)msg).deleteFile(); assertFalse(uploaded.exists()); } + @Override protected void tearDown() throws Exception { if (connection != null) { connection.stop(); } super.tearDown(); - + IOHelper.deleteFile(new File(tmpDir)); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java index 72a422d2ba..310f112c77 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java @@ -16,9 +16,13 @@ */ package org.apache.activemq.broker.jmx; +import static org.junit.Assert.assertEquals; + import java.net.Socket; import java.util.Set; + import javax.management.ObjectName; + import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; @@ -28,9 +32,6 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class TransportConnectorMBeanTest { private static final Logger LOG = LoggerFactory.getLogger(TransportConnectorMBeanTest.class); @@ -73,7 +74,7 @@ public class TransportConnectorMBeanTest { } private String extractLocalPort(ActiveMQConnection connection) throws Exception { - Socket socket = (Socket) connection.getTransport().narrow(Socket.class); + Socket socket = connection.getTransport().narrow(Socket.class); return String.valueOf(socket.getLocalPort()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterTest.java index e686c7c16c..a587be89d4 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterTest.java @@ -35,11 +35,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * + * */ public class IndividualDeadLetterTest extends DeadLetterTest { private static final Logger LOG = LoggerFactory.getLogger(IndividualDeadLetterTest.class); + @Override protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); @@ -56,11 +57,12 @@ public class IndividualDeadLetterTest extends DeadLetterTest { return broker; } + @Override protected Destination createDlqDestination() { String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue."; return new ActiveMQQueue(prefix + getClass().getName() + "." + getName()); } - + public void testDLQBrowsing() throws Exception { super.topic = false; deliveryMode = DeliveryMode.PERSISTENT; @@ -97,9 +99,9 @@ public class IndividualDeadLetterTest extends DeadLetterTest { assertNull("The message shouldn't be sent to another DLQ", testConsumer.receive(1000)); } - + protected void browseDlq() throws Exception { - Enumeration messages = dlqBrowser.getEnumeration(); + Enumeration messages = dlqBrowser.getEnumeration(); while (messages.hasMoreElements()) { LOG.info("Browsing: " + messages.nextElement()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/NoRetryDeadLetterTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/NoRetryDeadLetterTest.java index 7421245920..a14df74b7d 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/NoRetryDeadLetterTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/NoRetryDeadLetterTest.java @@ -18,12 +18,10 @@ package org.apache.activemq.broker.policy; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.RedeliveryPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class NoRetryDeadLetterTest extends DeadLetterTest { - private static final Logger LOG = LoggerFactory.getLogger(NoRetryDeadLetterTest.class); + @Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { ActiveMQConnectionFactory connectionFactory = super.createConnectionFactory(); RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy(); @@ -31,5 +29,5 @@ public class NoRetryDeadLetterTest extends DeadLetterTest { connectionFactory.setRedeliveryPolicy(redeliveryPolicy); return connectionFactory; } - + } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PerDurableConsumerDeadLetterTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PerDurableConsumerDeadLetterTest.java index 369d29f34c..05be639562 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PerDurableConsumerDeadLetterTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PerDurableConsumerDeadLetterTest.java @@ -16,21 +16,13 @@ */ package org.apache.activemq.broker.policy; -import java.util.Enumeration; -import javax.jms.DeliveryMode; import javax.jms.Destination; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.Queue; -import org.apache.activemq.ActiveMQConnection; + import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.broker.region.policy.DeadLetterStrategy; import org.apache.activemq.broker.region.policy.IndividualDeadLetterStrategy; import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.command.ActiveMQQueue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * for durable subs, allow a dlq per subscriber such that poison messages are not duplicates @@ -38,10 +30,10 @@ import org.slf4j.LoggerFactory; * https://issues.apache.org/jira/browse/AMQ-3003 */ public class PerDurableConsumerDeadLetterTest extends DeadLetterTest { - private static final Logger LOG = LoggerFactory.getLogger(PerDurableConsumerDeadLetterTest.class); private static final String CLIENT_ID = "george"; + @Override protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); @@ -59,10 +51,12 @@ public class PerDurableConsumerDeadLetterTest extends DeadLetterTest { return broker; } + @Override protected String createClientId() { return CLIENT_ID; } + @Override protected Destination createDlqDestination() { String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue."; String destinationName = prefix + getClass().getName() + "." + getName(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PriorityNetworkDispatchPolicyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PriorityNetworkDispatchPolicyTest.java index 354f970cae..448f47c349 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PriorityNetworkDispatchPolicyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/PriorityNetworkDispatchPolicyTest.java @@ -16,23 +16,26 @@ */ package org.apache.activemq.broker.policy; +import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.List; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.region.Subscription; import org.apache.activemq.broker.region.TopicSubscription; import org.apache.activemq.broker.region.policy.PriorityNetworkDispatchPolicy; -import org.apache.activemq.command.*; +import org.apache.activemq.command.ActiveMQDestination; +import org.apache.activemq.command.ActiveMQMessage; +import org.apache.activemq.command.ConsumerId; +import org.apache.activemq.command.ConsumerInfo; +import org.apache.activemq.command.MessageId; import org.apache.activemq.usage.SystemUsage; -import org.apache.derby.iapi.jdbc.BrokeredStatement; import org.junit.After; import org.junit.Before; import org.junit.Test; - -import static org.junit.Assert.assertEquals; - public class PriorityNetworkDispatchPolicyTest { PriorityNetworkDispatchPolicy underTest = new PriorityNetworkDispatchPolicy(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/SimpleDispatchPolicyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/SimpleDispatchPolicyTest.java index 0ca4029d44..0455950c71 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/SimpleDispatchPolicyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/SimpleDispatchPolicyTest.java @@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy; import java.util.Iterator; +import javax.jms.MessageConsumer; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.QueueSubscriptionTest; import org.apache.activemq.broker.region.policy.FixedCountSubscriptionRecoveryPolicy; @@ -28,6 +30,7 @@ import org.apache.activemq.util.MessageIdList; public class SimpleDispatchPolicyTest extends QueueSubscriptionTest { + @Override protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); @@ -42,24 +45,26 @@ public class SimpleDispatchPolicyTest extends QueueSubscriptionTest { return broker; } + @Override public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception { super.testOneProducerTwoConsumersSmallMessagesLargePrefetch(); // One consumer should have received all messages, and the rest none - // assertOneConsumerReceivedAllMessages(messageCount); + // assertOneConsumerReceivedAllMessages(messageCount); } + @Override public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception { super.testOneProducerTwoConsumersLargeMessagesLargePrefetch(); // One consumer should have received all messages, and the rest none - // assertOneConsumerReceivedAllMessages(messageCount); + // assertOneConsumerReceivedAllMessages(messageCount); } public void assertOneConsumerReceivedAllMessages(int messageCount) throws Exception { boolean found = false; - for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { - MessageIdList messageIdList = (MessageIdList)consumers.get(i.next()); + for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { + MessageIdList messageIdList = consumers.get(i.next()); int count = messageIdList.getMessageCount(); if (count > 0) { if (found) { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/StrictOrderDispatchPolicyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/StrictOrderDispatchPolicyTest.java index 145a542a42..91ef89c733 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/StrictOrderDispatchPolicyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/StrictOrderDispatchPolicyTest.java @@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy; import java.util.Iterator; +import javax.jms.MessageConsumer; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TopicSubscriptionTest; import org.apache.activemq.broker.region.policy.PolicyEntry; @@ -27,6 +29,7 @@ import org.apache.activemq.util.MessageIdList; public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest { + @Override protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); @@ -41,48 +44,56 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest { return broker; } + @Override public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception { super.testOneProducerTwoConsumersLargeMessagesOnePrefetch(); assertReceivedMessagesAreOrdered(); } + @Override public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception { super.testOneProducerTwoConsumersSmallMessagesOnePrefetch(); assertReceivedMessagesAreOrdered(); } + @Override public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception { super.testOneProducerTwoConsumersSmallMessagesLargePrefetch(); assertReceivedMessagesAreOrdered(); } + @Override public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception { super.testOneProducerTwoConsumersLargeMessagesLargePrefetch(); assertReceivedMessagesAreOrdered(); } + @Override public void testOneProducerManyConsumersFewMessages() throws Exception { super.testOneProducerManyConsumersFewMessages(); assertReceivedMessagesAreOrdered(); } + @Override public void testOneProducerManyConsumersManyMessages() throws Exception { super.testOneProducerManyConsumersManyMessages(); assertReceivedMessagesAreOrdered(); } + @Override public void testManyProducersOneConsumer() throws Exception { super.testManyProducersOneConsumer(); assertReceivedMessagesAreOrdered(); } + @Override public void testManyProducersManyConsumers() throws Exception { super.testManyProducersManyConsumers(); @@ -96,7 +107,7 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest { } // Get basis of order - Iterator i = consumers.keySet().iterator(); + Iterator i = consumers.keySet().iterator(); MessageIdList messageOrder = (MessageIdList)consumers.get(i.next()); for (; i.hasNext();) { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/store/LoadTester.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/store/LoadTester.java index a8ed2d0053..a6d78b4a60 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/store/LoadTester.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/store/LoadTester.java @@ -34,29 +34,29 @@ import org.apache.activemq.JmsTestSupport; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.ProgressPrinter; -import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; -import org.apache.activemq.memory.list.SimpleMessageList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * + * */ public class LoadTester extends JmsTestSupport { private static final Logger LOG = LoggerFactory.getLogger(LoadTester.class); - + protected int messageSize = 1024 * 64; protected int produceCount = 10000; + @Override protected BrokerService createBroker() throws Exception { return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/store/loadtester.xml")); } + @Override protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException { - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getServer().getConnectURI()); + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI()); factory.setUseAsyncSend(true); return factory; } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/ActiveMQTestCase.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/ActiveMQTestCase.java index 0beef83a89..01ecdb1a64 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/ActiveMQTestCase.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/ActiveMQTestCase.java @@ -17,7 +17,6 @@ package org.apache.activemq.bugs.amq1095; -import java.io.File; import java.net.URI; import java.util.Iterator; import java.util.LinkedList; @@ -34,7 +33,6 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import junit.framework.Assert; import junit.framework.TestCase; import org.apache.activemq.broker.BrokerFactory; @@ -45,7 +43,7 @@ import org.apache.activemq.command.ActiveMQTopic; *

* Common functionality for ActiveMQ test cases. *

- * + * * @author Rainer Klute <rainer.klute@dp-itsolutions.de> * @since 2007-08-10 @@ -57,15 +55,15 @@ public class ActiveMQTestCase extends TestCase private BrokerService broker; protected Connection connection; protected Destination destination; - private List consumersToEmpty = new LinkedList(); + private final List consumersToEmpty = new LinkedList(); protected final long RECEIVE_TIMEOUT = 500; /**

Constructor

*/ public ActiveMQTestCase() {} - - /**

Constructor

+ + /**

Constructor

* @param name the test case's name */ public ActiveMQTestCase(final String name) @@ -76,6 +74,7 @@ public class ActiveMQTestCase extends TestCase /** *

Sets up the JUnit testing environment. */ + @Override protected void setUp() { URI uri; @@ -84,7 +83,7 @@ public class ActiveMQTestCase extends TestCase /* Copy all system properties starting with "java.naming." to the initial context. */ final Properties systemProperties = System.getProperties(); final Properties jndiProperties = new Properties(); - for (final Iterator i = systemProperties.keySet().iterator(); i.hasNext();) + for (final Iterator i = systemProperties.keySet().iterator(); i.hasNext();) { final String key = (String) i.next(); if (key.startsWith("java.naming.") || key.startsWith("topic.") || @@ -94,7 +93,7 @@ public class ActiveMQTestCase extends TestCase jndiProperties.put(key, value); } } - context = new InitialContext(jndiProperties); + context = new InitialContext(jndiProperties); uri = new URI("xbean:org/apache/activemq/bugs/amq1095/activemq.xml"); broker = BrokerFactory.createBroker(uri); broker.start(); @@ -119,15 +118,15 @@ public class ActiveMQTestCase extends TestCase catch (JMSException ex1) { ex1.printStackTrace(); - Assert.fail(ex1.toString()); + fail(ex1.toString()); } catch (NamingException ex2) { ex2.printStackTrace(); - Assert.fail(ex2.toString()); + fail(ex2.toString()); } catch (Throwable ex3) { ex3.printStackTrace(); - Assert.fail(ex3.toString()); + fail(ex3.toString()); } } @@ -140,19 +139,20 @@ public class ActiveMQTestCase extends TestCase * to be empty. *

*/ + @Override protected void tearDown() throws Exception { TextMessage msg; try { - for (final Iterator i = consumersToEmpty.iterator(); i.hasNext();) - { - final MessageConsumer consumer = (MessageConsumer) i.next(); - if (consumer != null) - do - msg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT); - while (msg != null); - } - } catch (Exception e) { - } + for (final Iterator i = consumersToEmpty.iterator(); i.hasNext();) + { + final MessageConsumer consumer = i.next(); + if (consumer != null) + do + msg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT); + while (msg != null); + } + } catch (Exception e) { + } if (connection != null) { connection.stop(); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/MessageSelectorTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/MessageSelectorTest.java index a127422124..e9aa3cab02 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/MessageSelectorTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/amq1095/MessageSelectorTest.java @@ -24,14 +24,11 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; -import junit.framework.Assert; - - /** *

* Test cases for various ActiveMQ functionalities. *

- * + * *
    *
  • *

    @@ -50,7 +47,7 @@ import junit.framework.Assert; *

    *
  • *
- * + * * @author Rainer Klute <rainer.klute@dp-itsolutions.de> * @since 2007-08-09 @@ -64,7 +61,7 @@ public class MessageSelectorTest extends ActiveMQTestCase { /**

Constructor

*/ public MessageSelectorTest() {} - + /**

Constructor

* @param name the test case's name */ @@ -102,7 +99,7 @@ public class MessageSelectorTest extends ActiveMQTestCase { { runMessageSelectorTest(false); } - + /** *

* Tests whether message selectors work. This is done by sending two @@ -223,7 +220,7 @@ public class MessageSelectorTest extends ActiveMQTestCase { catch (JMSException ex) { ex.printStackTrace(); - Assert.fail(); + fail(); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java index 89548e0fc3..936603c3b8 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java @@ -26,15 +26,16 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest; /** - * + * */ public class BrokerXmlConfigFromJNDITest extends JmsTopicSendReceiveWithTwoConnectionsTest { + @Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { assertBaseDirectoryContainsSpaces(); // we could put these properties into a jndi.properties // on the classpath instead - Hashtable properties = new Hashtable(); + Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); // configure the embedded broker using an XML config file diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java b/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java index 465e1e5f20..704e40852a 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java @@ -22,6 +22,7 @@ import javax.jms.JMSException; import javax.jms.Session; import junit.framework.TestCase; + import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQMessageConsumer; import org.apache.activemq.command.ActiveMQQueue; @@ -55,7 +56,7 @@ public class ConfigUsingDestinationOptions extends TestCase { // JMS selector should be priority try { cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1"); - fail("Selector should be invalid"); + fail("Selector should be invalid" + cons); } catch (InvalidSelectorException e) { } @@ -63,7 +64,7 @@ public class ConfigUsingDestinationOptions extends TestCase { // Test setting using JMS destinations try { cons = (ActiveMQMessageConsumer) sess.createConsumer(queue); - fail("Selector should be invalid"); + fail("Selector should be invalid" + cons); } catch (InvalidSelectorException e) { } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/console/command/TestPurgeCommand.java b/activemq-unit-tests/src/test/java/org/apache/activemq/console/command/TestPurgeCommand.java index 3a00ab4bad..400fbe0f4f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/console/command/TestPurgeCommand.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/console/command/TestPurgeCommand.java @@ -52,417 +52,417 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestPurgeCommand extends TestCase { - private static final Logger LOG = LoggerFactory - .getLogger(TestPurgeCommand.class); + private static final Logger LOG = LoggerFactory + .getLogger(TestPurgeCommand.class); - protected static final int MESSAGE_COUNT = 10; - protected static final String PROPERTY_NAME = "XTestProperty"; - protected static final String PROPERTY_VALUE = "1:1"; - - // check for existence of property - protected static final String MSG_SEL_WITH_PROPERTY = PROPERTY_NAME - + " is not null"; + protected static final int MESSAGE_COUNT = 10; + protected static final String PROPERTY_NAME = "XTestProperty"; + protected static final String PROPERTY_VALUE = "1:1"; - // check for non-existence of property - protected static final String MSG_SEL_WITHOUT_PROPERTY = PROPERTY_NAME - + " is null"; - - // complex message selector query using XTestProperty and JMSPriority - protected static final String MSG_SEL_COMPLEX = PROPERTY_NAME + "='" + - "1:1" + "',JMSPriority>3"; - - // complex message selector query using XTestProperty AND JMSPriority - // but in SQL-92 syntax - protected static final String MSG_SEL_COMPLEX_SQL_AND = "(" + PROPERTY_NAME + "='" + - "1:1" + "') AND (JMSPriority>3)"; + // check for existence of property + protected static final String MSG_SEL_WITH_PROPERTY = PROPERTY_NAME + + " is not null"; - // complex message selector query using XTestProperty OR JMSPriority - // but in SQL-92 syntax - protected static final String MSG_SEL_COMPLEX_SQL_OR = "(" + PROPERTY_NAME + "='" + - "1:1" + "') OR (JMSPriority>3)"; - - - protected static final String QUEUE_NAME = "org.apache.activemq.network.jms.QueueBridgeTest"; + // check for non-existence of property + protected static final String MSG_SEL_WITHOUT_PROPERTY = PROPERTY_NAME + + " is null"; - protected AbstractApplicationContext context; - protected QueueConnection localConnection; - protected QueueRequestor requestor; - protected QueueSession requestServerSession; - protected MessageConsumer requestServerConsumer; - protected MessageProducer requestServerProducer; - protected Queue theQueue; + // complex message selector query using XTestProperty and JMSPriority + protected static final String MSG_SEL_COMPLEX = PROPERTY_NAME + "='" + + "1:1" + "',JMSPriority>3"; - protected void setUp() throws Exception { - super.setUp(); + // complex message selector query using XTestProperty AND JMSPriority + // but in SQL-92 syntax + protected static final String MSG_SEL_COMPLEX_SQL_AND = "(" + PROPERTY_NAME + "='" + + "1:1" + "') AND (JMSPriority>3)"; - context = createApplicationContext(); + // complex message selector query using XTestProperty OR JMSPriority + // but in SQL-92 syntax + protected static final String MSG_SEL_COMPLEX_SQL_OR = "(" + PROPERTY_NAME + "='" + + "1:1" + "') OR (JMSPriority>3)"; - createConnections(); - requestServerSession = localConnection.createQueueSession(false, - Session.AUTO_ACKNOWLEDGE); - theQueue = requestServerSession.createQueue(QUEUE_NAME); - requestServerConsumer = requestServerSession.createConsumer(theQueue); - requestServerProducer = requestServerSession.createProducer(null); + protected static final String QUEUE_NAME = "org.apache.activemq.network.jms.QueueBridgeTest"; - QueueSession session = localConnection.createQueueSession(false, - Session.AUTO_ACKNOWLEDGE); - requestor = new QueueRequestor(session, theQueue); - } + protected AbstractApplicationContext context; + protected QueueConnection localConnection; + protected QueueRequestor requestor; + protected QueueSession requestServerSession; + protected MessageConsumer requestServerConsumer; + protected MessageProducer requestServerProducer; + protected Queue theQueue; - protected void createConnections() throws JMSException { - ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context - .getBean("localFactory"); - localConnection = fac.createQueueConnection(); - localConnection.start(); - } + @Override + protected void setUp() throws Exception { + super.setUp(); - protected AbstractApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/activemq/console/command/activemq.xml"); - } + context = createApplicationContext(); - protected void tearDown() throws Exception { - localConnection.close(); - BrokerService broker = (BrokerService) context.getBean("localbroker"); - broker.stop(); - broker = (BrokerService) context.getBean("default"); - broker.stop(); - super.tearDown(); - } + createConnections(); - @SuppressWarnings("unchecked") - public int getMessageCount(QueueBrowser browser, String prefix) - throws JMSException { - Enumeration e = browser.getEnumeration(); - int with = 0; - while (e.hasMoreElements()) { - Object o = e.nextElement(); - System.out.println(prefix + o); - with++; - } - return with; - } + requestServerSession = localConnection.createQueueSession(false, + Session.AUTO_ACKNOWLEDGE); + theQueue = requestServerSession.createQueue(QUEUE_NAME); + requestServerConsumer = requestServerSession.createConsumer(theQueue); + requestServerProducer = requestServerSession.createProducer(null); - public void cleanup() throws JMSException { - for (int i = 0; i < MESSAGE_COUNT * 2; i++) { - requestServerConsumer.receive(); - } - } + QueueSession session = localConnection.createQueueSession(false, + Session.AUTO_ACKNOWLEDGE); + requestor = new QueueRequestor(session, theQueue); + } - protected MBeanServerConnection createJmxConnection() throws IOException { - return ManagementFactory.getPlatformMBeanServer(); - } + protected void createConnections() throws JMSException { + ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context + .getBean("localFactory"); + localConnection = fac.createQueueConnection(); + localConnection.start(); + } - @SuppressWarnings("unchecked") - public void purgeAllMessages() throws IOException, Exception { - List tokens = Arrays.asList(new String[] { "*" }); - for (String token : tokens) { - List queueList = JmxMBeansUtil.queryMBeans( - createJmxConnection(), "Type=Queue,Destination=" + token - + ",*"); - for (ObjectInstance oi : queueList) { - ObjectName queueName = oi.getObjectName(); - LOG.info("Purging all messages in queue: " - + queueName.getKeyProperty("Destination")); - createJmxConnection().invoke(queueName, "purge", - new Object[] {}, new String[] {}); - } - } - } + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/activemq/console/command/activemq.xml"); + } - public void addMessages() throws IOException, Exception { - // first clean out any messages that may exist. - purgeAllMessages(); + @Override + protected void tearDown() throws Exception { + localConnection.close(); + BrokerService broker = (BrokerService) context.getBean("localbroker"); + broker.stop(); + broker = (BrokerService) context.getBean("default"); + broker.stop(); + super.tearDown(); + } - for (int i = 0; i < MESSAGE_COUNT; i++) { - TextMessage msg = requestServerSession - .createTextMessage("test msg: " + i); - msg.setStringProperty(PROPERTY_NAME, PROPERTY_VALUE); - requestServerProducer.send(theQueue, msg); - } - for (int i = 0; i < MESSAGE_COUNT; i++) { - TextMessage msg = requestServerSession - .createTextMessage("test msg: " + i); - requestServerProducer.send(theQueue, msg); - } + public int getMessageCount(QueueBrowser browser, String prefix) throws JMSException { + Enumeration e = browser.getEnumeration(); + int with = 0; + while (e.hasMoreElements()) { + Object o = e.nextElement(); + System.out.println(prefix + o); + with++; + } + return with; + } - } + public void cleanup() throws JMSException { + for (int i = 0; i < MESSAGE_COUNT * 2; i++) { + requestServerConsumer.receive(); + } + } - public void validateCounts(int expectedWithCount, int expectedWithoutCount, - int expectedAllCount) throws JMSException { - QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( - theQueue, MSG_SEL_WITH_PROPERTY); - QueueBrowser withoutPropertyBrowser = requestServerSession - .createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY); - QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + protected MBeanServerConnection createJmxConnection() throws IOException { + return ManagementFactory.getPlatformMBeanServer(); + } - int withCount = getMessageCount(withPropertyBrowser, "withProperty "); - int withoutCount = getMessageCount(withoutPropertyBrowser, - "withoutProperty "); - int allCount = getMessageCount(allBrowser, "allMessages "); + @SuppressWarnings("unchecked") + public void purgeAllMessages() throws IOException, Exception { + List tokens = Arrays.asList(new String[] { "*" }); + for (String token : tokens) { + List queueList = JmxMBeansUtil.queryMBeans( + createJmxConnection(), "Type=Queue,Destination=" + token + + ",*"); + for (ObjectInstance oi : queueList) { + ObjectName queueName = oi.getObjectName(); + LOG.info("Purging all messages in queue: " + + queueName.getKeyProperty("Destination")); + createJmxConnection().invoke(queueName, "purge", + new Object[] {}, new String[] {}); + } + } + } - withPropertyBrowser.close(); - withoutPropertyBrowser.close(); - allBrowser.close(); + public void addMessages() throws IOException, Exception { + // first clean out any messages that may exist. + purgeAllMessages(); - assertEquals("Expected withCount to be " + expectedWithCount + " was " - + withCount, expectedWithCount, withCount); - assertEquals("Expected withoutCount to be " + expectedWithoutCount - + " was " + withoutCount, expectedWithoutCount, withoutCount); - assertEquals("Expected allCount to be " + expectedAllCount + " was " - + allCount, expectedAllCount, allCount); - LOG.info("withCount = " + withCount + "\n withoutCount = " - + withoutCount + "\n allCount = " + allCount + "\n = " + "\n"); - } + for (int i = 0; i < MESSAGE_COUNT; i++) { + TextMessage msg = requestServerSession + .createTextMessage("test msg: " + i); + msg.setStringProperty(PROPERTY_NAME, PROPERTY_VALUE); + requestServerProducer.send(theQueue, msg); + } + for (int i = 0; i < MESSAGE_COUNT; i++) { + TextMessage msg = requestServerSession + .createTextMessage("test msg: " + i); + requestServerProducer.send(theQueue, msg); + } - /** - * This test ensures that the queueViewMbean will work. - * - * @throws Exception - */ - @SuppressWarnings("unchecked") - public void testQueueViewMbean() throws Exception { + } - try { - addMessages(); + public void validateCounts(int expectedWithCount, int expectedWithoutCount, + int expectedAllCount) throws JMSException { + QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( + theQueue, MSG_SEL_WITH_PROPERTY); + QueueBrowser withoutPropertyBrowser = requestServerSession + .createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY); + QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); - validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); + int withCount = getMessageCount(withPropertyBrowser, "withProperty "); + int withoutCount = getMessageCount(withoutPropertyBrowser, + "withoutProperty "); + int allCount = getMessageCount(allBrowser, "allMessages "); - List tokens = Arrays.asList(new String[] { "*" }); - for (String token : tokens) { - List queueList = JmxMBeansUtil.queryMBeans( - createJmxConnection(), "Type=Queue,Destination=" - + token + ",*"); + withPropertyBrowser.close(); + withoutPropertyBrowser.close(); + allBrowser.close(); - for (ObjectInstance queue : queueList) { - ObjectName queueName = ((ObjectInstance) queue) - .getObjectName(); - QueueViewMBean proxy = (QueueViewMBean) MBeanServerInvocationHandler - .newProxyInstance(createJmxConnection(), queueName, - QueueViewMBean.class, true); - int removed = proxy - .removeMatchingMessages(MSG_SEL_WITH_PROPERTY); - LOG.info("Removed: " + removed); - } - } + assertEquals("Expected withCount to be " + expectedWithCount + " was " + + withCount, expectedWithCount, withCount); + assertEquals("Expected withoutCount to be " + expectedWithoutCount + + " was " + withoutCount, expectedWithoutCount, withoutCount); + assertEquals("Expected allCount to be " + expectedAllCount + " was " + + allCount, expectedAllCount, allCount); + LOG.info("withCount = " + withCount + "\n withoutCount = " + + withoutCount + "\n allCount = " + allCount + "\n = " + "\n"); + } - validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT); + /** + * This test ensures that the queueViewMbean will work. + * + * @throws Exception + */ + @SuppressWarnings("unchecked") + public void testQueueViewMbean() throws Exception { - } finally { - purgeAllMessages(); - } - } + try { + addMessages(); - public void testPurgeCommandSimpleSelector() throws Exception { - try { - PurgeCommand purgeCommand = new PurgeCommand(); - CommandContext context = new CommandContext(); + validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); - context.setFormatter(new CommandShellOutputFormatter(System.out)); + List tokens = Arrays.asList(new String[] { "*" }); + for (String token : tokens) { + List queueList = JmxMBeansUtil.queryMBeans( + createJmxConnection(), "Type=Queue,Destination=" + + token + ",*"); - purgeCommand.setCommandContext(context); - purgeCommand.setJmxUseLocal(true); + for (ObjectInstance queue : queueList) { + ObjectName queueName = queue + .getObjectName(); + QueueViewMBean proxy = MBeanServerInvocationHandler + .newProxyInstance(createJmxConnection(), queueName, + QueueViewMBean.class, true); + int removed = proxy + .removeMatchingMessages(MSG_SEL_WITH_PROPERTY); + LOG.info("Removed: " + removed); + } + } - List tokens = new ArrayList(); - tokens.add("--msgsel"); - tokens.add(MSG_SEL_WITH_PROPERTY); - - addMessages(); - validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); + validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT); - purgeCommand.execute(tokens); + } finally { + purgeAllMessages(); + } + } - validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT); - } finally { - purgeAllMessages(); - } - } - - public void testPurgeCommandComplexSelector() throws Exception { - try { - PurgeCommand purgeCommand = new PurgeCommand(); - CommandContext context = new CommandContext(); + public void testPurgeCommandSimpleSelector() throws Exception { + try { + PurgeCommand purgeCommand = new PurgeCommand(); + CommandContext context = new CommandContext(); - context.setFormatter(new CommandShellOutputFormatter(System.out)); + context.setFormatter(new CommandShellOutputFormatter(System.out)); - purgeCommand.setCommandContext(context); - purgeCommand.setJmxUseLocal(true); + purgeCommand.setCommandContext(context); + purgeCommand.setJmxUseLocal(true); - List tokens = new ArrayList(); - tokens.add("--msgsel"); - tokens.add(MSG_SEL_COMPLEX); - - addMessages(); - validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); + List tokens = new ArrayList(); + tokens.add("--msgsel"); + tokens.add(MSG_SEL_WITH_PROPERTY); - purgeCommand.execute(tokens); + addMessages(); + validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); - QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( - theQueue, MSG_SEL_COMPLEX); - QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + purgeCommand.execute(tokens); - int withCount = getMessageCount(withPropertyBrowser, "withProperty "); - int allCount = getMessageCount(allBrowser, "allMessages "); + validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT); + } finally { + purgeAllMessages(); + } + } - withPropertyBrowser.close(); - allBrowser.close(); - - assertEquals("Expected withCount to be " + "0" + " was " - + withCount, 0, withCount); - assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " - + allCount, MESSAGE_COUNT, allCount); - LOG.info("withCount = " + withCount + "\n allCount = " + - allCount + "\n = " + "\n"); - } finally { - purgeAllMessages(); - } - } - - public void testPurgeCommandComplexSQLSelector_AND() throws Exception { - try { - - String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100"; - String two = "\\*:100"; - try { - if (one.matches(two)) - LOG.info("String matches."); - else - LOG.info("string does not match."); - } catch (Exception ex) { - LOG.error(ex.getMessage()); - } - - PurgeCommand purgeCommand = new PurgeCommand(); - CommandContext context = new CommandContext(); + public void testPurgeCommandComplexSelector() throws Exception { + try { + PurgeCommand purgeCommand = new PurgeCommand(); + CommandContext context = new CommandContext(); - context.setFormatter(new CommandShellOutputFormatter(System.out)); + context.setFormatter(new CommandShellOutputFormatter(System.out)); - purgeCommand.setCommandContext(context); - purgeCommand.setJmxUseLocal(true); + purgeCommand.setCommandContext(context); + purgeCommand.setJmxUseLocal(true); - List tokens = new ArrayList(); - tokens.add("--msgsel"); - tokens.add(MSG_SEL_COMPLEX_SQL_AND); - - addMessages(); - validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); + List tokens = new ArrayList(); + tokens.add("--msgsel"); + tokens.add(MSG_SEL_COMPLEX); - purgeCommand.execute(tokens); + addMessages(); + validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); - QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( - theQueue, MSG_SEL_COMPLEX_SQL_AND); - QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + purgeCommand.execute(tokens); - int withCount = getMessageCount(withPropertyBrowser, "withProperty "); - int allCount = getMessageCount(allBrowser, "allMessages "); + QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( + theQueue, MSG_SEL_COMPLEX); + QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); - withPropertyBrowser.close(); - allBrowser.close(); - - assertEquals("Expected withCount to be " + "0" + " was " - + withCount, 0, withCount); - assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " - + allCount, MESSAGE_COUNT, allCount); - LOG.info("withCount = " + withCount + "\n allCount = " + - allCount + "\n = " + "\n"); - } finally { - purgeAllMessages(); - } - } - - public void testPurgeCommandComplexSQLSelector_OR() throws Exception { - try { - PurgeCommand purgeCommand = new PurgeCommand(); - CommandContext context = new CommandContext(); + int withCount = getMessageCount(withPropertyBrowser, "withProperty "); + int allCount = getMessageCount(allBrowser, "allMessages "); - context.setFormatter(new CommandShellOutputFormatter(System.out)); + withPropertyBrowser.close(); + allBrowser.close(); - purgeCommand.setCommandContext(context); - purgeCommand.setJmxUseLocal(true); + assertEquals("Expected withCount to be " + "0" + " was " + + withCount, 0, withCount); + assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " + + allCount, MESSAGE_COUNT, allCount); + LOG.info("withCount = " + withCount + "\n allCount = " + + allCount + "\n = " + "\n"); + } finally { + purgeAllMessages(); + } + } - List tokens = new ArrayList(); - tokens.add("--msgsel"); - tokens.add(MSG_SEL_COMPLEX_SQL_OR); - - addMessages(); - validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); + public void testPurgeCommandComplexSQLSelector_AND() throws Exception { + try { - purgeCommand.execute(tokens); + String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100"; + String two = "\\*:100"; + try { + if (one.matches(two)) + LOG.info("String matches."); + else + LOG.info("string does not match."); + } catch (Exception ex) { + LOG.error(ex.getMessage()); + } - QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( - theQueue, MSG_SEL_COMPLEX_SQL_OR); - QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + PurgeCommand purgeCommand = new PurgeCommand(); + CommandContext context = new CommandContext(); - int withCount = getMessageCount(withPropertyBrowser, "withProperty "); - int allCount = getMessageCount(allBrowser, "allMessages "); + context.setFormatter(new CommandShellOutputFormatter(System.out)); - withPropertyBrowser.close(); - allBrowser.close(); - - assertEquals("Expected withCount to be 0 but was " - + withCount, 0, withCount); - assertEquals("Expected allCount to be 0 but was " - + allCount, 0, allCount); - LOG.info("withCount = " + withCount + "\n allCount = " + - allCount + "\n = " + "\n"); - } finally { - purgeAllMessages(); - } - } - - public void testDummy() throws Exception { - try { - - String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100"; - String two = "ID*:100"; - try { - if (one.matches(two)) - LOG.info("String matches."); - else - LOG.info("string does not match."); - } catch (Exception ex) { - LOG.error(ex.getMessage()); - } - - PurgeCommand purgeCommand = new PurgeCommand(); - CommandContext context = new CommandContext(); + purgeCommand.setCommandContext(context); + purgeCommand.setJmxUseLocal(true); - context.setFormatter(new CommandShellOutputFormatter(System.out)); + List tokens = new ArrayList(); + tokens.add("--msgsel"); + tokens.add(MSG_SEL_COMPLEX_SQL_AND); - purgeCommand.setCommandContext(context); - purgeCommand.setJmxUseLocal(true); + addMessages(); + validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); - List tokens = new ArrayList(); - tokens.add("--msgsel"); - tokens.add("(XTestProperty LIKE '1:*') AND (JMSPriority>3)"); - - addMessages(); - - purgeCommand.execute(tokens); + purgeCommand.execute(tokens); + + QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( + theQueue, MSG_SEL_COMPLEX_SQL_AND); + QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + + int withCount = getMessageCount(withPropertyBrowser, "withProperty "); + int allCount = getMessageCount(allBrowser, "allMessages "); + + withPropertyBrowser.close(); + allBrowser.close(); + + assertEquals("Expected withCount to be " + "0" + " was " + + withCount, 0, withCount); + assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " + + allCount, MESSAGE_COUNT, allCount); + LOG.info("withCount = " + withCount + "\n allCount = " + + allCount + "\n = " + "\n"); + } finally { + purgeAllMessages(); + } + } + + public void testPurgeCommandComplexSQLSelector_OR() throws Exception { + try { + PurgeCommand purgeCommand = new PurgeCommand(); + CommandContext context = new CommandContext(); + + context.setFormatter(new CommandShellOutputFormatter(System.out)); + + purgeCommand.setCommandContext(context); + purgeCommand.setJmxUseLocal(true); + + List tokens = new ArrayList(); + tokens.add("--msgsel"); + tokens.add(MSG_SEL_COMPLEX_SQL_OR); + + addMessages(); + validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); + + purgeCommand.execute(tokens); + + QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( + theQueue, MSG_SEL_COMPLEX_SQL_OR); + QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + + int withCount = getMessageCount(withPropertyBrowser, "withProperty "); + int allCount = getMessageCount(allBrowser, "allMessages "); + + withPropertyBrowser.close(); + allBrowser.close(); + + assertEquals("Expected withCount to be 0 but was " + + withCount, 0, withCount); + assertEquals("Expected allCount to be 0 but was " + + allCount, 0, allCount); + LOG.info("withCount = " + withCount + "\n allCount = " + + allCount + "\n = " + "\n"); + } finally { + purgeAllMessages(); + } + } + + public void testDummy() throws Exception { + try { + + String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100"; + String two = "ID*:100"; + try { + if (one.matches(two)) + LOG.info("String matches."); + else + LOG.info("string does not match."); + } catch (Exception ex) { + LOG.error(ex.getMessage()); + } + + PurgeCommand purgeCommand = new PurgeCommand(); + CommandContext context = new CommandContext(); + + context.setFormatter(new CommandShellOutputFormatter(System.out)); + + purgeCommand.setCommandContext(context); + purgeCommand.setJmxUseLocal(true); + + List tokens = new ArrayList(); + tokens.add("--msgsel"); + tokens.add("(XTestProperty LIKE '1:*') AND (JMSPriority>3)"); + + addMessages(); + + purgeCommand.execute(tokens); + + /* + QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( + theQueue, MSG_SEL_COMPLEX_SQL_AND); + QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); + + int withCount = getMessageCount(withPropertyBrowser, "withProperty "); + int allCount = getMessageCount(allBrowser, "allMessages "); + + withPropertyBrowser.close(); + allBrowser.close(); + + assertEquals("Expected withCount to be " + "0" + " was " + + withCount, 0, withCount); + assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " + + allCount, MESSAGE_COUNT, allCount); + LOG.info("withCount = " + withCount + "\n allCount = " + + allCount + "\n = " + "\n"); + */ + } finally { + purgeAllMessages(); + } + } - /* - QueueBrowser withPropertyBrowser = requestServerSession.createBrowser( - theQueue, MSG_SEL_COMPLEX_SQL_AND); - QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue); - int withCount = getMessageCount(withPropertyBrowser, "withProperty "); - int allCount = getMessageCount(allBrowser, "allMessages "); - withPropertyBrowser.close(); - allBrowser.close(); - - assertEquals("Expected withCount to be " + "0" + " was " - + withCount, 0, withCount); - assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " - + allCount, MESSAGE_COUNT, allCount); - LOG.info("withCount = " + withCount + "\n allCount = " + - allCount + "\n = " + "\n"); - */ - } finally { - purgeAllMessages(); - } - } - - - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java index ffe8dd93a5..21dd60d946 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java @@ -17,13 +17,15 @@ package org.apache.activemq.filter; import java.util.Set; + import junit.framework.TestCase; + import org.apache.activemq.command.ActiveMQTempQueue; import org.apache.activemq.command.ConnectionId; import org.apache.activemq.util.IdGenerator; public class DestinationMapTempDestinationTest extends TestCase { - + public void testtestTempDestinations() throws Exception { ConnectionId id = new ConnectionId(new IdGenerator().generateId()); DestinationMap map = new DestinationMap(); @@ -36,7 +38,7 @@ public class DestinationMapTempDestinationTest extends TestCase { for (int i = 0; i < count; i++) { ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i); map.remove(queue, value); - Set set = map.get(queue); + Set set = map.get(queue); assertTrue(set.isEmpty()); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java index 0acf11f674..f3f5b725cc 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Set; import junit.framework.TestCase; + import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; @@ -50,7 +51,6 @@ public class DestinationMapTest extends TestCase { map.put(d1, d1); map.put(d2, d2); map.get(createDestination("TEST.BAR.D2,TEST.BAR.D3")); - } public void testSimpleDestinations() throws Exception { @@ -131,7 +131,7 @@ public class DestinationMapTest extends TestCase { map.put(d2, v2); map.put(d3, v3); - List allValues = Arrays.asList(new Object[] {v1, v2, v3}); + List allValues = Arrays.asList(new Object[] {v1, v2, v3}); assertMapValue(">", allValues); assertMapValue("TEST.>", allValues); @@ -305,10 +305,9 @@ public class DestinationMapTest extends TestCase { put("FOO.B", v2); assertMapValue("FOO.>", v1, v2); - Set set = map.removeAll(createDestination("FOO.A")); + map.removeAll(createDestination("FOO.A")); assertMapValue("FOO.>", v2); - } protected void loadSample2() { @@ -371,7 +370,7 @@ public class DestinationMapTest extends TestCase { assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5, expected6})); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) protected void assertMapValue(ActiveMQDestination destination, Object expected) { List expectedList = null; if (expected == null) { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java index 893952b2f0..3dde44fdea 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java @@ -20,17 +20,21 @@ import java.util.List; /** * Represents a destination based policy - * - * + * + * */ public class DummyPolicy extends DestinationMap { + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override protected Class getEntryClass() { return DummyPolicyEntry.class; } + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override public void setEntries(List entries) { super.setEntries(entries); } - + } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java index 99a718634d..5d71c54741 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java @@ -31,11 +31,12 @@ public class DummyPolicyTest extends SpringTestSupport { public void testPolicy() throws Exception { DummyPolicy policy = (DummyPolicy)getBean("policy"); - Set set = policy.get(new ActiveMQTopic("FOO.BAR")); + Set set = policy.get(new ActiveMQTopic("FOO.BAR")); assertSetEquals("FOO.BAR set", new Object[] {"Edam", "Cheddar"}, set); } + @Override protected AbstractApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext("org/apache/activemq/filter/dummyPolicy.xml"); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java index 8abc6978a1..517735b855 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/CustomConnectionFactoryNameTest.java @@ -23,16 +23,17 @@ import org.apache.activemq.ActiveMQConnectionFactory; /** * Test case for AMQ-141 * - * + * */ public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFactoryTest { - + + @Override public void testConnectionFactoriesArePresent() throws NamingException { super.testConnectionFactoriesArePresent(); assertConnectionFactoryPresent("jms/Connection"); assertConnectionFactoryPresent("jms/DURABLE_SUB_CONNECTION_FACTORY"); } - + public void testConnectionFactoriesAreConfigured() throws NamingException { super.testConnectionFactoriesArePresent(); ActiveMQConnectionFactory factory1 = (ActiveMQConnectionFactory) context.lookup("jms/Connection"); @@ -41,10 +42,12 @@ public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFacto assertEquals("testclient", factory2.getClientID()); } + @Override protected String getConnectionFactoryLookupName() { return "myConnectionFactory"; } + @Override protected void configureEnvironment() { super.configureEnvironment(); environment.put("connectionFactoryNames", " myConnectionFactory, jms/Connection, jms/DURABLE_SUB_CONNECTION_FACTORY"); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java index b3fda32b5b..6e3e9da76e 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/DestinationNameWithSlashTest.java @@ -20,7 +20,7 @@ package org.apache.activemq.jndi; /** * Test case for AMQ-140 * - * + * */ public class DestinationNameWithSlashTest extends JNDITestSupport { public void testNameWithSlash() throws Exception { @@ -28,6 +28,7 @@ public class DestinationNameWithSlashTest extends JNDITestSupport { } + @Override protected void configureEnvironment() { super.configureEnvironment(); environment.put("queue.jms/Queue", "example.myqueue"); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java index 9547f2742d..13adbc458d 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java @@ -28,17 +28,18 @@ import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; import junit.framework.TestCase; + import org.apache.activemq.ActiveMQConnectionFactory; /** - * + * */ public abstract class JNDITestSupport extends TestCase { - + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory .getLog(JNDITestSupport.class); - - protected Hashtable environment = new Hashtable(); + + protected Hashtable environment = new Hashtable(); protected Context context; protected void assertConnectionFactoryPresent(String lookupName) throws NamingException { @@ -53,15 +54,16 @@ public abstract class JNDITestSupport extends TestCase { assertTrue("Should have got a child context but got: " + object, object instanceof Context); Context childContext = (Context) object; - NamingEnumeration iter = childContext.listBindings(""); + NamingEnumeration iter = childContext.listBindings(""); while (iter.hasMore()) { - Binding destinationBinding = (Binding) iter.next(); + Binding destinationBinding = iter.next(); LOG.info("Found destination: " + destinationBinding.getName()); Object destination = destinationBinding.getObject(); assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination); } } + @Override protected void setUp() throws Exception { super.setUp(); @@ -77,10 +79,11 @@ public abstract class JNDITestSupport extends TestCase { * * @throws javax.naming.NamingException */ + @Override protected void tearDown() throws NamingException, JMSException { - NamingEnumeration iter = context.listBindings(""); + NamingEnumeration iter = context.listBindings(""); while (iter.hasMore()) { - Binding binding = (Binding) iter.next(); + Binding binding = iter.next(); Object connFactory = binding.getObject(); if (connFactory instanceof ActiveMQConnectionFactory) { // ((ActiveMQConnectionFactory) connFactory).stop(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java b/activemq-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java index 7841eb97d0..22b90642f5 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/load/LoadController.java @@ -24,25 +24,26 @@ import javax.jms.Destination; import javax.jms.JMSException; /** - * + * */ public class LoadController extends LoadClient{ + private int numberOfBatches=1; private int batchSize =1000; private int count; private final CountDownLatch stopped = new CountDownLatch(1); - public LoadController(String name,ConnectionFactory factory) { super(name,factory); } - + public int awaitTestComplete() throws InterruptedException { - boolean complete = stopped.await(60*5,TimeUnit.SECONDS); + stopped.await(60*5,TimeUnit.SECONDS); return count; } + @Override public void stop() throws JMSException, InterruptedException { running = false; stopped.countDown(); @@ -50,7 +51,8 @@ public class LoadController extends LoadClient{ this.connection.stop(); } } - + + @Override public void run() { try { for (int i = 0; i < numberOfBatches; i++) { @@ -73,33 +75,29 @@ public class LoadController extends LoadClient{ } } - public int getNumberOfBatches() { return numberOfBatches; } - public void setNumberOfBatches(int numberOfBatches) { this.numberOfBatches = numberOfBatches; } - public int getBatchSize() { return batchSize; } - public void setBatchSize(int batchSize) { this.batchSize = batchSize; } - + + @Override protected Destination getSendDestination() { return startDestination; } - + + @Override protected Destination getConsumeDestination() { return nextDestination; } - - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java index 2b8e54dfaf..294916e0a1 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/memory/MemoryPropertyTest.java @@ -16,30 +16,25 @@ */ package org.apache.activemq.memory; -import java.io.File; +import junit.framework.TestCase; -import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.xbean.BrokerFactoryBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; - -import junit.framework.TestCase; public class MemoryPropertyTest extends TestCase { private static final transient Logger LOG = LoggerFactory.getLogger(MemoryPropertyTest.class); BrokerService broker; - + /** * Sets up a test where the producer and consumer have their own connection. - * + * * @see junit.framework.TestCase#setUp() */ + @Override protected void setUp() throws Exception { // Create broker from resource LOG.info("Creating broker... "); @@ -47,17 +42,17 @@ public class MemoryPropertyTest extends TestCase { LOG.info("Success"); super.setUp(); } - + protected BrokerService createBroker(String resource) throws Exception { return BrokerFactory.createBroker(resource); } - /* * Stops the Broker - * + * * @see junit.framework.TestCase#tearDown() */ + @Override protected void tearDown() throws Exception { LOG.info("Closing Broker"); if (broker != null) { @@ -66,18 +61,15 @@ public class MemoryPropertyTest extends TestCase { LOG.info("Broker closed..."); } - - public void testBrokerInitialized() { assertTrue("We should have a broker", broker != null); assertEquals("test-broker", broker.getBrokerName()); assertEquals(1024, broker.getSystemUsage().getMemoryUsage().getLimit()); assertEquals(34, broker.getSystemUsage().getMemoryUsage().getPercentUsageMinDelta()); - + assertNotNull(broker.getSystemUsage().getStoreUsage().getStore()); // non persistent broker so no temp storage assertNull(broker.getSystemUsage().getTempUsage().getStore()); } - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java index 95b930cd47..58af6dc224 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java @@ -16,9 +16,9 @@ */ package org.apache.activemq.network; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.net.URI; import java.util.Arrays; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java index f5a18996d2..1491ba2231 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java @@ -19,6 +19,7 @@ package org.apache.activemq.network; import javax.jms.DeliveryMode; import junit.framework.Test; + import org.apache.activemq.broker.StubConnection; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ConnectionInfo; @@ -78,9 +79,10 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport { // Make sure the message was delivered via the remote. assertTrue("message was received", Wait.waitFor(new Wait.Condition() { + @Override public boolean isSatisified() throws Exception { return receiveMessage(connection2) != null; - } + } })); } @@ -122,9 +124,10 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport { // Send the message to the local boker. connection1.request(createMessage(producerInfo, destination, deliveryMode)); // Make sure the message was delivered via the remote. - Message m = receiveMessage(connection2); + receiveMessage(connection2); } + @Override protected void setUp() throws Exception { super.setUp(); NetworkBridgeConfiguration config = new NetworkBridgeConfiguration(); @@ -135,6 +138,7 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport { bridge.start(); } + @Override protected void tearDown() throws Exception { bridge.stop(); super.tearDown(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java index 1cb140eaf3..3afa7d13f8 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java @@ -16,16 +16,16 @@ */ package org.apache.activemq.network; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import javax.jms.MessageProducer; import javax.jms.TemporaryQueue; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.util.Wait; import org.junit.Test; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; - public class DuplexNetworkTest extends SimpleNetworkTest { @Override diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DynamicallyIncludedDestinationsDuplexNetworkTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DynamicallyIncludedDestinationsDuplexNetworkTest.java index 8036f9ef26..88aa1a21c7 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DynamicallyIncludedDestinationsDuplexNetworkTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DynamicallyIncludedDestinationsDuplexNetworkTest.java @@ -16,19 +16,20 @@ */ package org.apache.activemq.network; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.lang.reflect.Field; + +import javax.jms.MessageProducer; +import javax.jms.TemporaryQueue; + import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TransportConnection; import org.junit.Test; -import javax.jms.MessageProducer; -import javax.jms.TemporaryQueue; -import java.lang.reflect.Field; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; - /** * @author Christian Posta */ diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkConnectionsCleanedupTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkConnectionsCleanedupTest.java index ee1bb6bcd0..8d644a0915 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkConnectionsCleanedupTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkConnectionsCleanedupTest.java @@ -16,40 +16,22 @@ */ package org.apache.activemq.network; -import java.net.URI; import java.util.ArrayList; import java.util.List; import javax.jms.Connection; -import javax.jms.DeliveryMode; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.TopicRequestor; -import javax.jms.TopicSession; import junit.framework.TestCase; -import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQTopic; -import org.apache.activemq.xbean.BrokerFactoryBean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; public class NetworkConnectionsCleanedupTest extends TestCase { protected static final int MESSAGE_COUNT = 10; - private static final Logger LOG = LoggerFactory.getLogger(NetworkConnectionsCleanedupTest.class); protected AbstractApplicationContext context; protected Connection localConnection; @@ -65,28 +47,25 @@ public class NetworkConnectionsCleanedupTest extends TestCase { // skip this test. it runs for an hour, doesn't assert anything, and could probably // just be removed (seems like a throwaway impl for https://issues.apache.org/activemq/browse/AMQ-1202) public void skipTestNetworkConnections() throws Exception { - String uri = "static:(tcp://localhost:61617)?initialReconnectDelay=100"; - List list = new ArrayList(); - for (int i =0;i < 100;i++){ - list.add(new ActiveMQTopic("FOO"+i)); - } - String bindAddress = "tcp://localhost:61616"; - BrokerService broker = new BrokerService(); - broker.setUseJmx(false); - broker.setPersistent(false); - broker.addConnector(bindAddress); - NetworkConnector network = broker.addNetworkConnector(uri); - network.setDynamicOnly(true); - network.setStaticallyIncludedDestinations(list); - uri = "static:(tcp://localhost:61618)?initialReconnectDelay=100"; - network = broker.addNetworkConnector(uri); + String uri = "static:(tcp://localhost:61617)?initialReconnectDelay=100"; + List list = new ArrayList(); + for (int i =0;i < 100;i++){ + list.add(new ActiveMQTopic("FOO"+i)); + } + String bindAddress = "tcp://localhost:61616"; + BrokerService broker = new BrokerService(); + broker.setUseJmx(false); + broker.setPersistent(false); + broker.addConnector(bindAddress); + NetworkConnector network = broker.addNetworkConnector(uri); network.setDynamicOnly(true); network.setStaticallyIncludedDestinations(list); - broker.setUseShutdownHook(false); - broker.start(); - Thread.sleep(1000 * 3600); + uri = "static:(tcp://localhost:61618)?initialReconnectDelay=100"; + network = broker.addNetworkConnector(uri); + network.setDynamicOnly(true); + network.setStaticallyIncludedDestinations(list); + broker.setUseShutdownHook(false); + broker.start(); + Thread.sleep(1000 * 3600); } - - - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkFailoverTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkFailoverTest.java index a72d7f3ed3..b16dde00b8 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkFailoverTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkFailoverTest.java @@ -37,7 +37,6 @@ import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.DestinationDoesNotExistException; import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.broker.region.policy.AbstractDeadLetterStrategy; import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.transport.TransportFilter; @@ -62,9 +61,9 @@ public class NetworkFailoverTest extends TestCase { protected Session localSession; protected Session remoteSession; protected ActiveMQQueue included=new ActiveMQQueue("include.test.foo"); - private AtomicInteger replyToNonExistDest = new AtomicInteger(0); - private AtomicInteger roundTripComplete = new AtomicInteger(0); - private AtomicInteger remoteDLQCount = new AtomicInteger(0); + private final AtomicInteger replyToNonExistDest = new AtomicInteger(0); + private final AtomicInteger roundTripComplete = new AtomicInteger(0); + private final AtomicInteger remoteDLQCount = new AtomicInteger(0); public void testRequestReply() throws Exception { final MessageProducer remoteProducer = remoteSession.createProducer(null); @@ -116,7 +115,7 @@ public class NetworkFailoverTest extends TestCase { remoteDLQCount.incrementAndGet(); } }); - + // allow for consumer infos to perculate arround Thread.sleep(2000); long done = System.currentTimeMillis() + (MESSAGE_COUNT * 6000); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkRemovesSubscriptionsTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkRemovesSubscriptionsTest.java index 7f4d4f48ff..b444379877 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkRemovesSubscriptionsTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkRemovesSubscriptionsTest.java @@ -31,7 +31,7 @@ import org.apache.activemq.command.ActiveMQTopic; /** * Various Tests to show the memory leak suspect in network of brokers. This is * for https://issues.apache.org/activemq/browse/AMQ-2530 - * + * */ public class NetworkRemovesSubscriptionsTest extends TestCase { private final static String frontEndAddress = "tcp://0.0.0.0:61617"; @@ -109,6 +109,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase { for (int i = 0; i < 100; i++) { TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = subscriberSession.createSubscriber(topic); + assertNotNull(subscriber); } connection.close(); @@ -121,7 +122,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase { /** * Running this test you can produce a leak of only 2 ConsumerInfo on BE * broker, NOT 200 as in other cases! - * + * */ public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception { @@ -148,6 +149,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase { class DummyMessageListener implements MessageListener { + @Override public void onMessage(Message arg0) { // TODO Auto-generated method stub diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkTestSupport.java index fca8aaab85..6d825a5d69 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkTestSupport.java @@ -36,7 +36,7 @@ import org.apache.activemq.usage.SystemUsage; public class NetworkTestSupport extends BrokerTestSupport { - protected ArrayList connections = new ArrayList(); + protected ArrayList connections = new ArrayList(); protected TransportConnector connector; @@ -46,18 +46,19 @@ public class NetworkTestSupport extends BrokerTestSupport { protected TransportConnector remoteConnector; protected boolean useJmx = false; + @Override protected void setUp() throws Exception { super.setUp(); - remotePersistenceAdapter = createRemotePersistenceAdapter(true); + remotePersistenceAdapter = createRemotePersistenceAdapter(true); remoteBroker = createRemoteBroker(remotePersistenceAdapter); remoteConnector = createRemoteConnector(); remoteBroker.addConnector( remoteConnector ); BrokerRegistry.getInstance().bind("remotehost", remoteBroker); remoteBroker.start(); } - - + + @Override protected BrokerService createBroker() throws Exception { BrokerService broker = BrokerFactory.createBroker(new URI("broker:()/localhost?persistent=false&useJmx=false&")); connector = createConnector(); @@ -66,7 +67,6 @@ public class NetworkTestSupport extends BrokerTestSupport { return broker; } - /** * @return * @throws Exception @@ -111,6 +111,7 @@ public class NetworkTestSupport extends BrokerTestSupport { return answer; } + @Override protected StubConnection createConnection() throws Exception { Transport transport = TransportFactory.connect(connector.getServer().getConnectURI()); StubConnection connection = new StubConnection(transport); @@ -138,7 +139,7 @@ public class NetworkTestSupport extends BrokerTestSupport { /** * Simulates a broker restart. The memory based persistence adapter is * reused so that it does not "loose" it's "persistent" messages. - * + * * @throws Exception */ protected void restartRemoteBroker() throws Exception { @@ -150,16 +151,17 @@ public class NetworkTestSupport extends BrokerTestSupport { remotePersistenceAdapter.stop(); remotePersistenceAdapter = createRemotePersistenceAdapter(false); remotePersistenceAdapter.start(); - + remoteBroker = createRemoteBroker(remotePersistenceAdapter); remoteBroker.addConnector(getRemoteURI()); remoteBroker.start(); BrokerRegistry.getInstance().bind("remotehost", remoteBroker); } + @Override protected void tearDown() throws Exception { - for (Iterator iter = connections.iterator(); iter.hasNext();) { - StubConnection connection = (StubConnection)iter.next(); + for (Iterator iter = connections.iterator(); iter.hasNext();) { + StubConnection connection = iter.next(); connection.stop(); iter.remove(); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/SSHTunnelNetworkReconnectTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/SSHTunnelNetworkReconnectTest.java index 3f50bbb05e..a7e759bd8b 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/SSHTunnelNetworkReconnectTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/SSHTunnelNetworkReconnectTest.java @@ -20,45 +20,43 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.ArrayList; -import java.util.Iterator; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Test network reconnects over SSH tunnels. This case can be especially tricky * since the SSH tunnels fool the TCP transport into thinking that they are * initially connected. - * - * @author chirino + * */ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest { - private static final transient Logger LOG = LoggerFactory.getLogger(SSHTunnelNetworkReconnectTest.class); - ArrayList processes = new ArrayList(); + ArrayList processes = new ArrayList(); + @Override protected BrokerService createFirstBroker() throws Exception { return BrokerFactory .createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker1.xml")); } + @Override protected BrokerService createSecondBroker() throws Exception { return BrokerFactory .createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker2.xml")); } + @Override protected void setUp() throws Exception { startProcess("ssh -Nn -L60006:localhost:61616 localhost"); startProcess("ssh -Nn -L60007:localhost:61617 localhost"); super.setUp(); } + @Override protected void tearDown() throws Exception { super.tearDown(); - for (Iterator iter = processes.iterator(); iter.hasNext();) { - Process p = (Process)iter.next(); + for (Process p : processes) { p.destroy(); } } @@ -67,6 +65,7 @@ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest { final Process process = Runtime.getRuntime().exec(command); processes.add(process); new Thread("stdout: " + command) { + @Override public void run() { try { InputStream is = process.getInputStream(); @@ -79,6 +78,7 @@ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest { } }.start(); new Thread("stderr: " + command) { + @Override public void run() { try { InputStream is = process.getErrorStream(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java index 3c3fe524f5..52b4984317 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java @@ -16,9 +16,9 @@ */ package org.apache.activemq.network; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.net.URI; import java.util.Arrays; @@ -103,6 +103,7 @@ public class SimpleNetworkTest { final MessageProducer remoteProducer = remoteSession.createProducer(null); MessageConsumer remoteConsumer = remoteSession.createConsumer(included); remoteConsumer.setMessageListener(new MessageListener() { + @Override public void onMessage(Message msg) { try { TextMessage textMsg = (TextMessage)msg; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueBridgeStandaloneReconnectTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueBridgeStandaloneReconnectTest.java index a0066cb3df..bfba58b8e8 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueBridgeStandaloneReconnectTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueBridgeStandaloneReconnectTest.java @@ -16,7 +16,19 @@ */ package org.apache.activemq.network.jms; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Iterator; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; @@ -25,17 +37,9 @@ import org.apache.activemq.util.Wait; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jms.*; -import java.util.ArrayList; -import java.util.Iterator; public class QueueBridgeStandaloneReconnectTest { - private static final Logger LOG = LoggerFactory.getLogger(QueueBridgeStandaloneReconnectTest.class); - private SimpleJmsQueueConnector jmsQueueConnector; private BrokerService localBroker; @@ -47,7 +51,7 @@ public class QueueBridgeStandaloneReconnectTest { private Destination outbound; private Destination inbound; - private ArrayList connections = new ArrayList(); + private final ArrayList connections = new ArrayList(); @Test public void testSendAndReceiveOverConnectedBridges() throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueOutboundBridgeReconnectTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueOutboundBridgeReconnectTest.java index 3a4d92abac..ed0a6fe57f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueOutboundBridgeReconnectTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/QueueOutboundBridgeReconnectTest.java @@ -16,7 +16,23 @@ */ package org.apache.activemq.network.jms; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; @@ -25,13 +41,6 @@ import org.apache.activemq.util.Wait; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jms.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.concurrent.TimeUnit; /** * These test cases are used to verify that queue outbound bridge connections get @@ -40,14 +49,12 @@ import java.util.concurrent.TimeUnit; */ public class QueueOutboundBridgeReconnectTest { - private static final Logger LOG = LoggerFactory.getLogger(QueueOutboundBridgeReconnectTest.class); - private BrokerService producerBroker; private BrokerService consumerBroker; private ActiveMQConnectionFactory producerConnectionFactory; private ActiveMQConnectionFactory consumerConnectionFactory; private Destination destination; - private ArrayList connections = new ArrayList(); + private final ArrayList connections = new ArrayList(); @Test public void testMultipleProducerBrokerRestarts() throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicBridgeStandaloneReconnectTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicBridgeStandaloneReconnectTest.java index e1e6039066..c499ff36bc 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicBridgeStandaloneReconnectTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicBridgeStandaloneReconnectTest.java @@ -16,7 +16,19 @@ */ package org.apache.activemq.network.jms; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Iterator; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; @@ -25,17 +37,9 @@ import org.apache.activemq.util.Wait; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jms.*; -import java.util.ArrayList; -import java.util.Iterator; public class TopicBridgeStandaloneReconnectTest { - private static final Logger LOG = LoggerFactory.getLogger(TopicBridgeStandaloneReconnectTest.class); - private SimpleJmsTopicConnector jmsTopicConnector; private BrokerService localBroker; @@ -47,7 +51,7 @@ public class TopicBridgeStandaloneReconnectTest { private Destination outbound; private Destination inbound; - private ArrayList connections = new ArrayList(); + private final ArrayList connections = new ArrayList(); @Test public void testSendAndReceiveOverConnectedBridges() throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java index f6fee5da28..6a64b5c187 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java @@ -16,7 +16,23 @@ */ package org.apache.activemq.network.jms; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; @@ -25,14 +41,6 @@ import org.apache.activemq.util.Wait; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jms.*; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.concurrent.TimeUnit; /** * These test cases are used to verify that queue outbound bridge connections get @@ -41,14 +49,12 @@ import java.util.concurrent.TimeUnit; */ public class TopicOutboundBridgeReconnectTest { - private static final Logger LOG = LoggerFactory.getLogger(TopicOutboundBridgeReconnectTest.class); - private BrokerService producerBroker; private BrokerService consumerBroker; private ActiveMQConnectionFactory producerConnectionFactory; private ActiveMQConnectionFactory consumerConnectionFactory; private Destination destination; - private ArrayList connections = new ArrayList(); + private final ArrayList connections = new ArrayList(); @Test public void testMultipleProducerBrokerRestarts() throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/BooleanStreamTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/BooleanStreamTest.java index fa6d7db1e3..ebe1d07e43 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/BooleanStreamTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/BooleanStreamTest.java @@ -26,7 +26,7 @@ import junit.framework.AssertionFailedError; import junit.framework.TestCase; /** - * + * */ public class BooleanStreamTest extends TestCase { @@ -40,6 +40,7 @@ public class BooleanStreamTest extends TestCase { public void testBooleanMarshallingUsingAllTrue() throws Exception { testBooleanStream(numberOfBytes, new BooleanValueSet() { + @Override public boolean getBooleanValueFor(int index, int count) { return true; } @@ -48,6 +49,7 @@ public class BooleanStreamTest extends TestCase { public void testBooleanMarshallingUsingAllFalse() throws Exception { testBooleanStream(numberOfBytes, new BooleanValueSet() { + @Override public boolean getBooleanValueFor(int index, int count) { return false; } @@ -56,6 +58,7 @@ public class BooleanStreamTest extends TestCase { public void testBooleanMarshallingUsingOddAlternateTrueFalse() throws Exception { testBooleanStream(numberOfBytes, new BooleanValueSet() { + @Override public boolean getBooleanValueFor(int index, int count) { return (index & 1) == 0; } @@ -64,6 +67,7 @@ public class BooleanStreamTest extends TestCase { public void testBooleanMarshallingUsingEvenAlternateTrueFalse() throws Exception { testBooleanStream(numberOfBytes, new BooleanValueSet() { + @Override public boolean getBooleanValueFor(int index, int count) { return (index & 1) != 0; } @@ -121,13 +125,14 @@ public class BooleanStreamTest extends TestCase { // lets try read and we should get an exception try { - byte value = dis.readByte(); + dis.readByte(); fail("Should have reached the end of the stream"); } catch (IOException e) { // worked! } } + @Override protected void setUp() throws Exception { super.setUp(); openWireformat = createOpenWireFormat(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGenerator.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGenerator.java index fe56a0764c..ac9311b142 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGenerator.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGenerator.java @@ -25,11 +25,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Iterator; -import junit.framework.Assert; - -public abstract class DataFileGenerator extends Assert { +public abstract class DataFileGenerator extends org.junit.Assert { static final File MODULE_BASE_DIR; static final File CONTROL_DIR; @@ -52,16 +49,16 @@ public abstract class DataFileGenerator extends Assert { * @throws InstantiationException * @throws IllegalAccessException */ - public static ArrayList getAllDataFileGenerators() throws Exception { + public static ArrayList getAllDataFileGenerators() throws Exception { // System.out.println("Looking for generators in : "+classFileDir); - ArrayList l = new ArrayList(); + ArrayList l = new ArrayList(); File[] files = CLASS_FILE_DIR.listFiles(); for (int i = 0; files != null && i < files.length; i++) { File file = files[i]; if (file.getName().endsWith("Data.java")) { String cn = file.getName(); cn = cn.substring(0, cn.length() - ".java".length()); - Class clazz = DataFileGenerator.class.getClassLoader().loadClass("org.apache.activemq.openwire." + cn); + Class clazz = DataFileGenerator.class.getClassLoader().loadClass("org.apache.activemq.openwire." + cn); l.add((DataFileGenerator)clazz.newInstance()); } } @@ -69,12 +66,11 @@ public abstract class DataFileGenerator extends Assert { } private static void generateControlFiles() throws Exception { - ArrayList generators = getAllDataFileGenerators(); - for (Iterator iter = generators.iterator(); iter.hasNext();) { - DataFileGenerator object = (DataFileGenerator)iter.next(); + ArrayList generators = getAllDataFileGenerators(); + for (DataFileGenerator element : generators) { try { // System.out.println("Processing: "+object.getClass()); - object.generateControlFile(); + element.generateControlFile(); } catch (Exception e) { // System.err.println("Error while processing: // "+object.getClass() + ". Reason: " + e); @@ -112,11 +108,10 @@ public abstract class DataFileGenerator extends Assert { } public static void assertAllControlFileAreEqual() throws Exception { - ArrayList generators = getAllDataFileGenerators(); - for (Iterator iter = generators.iterator(); iter.hasNext();) { - DataFileGenerator object = (DataFileGenerator)iter.next(); + ArrayList generators = getAllDataFileGenerators(); + for (DataFileGenerator element : generators) { // System.out.println("Processing: "+object.getClass()); - object.assertControlFileIsEqual(); + element.assertControlFileIsEqual(); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java index 1a41dc37b6..0bc1fb6d15 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java @@ -152,7 +152,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { } else if (expectedValue instanceof DataStructure) { assertBeansEqual(message + name, comparedObjects, expectedValue, actualValue); } else if (expectedValue instanceof Enumeration) { - assertEnumerationEqual(message + name, comparedObjects, (Enumeration)expectedValue, (Enumeration)actualValue); + assertEnumerationEqual(message + name, comparedObjects, (Enumeration)expectedValue, (Enumeration)actualValue); } else { assertEquals(message, expectedValue, actualValue); } @@ -166,12 +166,12 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { assertPropertyValuesEqual(message + ". element: " + i, comparedObjects, expected[i], actual[i]); } } - - protected void assertEnumerationEqual(String message, Set comparedObjects, Enumeration expected, Enumeration actual) throws Exception { + + protected void assertEnumerationEqual(String message, Set comparedObjects, Enumeration expected, Enumeration actual) throws Exception { while (expected.hasMoreElements()) { - Object expectedElem = expected.nextElement(); - Object actualElem = actual.nextElement(); - assertPropertyValuesEqual(message + ". element: " + expectedElem, comparedObjects, expectedElem, actualElem); + Object expectedElem = expected.nextElement(); + Object actualElem = actual.nextElement(); + assertPropertyValuesEqual(message + ". element: " + expectedElem, comparedObjects, expectedElem, actualElem); } } @@ -204,6 +204,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { assertEquals(message, expected.getMessage(), actual.getMessage()); } + @Override protected void setUp() throws Exception { super.setUp(); openWireformat = createOpenWireFormat(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java index c91e87c67e..973a00734b 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java @@ -23,13 +23,14 @@ import java.io.DataOutputStream; import java.io.IOException; import junit.framework.TestCase; + import org.apache.activemq.command.ActiveMQTextMessage; import org.apache.activemq.command.SessionId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * + * */ public class NumberRangesWhileMarshallingTest extends TestCase { @@ -87,7 +88,7 @@ public class NumberRangesWhileMarshallingTest extends TestCase { // lets try read and we should get an exception try { byte value = dis.readByte(); - fail("Should have reached the end of the stream"); + fail("Should have reached the end of the stream: " + value); } catch (IOException e) { // worked! } @@ -124,6 +125,7 @@ public class NumberRangesWhileMarshallingTest extends TestCase { assertEquals(Long.MAX_VALUE, wf.getMaxFrameSize()); } + @Override protected void setUp() throws Exception { super.setUp(); openWireformat = createOpenWireFormat();