add test of TopicSubscriber contract when closed, implement getNoLocal to pass
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/23e8a220 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/23e8a220 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/23e8a220 Branch: refs/heads/master Commit: 23e8a220d5fe169e3a446a1ebad89d481280ac67 Parents: b23f531 Author: Robert Gemmell <[email protected]> Authored: Mon Jan 12 10:37:51 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Mon Jan 12 12:53:51 2015 +0000 ---------------------------------------------------------------------- .../org/apache/qpid/jms/JmsMessageConsumer.java | 2 +- .../org/apache/qpid/jms/JmsTopicSubscriber.java | 6 ++ .../consumer/JmsTopicSubscriberClosedTest.java | 65 ++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/23e8a220/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java index 9afe13a..bdc2e6c 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java @@ -481,7 +481,7 @@ public class JmsMessageConsumer implements MessageConsumer, JmsMessageAvailableC return this.messageQueue.size(); } - public boolean getNoLocal() throws IllegalStateException { + protected boolean isNoLocal() { return this.consumerInfo.isNoLocal(); } http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/23e8a220/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsTopicSubscriber.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsTopicSubscriber.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsTopicSubscriber.java index 0ef463a..efcd731 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsTopicSubscriber.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsTopicSubscriber.java @@ -67,4 +67,10 @@ public class JmsTopicSubscriber extends JmsMessageConsumer implements TopicSubsc checkClosed(); return (Topic) this.getDestination(); } + + @Override + public boolean getNoLocal() throws JMSException { + checkClosed(); + return isNoLocal(); + } } http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/23e8a220/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsTopicSubscriberClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsTopicSubscriberClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsTopicSubscriberClosedTest.java new file mode 100644 index 0000000..d2d992c --- /dev/null +++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsTopicSubscriberClosedTest.java @@ -0,0 +1,65 @@ +/** + * 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.jms.consumer; + +import javax.jms.JMSException; +import javax.jms.Session; +import javax.jms.Topic; +import javax.jms.TopicConnection; +import javax.jms.TopicSession; +import javax.jms.TopicSubscriber; + +import org.apache.qpid.jms.JmsConnectionFactory; +import org.apache.qpid.jms.support.AmqpTestSupport; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests TopicSubscriber method contracts after the TopicSubscriber is closed. + */ +public class JmsTopicSubscriberClosedTest extends AmqpTestSupport { + + protected TopicSubscriber subscriber; + + protected TopicSubscriber createAndCloseSubscriber() throws Exception { + JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); + connection = factory.createTopicConnection(); + + TopicSession session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + Topic destination = session.createTopic(name.getMethodName()); + TopicSubscriber subscriber = session.createSubscriber(destination); + subscriber.close(); + return subscriber; + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + subscriber = createAndCloseSubscriber(); + } + + @Test(timeout=30000, expected=javax.jms.IllegalStateException.class) + public void testGetNoLocalFails() throws JMSException { + subscriber.getNoLocal(); + } + + @Test(timeout=30000, expected=javax.jms.IllegalStateException.class) + public void testGetTopicFails() throws JMSException { + subscriber.getTopic(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
