diff --git a/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/ThreadLeakCheckRule.java b/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/ThreadLeakCheckRule.java index 62b14357ec..3fc8d2f6af 100644 --- a/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/ThreadLeakCheckRule.java +++ b/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/ThreadLeakCheckRule.java @@ -41,6 +41,13 @@ public class ThreadLeakCheckRule extends ExternalResource { private static Set knownThreads = new HashSet<>(); + static { + addKownThread("MemoryPoolMXBean notification dispatcher"); + addKownThread("threadDeathWatcher"); + addKownThread("SeedGenerator Thread"); + addKownThread("Attach Listener"); + } + boolean enabled = true; private Map previousThreads; diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceTest.java index 891a52f594..cf7f84a9a9 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceTest.java @@ -26,7 +26,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class ActiveMQDynamicProducerResourceTest { @@ -44,9 +43,6 @@ public class ActiveMQDynamicProducerResourceTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); } EmbeddedActiveMQResource server = new EmbeddedActiveMQResource(); @@ -63,14 +59,8 @@ public class ActiveMQDynamicProducerResourceTest { public void tearDown() throws Exception { assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_QUEUE_ONE), sentOne); assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_QUEUE_TWO), sentTwo); - Wait.waitFor(new Wait.Condition() { - @Override - public boolean isSatisfied() throws Exception { - return server.getMessageCount(TEST_QUEUE_ONE) == 1 && server.getMessageCount(TEST_QUEUE_TWO) == 1; - } - }, 5000, 100); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE_ONE), 1, server.getMessageCount(TEST_QUEUE_ONE)); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE_TWO), 1, server.getMessageCount(TEST_QUEUE_TWO)); + Wait.assertEquals(1L, () -> server.getMessageCount(TEST_QUEUE_ONE), 30_000, 10); + Wait.assertEquals(1L, () -> server.getMessageCount(TEST_QUEUE_TWO), 30_000, 10); ClientMessage receivedOne = server.receiveMessage(TEST_QUEUE_ONE); assertNotNull(String.format(ASSERT_RECEIVED_FORMAT, TEST_QUEUE_ONE), receivedOne); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressExceptionTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressExceptionTest.java index 1af2a40777..47e6a2b031 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressExceptionTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressExceptionTest.java @@ -37,9 +37,6 @@ public class ActiveMQDynamicProducerResourceWithoutAddressExceptionTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); } EmbeddedActiveMQResource server = new EmbeddedActiveMQResource(); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressTest.java index f3c5d99c32..b945ea61df 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQDynamicProducerResourceWithoutAddressTest.java @@ -27,7 +27,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class ActiveMQDynamicProducerResourceWithoutAddressTest { @@ -45,9 +44,6 @@ public class ActiveMQDynamicProducerResourceWithoutAddressTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); } EmbeddedActiveMQResource server = new EmbeddedActiveMQResource(); @@ -71,14 +67,8 @@ public class ActiveMQDynamicProducerResourceWithoutAddressTest { public void tearDown() throws Exception { assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_QUEUE_ONE), sentOne); assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_QUEUE_TWO), sentTwo); - Wait.waitFor(new Wait.Condition() { - @Override - public boolean isSatisfied() throws Exception { - return server.getMessageCount(TEST_QUEUE_ONE) == 1 && server.getMessageCount(TEST_QUEUE_TWO) == 1; - } - }, 5000, 100); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE_ONE), 1, server.getMessageCount(TEST_QUEUE_ONE)); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE_TWO), 1, server.getMessageCount(TEST_QUEUE_TWO)); + Wait.assertEquals(1L, ()-> server.getMessageCount(TEST_QUEUE_ONE), 30_000, 10); + Wait.assertEquals(1L, ()-> server.getMessageCount(TEST_QUEUE_TWO), 30_000, 10); ClientMessage receivedOne = server.receiveMessage(TEST_QUEUE_ONE); assertNotNull(String.format(ASSERT_RECEIVED_FORMAT, TEST_QUEUE_ONE), receivedOne); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQProducerResourceTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQProducerResourceTest.java index 695fef51b2..82be91bb41 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQProducerResourceTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/ActiveMQProducerResourceTest.java @@ -43,9 +43,6 @@ public class ActiveMQProducerResourceTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); } EmbeddedActiveMQResource server = new EmbeddedActiveMQResource(); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceCustomConfigurationTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceCustomConfigurationTest.java index 006fdd7a73..37cff8978a 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceCustomConfigurationTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceCustomConfigurationTest.java @@ -37,12 +37,6 @@ public class EmbeddedActiveMQResourceCustomConfigurationTest { static final String TEST_QUEUE = "test.queue"; static final String TEST_ADDRESS = "test.address"; - static { - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - ThreadLeakCheckRule.addKownThread("SeedGenerator Thread"); - } - CoreQueueConfiguration queueConfiguration = new CoreQueueConfiguration().setAddress(TEST_ADDRESS).setName(TEST_QUEUE); Configuration customConfiguration = new ConfigurationImpl().setPersistenceEnabled(false).setSecurityEnabled(true).addQueueConfiguration(queueConfiguration); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceFileConfigurationTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceFileConfigurationTest.java index 188efdaa69..077049b907 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceFileConfigurationTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceFileConfigurationTest.java @@ -33,12 +33,6 @@ public class EmbeddedActiveMQResourceFileConfigurationTest { static final String TEST_QUEUE = "test.queue"; static final String TEST_ADDRESS = "test.address"; - static { - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - ThreadLeakCheckRule.addKownThread("SeedGenerator Thread"); - } - private EmbeddedActiveMQResource server = new EmbeddedActiveMQResource("embedded-artemis-server.xml"); @Rule diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceTest.java index 7c7132d1af..551a97027c 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResourceTest.java @@ -27,7 +27,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class EmbeddedActiveMQResourceTest { @@ -45,9 +44,6 @@ public class EmbeddedActiveMQResourceTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); } public EmbeddedActiveMQResource server = new EmbeddedActiveMQResource(); @@ -65,13 +61,7 @@ public class EmbeddedActiveMQResourceTest { @After public void tearDown() throws Exception { assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_ADDRESS), sent); - Wait.waitFor(new Wait.Condition() { - @Override - public boolean isSatisfied() throws Exception { - return server.getMessageCount(TEST_QUEUE) == 1; - } - }, 5000, 100); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE), 1, server.getMessageCount(TEST_QUEUE)); + Wait.assertEquals(1L, () -> server.getMessageCount(TEST_QUEUE), 30_000, 10); ClientMessage received = server.receiveMessage(TEST_QUEUE); assertNotNull(String.format(ASSERT_RECEIVED_FORMAT, TEST_ADDRESS), received); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceMultipleFileConfigurationTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceMultipleFileConfigurationTest.java index a5d695bc9d..868f2e4e76 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceMultipleFileConfigurationTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceMultipleFileConfigurationTest.java @@ -43,12 +43,6 @@ public class EmbeddedJMSResourceMultipleFileConfigurationTest { static final String ASSERT_PUSHED_FORMAT = "Message should have been pushed a message to %s"; static final String ASSERT_COUNT_FORMAT = "Unexpected message count in destination %s"; - static { - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - ThreadLeakCheckRule.addKownThread("SeedGenerator Thread"); - } - public EmbeddedJMSResource jmsServer = new EmbeddedJMSResource("embedded-artemis-minimal-server.xml", "embedded-artemis-jms-only.xml"); @Rule diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceQueueTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceQueueTest.java index 8f9c9c3584..0db347a657 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceQueueTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceQueueTest.java @@ -26,7 +26,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class EmbeddedJMSResourceQueueTest { @@ -47,10 +46,6 @@ public class EmbeddedJMSResourceQueueTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - ThreadLeakCheckRule.addKownThread("SeedGenerator Thread"); } public EmbeddedJMSResource jmsServer = new EmbeddedJMSResource(); @@ -63,13 +58,7 @@ public class EmbeddedJMSResourceQueueTest { @After public void tearDown() throws Exception { assertNotNull(String.format(ASSERT_PUSHED_FORMAT, TEST_DESTINATION_NAME), pushed); - Wait.waitFor(new Wait.Condition() { - @Override - public boolean isSatisfied() throws Exception { - return jmsServer.getMessageCount(TEST_DESTINATION_NAME) == 1; - } - }, 5000, 100); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_DESTINATION_NAME), 1, jmsServer.getMessageCount(TEST_DESTINATION_NAME)); + Wait.assertEquals(1L, () -> jmsServer.getMessageCount(TEST_DESTINATION_NAME), (long)30_000, (long)10); } @Test diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceSingleFileConfigurationTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceSingleFileConfigurationTest.java index 7f2a675bbc..3cf0cb5f69 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceSingleFileConfigurationTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceSingleFileConfigurationTest.java @@ -43,12 +43,6 @@ public class EmbeddedJMSResourceSingleFileConfigurationTest { static final String ASSERT_PUSHED_FORMAT = "Message should have been pushed a message to %s"; static final String ASSERT_COUNT_FORMAT = "Unexpected message count in destination %s"; - static { - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - ThreadLeakCheckRule.addKownThread("SeedGenerator Thread"); - } - public EmbeddedJMSResource jmsServer = new EmbeddedJMSResource("embedded-artemis-jms-server.xml"); @Rule diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceTopicTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceTopicTest.java index 0e89de24e1..af924bf027 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceTopicTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/EmbeddedJMSResourceTopicTest.java @@ -33,7 +33,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class EmbeddedJMSResourceTopicTest { @@ -54,10 +53,6 @@ public class EmbeddedJMSResourceTopicTest { TEST_PROPERTIES = new HashMap(2); TEST_PROPERTIES.put("PropertyOne", "Property Value 1"); TEST_PROPERTIES.put("PropertyTwo", "Property Value 2"); - - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - ThreadLeakCheckRule.addKownThread("SeedGenerator Thread"); } public EmbeddedJMSResource jmsServer = new EmbeddedJMSResource(); @@ -84,13 +79,7 @@ public class EmbeddedJMSResourceTopicTest { @After public void tearDown() throws Exception { assertNotNull(String.format(ASSERT_PUSHED_FORMAT, TEST_DESTINATION_NAME), pushed); - Wait.waitFor(new Wait.Condition() { - @Override - public boolean isSatisfied() throws Exception { - return jmsServer.getMessageCount(TEST_DESTINATION_NAME) == 1; - } - }, 5000, 100); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_DESTINATION_NAME), 1, jmsServer.getMessageCount(TEST_DESTINATION_NAME)); + Wait.assertEquals(1L, () -> jmsServer.getMessageCount(TEST_DESTINATION_NAME), (long)30_000, (long)10); consumer.close(); session.close(); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedActiveMQResourcesTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedActiveMQResourcesTest.java index b6c5c7d95a..2f9da05761 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedActiveMQResourcesTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedActiveMQResourcesTest.java @@ -39,11 +39,6 @@ public class MultipleEmbeddedActiveMQResourcesTest { static final String ASSERT_RECEIVED_FORMAT = "Message should have been received from %s"; static final String ASSERT_COUNT_FORMAT = "Unexpected message count in queue %s"; - static { - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - } - public EmbeddedActiveMQResource serverOne = new EmbeddedActiveMQResource(0); public EmbeddedActiveMQResource serverTwo = new EmbeddedActiveMQResource(1); diff --git a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedJMSResourcesTest.java b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedJMSResourcesTest.java index 2e81724b35..fe9d1758bd 100644 --- a/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedJMSResourcesTest.java +++ b/artemis-junit/src/test/java/org/apache/activemq/artemis/junit/MultipleEmbeddedJMSResourcesTest.java @@ -24,7 +24,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class MultipleEmbeddedJMSResourcesTest { @@ -36,11 +35,6 @@ public class MultipleEmbeddedJMSResourcesTest { static final String ASSERT_PUSHED_FORMAT = "Message should have been pushed a message to %s"; static final String ASSERT_COUNT_FORMAT = "Unexpected message count in destination %s"; - static { - ThreadLeakCheckRule.addKownThread("MemoryPoolMXBean notification dispatcher"); - ThreadLeakCheckRule.addKownThread("threadDeathWatcher"); - } - public EmbeddedJMSResource jmsServerOne = new EmbeddedJMSResource(0); public EmbeddedJMSResource jmsServerTwo = new EmbeddedJMSResource(1); @@ -58,15 +52,8 @@ public class MultipleEmbeddedJMSResourcesTest { Message pushedTwo = jmsServerTwo.pushMessage(TEST_QUEUE_TWO, TEST_BODY); assertNotNull(String.format(ASSERT_PUSHED_FORMAT, TEST_QUEUE_TWO), pushedTwo); - - Wait.waitFor(new Wait.Condition() { - @Override - public boolean isSatisfied() throws Exception { - return jmsServerOne.getMessageCount(TEST_QUEUE_ONE) == 1 && jmsServerTwo.getMessageCount(TEST_QUEUE_TWO) == 1; - } - }, 5000, 100); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE_ONE), 1, jmsServerOne.getMessageCount(TEST_QUEUE_ONE)); - assertEquals(String.format(ASSERT_COUNT_FORMAT, TEST_QUEUE_TWO), 1, jmsServerTwo.getMessageCount(TEST_QUEUE_TWO)); + Wait.assertEquals(1L, () -> jmsServerOne.getMessageCount(TEST_QUEUE_ONE), 30_000, 10); + Wait.assertEquals(1L, () -> jmsServerTwo.getMessageCount(TEST_QUEUE_TWO), 30_000, 10); } } \ No newline at end of file