Repository: activemq
Updated Branches:
  refs/heads/master 35e8a5288 -> d4c7cce7d


https://issues.apache.org/jira/browse/AMQ-6438

Makes some improvements to the profiling test for the transformers. 

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

Branch: refs/heads/master
Commit: d4c7cce7d733df9fcdcd0daec4ce64fb3844ce64
Parents: 35e8a52
Author: Timothy Bish <tabish...@gmail.com>
Authored: Wed Sep 21 18:18:41 2016 -0400
Committer: Timothy Bish <tabish...@gmail.com>
Committed: Wed Sep 21 18:18:41 2016 -0400

----------------------------------------------------------------------
 .../JMSTransformationSpeedComparisonTest.java   | 158 +++++++++++--------
 1 file changed, 88 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/d4c7cce7/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java
----------------------------------------------------------------------
diff --git 
a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java
 
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java
index b008f1c..e1b6a46 100644
--- 
a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java
+++ 
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.activemq.transport.amqp.message;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collection;
@@ -36,7 +39,9 @@ import org.apache.qpid.proton.codec.WritableBuffer;
 import org.apache.qpid.proton.message.Message;
 import org.apache.qpid.proton.message.ProtonJMessage;
 import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TestName;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
@@ -52,9 +57,12 @@ public class JMSTransformationSpeedComparisonTest {
 
     protected static final Logger LOG = 
LoggerFactory.getLogger(JMSInteroperabilityTest.class);
 
+    @Rule
+    public TestName test = new TestName();
+
     private final String transformer;
 
-    private final int WARM_CYCLES = 10;
+    private final int WARM_CYCLES = 50;
     private final int PROFILE_CYCLES = 1000000;
 
     public JMSTransformationSpeedComparisonTest(String transformer) {
@@ -119,8 +127,8 @@ public class JMSTransformationSpeedComparisonTest {
         }
         totalDuration += System.nanoTime() - startTime;
 
-        LOG.info("[{}] Total time for {} cycles of transforms = {} ms",
-            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration));
+        LOG.info("[{}] Total time for {} cycles of transforms = {} ms  -> 
[{}]",
+            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration), test.getMethodName());
     }
 
     @Test
@@ -155,33 +163,14 @@ public class JMSTransformationSpeedComparisonTest {
         }
         totalDuration += System.nanoTime() - startTime;
 
-        LOG.info("[{}] Total time for {} cycles of transforms = {} ms",
-            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration));
+        LOG.info("[{}] Total time for {} cycles of transforms = {} ms  -> 
[{}]",
+            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration), test.getMethodName());
     }
 
     @Test
     public void testTypicalQpidJMSMessage() throws Exception {
 
-        Map<String, Object> applicationProperties = new HashMap<String, 
Object>();
-        Map<Symbol, Object> messageAnnotations = new HashMap<Symbol, Object>();
-
-        applicationProperties.put("property-1", "string");
-        applicationProperties.put("property-2", 512);
-        applicationProperties.put("property-3", true);
-
-        messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0);
-
-        Message message = Proton.message();
-
-        message.setAddress("queue://test-queue");
-        message.setDeliveryCount(1);
-        message.setApplicationProperties(new 
ApplicationProperties(applicationProperties));
-        message.setMessageAnnotations(new 
MessageAnnotations(messageAnnotations));
-        message.setCreationTime(System.currentTimeMillis());
-        message.setContentType("text/plain");
-        message.setBody(new AmqpValue("String payload for AMQP message 
conversion performance testing."));
-
-        EncodedMessage encoded = encode(message);
+        EncodedMessage encoded = encode(createTypicalQpidJMSMessage());
         InboundTransformer inboundTransformer = getInboundTransformer();
         OutboundTransformer outboundTransformer = getOutboundTransformer();
 
@@ -202,56 +191,106 @@ public class JMSTransformationSpeedComparisonTest {
         }
         totalDuration += System.nanoTime() - startTime;
 
-        LOG.info("[{}] Total time for {} cycles of transforms = {} ms",
-            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration));
+        LOG.info("[{}] Total time for {} cycles of transforms = {} ms  -> 
[{}]",
+            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration), test.getMethodName());
     }
 
     @Test
     public void testTypicalQpidJMSMessageInBoundOnly() throws Exception {
 
-        Map<String, Object> applicationProperties = new HashMap<String, 
Object>();
-        Map<Symbol, Object> messageAnnotations = new HashMap<Symbol, Object>();
+        EncodedMessage encoded = encode(createTypicalQpidJMSMessage());
+        InboundTransformer inboundTransformer = getInboundTransformer();
 
-        applicationProperties.put("property-1", "string");
-        applicationProperties.put("property-2", 512);
-        applicationProperties.put("property-3", true);
+        // Warm up
+        for (int i = 0; i < WARM_CYCLES; ++i) {
+            inboundTransformer.transform(encoded);
+        }
 
-        messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0);
+        long totalDuration = 0;
 
-        Message message = Proton.message();
+        long startTime = System.nanoTime();
+        for (int i = 0; i < PROFILE_CYCLES; ++i) {
+            inboundTransformer.transform(encoded);
+        }
 
