Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -111,7 +111,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 = listFiles(persistentDir, "*.log").size();

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

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

Expand All @@ -159,7 +159,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 listFiles(persistentDir, "*.log").size() == original;
}
}, 5000, 500));

Expand All @@ -169,7 +169,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 : listFiles(persistentDir, "db.*")) {
FileUtils.deleteQuietly(index);
}

Expand Down Expand Up @@ -208,7 +208,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 = listFiles(persistentDir, "*.log").size();

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

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

Expand All @@ -255,7 +255,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 listFiles(persistentDir, "*.log").size() == original;
}
}));

Expand All @@ -265,7 +265,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 : listFiles(persistentDir, "db.*")) {
FileUtils.deleteQuietly(index);
}

Expand All @@ -288,4 +288,9 @@ public boolean isSatisified() throws Exception {

assertNull(durable2.receive(500));
}
}

private Collection<File> listFiles(File directory, String filterPattern) {
WildcardFileFilter filter = WildcardFileFilter.builder().setWildcards(filterPattern).get();
return FileUtils.listFiles(directory, filter, TrueFileFilter.INSTANCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.TimeUnit;

import jakarta.jms.BytesMessage;
Expand Down Expand Up @@ -118,7 +118,7 @@ private void restartWithRecovery(File persistenceDir) throws Exception {
broker.waitUntilStopped();

// 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 : listFiles(persistenceDir, "db.*")) {
FileUtils.deleteQuietly(index);
}

Expand Down Expand Up @@ -201,15 +201,18 @@ 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();
return listFiles(getPersistentDir(), "*.log").size();
}

private File getPersistentDir() throws IOException {
return broker.getPersistenceAdapter().getDirectory();
}

private Collection<File> listFiles(File directory, String filterPattern) {
WildcardFileFilter filter = WildcardFileFilter.builder().setWildcards(filterPattern).get();
return FileUtils.listFiles(directory, filter, TrueFileFilter.INSTANCE);
}

protected QueueViewMBean getProxyToQueue(String name) throws MalformedObjectNameException, JMSException {
ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName="+name);
QueueViewMBean proxy = (QueueViewMBean) broker.getManagementContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Collection;

import org.apache.activemq.store.AbstractMessageStoreSizeTest;
import org.apache.activemq.store.MessageStore;
Expand Down Expand Up @@ -124,7 +125,9 @@ 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)) {
WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.data").get();
Collection<File> files = FileUtils.listFiles(new File(dataDirectory), fileFilter, TrueFileFilter.INSTANCE);
for (File index : files) {
FileUtils.deleteQuietly(index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ 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());
WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("db*").get();
Collection<File> storeFiles = FileUtils.listFiles(storeDir, fileFilter, getStoreFileFilter());
assertTrue("Store index should still exist", storeFiles.size() >= 1);
}

Expand All @@ -151,7 +152,8 @@ 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());
WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("db*").get();
Collection<File> storeFiles = FileUtils.listFiles(storeDir, fileFilter, getStoreFileFilter());
assertTrue("Store index should still exist", storeFiles.size() >= 1);
}

Expand All @@ -170,7 +172,8 @@ 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());
WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("db*").get();
Collection<File> storeFiles = FileUtils.listFiles(storeDir, fileFilter, getStoreFileFilter());
assertEquals("Store files should be deleted", 0, storeFiles.size());

}
Expand All @@ -189,9 +192,9 @@ 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());
WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards("db*").get();
Collection<File> storeFiles = FileUtils.listFiles(storeDir, fileFilter, 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 @@ -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)) {
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