Skip to content

Commit 75627fb

Browse files
committed
fix(test): make StoreOrderTest parallel-safe with unique broker names
- Use UUID-based unique broker name per test instance to avoid BrokerRegistry collisions between parallel runs - Replace hardcoded vm://localhost with vm://<brokerName> connection - Add TemporaryFolder in KahaDBStoreOrderTest to avoid shared data directory at target/activemq-data/kahadb/storeOrder - Add waitUntilStarted()/waitUntilStopped() for proper lifecycle
1 parent 4e7652d commit 75627fb

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

activemq-unit-tests/src/test/java/org/apache/activemq/store/StoreOrderTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertTrue;
2222
import static org.junit.Assert.fail;
2323

24+
import java.util.UUID;
2425
import java.util.concurrent.CountDownLatch;
2526
import java.util.concurrent.Executor;
2627
import java.util.concurrent.Executors;
@@ -56,6 +57,7 @@ public abstract class StoreOrderTest {
5657
protected BrokerService broker;
5758
private ActiveMQConnection connection;
5859
public Destination destination = new ActiveMQQueue("StoreOrderTest?consumer.prefetchSize=0");
60+
protected final String brokerName = "StoreOrderTest-" + UUID.randomUUID().toString().substring(0, 8);
5961

6062
protected abstract void setPersistentAdapter(BrokerService brokerService) throws Exception;
6163
protected void dumpMessages() throws Exception {}
@@ -107,7 +109,7 @@ public void setup() throws Exception {
107109
}
108110

109111
public void initConnection() throws Exception {
110-
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false");
112+
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName + "?create=false");
111113
connection = (ActiveMQConnection) connectionFactory.createConnection();
112114
connection.setWatchTopicAdvisories(false);
113115
connection.start();
@@ -120,6 +122,7 @@ public void stopBroker() throws Exception {
120122
}
121123
if (broker != null) {
122124
broker.stop();
125+
broker.waitUntilStopped();
123126
}
124127
}
125128

@@ -257,10 +260,12 @@ protected BrokerService startBroker(boolean deleteMessagesOnStartup) throws Exce
257260
configureBroker(newBroker);
258261
newBroker.setDeleteAllMessagesOnStartup(deleteMessagesOnStartup);
259262
newBroker.start();
263+
newBroker.waitUntilStarted();
260264
return newBroker;
261265
}
262266

263267
protected void configureBroker(BrokerService brokerService) throws Exception {
268+
brokerService.setBrokerName(brokerName);
264269
setPersistentAdapter(brokerService);
265270
brokerService.setAdvisorySupport(false);
266271

activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBStoreOrderTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020

2121
import org.apache.activemq.broker.BrokerService;
2222
import org.apache.activemq.store.StoreOrderTest;
23+
import org.junit.Rule;
24+
import org.junit.rules.TemporaryFolder;
2325

2426
// https://issues.apache.org/activemq/browse/AMQ-2594
2527
public class KahaDBStoreOrderTest extends StoreOrderTest {
26-
28+
29+
@Rule
30+
public TemporaryFolder tempFolder = new TemporaryFolder(new File("target"));
31+
2732
@Override
2833
protected void setPersistentAdapter(BrokerService brokerService)
2934
throws Exception {
3035
KahaDBStore kaha = new KahaDBStore();
31-
File directory = new File("target/activemq-data/kahadb/storeOrder");
32-
kaha.setDirectory(directory);
36+
kaha.setDirectory(tempFolder.newFolder("kahadb-storeOrder"));
3337
brokerService.setPersistenceAdapter(kaha);
3438
}
3539
}

0 commit comments

Comments
 (0)