ARTEMIS-4962: add test, clarify some related comments

This commit is contained in:
Robbie Gemmell 2024-09-03 14:55:50 +01:00 committed by Justin Bertram
parent d929c5dd66
commit 9133cdb466
3 changed files with 30 additions and 4 deletions

View File

@ -78,7 +78,7 @@ public final class FilterConstants {
public static final SimpleString ACTIVEMQ_PREFIX = SimpleString.of("AMQ");
/**
* Proton protocol stores JMSMessageID as NATIVE_MESSAGE_ID
* Core to AMQP wrapper can store JMSMessageID as NATIVE_MESSAGE_ID internally
*/
public static final String NATIVE_MESSAGE_ID = "NATIVE_MESSAGE_ID";

View File

@ -159,7 +159,8 @@ public class FilterImpl implements Filter {
private static Object getHeaderFieldValue(final Message msg, final SimpleString fieldName) {
if (FilterConstants.ACTIVEMQ_USERID.equals(fieldName)) {
if (msg.getUserID() == null) {
// Proton stores JMSMessageID as NATIVE_MESSAGE_ID that is an arbitrary string
// Artemis can store JMSMessageID as NATIVE_MESSAGE_ID that is an arbitrary string,
// in wrapper used internally when converting from Core to AMQP.
String amqpNativeID = msg.getStringProperty(NATIVE_MESSAGE_ID);
if (amqpNativeID != null) {
return SimpleString.of(amqpNativeID);

View File

@ -21,6 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.UUID;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQInvalidFilterExpressionException;
import org.apache.activemq.artemis.api.core.Message;
@ -106,7 +108,6 @@ public class FilterTest extends SilentTestCase {
message.setDurable(false);
assertTrue(filter.match(message));
}
@Test
@ -126,7 +127,6 @@ public class FilterTest extends SilentTestCase {
assertFalse(lessThanSmall.match(message));
assertFalse(moreThanLarge.match(message));
}
@Test
@ -157,6 +157,31 @@ public class FilterTest extends SilentTestCase {
assertTrue(filter.match(message));
}
// AMQUserID, i.e. 'user-provided message ID', or what is typically thought of as the MessageID.
@Test
public void testAMQUserID() throws Exception {
// This 'MessageID' is the Artemis 'internal numeric id' assigned to each message
message = new CoreMessage().initBuffer(1024).setMessageID(1);
UUID randomUUID = UUID.randomUUID();
org.apache.activemq.artemis.utils.UUID artemisUUID = new org.apache.activemq.artemis.utils.UUID(randomUUID);
filter = FilterImpl.createFilter(SimpleString.of("AMQUserID='ID:" + randomUUID + "'"));
Filter nullFilter = FilterImpl.createFilter(SimpleString.of("AMQUserID IS NULL"));
Filter notNullFilter = FilterImpl.createFilter(SimpleString.of("AMQUserID IS NOT NULL"));
assertFalse(filter.match(message));
assertTrue(nullFilter.match(message));
assertFalse(notNullFilter.match(message));
// This 'UserID' is not about user names etc, but what is typically considered as a MessageID.
message.setUserID(artemisUUID);
assertTrue(filter.match(message));
assertFalse(nullFilter.match(message));
assertTrue(notNullFilter.match(message));
}
@Test
public void testBooleanTrue() throws Exception {
filter = FilterImpl.createFilter(SimpleString.of("MyBoolean=true"));