ARTEMIS-5170 Fix AutoCreateExpiryResourcesTest and document expiry of expiry

This commit is contained in:
Clebert Suconic 2024-11-20 22:28:43 -05:00 committed by clebertsuconic
parent 8483e4e558
commit 7965877760
2 changed files with 28 additions and 1 deletions

View File

@ -76,6 +76,13 @@ If `min-expiry-delay` is not defined then the message will not be changed.
The default for both `min-expiry-delay` and `max-expiry-delay` is `-1` (i.e. disabled).
[WARNING]
====
**If you set expiry-delay, or min/max-expiry-delay, on the expiration target address beware of the following:**
* Messages will get a new expiration when moved to the expiry queue, rather than being set to 0 as usual, and so may disappear after the new expiration.
====
== Configuring Expiry Addresses
Expiry address are defined in the address-setting configuration:

View File

@ -60,6 +60,9 @@ public class AutoCreateExpiryResourcesTest extends ActiveMQTestBase {
// set common address settings needed for all tests; make sure to use getMatch instead of addMatch in invidual tests or these will be overwritten
server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateExpiryResources(true).setExpiryAddress(expiryAddress).setExpiryDelay(EXPIRY_DELAY));
// avoiding expiration of the expiration
server.getAddressSettingsRepository().addMatch(String.valueOf(expiryAddress), new AddressSettings().setExpiryDelay(-1L));
server.start();
}
@ -129,7 +132,7 @@ public class AutoCreateExpiryResourcesTest extends ActiveMQTestBase {
}
private void testAutoCreatedExpiryFilter(RoutingType routingType) throws Exception {
final int ITERATIONS = 50;
final int ITERATIONS = 5;
final int MESSAGE_COUNT = 5;
for (int i = 0; i < ITERATIONS; i++) {
@ -149,6 +152,11 @@ public class AutoCreateExpiryResourcesTest extends ActiveMQTestBase {
locator.close();
Wait.assertTrue(() -> server.locateQueue(getDefaultExpiryQueueName(address)) != null, 2000, 10);
Queue expiry = server.locateQueue(AddressSettings.DEFAULT_EXPIRY_QUEUE_PREFIX.concat(address).concat(AddressSettings.DEFAULT_EXPIRY_QUEUE_SUFFIX));
// This sleep is to make the message would survive in the Expiry Address after the default delay
// to catch any eventual misconfiguration
Thread.sleep(EXPIRY_DELAY);
Wait.assertEquals(MESSAGE_COUNT, expiry::getMessageCount);
}
@ -168,6 +176,10 @@ public class AutoCreateExpiryResourcesTest extends ActiveMQTestBase {
Wait.assertTrue(() -> server.locateQueue(expiryQueueName) != null, 2000, 100);
Wait.assertEquals(1, server.locateQueue(expiryQueueName) :: getMessageCount);
// This sleep is to make the message would survive in the Expiry Address after the default delay
// to catch any eventual misconfiguration
Thread.sleep(EXPIRY_DELAY);
ClientConsumer consumer = session.createConsumer(expiryQueueName);
session.start();
ClientMessage message = consumer.receive(5_000);
@ -194,6 +206,10 @@ public class AutoCreateExpiryResourcesTest extends ActiveMQTestBase {
triggerExpiration();
// This sleep is to make the message would survive in the Expiry Address after the default delay
// to catch any eventual misconfiguration
Thread.sleep(EXPIRY_DELAY);
JMSContext context = new ActiveMQConnectionFactory("vm://0").createContext();
context.start();
assertNotNull(context.createConsumer(context.createQueue(fqqn)).receive(2000));
@ -210,6 +226,10 @@ public class AutoCreateExpiryResourcesTest extends ActiveMQTestBase {
triggerExpiration(false);
// This sleep is to make the message would survive in the Expiry Address after the default delay
// to catch any eventual misconfiguration
Thread.sleep(EXPIRY_DELAY);
Wait.assertTrue(() -> server.locateQueue(expiryQueueName) != null, 2_000, 20);
Wait.assertEquals(COUNT, () -> server.locateQueue(expiryQueueName).getMessageCount(), 2000, 20);
}