Skip to content

Commit 0d7250d

Browse files
committed
ARTEMIS-TEMP Fix auto delete for non-empty addresses
1 parent 9f7ebd6 commit 0d7250d

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,12 @@ private void deleteDuplicateCache(SimpleString address) throws Exception {
10681068
@Override
10691069
public boolean isAddressBound(final SimpleString address) throws Exception {
10701070
Collection<Binding> bindings = getDirectBindings(address);
1071-
return bindings != null && !bindings.isEmpty();
1071+
return (bindings != null && !bindings.isEmpty()) ||
1072+
// When an address has no direct bindings but the address size is > 0, it means queues on other addresses
1073+
// have one or more message references pointing to this address (e.g., queues bound to wildcard addresses).
1074+
// The address must be considered bound because these message references keep it in use, preventing
1075+
// operations like auto-deletion that should only occur when the address is truly unused.
1076+
pagingManager.getPageStore(address).getAddressSize() > 0;
10721077
}
10731078

10741079
@Override

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteAddressTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertNotNull;
2020
import static org.junit.jupiter.api.Assertions.assertNull;
21-
import static org.junit.jupiter.api.Assertions.assertTrue;
2221

2322
import java.util.ArrayList;
2423
import java.util.Arrays;
2524
import java.util.List;
2625
import java.util.concurrent.CountDownLatch;
27-
import java.util.concurrent.TimeUnit;
2826

2927
import org.apache.activemq.artemis.api.core.QueueConfiguration;
3028
import org.apache.activemq.artemis.api.core.RoutingType;
3129
import org.apache.activemq.artemis.api.core.SimpleString;
3230
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
31+
import org.apache.activemq.artemis.api.core.client.ClientMessage;
3332
import org.apache.activemq.artemis.api.core.client.ClientProducer;
3433
import org.apache.activemq.artemis.api.core.client.ClientSession;
3534
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
@@ -122,13 +121,11 @@ public void testAutoDeleteAddressWithWildcardAddress() throws Exception {
122121
String wildcardAddress = prefix + ".#";
123122
String queue = RandomUtil.randomUUIDString();
124123
final int MESSAGE_COUNT = 10;
125-
final CountDownLatch latch = new CountDownLatch(MESSAGE_COUNT);
126124

127125
server.createQueue(QueueConfiguration.of(queue).setAddress(wildcardAddress).setRoutingType(RoutingType.ANYCAST).setAutoCreated(true));
128126

129127
ClientSession consumerSession = cf.createSession();
130128
ClientConsumer consumer = consumerSession.createConsumer(queue);
131-
consumer.setMessageHandler(message -> latch.countDown());
132129
consumerSession.start();
133130

134131
ClientSession producerSession = cf.createSession();
@@ -143,7 +140,19 @@ public void testAutoDeleteAddressWithWildcardAddress() throws Exception {
143140
}
144141
producerSession.close();
145142

146-
assertTrue(latch.await(2, TimeUnit.SECONDS));
143+
PostOfficeTestAccessor.sweepAndReapAddresses((PostOfficeImpl) server.getPostOffice());
144+
145+
for (String address : addresses) {
146+
assertNotNull(server.getAddressInfo(SimpleString.of(address)));
147+
Wait.assertTrue(() -> Arrays.asList(server.getPagingManager().getStoreNames()).contains(SimpleString.of(address)), 2000, 100);
148+
}
149+
150+
for (int i = 0; i < MESSAGE_COUNT; i++) {
151+
ClientMessage message = consumer.receive(3000);
152+
assertNotNull(message);
153+
message.acknowledge();
154+
}
155+
consumerSession.commit();
147156

148157
for (String address : addresses) {
149158
assertNotNull(server.getAddressInfo(SimpleString.of(address)));

0 commit comments

Comments
 (0)