Skip to content

Commit

Permalink
AMQ-9544 Replace the deprecated WildcardFileFilter constructor with a…
Browse files Browse the repository at this point in the history
… builder.
  • Loading branch information
Patrick Deasy committed Aug 19, 2024
1 parent e45ee4a commit cdce20a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size();
final int original = new ArrayList<File>(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size();

// 100k messages
final byte[] data = new byte[100000];
Expand All @@ -132,7 +135,7 @@ public boolean isSatisified() throws Exception {
messageCount.getAndIncrement();
}

return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() > original;
return new ArrayList<File>(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() > original;
}
}));

Expand All @@ -159,7 +162,7 @@ public boolean isSatisified() throws Exception {

@Override
public boolean isSatisified() throws Exception {
return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() == original;
return new ArrayList<File>(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() == original;
}
}, 5000, 500));

Expand All @@ -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);
}

Expand Down Expand Up @@ -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<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size();
final int original = new ArrayList<File>(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size();

// 100k messages
final byte[] data = new byte[100000];
Expand All @@ -229,7 +232,7 @@ public boolean isSatisified() throws Exception {
messageCount.getAndIncrement();
}

return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() > original;
return new ArrayList<File>(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() > original;
}
}));

Expand All @@ -255,7 +258,7 @@ public boolean isSatisified() throws Exception {

@Override
public boolean isSatisified() throws Exception {
return new ArrayList<File>(FileUtils.listFiles(persistentDir, new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size() == original;
return new ArrayList<File>(FileUtils.listFiles(persistentDir, LOG_FILE_FILTER, TrueFileFilter.INSTANCE)).size() == original;
}
}));

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -201,9 +202,8 @@ private void createBroker(boolean deleteAllMessages) throws Exception {
}

private int getLogFileCount() throws Exception {
return new ArrayList<File>(
FileUtils.listFiles(getPersistentDir(),
new WildcardFileFilter("*.log"), TrueFileFilter.INSTANCE)).size();
final WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.log").get();
return new ArrayList<File>(FileUtils.listFiles(getPersistentDir(), fileFilter, TrueFileFilter.INSTANCE)).size();
}

private File getPersistentDir() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<File> storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter());
Collection<File> storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter());
assertTrue("Store index should still exist", storeFiles.size() >= 1);
}

Expand All @@ -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<File> storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter());
Collection<File> storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter());
assertTrue("Store index should still exist", storeFiles.size() >= 1);
}

Expand All @@ -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<File> storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter());
Collection<File> storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter());
assertEquals("Store files should be deleted", 0, storeFiles.size());

}
Expand All @@ -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<File> storeFiles = FileUtils.listFiles(storeDir, new WildcardFileFilter("db*"), getStoreFileFilter());
Collection<File> storeFiles = FileUtils.listFiles(storeDir, DB_FILE_FILTER, getStoreFileFilter());
assertEquals("Store files should be deleted", 0, storeFiles.size());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit cdce20a

Please sign in to comment.