-        message.setAddress("queue://test-queue");
-        message.setDeliveryCount(1);
-        message.setApplicationProperties(new 
ApplicationProperties(applicationProperties));
-        message.setMessageAnnotations(new 
MessageAnnotations(messageAnnotations));
-        message.setCreationTime(System.currentTimeMillis());
-        message.setContentType("text/plain");
-        message.setBody(new AmqpValue("String payload for AMQP message 
conversion performance testing."));
+        totalDuration += System.nanoTime() - startTime;
 
-        EncodedMessage encoded = encode(message);
+        LOG.info("[{}] Total time for {} cycles of transforms = {} ms  -> 
[{}]",
+            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration), test.getMethodName());
+    }
+
+    @Test
+    public void testTypicalQpidJMSMessageOutBoundOnly() throws Exception {
+
+        EncodedMessage encoded = encode(createTypicalQpidJMSMessage());
         InboundTransformer inboundTransformer = getInboundTransformer();
+        OutboundTransformer outboundTransformer = getOutboundTransformer();
+
+        ActiveMQMessage outbound = (ActiveMQMessage) 
inboundTransformer.transform(encoded);
+        outbound.onSend();
 
         // Warm up
         for (int i = 0; i < WARM_CYCLES; ++i) {
-            inboundTransformer.transform(encoded);
+            outboundTransformer.transform(outbound);
         }
 
         long totalDuration = 0;
 
         long startTime = System.nanoTime();
         for (int i = 0; i < PROFILE_CYCLES; ++i) {
-            inboundTransformer.transform(encoded);
+            outboundTransformer.transform(outbound);
         }
 
         totalDuration += System.nanoTime() - startTime;
 
-        LOG.info("[{}] Total time for {} cycles of transforms = {} ms",
-            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration));
+        LOG.info("[{}] Total time for {} cycles of transforms = {} ms  -> 
[{}]",
+            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration), test.getMethodName());
     }
 
+    @Ignore
     @Test
-    public void testTypicalQpidJMSMessageOutBoundOnly() throws Exception {
+    public void testEncodeDecodeIsWorking() throws Exception {
+        Message incomingMessage = createTypicalQpidJMSMessage();
+        EncodedMessage encoded = encode(incomingMessage);
+        InboundTransformer inboundTransformer = getInboundTransformer();
+        OutboundTransformer outboundTransformer = getOutboundTransformer();
+
+        ActiveMQMessage outbound = (ActiveMQMessage) 
inboundTransformer.transform(encoded);
+        outbound.onSend();
+        Message outboudMessage = 
outboundTransformer.transform(outbound).decode();
+
+        // Test that message details are equal
+        assertEquals(incomingMessage.getAddress(), 
outboudMessage.getAddress());
+        assertEquals(incomingMessage.getDeliveryCount(), 
outboudMessage.getDeliveryCount());
+        assertEquals(incomingMessage.getCreationTime(), 
outboudMessage.getCreationTime());
+        assertEquals(incomingMessage.getContentType(), 
outboudMessage.getContentType());
+
+        // Test Message annotations
+        ApplicationProperties incomingApplicationProperties = 
incomingMessage.getApplicationProperties();
+        ApplicationProperties outgoingApplicationProperties = 
outboudMessage.getApplicationProperties();
+
+        assertEquals(incomingApplicationProperties.getValue(), 
outgoingApplicationProperties.getValue());
+
+        // Test Message properties
+        MessageAnnotations incomingMessageAnnotations = 
incomingMessage.getMessageAnnotations();
+        MessageAnnotations outgoingMessageAnnotations = 
outboudMessage.getMessageAnnotations();
+
+        assertEquals(incomingMessageAnnotations.getValue(), 
outgoingMessageAnnotations.getValue());
+
+        // Test that bodies are equal
+        assertTrue(incomingMessage.getBody() instanceof AmqpValue);
+        assertTrue(outboudMessage.getBody() instanceof AmqpValue);
+
+        AmqpValue incomingBody = (AmqpValue) incomingMessage.getBody();
+        AmqpValue outgoingBody = (AmqpValue) outboudMessage.getBody();
 
+        assertTrue(incomingBody.getValue() instanceof String);
+        assertTrue(outgoingBody.getValue() instanceof String);
+
+        assertEquals(incomingBody.getValue(), outgoingBody.getValue());
+    }
+
+    private Message createTypicalQpidJMSMessage() {
         Map<String, Object> applicationProperties = new HashMap<String, 
Object>();
         Map<Symbol, Object> messageAnnotations = new HashMap<Symbol, Object>();
 
@@ -260,6 +299,7 @@ public class JMSTransformationSpeedComparisonTest {
         applicationProperties.put("property-3", true);
 
         messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0);
+        messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0);
 
         Message message = Proton.message();
 
@@ -271,29 +311,7 @@ public class JMSTransformationSpeedComparisonTest {
         message.setContentType("text/plain");
         message.setBody(new AmqpValue("String payload for AMQP message 
conversion performance testing."));
 
-        EncodedMessage encoded = encode(message);
-        InboundTransformer inboundTransformer = getInboundTransformer();
-        OutboundTransformer outboundTransformer = getOutboundTransformer();
-
-        ActiveMQMessage outbound = (ActiveMQMessage) 
inboundTransformer.transform(encoded);
-        outbound.onSend();
-
-        // Warm up
-        for (int i = 0; i < WARM_CYCLES; ++i) {
-            outboundTransformer.transform(outbound);
-        }
-
-        long totalDuration = 0;
-
-        long startTime = System.nanoTime();
-        for (int i = 0; i < PROFILE_CYCLES; ++i) {
-            outboundTransformer.transform(outbound);
-        }
-
-        totalDuration += System.nanoTime() - startTime;
-
-        LOG.info("[{}] Total time for {} cycles of transforms = {} ms",
-            transformer, PROFILE_CYCLES, 
TimeUnit.NANOSECONDS.toMillis(totalDuration));
+        return message;
     }
 
     private EncodedMessage encode(Message message) {

Reply via email to