From d2bd152960a74de6a61c2ddbea81ddcdcb70c177 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Thu, 17 Sep 2015 11:27:42 +0000 Subject: [PATCH] Tweaking some unit tests to improve reliability --- .../transport/auto/nio/AutoNIOTransport.java | 3 +++ .../cursors/AbstractPendingMessageCursorTest.java | 12 ++++++------ .../cursors/KahaDBPendingMessageCursorTest.java | 4 ++-- .../store/AbstractMessageStoreSizeStatTest.java | 8 ++++---- .../store/kahadb/KahaDBMessageStoreSizeStatTest.java | 2 +- .../kahadb/MultiKahaDBMessageStoreSizeStatTest.java | 4 ++-- .../auto/AutoTransportMaxConnectionsTest.java | 9 ++++++--- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/transport/auto/nio/AutoNIOTransport.java b/activemq-broker/src/main/java/org/apache/activemq/transport/auto/nio/AutoNIOTransport.java index a9a9f5d31f..8927c8e1c7 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/transport/auto/nio/AutoNIOTransport.java +++ b/activemq-broker/src/main/java/org/apache/activemq/transport/auto/nio/AutoNIOTransport.java @@ -64,6 +64,9 @@ public class AutoNIOTransport extends NIOTransport { if (nextFrameSize == -1) { readSize = 4; this.initBuffer.buffer.flip(); + if (this.initBuffer.buffer.remaining() < 8) { + throw new IOException("Protocol type could not be determined."); + } for (int i = 0; i < 4; i++) { currentBuffer.put(initBuffer.buffer.get()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursorTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursorTest.java index 798746bf56..f496806d34 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursorTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursorTest.java @@ -179,7 +179,7 @@ public abstract class AbstractPendingMessageCursorTest extends AbstractStoreStat verifyStoreStats(dest, 0, 0); } - @Test(timeout=30000) + @Test(timeout=60000) public void testTopicMessageSize() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -205,7 +205,7 @@ public abstract class AbstractPendingMessageCursorTest extends AbstractStoreStat connection.close(); } - @Test(timeout=30000) + @Test(timeout=60000) public void testTopicNonPersistentMessageSize() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -232,7 +232,7 @@ public abstract class AbstractPendingMessageCursorTest extends AbstractStoreStat connection.close(); } - @Test(timeout=30000) + @Test(timeout=60000) public void testTopicPersistentAndNonPersistentMessageSize() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -261,7 +261,7 @@ public abstract class AbstractPendingMessageCursorTest extends AbstractStoreStat connection.close(); } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeOneDurable() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection(); @@ -286,7 +286,7 @@ public abstract class AbstractPendingMessageCursorTest extends AbstractStoreStat connection.close(); } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeOneDurablePartialConsumption() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -312,7 +312,7 @@ public abstract class AbstractPendingMessageCursorTest extends AbstractStoreStat connection.close(); } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeTwoDurables() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/KahaDBPendingMessageCursorTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/KahaDBPendingMessageCursorTest.java index b0bca7d9e4..e0921dcf90 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/KahaDBPendingMessageCursorTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/KahaDBPendingMessageCursorTest.java @@ -68,7 +68,7 @@ public class KahaDBPendingMessageCursorTest extends * * @throws Exception */ - @Test(timeout=30000) + @Test(timeout=60000) public void testDurableMessageSizeAfterRestartAndPublish() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -107,7 +107,7 @@ public class KahaDBPendingMessageCursorTest extends * * @throws Exception */ - @Test(timeout=30000) + @Test(timeout=60000) public void testNonPersistentDurableMessageSize() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/AbstractMessageStoreSizeStatTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/AbstractMessageStoreSizeStatTest.java index 8f17746640..9bbbdb6652 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/AbstractMessageStoreSizeStatTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/AbstractMessageStoreSizeStatTest.java @@ -92,7 +92,7 @@ public abstract class AbstractMessageStoreSizeStatTest extends AbstractStoreStat protected abstract void initPersistence(BrokerService brokerService) throws IOException; - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSize() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -100,7 +100,7 @@ public abstract class AbstractMessageStoreSizeStatTest extends AbstractStoreStat verifyStats(dest, 200, publishedMessageSize.get()); } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeAfterConsumption() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -112,7 +112,7 @@ public abstract class AbstractMessageStoreSizeStatTest extends AbstractStoreStat verifyStats(dest, 0, 0); } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeOneDurable() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection(); @@ -133,7 +133,7 @@ public abstract class AbstractMessageStoreSizeStatTest extends AbstractStoreStat connection.close(); } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeTwoDurables() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBMessageStoreSizeStatTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBMessageStoreSizeStatTest.java index 5a302ca129..1efb59e403 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBMessageStoreSizeStatTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBMessageStoreSizeStatTest.java @@ -65,7 +65,7 @@ public class KahaDBMessageStoreSizeStatTest extends * * @throws Exception */ - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeAfterRestartAndPublish() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Destination dest = publishTestQueueMessages(200, publishedMessageSize); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBMessageStoreSizeStatTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBMessageStoreSizeStatTest.java index 0adfcff521..0c4fc763e6 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBMessageStoreSizeStatTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBMessageStoreSizeStatTest.java @@ -85,7 +85,7 @@ public class MultiKahaDBMessageStoreSizeStatTest extends * * @throws Exception */ - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeAfterRestartAndPublish() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); @@ -104,7 +104,7 @@ public class MultiKahaDBMessageStoreSizeStatTest extends } - @Test(timeout=30000) + @Test(timeout=60000) public void testMessageSizeAfterRestartAndPublishMultiQueue() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); AtomicLong publishedMessageSize2 = new AtomicLong(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/auto/AutoTransportMaxConnectionsTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/auto/AutoTransportMaxConnectionsTest.java index bbc20a3c89..77fd74f3e4 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/auto/AutoTransportMaxConnectionsTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/auto/AutoTransportMaxConnectionsTest.java @@ -39,7 +39,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.springframework.jms.support.JmsUtils; @RunWith(Parameterized.class) public class AutoTransportMaxConnectionsTest { @@ -95,18 +94,22 @@ public class AutoTransportMaxConnectionsTest { return new ActiveMQConnectionFactory(connectionUri); } - @Test + @Test(timeout=60000) public void testMaxConnectionControl() throws Exception { final ConnectionFactory cf = createConnectionFactory(); final CountDownLatch startupLatch = new CountDownLatch(1); - for(int i = 0; i < maxConnections + 20; i++) { + //create an extra 10 connections above max + for(int i = 0; i < maxConnections + 10; i++) { + final int count = i; executor.submit(new Runnable() { @Override public void run() { Connection conn = null; try { startupLatch.await(); + //sleep for a short period of time + Thread.sleep(count * 3); conn = cf.createConnection(); conn.start(); } catch (Exception e) {