QPID-6933: [System Tests] Add durable subscriber test and remove redundant durable subscriber 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/e3f8e59a Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/e3f8e59a Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/e3f8e59a Branch: refs/heads/master Commit: e3f8e59addf2eddda0ead475b4df18f87fe269e3 Parents: 40a7fdb Author: Alex Rudyy <[email protected]> Authored: Thu Dec 28 19:56:19 2017 +0000 Committer: Alex Rudyy <[email protected]> Committed: Thu Dec 28 21:48:24 2017 +0000 ---------------------------------------------------------------------- .../jms_1_1/topic/DurableSubscribtionTest.java | 62 +++++++ .../persistent/NoLocalAfterRecoveryTest.java | 185 ------------------- test-profiles/CPPExcludes | 3 - test-profiles/JavaTransientExcludes | 1 - 4 files changed, 62 insertions(+), 189 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/e3f8e59a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/topic/DurableSubscribtionTest.java ---------------------------------------------------------------------- diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/topic/DurableSubscribtionTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/topic/DurableSubscribtionTest.java index c759207..1a5f163 100644 --- a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/topic/DurableSubscribtionTest.java +++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/topic/DurableSubscribtionTest.java @@ -463,6 +463,68 @@ public class DurableSubscribtionTest extends JmsTestBase } } + + @Test + public void testResubscribeWithChangedNoLocal() throws Exception + { + String subscriptionName = getTestName() + "_sub"; + Topic topic = createTopic(getTestName()); + String clientId = "testClientId"; + Connection connection = getConnectionBuilder().setClientId(clientId).build(); + try + { + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + TopicSubscriber durableSubscriber = + session.createDurableSubscriber(topic, subscriptionName, null, false); + + MessageProducer producer = session.createProducer(topic); + producer.send(session.createTextMessage("A")); + producer.send(session.createTextMessage("B")); + session.commit(); + + connection.start(); + + Message receivedMessage = durableSubscriber.receive(getReceiveTimeout()); + assertTrue("TextMessage should be received", receivedMessage instanceof TextMessage); + assertEquals("Unexpected message received", "A", ((TextMessage)receivedMessage).getText()); + + session.commit(); + } + finally + { + connection.close(); + } + + connection = getConnectionBuilder().setClientId(clientId).build(); + try + { + connection.start(); + + Session session2 = connection.createSession(true, Session.SESSION_TRANSACTED); + TopicSubscriber noLocalSubscriber2 = session2.createDurableSubscriber(topic, subscriptionName, null, true); + + Connection secondConnection = getConnectionBuilder().setClientId("secondConnection").build(); + try + { + Session secondSession = secondConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer secondProducer = secondSession.createProducer(topic); + secondProducer.send(secondSession.createTextMessage("C")); + } + finally + { + secondConnection.close(); + } + + Message noLocalSubscriberMessage = noLocalSubscriber2.receive(getReceiveTimeout()); + assertTrue("TextMessage should be received", noLocalSubscriberMessage instanceof TextMessage); + assertEquals("Unexpected message received", "C", ((TextMessage)noLocalSubscriberMessage).getText()); + } + finally + { + connection.close(); + } + } + /** * create and register a durable subscriber with a message selector and then close it * crash the broker http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/e3f8e59a/systests/src/test/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java ---------------------------------------------------------------------- diff --git a/systests/src/test/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java b/systests/src/test/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java deleted file mode 100644 index 35cc271..0000000 --- a/systests/src/test/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java +++ /dev/null @@ -1,185 +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.persistent; - -import java.util.ArrayList; -import java.util.List; - -import javax.jms.Connection; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.Session; -import javax.jms.Topic; -import javax.jms.TopicSubscriber; - -import org.apache.qpid.test.utils.QpidBrokerTestCase; - -/** - * Verifies that after recovery, a new Connection with no-local in use is - * able to receive messages sent prior to the broker restart. - */ -public class NoLocalAfterRecoveryTest extends QpidBrokerTestCase -{ - protected final String MY_TOPIC_SUBSCRIPTION_NAME = getTestQueueName(); - protected static final int SEND_COUNT = 10; - - public void testNoLocalNotQueued() throws Exception - { - if(!isBrokerStorePersistent()) - { - fail("This test requires a broker with a persistent store"); - } - - Connection connection = getConnection(); - Session session = connection.createSession(true, Session.SESSION_TRANSACTED); - Topic topic = createTopic(connection, MY_TOPIC_SUBSCRIPTION_NAME); - - TopicSubscriber noLocalSubscriber = session. - createDurableSubscriber(topic, MY_TOPIC_SUBSCRIPTION_NAME + "-NoLocal", - null, true); - - TopicSubscriber normalSubscriber = session. - createDurableSubscriber(topic, MY_TOPIC_SUBSCRIPTION_NAME + "-Normal", - null, false); - - sendMessage(session, topic, SEND_COUNT); - - // Check messages can be received as expected. - connection.start(); - - //As the no-local subscriber was on the same connection the messages were - //published on, tit will receive no messages as they will be discarded on the broker - List<Message> received = receiveMessage(noLocalSubscriber, SEND_COUNT); - assertEquals("No Local Subscriber Received messages", 0, received.size()); - - received = receiveMessage(normalSubscriber, SEND_COUNT); - assertEquals("Normal Subscriber Received no messages", - SEND_COUNT, received.size()); - session.commit(); - - normalSubscriber.close(); - connection.close(); - - //Ensure the no-local subscribers messages were discarded by restarting the broker - //and reconnecting to the subscription to ensure they were not recovered. - restartDefaultBroker(); - - Connection connection2 = getConnection(); - connection2.start(); - - Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED); - Topic topic2 = session2.createTopic(MY_TOPIC_SUBSCRIPTION_NAME); - - TopicSubscriber noLocalSubscriber2 = session2. - createDurableSubscriber(topic2, MY_TOPIC_SUBSCRIPTION_NAME + "-NoLocal", - null, true); - - // The NO-local subscriber should not get any messages - received = receiveMessage(noLocalSubscriber2, SEND_COUNT); - session2.commit(); - assertEquals("No Local Subscriber Received messages", 0, received.size()); - - noLocalSubscriber2.close(); - - - } - - - public void testNonNoLocalQueued() throws Exception - { - if(!isBrokerStorePersistent()) - { - fail("This test requires a broker with a persistent store"); - } - - Connection connection = getConnectionBuilder().setClientId("testClientId").build(); - Session session = connection.createSession(true, Session.SESSION_TRANSACTED); - Topic topic = createTopic(connection, MY_TOPIC_SUBSCRIPTION_NAME); - - TopicSubscriber noLocalSubscriber = - session.createDurableSubscriber(topic, MY_TOPIC_SUBSCRIPTION_NAME + "-NoLocal", null, true); - - - sendMessage(session, topic, SEND_COUNT); - - // Check messages can be received as expected. - connection.start(); - - List<Message> received = receiveMessage(noLocalSubscriber, SEND_COUNT); - assertEquals("No Local Subscriber Received messages", 0, received.size()); - - - - session.commit(); - - Connection connection3 = getConnection(); - Session session3 = connection3.createSession(true, Session.SESSION_TRANSACTED); - sendMessage(session3, topic, SEND_COUNT); - - - connection.close(); - - //We didn't receive the messages on the durable queue for the no-local subscriber - //so they are still on the broker. Restart the broker, prompting their recovery. - restartDefaultBroker(); - - Connection connection2 = getConnectionBuilder().setClientId("testClientId").build(); - connection2.start(); - - Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED); - Topic topic2 = createTopic(connection2, MY_TOPIC_SUBSCRIPTION_NAME); - - TopicSubscriber noLocalSubscriber2 = - session2.createDurableSubscriber(topic2, MY_TOPIC_SUBSCRIPTION_NAME + "-NoLocal",null, true); - - // The NO-local subscriber should receive messages sent from connection3 - received = receiveMessage(noLocalSubscriber2, SEND_COUNT); - session2.commit(); - assertEquals("No Local Subscriber did not receive expected messages", SEND_COUNT, received.size()); - - noLocalSubscriber2.close(); - - - } - - protected List<Message> receiveMessage(MessageConsumer messageConsumer, - int count) throws JMSException - { - - List<Message> receivedMessages = new ArrayList<Message>(count); - for (int i = 0; i < count; i++) - { - Message received = messageConsumer.receive(1000); - - if (received != null) - { - receivedMessages.add(received); - } - else - { - break; - } - } - - return receivedMessages; - } -} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/e3f8e59a/test-profiles/CPPExcludes ---------------------------------------------------------------------- diff --git a/test-profiles/CPPExcludes b/test-profiles/CPPExcludes index 6b10a13..966aebd 100755 --- a/test-profiles/CPPExcludes +++ b/test-profiles/CPPExcludes @@ -63,9 +63,6 @@ org.apache.qpid.test.client.QueueBrowsingFlowToDiskTest#* // This test currently does not pick up the runtime location of the nonVm queueBacking store. org.apache.qpid.test.unit.close.FlowToDiskBackingQueueDeleteTest#* -//QPID-1818 : 0-10 Client code path does not correctly restore a transacted session after failover. -org.apache.qpid.server.persistent.NoLocalAfterRecoveryTest#* - // QPID-1730: the C++ server has a totally different logging mechanism. We should split this file differently org.apache.qpid.server.AlertingTest#* http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/e3f8e59a/test-profiles/JavaTransientExcludes ---------------------------------------------------------------------- diff --git a/test-profiles/JavaTransientExcludes b/test-profiles/JavaTransientExcludes index 632f63d..964aefd 100644 --- a/test-profiles/JavaTransientExcludes +++ b/test-profiles/JavaTransientExcludes @@ -18,7 +18,6 @@ // //These tests require a persistent store -org.apache.qpid.server.persistent.NoLocalAfterRecoveryTest#* org.apache.qpid.server.store.PersistentStoreTest#* org.apache.qpid.server.store.SplitStoreTest#* org.apache.qpid.server.logging.AlertingTest#testAlertingReallyWorksWithRestart --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
