Skip to content

Commit

Permalink
ARTEMIS-3535 bytes messages not obeying management limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Dec 14, 2021
1 parent 753cf2a commit fb2270d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,13 @@ public Map<String, Object> getFields(CoreMessage m, int valueSizeLimit, int deli
rc.put(CompositeDataConstants.TYPE, m.getType());
if (!m.isLargeMessage()) {
ActiveMQBuffer bodyCopy = m.getReadOnlyBodyBuffer();
byte[] bytes = new byte[bodyCopy.readableBytes() <= valueSizeLimit ? bodyCopy.readableBytes() : valueSizeLimit + 1];
int arraySize;
if (valueSizeLimit == -1 || bodyCopy.readableBytes() <= valueSizeLimit) {
arraySize = bodyCopy.readableBytes();
} else {
arraySize = valueSizeLimit;
}
byte[] bytes = new byte[arraySize];
bodyCopy.readBytes(bytes);
rc.put(CompositeDataConstants.BODY, JsonUtil.truncate(bytes, valueSizeLimit));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,48 @@ public void testMessageAttributeLimits() throws Exception {
session.deleteQueue(queue);
}

@Test
public void testBytesMessageBodyWithoutLimits() throws Exception {
final int BYTE_COUNT = 2048;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();

AddressSettings addressSettings = new AddressSettings().setManagementMessageAttributeSizeLimit(-1);
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);

session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(durable));

byte[] randomBytes = RandomUtil.randomBytes(BYTE_COUNT);

ClientMessage clientMessage = session.createMessage(false);
clientMessage.getBodyBuffer().writeBytes(randomBytes);

QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(0, getMessageCount(queueControl));

ClientProducer producer = session.createProducer(address);
producer.send(clientMessage);

Wait.assertEquals(1, () -> getMessageCount(queueControl));

CompositeData[] browseResult = queueControl.browse(1, 1);
boolean tested = false;
for (CompositeData compositeData : browseResult) {
for (String key : compositeData.getCompositeType().keySet()) {
Object value = compositeData.get(key);
if (value != null) {
if (value instanceof byte[]) {
assertEqualsByteArrays(randomBytes, (byte[]) value);
tested = true;
}
}
}
}

assertTrue("Nothing tested!", tested);
session.deleteQueue(queue);
}

@Test
public void testTextMessageAttributeLimits() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
Expand Down

0 comments on commit fb2270d

Please sign in to comment.