Makes some improvements to the profiling test for the transformers.
This commit is contained in:
Timothy Bish 2016-09-21 18:18:41 -04:00
parent 35e8a52888
commit d4c7cce7d7
1 changed files with 89 additions and 71 deletions

View File

@ -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,33 +191,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 testTypicalQpidJMSMessageInBoundOnly() 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();
// Warm up
@ -245,33 +215,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 testTypicalQpidJMSMessageOutBoundOnly() 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();
@ -292,8 +243,75 @@ 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());
}
@Ignore
@Test
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>();
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);
messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 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."));
return message;
}
private EncodedMessage encode(Message message) {