Repository: qpid-broker-j Updated Branches: refs/heads/master 557109a04 -> c38f9eee2
QPID-6933: [System Tests] Refactor consumer priority tests as JMS 1.1 system test 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/c38f9eee Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/c38f9eee Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/c38f9eee Branch: refs/heads/master Commit: c38f9eee255667d55620a75d884bff7997776307 Parents: 557109a Author: Alex Rudyy <[email protected]> Authored: Thu Dec 28 15:23:09 2017 +0000 Committer: Alex Rudyy <[email protected]> Committed: Thu Dec 28 15:23:09 2017 +0000 ---------------------------------------------------------------------- .../consumerpriority/ConsumerPriorityTest.java | 307 +++++++++++++++++++ .../qpid/server/queue/ConsumerPriorityTest.java | 183 ----------- test-profiles/CPPExcludes | 3 - test-profiles/Java10BrokenTestsExcludes | 2 - 4 files changed, 307 insertions(+), 188 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c38f9eee/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/consumerpriority/ConsumerPriorityTest.java ---------------------------------------------------------------------- diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/consumerpriority/ConsumerPriorityTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/consumerpriority/ConsumerPriorityTest.java new file mode 100644 index 0000000..3047cb3 --- /dev/null +++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/consumerpriority/ConsumerPriorityTest.java @@ -0,0 +1,307 @@ +/* + * + * 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.extensions.consumerpriority; + +import static junit.framework.TestCase.assertNull; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeThat; + +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.junit.Test; + +import org.apache.qpid.server.model.Protocol; +import org.apache.qpid.systests.JmsTestBase; + + +public class ConsumerPriorityTest extends JmsTestBase +{ + private static final String LEGACY_BINDING_URL = "BURL:direct://amq.direct/%s/%s?x-priority='%d'"; + private static final String LEGACY_ADDRESS_URL = "ADDR:%s; { create: always, node: { type: queue }," + + "link : { x-subscribe: { arguments : { x-priority : '%d' } } } }"; + + @Test + public void testLowPriorityConsumerReceivesMessages() throws Exception + { + assumeThat("Only legacy client implements this feature", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0)))); + + final String queueName = getTestName(); + final Queue queue = createQueue(queueName); + final Connection consumingConnection = getConnection(); + try + { + final Connection producingConnection = getConnection(); + try + { + final Session consumingSession = consumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + consumingConnection.start(); + + final Queue consumerDestination = + consumingSession.createQueue(String.format(LEGACY_BINDING_URL, queueName, queueName, 10)); + final MessageConsumer consumer = consumingSession.createConsumer(consumerDestination); + assertNull("There should be no messages in the queue", consumer.receive(getShortReceiveTimeout())); + + Session producingSession = producingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = producingSession.createProducer(queue); + producer.send(producingSession.createTextMessage(getTestName())); + assertNotNull("Expected message is not received", consumer.receive(getReceiveTimeout())); + } + finally + { + producingConnection.close(); + } + } + finally + { + consumingConnection.close(); + } + } + + @Test + public void testLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityConsumerAvailable() throws Exception + { + assumeThat("Only legacy client implements this feature", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0)))); + + final String queueName = getTestName(); + final String consumerQueue = String.format(LEGACY_BINDING_URL, queueName, queueName, 10); + doTestLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityAvailable(queueName, consumerQueue); + } + + @Test + public void testLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityConsumerAvailableUsingADDR() + throws Exception + { + assumeThat("Only legacy client implements this feature", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0)))); + + final String queueName = getTestName(); + String consumerQueue = String.format(LEGACY_ADDRESS_URL, queueName, 10); + doTestLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityAvailable(queueName, consumerQueue); + } + + private void doTestLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityAvailable(final String queueName, + final String consumerQueue) + throws Exception + { + final Queue queue = createQueue(queueName); + final Connection consumingConnection = getConnection(); + try + { + final Connection producingConnection = getConnection(); + try + { + final Session consumingSession = consumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + consumingConnection.start(); + + final MessageConsumer consumer = + consumingSession.createConsumer(consumingSession.createQueue(consumerQueue)); + assertNull("There should be no messages in the queue", consumer.receive(getShortReceiveTimeout())); + + final Connection secondConsumingConnection = getConnection(); + try + { + final Session secondConsumingSession = + secondConsumingConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); + secondConsumingConnection.start(); + + final MessageConsumer standardPriorityConsumer = secondConsumingSession.createConsumer(queue); + assertNull("There should be no messages in the queue", + standardPriorityConsumer.receive(getShortReceiveTimeout())); + + final Session producingSession = producingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = producingSession.createProducer(queue); + producer.send(producingSession.createTextMessage(getTestName())); + assertNull("Message should not go to the low priority consumer", + consumer.receive(getShortReceiveTimeout())); + producer.send(producingSession.createTextMessage(getTestName() + " 2")); + assertNull("Message should not go to the low priority consumer", + consumer.receive(getShortReceiveTimeout())); + + assertNotNull(standardPriorityConsumer.receive(getReceiveTimeout())); + assertNotNull(standardPriorityConsumer.receive(getReceiveTimeout())); + } + finally + { + secondConsumingConnection.close(); + } + } + finally + { + producingConnection.close(); + } + } + finally + { + consumingConnection.close(); + } + } + + @Test + public void testLowPriorityConsumerReceiveMessagesIfHigherPriorityConsumerHasNoCredit() throws Exception + { + assumeThat("Only legacy client implements this feature", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0)))); + + final String queueName = getTestName(); + final Queue queue = createQueue(queueName); + final Connection consumingConnection = getConnection(); + try + { + final Connection producingConnection = getConnection(); + try + { + final Session consumingSession = consumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + consumingConnection.start(); + final Queue consumerDestination = + consumingSession.createQueue(String.format(LEGACY_BINDING_URL, queueName, queueName, 10)); + final MessageConsumer consumer = consumingSession.createConsumer(consumerDestination); + assertNull("There should be no messages in the queue", consumer.receive(getShortReceiveTimeout())); + + final Connection secondConsumingConnection = getConnectionBuilder().setPrefetch(2).build(); + try + { + final Session secondConsumingSession = + secondConsumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + secondConsumingConnection.start(); + final MessageConsumer standardPriorityConsumer = secondConsumingSession.createConsumer(queue); + assertNull("There should be no messages in the queue", + standardPriorityConsumer.receive(getShortReceiveTimeout())); + + final Session producingSession = producingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = producingSession.createProducer(queue); + + producer.send(createTextMessage(1, producingSession)); + assertNull("Message should not go to the low priority consumer", + consumer.receive(getShortReceiveTimeout())); + producer.send(createTextMessage(2, producingSession)); + assertNull("Message should not go to the low priority consumer", + consumer.receive(getShortReceiveTimeout())); + producer.send(createTextMessage(3, producingSession)); + final Message message = consumer.receive(getReceiveTimeout()); + assertNotNull( + "Message should go to the low priority consumer as standard priority consumer has no credit", + message); + assertTrue("Message is not a text message", message instanceof TextMessage); + assertEquals(getTestName() + " 3", ((TextMessage) message).getText()); + } + finally + { + secondConsumingConnection.close(); + } + } + finally + { + producingConnection.close(); + } + } + finally + { + consumingConnection.close(); + } + } + + @Test + public void testLowPriorityConsumerReceiveMessagesIfHigherPriorityConsumerDoesNotSelect() throws Exception + { + assumeThat("Only legacy client implements this feature", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0)))); + + final String queueName = getTestName(); + final Queue queue = createQueue(queueName); + Connection consumingConnection = getConnection(); + try + { + Connection producingConnection = getConnection(); + try + { + Session consumingSession = consumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + consumingConnection.start(); + + Session producingSession = producingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + final Queue consumerDestination = + consumingSession.createQueue(String.format(LEGACY_BINDING_URL, queueName, queueName, 10)); + final MessageConsumer consumer = consumingSession.createConsumer(consumerDestination); + assertNull("There should be no messages in the queue", consumer.receive(getShortReceiveTimeout())); + + final Connection secondConsumingConnection = getConnection(); + try + { + final Session secondConsumingSession = + secondConsumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + secondConsumingConnection.start(); + final MessageConsumer standardPriorityConsumer = + secondConsumingSession.createConsumer(queue, + "msg <> 2"); + assertNull("There should be no messages in the queue", standardPriorityConsumer.receive( + getShortReceiveTimeout())); + + final MessageProducer producer = producingSession.createProducer(queue); + + producer.send(createTextMessage(1, producingSession)); + assertNull("Message should not go to the low priority consumer", consumer.receive( + getShortReceiveTimeout())); + producer.send(createTextMessage(2, producingSession)); + Message message = consumer.receive(getReceiveTimeout()); + assertNotNull( + "Message should go to the low priority consumer as standard priority consumer is not interested", + message); + assertTrue("Message is not a text message", message instanceof TextMessage); + assertEquals(getTestName() + " 2", ((TextMessage) message).getText()); + } + finally + { + secondConsumingConnection.close(); + } + } + finally + { + producingConnection.close(); + } + } + finally + { + consumingConnection.close(); + } + } + + private long getShortReceiveTimeout() + { + return getReceiveTimeout() / 4; + } + + + private TextMessage createTextMessage(final int msgId, final Session producingSession) throws JMSException + { + TextMessage textMessage = producingSession.createTextMessage(getTestName() + " " + msgId); + textMessage.setIntProperty("msg", msgId); + return textMessage; + } +} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c38f9eee/systests/src/test/java/org/apache/qpid/server/queue/ConsumerPriorityTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/queue/ConsumerPriorityTest.java b/systests/src/test/java/org/apache/qpid/server/queue/ConsumerPriorityTest.java deleted file mode 100644 index 81fdb23..0000000 --- a/systests/src/test/java/org/apache/qpid/server/queue/ConsumerPriorityTest.java +++ /dev/null @@ -1,183 +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.server.queue; - -import java.util.HashMap; -import java.util.Map; - -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.test.utils.QpidBrokerTestCase; - -public class ConsumerPriorityTest extends QpidBrokerTestCase -{ - - private Connection _consumingConnection; - private Session _consumingSession; - private Connection _producingConnection; - private Session _producingSession; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - _consumingConnection = getConnection(); - _consumingSession = _consumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); - _consumingConnection.start(); - - _producingConnection = getConnection(); - _producingSession = _producingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); - _producingConnection.start(); - - } - - - public void testLowPriorityConsumerReceivesMessages() throws Exception - { - Queue queue = _consumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName() + "?x-priority='10'"); - final MessageConsumer consumer = _consumingSession.createConsumer(queue); - assertNull("There should be no messages in the queue", consumer.receive(100L)); - Destination producerDestination = _producingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageProducer producer = _producingSession.createProducer(producerDestination); - producer.send(_producingSession.createTextMessage(getTestName())); - assertNotNull("There should be no messages in the queue", consumer.receive(2000L)); - } - - - public void testLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityConsumerAvailable() throws Exception - { - Queue queue = _consumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName() + "?x-priority='10'"); - doTestLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityAvailable(queue); - } - - public void testLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityConsumerAvailableUsingADDR() throws Exception - { - Queue queue = _consumingSession.createQueue("ADDR:" + getTestQueueName() + "; { create: always, node: { type: queue }, link : { x-subscribe: { arguments : { x-priority : '10' } } } }"); - doTestLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityAvailable(queue); - } - - private void doTestLowPriorityConsumerDoesNotReceiveMessagesIfHigherPriorityAvailable(final Queue queue) throws Exception - { - final MessageConsumer consumer = _consumingSession.createConsumer(queue); - assertNull("There should be no messages in the queue", consumer.receive(100L)); - - final Connection secondConsumingConnection = getConnection(); - final Session secondConsumingSession = secondConsumingConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - secondConsumingConnection.start(); - secondConsumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageConsumer standardPriorityConsumer = secondConsumingSession.createConsumer(secondConsumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName())); - assertNull("There should be no messages in the queue", standardPriorityConsumer.receive(100L)); - - - Destination producerDestination = _producingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageProducer producer = _producingSession.createProducer(producerDestination); - producer.send(_producingSession.createTextMessage(getTestName())); - assertNull("Message should not go to the low priority consumer", consumer.receive(100L)); - producer.send(_producingSession.createTextMessage(getTestName() + " 2")); - assertNull("Message should not go to the low priority consumer", consumer.receive(100L)); - - assertNotNull(standardPriorityConsumer.receive(100L)); - - assertNotNull(standardPriorityConsumer.receive(100L)); - - } - - public void testLowPriorityConsumerReceiveMessagesIfHigherPriorityConsumerHasNoCredit() throws Exception - { - Queue queue = _consumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName() + "?x-priority='10'"); - final MessageConsumer consumer = _consumingSession.createConsumer(queue); - assertNull("There should be no messages in the queue", consumer.receive(100L)); - - Map<String, String> options = new HashMap<String, String>(); - options.put(ConnectionURL.OPTIONS_MAXPREFETCH, "2"); - - final Connection secondConsumingConnection = getConnectionWithOptions(options); - final Session secondConsumingSession = secondConsumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); - secondConsumingConnection.start(); - secondConsumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageConsumer standardPriorityConsumer = secondConsumingSession.createConsumer(secondConsumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName())); - assertNull("There should be no messages in the queue", standardPriorityConsumer.receive(100L)); - - - Destination producerDestination = _producingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageProducer producer = _producingSession.createProducer(producerDestination); - - producer.send(createTextMessage(1)); - assertNull("Message should not go to the low priority consumer", consumer.receive(100L)); - producer.send(createTextMessage(2)); - assertNull("Message should not go to the low priority consumer", consumer.receive(100L)); - producer.send(createTextMessage(3)); - Message message = consumer.receive(100L); - assertNotNull("Message should go to the low priority consumer as standard priority consumer has no credit", message); - assertTrue("Message is not a text message", message instanceof TextMessage); - assertEquals(getTestName() + " 3", ((TextMessage)message).getText()); - - - } - - - public void testLowPriorityConsumerReceiveMessagesIfHigherPriorityConsumerDoesNotSelect() throws Exception - { - Queue queue = _consumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName() + "?x-priority='10'"); - final MessageConsumer consumer = _consumingSession.createConsumer(queue); - assertNull("There should be no messages in the queue", consumer.receive(100L)); - - - final Connection secondConsumingConnection = getConnection(); - final Session secondConsumingSession = secondConsumingConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); - secondConsumingConnection.start(); - secondConsumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageConsumer standardPriorityConsumer = secondConsumingSession.createConsumer(secondConsumingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()), "msg <> 2"); - assertNull("There should be no messages in the queue", standardPriorityConsumer.receive(100L)); - - - Destination producerDestination = _producingSession.createQueue("direct://amq.direct/" + getTestQueueName() + "/" + getTestQueueName()); - final MessageProducer producer = _producingSession.createProducer(producerDestination); - - producer.send(createTextMessage(1)); - assertNull("Message should not go to the low priority consumer", consumer.receive(100L)); - producer.send(createTextMessage(2)); - Message message = consumer.receive(100L); - assertNotNull("Message should go to the low priority consumer as standard priority consumer is not interested", message); - assertTrue("Message is not a text message", message instanceof TextMessage); - assertEquals(getTestName() + " 2", ((TextMessage)message).getText()); - - - } - - - private TextMessage createTextMessage(final int msgId) throws JMSException - { - TextMessage textMessage = _producingSession.createTextMessage(getTestName() + " " + msgId); - textMessage.setIntProperty("msg", msgId); - return textMessage; - } -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c38f9eee/test-profiles/CPPExcludes ---------------------------------------------------------------------- diff --git a/test-profiles/CPPExcludes b/test-profiles/CPPExcludes index d1637c2..1b42582 100755 --- a/test-profiles/CPPExcludes +++ b/test-profiles/CPPExcludes @@ -184,9 +184,6 @@ org.apache.qpid.test.unit.client.connection.BrokerClosesClientConnectionTest#tes #Node Creation Policy Tests use Qpid Broker-J Specific Config org.apache.qpid.server.queue.NodeAutoCreationPolicyTest#* -# The consumer x-priority feature is Java Broker Specific -org.apache.qpid.server.queue.ConsumerPriorityTest#* - #The C++ broker does not implement AMQP management org.apache.qpid.systest.management.amqp.* http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c38f9eee/test-profiles/Java10BrokenTestsExcludes ---------------------------------------------------------------------- diff --git a/test-profiles/Java10BrokenTestsExcludes b/test-profiles/Java10BrokenTestsExcludes index 33a3cd6..ee10587 100644 --- a/test-profiles/Java10BrokenTestsExcludes +++ b/test-profiles/Java10BrokenTestsExcludes @@ -42,5 +42,3 @@ org.apache.qpid.systest.management.amqp.AmqpManagementTest#testGetTypesOnVhostMa // Test uses AMQP 0-x ack modes and assumes the name of the queues backing subscriptions org.apache.qpid.test.unit.topic.DurableSubscriptionTest#* -// These tests require some way to set properties on the link established by the client -org.apache.qpid.server.queue.ConsumerPriorityTest#* --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
