Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTEMIS-5142 setting 0 for min/max expiry-delivery not working as expected #5334

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jbertram
Copy link
Contributor

@jbertram jbertram commented Nov 1, 2024

No description provided.

pom.xml Outdated Show resolved Hide resolved
@gemmellr
Copy link
Member

gemmellr commented Nov 1, 2024

The min and max settings aren't listed in the address-settings doc, might be good to add them with this.

(They are covered in the expiry section referenced from the address setting doc for the other expiry setting).

@jbertram
Copy link
Contributor Author

jbertram commented Nov 1, 2024

@gemmellr, I took care of the documentation.

import org.junit.Test;
import org.mockito.Mockito;

public class ExpiryTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be more obvious/discoverable later for this class to be called PostOfficeImplTest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.


import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.junit.Test;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the JUnit 4 test annotation (still present in this module because the vintage runner is needed for some tests), should be using org.junit.jupiter.api.Test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public class ExpiryTest {

@Test
public void testZeroMaxExpiryDelayWhenExpirationSet() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For properly testing the areas being changed, we should include tests with and without the expiration set originally (these 2 both set it), and probably also with the 'expiry-delay' set instead of the min/max ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the ones you mentioned plus a few more.

Comment on lines +1372 to +1376
if (maxExpiration != AddressSettings.DEFAULT_MAX_EXPIRY_DELAY && maxExpiration != 0) {
message.setExpiration(getExpirationToSet(maxExpiration));
} else if (minExpiration != AddressSettings.DEFAULT_MIN_EXPIRY_DELAY && minExpiration != 0) {
message.setExpiration(getExpirationToSet(minExpiration));
}
Copy link
Member

@gemmellr gemmellr Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recent "&& maxExpiration != 0" addition seems like a logic bug. Setting the max to 0 is still classed as setting it, and the doc says that in this situation the max value will be applied if set...however this would instead deliberately not set it and then perhaps apply the minimum if it were set (which initially seemed like a strange setup, but perhaps not given the next comment...and either way it doesnt seem like anything prevents it...and its debatable whether a non-zero minimum is still lower than never-expire maximum).

The maxExpiration != 0 check would need to be in its own nested if to do what the doc says. Alternatively, the getExpirationToSet(maxExpiration) call could always be made, and the message.setExpiration call only applied if that value differed from the existing message expiration.

Comment on lines +1377 to +1378
} else if (maxExpiration != AddressSettings.DEFAULT_MAX_EXPIRY_DELAY && message.getExpiration() > (System.currentTimeMillis() + maxExpiration)) {
message.setExpiration(getExpirationToSet(maxExpiration));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this and the segment below seems to try handling the 'max/min expiration delay 0' special case, setting the expiration to 0. One covers >current and the other covers <current.

However if setting both settings to 0, presumably for an implied do-no-expiry-ever, then this setup will currently miss the case where the value exactly matches the current time reference, which will then be left unchanged and be allowed to expire which could be considered against the expectations for this special case?

@gemmellr
Copy link
Member

In addition to the above comments on potential for mismatch between doc and/or expectations and the actual behaviour...I pushed another commit with some more tests, and tweaks to some of the existing tests, to more strictly verify the resulting expiration value set is in the expected range. See what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants