You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2021/12/14 03:58:13 UTC

[activemq-artemis] branch main updated: ARTEMIS-3535 bytes messages not obeying management limit

This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new fb2270d  ARTEMIS-3535 bytes messages not obeying management limit
     new 1b32004  This closes #3824
fb2270d is described below

commit fb2270dc057c773f99e679132fd8ce926ff2fc58
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Fri Oct 29 11:01:05 2021 -0500

    ARTEMIS-3535 bytes messages not obeying management limit
---
 .../artemis/core/message/impl/CoreMessage.java     |  8 ++++-
 .../integration/management/QueueControlTest.java   | 42 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
index 6c55c3f..48ea5fd 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
@@ -1378,7 +1378,13 @@ public class CoreMessage extends RefCountMessage implements ICoreMessage {
          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 {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java
index 7d4804c..aa7c897 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java
@@ -578,6 +578,48 @@ public class QueueControlTest extends ManagementTestBase {
    }
 
    @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();
       SimpleString queue = RandomUtil.randomSimpleString();