Skip to content

Commit

Permalink
ARTEMIS-4962: add test, clarify some related comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmellr authored and jbertram committed Sep 3, 2024
1 parent d929c5d commit 9133cdb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public String toString() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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;
Expand Down Expand Up @@ -106,7 +108,6 @@ public void testAMQDurable() throws Exception {
message.setDurable(false);

assertTrue(filter.match(message));

}

@Test
Expand All @@ -126,7 +127,6 @@ public void testAMQSize() throws Exception {

assertFalse(lessThanSmall.match(message));
assertFalse(moreThanLarge.match(message));

}

@Test
Expand Down Expand Up @@ -157,6 +157,31 @@ public void testAMQTimestamp() throws Exception {
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"));
Expand Down

0 comments on commit 9133cdb

Please sign in to comment.