activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kea...@apache.org
Subject git commit: Added test to reproduce AMQ-4887
Date Thu, 05 Dec 2013 09:45:46 GMT
Updated Branches:
  refs/heads/trunk 374cab9cd -> 8b06c44cc


Added test to reproduce AMQ-4887


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

Branch: refs/heads/trunk
Commit: 8b06c44cc0028565b1de42bebad024f20fbc1a00
Parents: 374cab9
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Thu Dec 5 10:45:38 2013 +0100
Committer: Kevin Earls <kevin@kevinearls.com>
Committed: Thu Dec 5 10:45:38 2013 +0100

----------------------------------------------------------------------
 .../org/apache/activemq/bugs/AMQ4887Test.java   | 81 ++++++++++++++++++++
 1 file changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/8b06c44c/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4887Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4887Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4887Test.java
new file mode 100644
index 0000000..f29f605
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4887Test.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.bugs;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import static org.junit.Assert.*;
+
+public class AMQ4887Test {
+    private static final transient Logger LOG = LoggerFactory.getLogger(AMQ4887Test.class);
+    private static final Integer ITERATIONS = 10;
+    @Rule
+    public TestName name = new TestName();
+
+    @Test
+    public void testSetPropertyBeforeCopy() throws Exception {
+        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
+        ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
+        connection.start();
+
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Destination destination = session.createQueue(name.toString());
+        MessageConsumer consumer = session.createConsumer(destination);
+        MessageProducer producer = session.createProducer(destination);
+
+        byte[] messageContent = "bytes message".getBytes();
+        BytesMessage bytesMessage = session.createBytesMessage();
+        bytesMessage.writeBytes(messageContent);
+
+        for (int i=0; i < ITERATIONS; i++) {
+            long sendTime = System.currentTimeMillis();
+            bytesMessage.setLongProperty("sendTime", sendTime);
+            producer.send(bytesMessage);
+
+            LOG.debug("Receiving message " + i);
+            Message receivedMessage =  consumer.receive(5000);
+            assertNotNull("On message " + i, receivedMessage);
+            assertTrue("On message " + i, receivedMessage instanceof BytesMessage);
+
+            BytesMessage receivedBytesMessage = (BytesMessage) receivedMessage;
+            byte[] receivedBytes = new byte[(int) receivedBytesMessage.getBodyLength()];
+            receivedBytesMessage.readBytes(receivedBytes);
+            LOG.debug("Message " + i + " content [" + new String(receivedBytes) + "]");
+            assertEquals("On message " + i, messageContent.length, receivedBytes.length);
+            assertArrayEquals("On message " + i, messageContent, receivedBytes);
+
+            long receivedSendTime = receivedBytesMessage.getLongProperty("sendTime");
+            assertEquals("On message " + i, receivedSendTime, sendTime);
+
+            Thread.sleep(10);
+        }
+    }
+
+}


Mime
View raw message