qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject [1/4] qpid-broker-j git commit: QPID-6933: [System Tests] Add JMS message headers and properties tests
Date Fri, 01 Dec 2017 17:02:40 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 1fc001fea -> 4ad30dd90


QPID-6933: [System Tests] Add JMS message headers and properties tests


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/c9932632
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/c9932632
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/c9932632

Branch: refs/heads/master
Commit: c9932632251104f2c5d08f1ca1f6305c84fb0dfa
Parents: 1fc001f
Author: Alex Rudyy <orudyy@apache.org>
Authored: Fri Dec 1 16:04:48 2017 +0000
Committer: Alex Rudyy <orudyy@apache.org>
Committed: Fri Dec 1 16:04:48 2017 +0000

----------------------------------------------------------------------
 .../message/JMSHeadersAndPropertiesTest.java    | 275 +++++++++++++++++++
 .../qpid/test/unit/message/JMSHeaderTest.java   |  68 -----
 .../test/unit/message/JMSPropertiesTest.java    |  88 +-----
 3 files changed, 278 insertions(+), 153 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c9932632/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/JMSHeadersAndPropertiesTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/JMSHeadersAndPropertiesTest.java
b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/JMSHeadersAndPropertiesTest.java
new file mode 100644
index 0000000..1a8612a
--- /dev/null
+++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/JMSHeadersAndPropertiesTest.java
@@ -0,0 +1,275 @@
+/*
+ * 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.qpid.systests.jms_1_1.message;
+
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeThat;
+
+import java.util.Enumeration;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionMetaData;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.qpid.systests.JmsTestBase;
+
+public class JMSHeadersAndPropertiesTest extends JmsTestBase
+{
+
+    @Ignore("QPID-8031")
+    @Test
+    public void testResentJMSMessageGetsReplacementJMSMessageID() throws Exception
+    {
+        Queue queue = createQueue(getTestName());
+        Connection connection = getConnection();
+        try
+        {
+            connection.start();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            ConnectionMetaData metaData = connection.getMetaData();
+
+            MessageProducer producer = session.createProducer(queue);
+
+            final Message sentMessage = session.createMessage();
+            producer.send(sentMessage);
+
+            final String originalId = sentMessage.getJMSMessageID();
+            assertNotNull("JMSMessageID must be set after first publish", originalId);
+
+            producer.send(sentMessage);
+            final String firstResendID = sentMessage.getJMSMessageID();
+            assertNotNull("JMSMessageID must be set after first resend", firstResendID);
+            assertNotSame("JMSMessageID must be changed second publish", originalId, firstResendID);
+
+            producer.setDisableMessageID(true);
+            producer.send(sentMessage);
+            final String secondResendID = sentMessage.getJMSMessageID();
+            assertNull("JMSMessageID must be unset after second resend with IDs disabled",
secondResendID);
+        }
+        finally
+        {
+            connection.close();
+        }
+    }
+
+    @Test
+    public void JMSRedelivered() throws Exception
+    {
+        Queue queue = createQueue(getTestName());
+        Connection connection = getConnection();
+        try
+        {
+            Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+            MessageProducer producer = session.createProducer(queue);
+            String messageText = "Test";
+            producer.send(session.createTextMessage(messageText));
+            session.commit();
+
+            MessageConsumer consumer = session.createConsumer(queue);
+            connection.start();
+
+            Message message = consumer.receive(getReceiveTimeout());
+            assertTrue("TextMessage should be received", message instanceof TextMessage);
+            assertFalse("Unexpected JMSRedelivered after first receive", message.getJMSRedelivered());
+            assertEquals("Unexpected message content", messageText, ((TextMessage) message).getText());
+
+            session.rollback();
+
+            message = consumer.receive(getReceiveTimeout());
+            assertTrue("TextMessage should be received", message instanceof TextMessage);
+            assertTrue("Unexpected JMSRedelivered after second receive", message.getJMSRedelivered());
+            assertEquals("Unexpected message content", messageText, ((TextMessage) message).getText());
+
+            session.commit();
+        }
+        finally
+        {
+            connection.close();
+        }
+    }
+
+    @Test
+    public void testJMSHeaders() throws Exception
+    {
+        final Queue queue = createQueue(getTestName());
+        final Destination replyTo = createQueue(getTestName() + "_replyTo");
+        final Connection consumerConnection = getConnection();
+        try
+        {
+            final Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            final MessageConsumer consumer = consumerSession.createConsumer(queue);
+
+            final String correlationId = "testCorrelationId";
+            final String jmsType = "testJmsType";
+
+            final int priority = 1;
+            final long timeToLive = 30 * 60 * 1000;
+            final Connection producerConnection = getConnection();
+            try
+            {
+                final Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+                final MessageProducer producer = producerSession.createProducer(queue);
+
+                final Message message = producerSession.createMessage();
+                message.setJMSCorrelationID(correlationId);
+                message.setJMSType(jmsType);
+                message.setJMSReplyTo(replyTo);
+
+                long currentTime = System.currentTimeMillis();
+                producer.send(message, DeliveryMode.NON_PERSISTENT, priority, timeToLive);
+
+                consumerConnection.start();
+
+                Message receivedMessage = consumer.receive(getReceiveTimeout());
+                assertNotNull(receivedMessage);
+
+                assertEquals("JMSCorrelationID mismatch", correlationId, receivedMessage.getJMSCorrelationID());
+                assertEquals("JMSType mismatch", message.getJMSType(), receivedMessage.getJMSType());
+                assertEquals("JMSReply To mismatch", message.getJMSReplyTo(), receivedMessage.getJMSReplyTo());
+                assertTrue("JMSMessageID does not start 'ID:'", receivedMessage.getJMSMessageID().startsWith("ID:"));
+                assertEquals("JMSPriority mismatch", priority, receivedMessage.getJMSPriority());
+                assertTrue(String.format(
+                        "Unexpected JMSExpiration: got '%d', but expected value equals or
greater than '%d'",
+                        receivedMessage.getJMSExpiration(),
+                        currentTime + timeToLive),
+
+                           receivedMessage.getJMSExpiration() >= currentTime + timeToLive
+                           && receivedMessage.getJMSExpiration() <= System.currentTimeMillis()
+ timeToLive);
+            }
+            finally
+            {
+                producerConnection.close();
+            }
+        }
+        finally
+        {
+            consumerConnection.close();
+        }
+    }
+
+
+    @Test
+    public void testJMSXGroupIDAndJMSXGroupSeq() throws Exception
+    {
+        final Connection connection = getConnection();
+        try
+        {
+            assumeThat(isJMSXPropertySupported(connection, "JMSXGroupID"), is(equalTo(true)));
+            assumeThat(isJMSXPropertySupported(connection, "JMSXGroupSeq"), is(equalTo(true)));
+
+            final String groupId = "testGroup";
+            final int groupSequence = 3;
+            final Queue queue = createQueue(getTestName());
+            final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            final MessageProducer producer = session.createProducer(queue);
+            final MessageConsumer consumer = session.createConsumer(queue);
+            final Message message = session.createMessage();
+            message.setStringProperty("JMSXGroupID", groupId);
+            message.setIntProperty("JMSXGroupSeq", groupSequence);
+
+            producer.send(message);
+            connection.start();
+
+            final Message receivedMessage = consumer.receive(getReceiveTimeout());
+            assertNotNull(receivedMessage);
+
+            assertEquals("Unexpected JMSXGroupID", groupId, receivedMessage.getStringProperty("JMSXGroupID"));
+            assertEquals("Unexpected JMSXGroupSeq", groupSequence, receivedMessage.getIntProperty("JMSXGroupSeq"));
+        }
+        finally
+        {
+            connection.close();
+        }
+    }
+
+    @Test
+    public void unsupportedObjectPropertyValue() throws Exception
+    {
+        Queue queue = createQueue(getTestName());
+        Connection connection = getConnection();
+        try
+        {
+            Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+            MessageProducer producer = session.createProducer(queue);
+            Message message = session.createMessage();
+            try
+            {
+                message.setObjectProperty("invalidObject", new Exception());
+            }
+            catch (MessageFormatException e)
+            {
+                // pass
+            }
+            String validValue = "validValue";
+            message.setObjectProperty("validObject", validValue);
+            producer.send(message);
+            session.commit();
+
+            final MessageConsumer consumer = session.createConsumer(queue);
+            connection.start();
+
+            final Message receivedMessage = consumer.receive(getReceiveTimeout());
+            assertNotNull(receivedMessage);
+
+            assertFalse("Unexpected property found", message.propertyExists("invalidObject"));
+            assertEquals("Unexpected property value", validValue, message.getObjectProperty("validObject"));
+        }
+        finally
+        {
+            connection.close();
+        }
+    }
+
+    private boolean isJMSXPropertySupported(final Connection connection, final String propertyName)
throws JMSException
+    {
+        boolean supported = false;
+        Enumeration props = connection.getMetaData().getJMSXPropertyNames();
+        while (props.hasMoreElements())
+        {
+            String name = (String) props.nextElement();
+            if (name.equals(propertyName))
+            {
+                supported = true;
+            }
+
+        }
+        return supported;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c9932632/systests/src/test/java/org/apache/qpid/test/unit/message/JMSHeaderTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/message/JMSHeaderTest.java b/systests/src/test/java/org/apache/qpid/test/unit/message/JMSHeaderTest.java
deleted file mode 100644
index 0f3d219..0000000
--- a/systests/src/test/java/org/apache/qpid/test/unit/message/JMSHeaderTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.qpid.test.unit.message;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionMetaData;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-public class JMSHeaderTest extends QpidBrokerTestCase
-{
-
-    public void testResentJMSMessageGetsReplacementJMSMessageID() throws Exception
-    {
-        Connection con = getConnection();
-        final ConnectionMetaData metaData = con.getMetaData();
-
-        if ( metaData.getProviderMajorVersion() < 6 || (metaData.getProviderMajorVersion()
== 6 && metaData.getProviderMinorVersion() <= 1))
-        {
-            // TODO  This defect was fixed after 6.1
-            return;
-        }
-
-        con.start();
-        Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-        Queue queue = createTestQueue(session);
-
-        MessageProducer producer = session.createProducer(queue);
-
-        final Message sentMessage = session.createMessage();
-        producer.send(sentMessage);
-
-        final String originalId = sentMessage.getJMSMessageID();
-        assertNotNull("JMSMessageID must be set after first publish", originalId);
-
-        producer.send(sentMessage);
-        final String firstResendID = sentMessage.getJMSMessageID();
-        assertNotNull("JMSMessageID must be set after first resend", firstResendID);
-        assertNotSame("JMSMessageID must be changed second publish", originalId, firstResendID);
-
-        producer.setDisableMessageID(true);
-        producer.send(sentMessage);
-        final String secondResendID = sentMessage.getJMSMessageID();
-        assertNull("JMSMessageID must be unset after second resend with IDs disabled", secondResendID);
-    }
-}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c9932632/systests/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
b/systests/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
index 1e37711..0abc967 100644
--- a/systests/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
+++ b/systests/src/test/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
@@ -38,93 +38,11 @@ import javax.jms.Topic;
 import org.apache.qpid.client.message.QpidMessageProperties;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
 
+/**
+ * JMS AMQP 0-x specific tests
+ */
 public class JMSPropertiesTest extends QpidBrokerTestCase
 {
-    private static final String JMS_CORR_ID = "QPIDID_01";
-    private static final String JMS_TYPE = "test.jms.type";
-    private static final String INVALID_OBJECT_PROPERTY = "InvalidObject";
-
-    public void testJMSProperties() throws Exception
-    {
-        Connection con = getConnection();
-        Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
-        Queue queue = createTestQueue(consumerSession, "someQ");
-        MessageConsumer consumer = consumerSession.createConsumer(queue);
-
-        Connection con2 = getConnection();
-        final Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-        final MessageProducer producer = producerSession.createProducer(queue);
-        Destination replyTo = createTestQueue(producerSession, "my.replyto");
-
-        // create a test message to send
-        ObjectMessage sentMsg = producerSession.createObjectMessage();
-        sentMsg.setJMSCorrelationID(JMS_CORR_ID);
-        sentMsg.setJMSType(JMS_TYPE);
-        sentMsg.setJMSReplyTo(replyTo);
-
-        String JMSXGroupID_VALUE = "group";
-        sentMsg.setStringProperty("JMSXGroupID", JMSXGroupID_VALUE);
-        
-        int JMSXGroupSeq_VALUE = 1;
-        sentMsg.setIntProperty("JMSXGroupSeq", JMSXGroupSeq_VALUE);
-
-        try
-        {
-            sentMsg.setObjectProperty(INVALID_OBJECT_PROPERTY, new Exception());
-            fail("Non serializable Object Property value set");
-        }
-        catch (MessageFormatException mfe)
-        {
-            // pass
-
-        }
-
-        // send it
-        producer.send(sentMsg);
-
-        con2.close();
-
-        con.start();
-
-        // get message and check JMS properties
-        ObjectMessage rm = (ObjectMessage) consumer.receive(getReceiveTimeout());
-        assertNotNull(rm);
-
-        assertEquals("JMS Correlation ID mismatch", sentMsg.getJMSCorrelationID(), rm.getJMSCorrelationID());
-        assertEquals("JMS Type mismatch", sentMsg.getJMSType(), rm.getJMSType());
-        assertEquals("JMS Reply To mismatch", sentMsg.getJMSReplyTo(), rm.getJMSReplyTo());
-        assertTrue("JMSMessageID Does not start ID:", rm.getJMSMessageID().startsWith("ID:"));
-        assertEquals("JMS Default priority should be 4",Message.DEFAULT_PRIORITY,rm.getJMSPriority());
-
-        //Validate that the JMSX values are correct
-        assertEquals("JMSXGroupID is not as expected:", JMSXGroupID_VALUE, rm.getStringProperty("JMSXGroupID"));
-        assertEquals("JMSXGroupSeq is not as expected:", JMSXGroupSeq_VALUE, rm.getIntProperty("JMSXGroupSeq"));
-
-        boolean JMSXGroupID_Available = false;
-        boolean JMSXGroupSeq_Available = false;
-        Enumeration props = con.getMetaData().getJMSXPropertyNames();
-        while (props.hasMoreElements())
-        {
-            String name = (String) props.nextElement();
-            if (name.equals("JMSXGroupID"))
-            {
-                JMSXGroupID_Available = true;
-            }
-            if (name.equals("JMSXGroupSeq"))
-            {
-                JMSXGroupSeq_Available = true;
-            }
-        }
-
-        assertTrue("JMSXGroupID not available.",JMSXGroupID_Available);
-        assertTrue("JMSXGroupSeq not available.",JMSXGroupSeq_Available);
-
-        // Check that the INVALID_OBJECT_PROPERTY was not set or transmitted.
-        assertFalse(INVALID_OBJECT_PROPERTY + " was not set.", rm.propertyExists(INVALID_OBJECT_PROPERTY));
-
-        con.close();
-    }
 
     /**
      * Test Goal : Test if custom message properties can be set and retrieved properly with
out an error.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message