From 9133cdb466ac952d9b0256386cf99c88652b12f2 Mon Sep 17 00:00:00 2001 From: Robbie Gemmell Date: Tue, 3 Sep 2024 14:55:50 +0100 Subject: [PATCH] ARTEMIS-4962: add test, clarify some related comments --- .../artemis/api/core/FilterConstants.java | 2 +- .../artemis/core/filter/impl/FilterImpl.java | 3 +- .../artemis/core/filter/impl/FilterTest.java | 29 +++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java index e690ba602d..d50b7217e8 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java @@ -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"; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java index 4246f7b4fe..3893d463f8 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java @@ -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); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java index 8747a1155e..4c95171ecd 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java @@ -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"));