From cdce20a128c81e603b80a479d7189caf815d660c Mon Sep 17 00:00:00 2001 From: Patrick Deasy Date: Fri, 16 Aug 2024 13:35:55 -0700 Subject: [PATCH] AMQ-9544 Replace the deprecated WildcardFileFilter constructor with a builder. --- .../org/apache/activemq/bugs/AMQ6131Test.java | 19 +++++++++++-------- .../bugs/AMQ6133PersistJMSRedeliveryTest.java | 8 ++++---- .../AbstractKahaDBMessageStoreSizeTest.java | 3 ++- .../AbstractMultiKahaDBDeletionTest.java | 9 +++++---- .../kahadb/MultiKahaDBQueueDeletionTest.java | 2 +- .../kahadb/MultiKahaDBTopicDeletionTest.java | 2 +- .../kahadb/SubscriptionRecoveryTest.java | 3 ++- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6131Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6131Test.java index 1c28d64504f..8d6bacc819e 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6131Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6131Test.java @@ -56,6 +56,9 @@ */ public class AMQ6131Test { + private final static WildcardFileFilter LOG_FILE_FILTER = WildcardFileFilter.builder().setWildcards("*.log").get(); + private final static WildcardFileFilter DB_FILE_FILTER = WildcardFileFilter.builder().setWildcards("db.*").get(); + protected BrokerService broker; protected URI brokerConnectURI; @@ -111,7 +114,7 @@ public void testDurableWithOnePendingAfterRestartAndIndexRecovery() throws Excep TopicSubscriber durable = jmsSession.createDurableSubscriber(new ActiveMQTopic("durable.sub"), "sub"); final MessageProducer producer = jmsSession.createProducer(new ActiveMQTopic("durable.sub")); - final int original = new ArrayList(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size(); + final int original = new ArrayList(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size(); // 100k messages final byte[] data = new byte[100000]; @@ -132,7 +135,7 @@ public boolean isSatisified() throws Exception { messageCount.getAndIncrement(); } - return new ArrayList(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() > original; + return new ArrayList(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() > original; } })); @@ -159,7 +162,7 @@ public boolean isSatisified() throws Exception { @Override public boolean isSatisified() throws Exception { - return new ArrayList(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() == original; + return new ArrayList(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() == original; } }, 5000, 500)); @@ -169,7 +172,7 @@ public boolean isSatisified() throws Exception { // delete the index so that the durables are gone from the index // The test passes if you take out this delete section - for (File index : FileUtils.listFiles(persistentDir, new WildcardFileFilter("db.*"), TrueFileFilter.INSTANCE)) { + for (File index : FileUtils.listFiles(persistentDir, DB_FILE_FILTER, TrueFileFilter.INSTANCE)) { FileUtils.deleteQuietly(index); } @@ -208,7 +211,7 @@ public void testDurableWithNoMessageAfterRestartAndIndexRecovery() throws Except TopicSubscriber durable = jmsSession.createDurableSubscriber(new ActiveMQTopic("durable.sub"), "sub"); final MessageProducer producer = jmsSession.createProducer(new ActiveMQTopic("durable.sub")); - final int original = new ArrayList(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size(); + final int original = new ArrayList(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size(); // 100k messages final byte[] data = new byte[100000]; @@ -229,7 +232,7 @@ public boolean isSatisified() throws Exception { messageCount.getAndIncrement(); } - return new ArrayList(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() > original; + return new ArrayList(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() > original; } })); @@ -255,7 +258,7 @@ public boolean isSatisified() throws Exception { @Override public boolean isSatisified() throws Exception { - return new ArrayList(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() == original; + return new ArrayList(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() == original; } })); @@ -265,7 +268,7 @@ public boolean isSatisified() throws Exception { // delete the index so that the durables are gone from the index // The test passes if you take out this delete section - for (File index : FileUtils.listFiles(persistentDir, new WildcardFileFilter("db.*"), TrueFileFilter.INSTANCE)) { + for (File index : FileUtils.listFiles(persistentDir, DB_FILE_FILTER, TrueFileFilter.INSTANCE)) { FileUtils.deleteQuietly(index); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6133PersistJMSRedeliveryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6133PersistJMSRedeliveryTest.java index f281a6b8797..02ce2146bea 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6133PersistJMSRedeliveryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6133PersistJMSRedeliveryTest.java @@ -117,8 +117,9 @@ private void restartWithRecovery(File persistenceDir) throws Exception { broker.stop(); broker.waitUntilStopped(); + final WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("db.*").get(); // delete the index so that it needs to be rebuilt from replay - for (File index : FileUtils.listFiles(persistenceDir, new WildcardFileFilter("db.*"), TrueFileFilter.INSTANCE)) { + for (File index : FileUtils.listFiles(persistenceDir, fileFilter, TrueFileFilter.INSTANCE)) { FileUtils.deleteQuietly(index); } @@ -201,9 +202,8 @@ private void createBroker(boolean deleteAllMessages) throws Exception { } private int getLogFileCount() throws Exception { - return new ArrayList( - FileUtils.listFiles(getPersistentDir(), - new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size(); + final WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.log").get(); + return new ArrayList(FileUtils.listFiles(getPersistentDir(), fileFilter, TrueFileFilter.INSTANCE)).size(); } private File getPersistentDir() throws IOException { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractKahaDBMessageStoreSizeTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractKahaDBMessageStoreSizeTest.java index 7d53cbd0f0c..0aac04c49c8 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractKahaDBMessageStoreSizeTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractKahaDBMessageStoreSizeTest.java @@ -124,7 +124,8 @@ public void testMessageSizeStoreRecoveryVersion5RebuildIndex() throws Exception FileUtils.deleteDirectory(new File(dataDirectory)); FileUtils.copyDirectory(new File(getVersion5Dir()), dataDir); - for (File index : FileUtils.listFiles(new File(dataDirectory), new WildcardFileFilter("*.data"), TrueFileFilter.INSTANCE)) { + final WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.data").get(); + for (File index : FileUtils.listFiles(new File(dataDirectory), fileFilter, TrueFileFilter.INSTANCE)) { FileUtils.deleteQuietly(index); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractMultiKahaDBDeletionTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractMultiKahaDBDeletionTest.java index bc354011925..2e8ee91e2be 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractMultiKahaDBDeletionTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/AbstractMultiKahaDBDeletionTest.java @@ -44,6 +44,7 @@ public abstract class AbstractMultiKahaDBDeletionTest { + private final static WildcardFileFilter DB_FILE_FILTER = WildcardFileFilter.builder().setWildcards("db*").get(); protected static final Logger LOG = LoggerFactory .getLogger(MultiKahaDBTopicDeletionTest.class); @@ -131,7 +132,7 @@ public void testDest1Deletion() throws Exception { // try and create a consumer on dest2, before AMQ-5875 this //would cause an IllegalStateException for Topics createConsumer(dest2); - Collection storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter()); + Collection storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter()); assertTrue("Store index should still exist", storeFiles.size() >= 1); } @@ -151,7 +152,7 @@ public void testDest2Deletion() throws Exception { // try and create a consumer on dest1, before AMQ-5875 this //would cause an IllegalStateException for Topics createConsumer(dest1); - Collection storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter()); + Collection storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter()); assertTrue("Store index should still exist", storeFiles.size() >= 1); } @@ -170,7 +171,7 @@ public void testStoreCleanupDeleteDest1First() throws Exception { broker.removeDestination(brokerService.getAdminConnectionContext(), dest2, 100); //Assert that with no more destinations attached to a store that it has been cleaned up - Collection storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter()); + Collection storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter()); assertEquals("Store files should be deleted", 0, storeFiles.size()); } @@ -189,7 +190,7 @@ public void testStoreCleanupDeleteDest2First() throws Exception { broker.removeDestination(brokerService.getAdminConnectionContext(), dest1, 100); //Assert that with no more destinations attached to a store that it has been cleaned up - Collection storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter()); + Collection storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter()); assertEquals("Store files should be deleted", 0, storeFiles.size()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBQueueDeletionTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBQueueDeletionTest.java index 140573e459e..162faebc5e9 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBQueueDeletionTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBQueueDeletionTest.java @@ -85,7 +85,7 @@ protected void createConsumer(ActiveMQDestination dest) throws JMSException { */ @Override protected WildcardFileFilter getStoreFileFilter() { - return new WildcardFileFilter("queue*"); + return WildcardFileFilter.builder().setWildcards("queue*").get(); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBTopicDeletionTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBTopicDeletionTest.java index 52941284538..bd9c8254c54 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBTopicDeletionTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/MultiKahaDBTopicDeletionTest.java @@ -80,7 +80,7 @@ protected void createConsumer(ActiveMQDestination dest) throws JMSException { @Override protected WildcardFileFilter getStoreFileFilter() { - return new WildcardFileFilter("topic*"); + return WildcardFileFilter.builder().setWildcards("topic*").get(); } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/SubscriptionRecoveryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/SubscriptionRecoveryTest.java index a9ccf8585a0..22398c58cee 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/SubscriptionRecoveryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/SubscriptionRecoveryTest.java @@ -81,7 +81,8 @@ public void createBroker(boolean deleteAllMessages, boolean recover) throws Exce pa.setCleanupInterval(TimeUnit.SECONDS.toMillis(5)); //Delete the index files on recovery if (recover) { - for (File index : FileUtils.listFiles(dataFile, new WildcardFileFilter("*.data"), TrueFileFilter.INSTANCE)) { + final WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.data").get(); + for (File index : FileUtils.listFiles(dataFile, fileFilter, TrueFileFilter.INSTANCE)) { LOG.info("deleting: " + index); FileUtils.deleteQuietly(index); }