You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/02/04 14:52:18 UTC
svn commit: r1564300 - in /qpid/jms/trunk/src/test/java/org/apache/qpid/jms:
MessageIntegrationTest.java impl/MessageImplTest.java
test/testpeer/matchers/sections/MessageAnnotationsSectionMatcher.java
Author: robbie
Date: Tue Feb 4 13:52:18 2014
New Revision: 1564300
URL: http://svn.apache.org/r1564300
Log:
QPIDJMS-9: add integration tests for recieving messages with correlation-id, and basic string test for sending. Add/reword javadoc and split unit tests to be more clearer and more specific.
Modified:
qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java
qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/MessageAnnotationsSectionMatcher.java
Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java?rev=1564300&r1=1564299&r2=1564300&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java Tue Feb 4 13:52:18 2014
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.math.BigInteger;
import java.util.Date;
@@ -39,6 +40,7 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
+import org.apache.qpid.jms.impl.ClientProperties;
import org.apache.qpid.jms.impl.DestinationHelper;
import org.apache.qpid.jms.impl.MessageIdHelper;
import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
@@ -53,6 +55,7 @@ import org.apache.qpid.jms.test.testpeer
import org.apache.qpid.jms.test.testpeer.matchers.sections.TransferPayloadCompositeMatcher;
import org.apache.qpid.jms.test.testpeer.matchers.types.EncodedAmqpValueMatcher;
import org.apache.qpid.proton.amqp.DescribedType;
+import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.UnsignedLong;
import org.junit.Test;
@@ -130,6 +133,8 @@ public class MessageIntegrationTest exte
message.setDoubleProperty(DOUBLE_PROP, DOUBLE_PROP_VALUE);
producer.send(message);
+
+ testPeer.waitForAllHandlersToComplete(1000);
}
}
@@ -521,4 +526,168 @@ public class MessageIntegrationTest exte
assertEquals("ID:" + expectedBaseIdString, receivedMessage.getJMSMessageID());
}
}
+
+ /**
+ * Tests that receiving a message with a string typed correlation-id results in returning the
+ * expected value for JMSCorrelationID where the JMS "ID:" prefix has been added.
+ */
+ @Test
+ public void testReceivedMessageWithStringCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception
+ {
+ receivedMessageWithCorrelationIdTestImpl("myTestCorrelationIdString", false);
+ }
+
+ /**
+ * Tests that receiving a message with a string typed correlation-id, which is indicated to be an
+ * application-specific value, results in returning the expected value for JMSCorrelationID
+ * where the JMS "ID:" prefix has NOT been added.
+ */
+ @Test
+ public void testReceivedMessageWithAppSpecificStringCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception
+ {
+ receivedMessageWithCorrelationIdTestImpl("myTestCorrelationIdString", true);
+ }
+ /**
+ * Tests that receiving a message with a UUID typed correlation-id results in returning the
+ * expected value for JMSCorrelationID where the JMS "ID:" prefix has been added to the UUID.tostring()
+ */
+ @Test
+ public void testReceivedMessageWithUUIDCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception
+ {
+ receivedMessageWithCorrelationIdTestImpl(UUID.randomUUID(), false);
+ }
+
+ /**
+ * Tests that receiving a message with a UUID typed correlation-id results in returning the
+ * expected value for JMSCorrelationID where the JMS "ID:" prefix has been added to the UUID.tostring()
+ */
+ @Test
+ public void testReceivedMessageWithLongCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception
+ {
+ receivedMessageWithCorrelationIdTestImpl(BigInteger.valueOf(123456789L), false);
+ }
+
+ private void receivedMessageWithCorrelationIdTestImpl(Object correlationId, boolean appSpecific) throws Exception
+ {
+ try(TestAmqpPeer testPeer = new TestAmqpPeer(IntegrationTestFixture.PORT);)
+ {
+ Connection connection = _testFixture.establishConnecton(testPeer);
+ connection.start();
+
+ testPeer.expectBegin();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = session.createQueue("myQueue");
+
+ Object underlyingAmqpCorrelationId = correlationId;
+ if(underlyingAmqpCorrelationId instanceof BigInteger)
+ {
+ //Proton uses UnsignedLong
+ underlyingAmqpCorrelationId = UnsignedLong.valueOf((BigInteger)underlyingAmqpCorrelationId);
+ }
+
+ PropertiesDescribedType props = new PropertiesDescribedType();
+ DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
+ MessageAnnotationsDescribedType ann = null;
+
+ props.setCorrelationId(underlyingAmqpCorrelationId);
+ if(appSpecific)
+ {
+ ann = new MessageAnnotationsDescribedType();
+ ann.setSymbolKeyedAnnotation(ClientProperties.X_OPT_APP_CORRELATION_ID, true);
+ }
+
+ testPeer.expectReceiverAttach();
+ testPeer.expectLinkFlowRespondWithTransfer(null, ann, props, null, amqpValueNullContent);
+ testPeer.expectDispositionThatIsAcceptedAndSettled();
+
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+ Message receivedMessage = messageConsumer.receive(1000);
+ testPeer.waitForAllHandlersToComplete(3000);
+
+ assertNotNull(receivedMessage);
+ String expectedBaseIdString = new MessageIdHelper().toBaseMessageIdString(underlyingAmqpCorrelationId);
+ String expected = expectedBaseIdString;
+ if(!appSpecific)
+ {
+ expected = "ID:" + expected;
+ }
+
+ assertEquals(expected, receivedMessage.getJMSCorrelationID());
+ }
+ }
+
+ /**
+ * Tests that sending a message with a string typed correlation-id value which is a
+ * message-id results in an AMQP message with the expected encoding of the correlation-id,
+ * where the "ID:" prefix of the JMSCorrelationID value is not present, and there is
+ * no presence of the message annotation to indicate an app-specific correlation-id.
+ */
+ @Test
+ public void testSentMessageWithCorrelationIdString() throws Exception
+ {
+
+ String stringCorrelationId = "ID:myTestMessageIdString";
+ String underlyingCorrelationId = "myTestMessageIdString";
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, underlyingCorrelationId, false);
+ }
+
+ /**
+ * Tests that sending a message with a string typed correlation-id value which is a
+ * app-specific results in an AMQP message with the expected encoding of the correlation-id,
+ * and the presence of the message annotation to indicate an app-specific correlation-id.
+ */
+ @Test
+ public void testSentMessageWithCorrelationIdStringAppSpecific() throws Exception
+ {
+ String stringCorrelationId = "myTestAppSpecificString";
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, stringCorrelationId, true);
+ }
+
+ private void sentMessageWithCorrelationIdTestImpl(String stringCorrelationId, Object underlyingAmqpCorrelationId, boolean appSpecific) throws Exception
+ {
+ try(TestAmqpPeer testPeer = new TestAmqpPeer(IntegrationTestFixture.PORT);)
+ {
+ Connection connection = _testFixture.establishConnecton(testPeer);
+ testPeer.expectBegin();
+ testPeer.expectSenderAttach();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String queueName = "myQueue";
+ Queue queue = session.createQueue(queueName);
+ MessageProducer producer = session.createProducer(queue);
+
+ MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
+ MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
+ MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true);
+
+ //Set matcher to validate the correlation-id, and the annotation
+ //presence+value if it is application-specific
+ propsMatcher.withCorrelationId(equalTo(underlyingAmqpCorrelationId));
+ if(appSpecific)
+ {
+ msgAnnotationsMatcher.withEntry(Symbol.valueOf(ClientProperties.X_OPT_APP_CORRELATION_ID), equalTo(Boolean.TRUE));
+ }
+
+ TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
+ messageMatcher.setHeadersMatcher(headersMatcher);
+ messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
+ messageMatcher.setPropertiesMatcher(propsMatcher);
+ messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(null));
+ testPeer.expectTransfer(messageMatcher);
+
+ Message message = session.createTextMessage();
+ message.setJMSCorrelationID(stringCorrelationId);
+
+ producer.send(message);
+
+ testPeer.waitForAllHandlersToComplete(3000);
+
+ //validate the annotation was not present if the value was a message-id
+ if(!appSpecific)
+ {
+ assertFalse(msgAnnotationsMatcher.keyExistsInReceivedAnnotations(Symbol.valueOf(ClientProperties.X_OPT_APP_CORRELATION_ID)));
+ }
+ }
+ }
}
Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java?rev=1564300&r1=1564299&r2=1564300&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java Tue Feb 4 13:52:18 2014
@@ -1034,6 +1034,11 @@ public class MessageImplTest extends Qpi
assertNull("JMSCorrelationID should be null on new message", _testMessage.getJMSCorrelationID());
}
+ /**
+ * Test that the message annotation used to denote an application-specific JMSCorrelationID
+ * value does not exist on new messages (which have no correlation-id, as per
+ * {@link #testGetJMSCorrelationIDIsNullOnNewMessage})
+ */
@Test
public void testAppSpecificCorrelationIdAnnotationDoesNotExistOnNewMessage() throws Exception
{
@@ -1042,10 +1047,11 @@ public class MessageImplTest extends Qpi
}
/**
- * Test that {@link MessageImpl#setJMSCorrelationID(String)} accepts null and clears an existing value
+ * Test that {@link MessageImpl#setJMSCorrelationID(String)} accepts null and clears any
+ * existing value that happened to be a message id.
*/
@Test
- public void testSetJMSCorrelationIDAcceptsNullAndClearsPreviousValue() throws Exception
+ public void testSetJMSCorrelationIDAcceptsNullAndClearsPreviousMessageIdValue() throws Exception
{
//test setting null on fresh message is accepted
_testMessage.setJMSCorrelationID(null);
@@ -1063,7 +1069,7 @@ public class MessageImplTest extends Qpi
/**
* Test that {@link MessageImpl#setJMSCorrelationID(String)} accepts null and clears an existing app-specific
- * value, additionally clearing the message annotation indicating the value was app-specific
+ * value, additionally clearing the message annotation indicating the value was app-specific.
*/
@Test
public void testSetJMSCorrelationIDAcceptsNullAndClearsPreviousAppSpecificValue() throws Exception
@@ -1083,11 +1089,10 @@ public class MessageImplTest extends Qpi
/**
* Test that {@link MessageImpl#setJMSCorrelationID(String)} sets the expected value
- * on the underlying message, i.e the JMS CorrelationID minus the "ID:" prefix,
- * and does not set the annotation to indicate the value is application-specific.
+ * on the underlying message, i.e the JMS CorrelationID minus the "ID:" prefix
*/
@Test
- public void testSetJMSCorrelationIDSetsUnderlyingMessageWithString() throws Exception
+ public void testSetJMSCorrelationIDSetsUnderlyingMessageWithMessageIdString() throws Exception
{
String baseId = "something";
String jmsId = "ID:" + baseId;
@@ -1096,6 +1101,20 @@ public class MessageImplTest extends Qpi
assertNotNull("Underlying correlation id should not be null", _testAmqpMessage.getCorrelationId());
assertEquals("Underlying correlation id value was not as expected", baseId, _testAmqpMessage.getCorrelationId());
+ }
+
+ /**
+ * Test that {@link MessageImpl#setJMSCorrelationID(String)} with a value that happens to be
+ * a message id does not set the annotation on the underlying message
+ * to indicate the correlation-id value is application-specific (sicne it isnt).
+ */
+ @Test
+ public void testSetJMSCorrelationIDDoesntSetsUnderlyingMessageAnnotationWithMessageIdString() throws Exception
+ {
+ String baseId = "something";
+ String jmsId = "ID:" + baseId;
+
+ _testMessage.setJMSCorrelationID(jmsId);
assertFalse("MessageAnnotation should not exist to indicate app-specific correlation-id",
_testAmqpMessage.messageAnnotationExists(ClientProperties.X_OPT_APP_CORRELATION_ID));
@@ -1103,8 +1122,7 @@ public class MessageImplTest extends Qpi
/**
* Test that {@link MessageImpl#setJMSCorrelationID(String)} sets the expected value
- * on the underlying message when provided an application-specific string, and that
- * the it also sets the annotation to indicate the value is application-specific.
+ * on the underlying message when provided an application-specific string.
*/
@Test
public void testSetJMSCorrelationIDSetsUnderlyingMessageWithAppSpecificString() throws Exception
@@ -1115,9 +1133,23 @@ public class MessageImplTest extends Qpi
assertNotNull("Underlying correlation id should not be null", _testAmqpMessage.getCorrelationId());
assertEquals("Underlying correlation id value was not as expected", baseId, _testAmqpMessage.getCorrelationId());
+ }
+
+ /**
+ * Test that {@link MessageImpl#setJMSCorrelationID(String)} sets the expected
+ * message annotation on the underlying message when provided an application-specific string
+ */
+ @Test
+ public void testSetJMSCorrelationIDSetsUnderlyingMessageAnnotationWithAppSpecificString() throws Exception
+ {
+ String baseId = "app-specific";
+
+ _testMessage.setJMSCorrelationID(baseId);
- assertTrue("MessageAnnotation should not exist to indicate app-specific correlation-id",
+ assertTrue("MessageAnnotation should exist to indicate app-specific correlation-id",
_testAmqpMessage.messageAnnotationExists(ClientProperties.X_OPT_APP_CORRELATION_ID));
+ assertEquals("MessageAnnotation should be true to indicate app-specific correlation-id", Boolean.TRUE,
+ _testAmqpMessage.getMessageAnnotation(ClientProperties.X_OPT_APP_CORRELATION_ID));
}
/**
Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/MessageAnnotationsSectionMatcher.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/MessageAnnotationsSectionMatcher.java?rev=1564300&r1=1564299&r2=1564300&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/MessageAnnotationsSectionMatcher.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/MessageAnnotationsSectionMatcher.java Tue Feb 4 13:52:18 2014
@@ -21,6 +21,7 @@
package org.apache.qpid.jms.test.testpeer.matchers.sections;
import java.util.HashMap;
+import java.util.Map;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.UnsignedLong;
@@ -42,7 +43,33 @@ public class MessageAnnotationsSectionMa
@Override
public MessageAnnotationsSectionMatcher withEntry(Object key, Matcher<?> m)
{
+ validateType(key);
+
return (MessageAnnotationsSectionMatcher) super.withEntry(key, m);
}
+
+ private void validateType(Object key)
+ {
+ if(!(key instanceof Long || key instanceof Symbol))
+ {
+ throw new IllegalArgumentException("Message Annotation keys must be of type Symbol or long (reserved)");
+ }
+ }
+
+ public boolean keyExistsInReceivedAnnotations(Object key)
+ {
+ validateType(key);
+
+ Map<Object, Object> receivedFields = super.getReceivedFields();
+
+ if(receivedFields != null)
+ {
+ return receivedFields.containsKey(key);
+ }
+ else
+ {
+ return false;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org