You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/11/21 14:14:55 UTC

[1/2] activemq-artemis git commit: ARTEMIS-1514 Fix read large message into buffer

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 9a8055bd3 -> 3fba3573a


ARTEMIS-1514 Fix read large message into buffer


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

Branch: refs/heads/master
Commit: eddb144debac2c3dd25e9354151e230e4ab73172
Parents: 9a8055b
Author: Martyn Taylor <mt...@redhat.com>
Authored: Tue Nov 21 13:22:27 2017 +0000
Committer: Martyn Taylor <mt...@redhat.com>
Committed: Tue Nov 21 13:23:12 2017 +0000

----------------------------------------------------------------------
 .../impl/journal/LargeServerMessageImpl.java    | 11 +++----
 .../openwire/OpenWireLargeMessageTest.java      | 31 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/eddb144d/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/LargeServerMessageImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/LargeServerMessageImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/LargeServerMessageImpl.java
index 11d1a21..d10f3b8 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/LargeServerMessageImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/LargeServerMessageImpl.java
@@ -19,12 +19,13 @@ package org.apache.activemq.artemis.core.persistence.impl.journal;
 import java.nio.ByteBuffer;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import io.netty.buffer.Unpooled;
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
-import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
 import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
 import org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException;
 import org.apache.activemq.artemis.api.core.Message;
+import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
 import org.apache.activemq.artemis.core.io.SequentialFile;
 import org.apache.activemq.artemis.core.message.LargeBodyEncoder;
 import org.apache.activemq.artemis.core.message.impl.CoreMessage;
@@ -205,9 +206,10 @@ public final class LargeServerMessageImpl extends CoreMessage implements LargeSe
    public ActiveMQBuffer getReadOnlyBodyBuffer() {
       try {
          file.open();
-         ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer((int) file.size());
-         file.read(buffer.toByteBuffer());
-         return buffer;
+         int fileSize = (int) file.size();
+         ByteBuffer buffer = this.storageManager.largeMessagesFactory.newBuffer(fileSize);
+         file.read(buffer);
+         return new ChannelBufferWrapper(Unpooled.wrappedBuffer(buffer));
       } catch (Exception e) {
          throw new RuntimeException(e);
       } finally {
@@ -215,7 +217,6 @@ public final class LargeServerMessageImpl extends CoreMessage implements LargeSe
             file.close();
          } catch (Exception ignored) {
          }
-
       }
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/eddb144d/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireLargeMessageTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireLargeMessageTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireLargeMessageTest.java
index 35cea1b..9535cc5 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireLargeMessageTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/OpenWireLargeMessageTest.java
@@ -19,6 +19,7 @@ package org.apache.activemq.artemis.tests.integration.openwire;
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
@@ -60,4 +61,34 @@ public class OpenWireLargeMessageTest extends BasicOpenWireTest {
          producer.send(message);
       }
    }
+
+   @Test
+   public void testSendReceiveLargeMessage() throws Exception {
+      try (Connection connection = factory.createConnection()) {
+         connection.start();
+
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = session.createQueue(lmAddress.toString());
+         MessageProducer producer = session.createProducer(queue);
+         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+         // Create 1MB Message
+         int size = 1024 * 1024;
+         byte[] bytes = new byte[size];
+         bytes[0] = 1;
+
+         BytesMessage message = session.createBytesMessage();
+         message.writeBytes(bytes);
+         producer.send(message);
+
+         MessageConsumer consumer = session.createConsumer(queue);
+         BytesMessage m = (BytesMessage) consumer.receive();
+         assertNotNull(m);
+
+         byte[] body = new byte[size];
+         m.readBytes(body);
+
+         assertArrayEquals(body, bytes);
+      }
+   }
 }


[2/2] activemq-artemis git commit: This closes #1662

Posted by cl...@apache.org.
This closes #1662


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

Branch: refs/heads/master
Commit: 3fba3573a5d4ea7f4678c25b2782a91722f547b5
Parents: 9a8055b eddb144
Author: Clebert Suconic <cl...@apache.org>
Authored: Tue Nov 21 08:57:08 2017 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Nov 21 08:57:08 2017 -0500

----------------------------------------------------------------------
 .../impl/journal/LargeServerMessageImpl.java    | 11 +++----
 .../openwire/OpenWireLargeMessageTest.java      | 31 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------