activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-2025 Ensure correct calculation of message body size
Date Sun, 12 Aug 2018 20:34:16 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 3ac7b9aef -> 2ec8927ae


ARTEMIS-2025 Ensure correct calculation of message body size


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/d6d73c7f
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/d6d73c7f
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/d6d73c7f

Branch: refs/heads/master
Commit: d6d73c7f2372e211022c5aca7f0052e84170a6f0
Parents: 3ac7b9a
Author: Martyn Taylor <mtaylor@redhat.com>
Authored: Sun Aug 12 15:12:11 2018 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Sun Aug 12 16:33:49 2018 -0400

----------------------------------------------------------------------
 .../core/client/impl/ClientMessageImpl.java     |  3 ++-
 .../artemis/core/message/impl/CoreMessage.java  |  2 +-
 .../tests/integration/ra/JMSContextTest.java    | 26 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d6d73c7f/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientMessageImpl.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientMessageImpl.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientMessageImpl.java
index 8068aa9..d14c64e 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientMessageImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientMessageImpl.java
@@ -189,7 +189,8 @@ public class ClientMessageImpl extends CoreMessage implements ClientMessageInter
 
    @Override
    public int getBodySize() {
-      return getBodyBuffer().writerIndex() - getBodyBuffer().readerIndex();
+      checkEncode();
+      return endOfBodyPosition - BUFFER_HEADER_SPACE;
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d6d73c7f/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
----------------------------------------------------------------------
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 0918828..323d9f4 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
@@ -308,7 +308,7 @@ public class CoreMessage extends RefCountMessage implements ICoreMessage
{
       sendBuffer.readerIndex(0);
    }
 
-   private synchronized void checkEncode() {
+   protected synchronized void checkEncode() {
       if (!validBuffer) {
          encode();
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d6d73c7f/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/JMSContextTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/JMSContextTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/JMSContextTest.java
index 6956499..658b323 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/JMSContextTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/JMSContextTest.java
@@ -16,8 +16,13 @@
  */
 package org.apache.activemq.artemis.tests.integration.ra;
 
+import javax.jms.JMSConsumer;
 import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
 import javax.jms.JMSRuntimeException;
+import javax.jms.MessageFormatRuntimeException;
+import javax.jms.Queue;
+import javax.jms.TextMessage;
 import javax.transaction.TransactionManager;
 import java.util.HashSet;
 import java.util.Set;
@@ -143,4 +148,25 @@ public class JMSContextTest extends ActiveMQRATestBase {
       assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
    }
 
+   @Test
+   public void testJMSContextConsumerThrowsMessageFormatExceptionOnMalformedBody() throws
Exception {
+      Queue queue = createQueue(true, "ContextMalformedBodyTestQueue");
+
+      JMSContext context = qraConnectionFactory.createContext();
+      JMSProducer producer = context.createProducer();
+
+      TextMessage message = context.createTextMessage("TestMessage");
+      producer.send(queue, message);
+
+      JMSConsumer consumer = context.createConsumer(queue);
+
+      try {
+         consumer.receiveBody(Boolean.class);
+         fail("Should thrown MessageFormatException");
+      } catch (MessageFormatRuntimeException mfre) {
+         // Do nothing test passed
+      } catch (Exception e) {
+         fail("Threw wrong exception, should be MessageFormatRuntimeException, instead got:
" + e.getClass().getCanonicalName());
+      }
+   }
 }


Mime
View raw message