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 2015/01/12 15:13:01 UTC

[1/3] qpid-jms git commit: reorder methods for clarity

Repository: qpid-jms
Updated Branches:
  refs/heads/master b23f531af -> 63c4e0865


reorder methods for clarity


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/63c4e086
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/63c4e086
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/63c4e086

Branch: refs/heads/master
Commit: 63c4e0865daf28ff006bcaa390b44839af0962e1
Parents: d53274f
Author: Robert Gemmell <ro...@apache.org>
Authored: Mon Jan 12 12:32:04 2015 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Mon Jan 12 12:53:51 2015 +0000

----------------------------------------------------------------------
 .../org/apache/qpid/jms/JmsMessageProducer.java | 24 ++++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/63c4e086/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
index 50e70a8..6f95deb 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
@@ -174,18 +174,6 @@ public class JmsMessageProducer implements MessageProducer {
     }
 
     /**
-     * @param destination
-     * @param message
-     * @throws JMSException
-     * @see javax.jms.MessageProducer#send(javax.jms.Destination,
-     *      javax.jms.Message)
-     */
-    @Override
-    public void send(Destination destination, Message message) throws JMSException {
-        send(destination, message, this.deliveryMode, this.priority, this.timeToLive);
-    }
-
-    /**
      * @param message
      * @param deliveryMode
      * @param priority
@@ -207,6 +195,18 @@ public class JmsMessageProducer implements MessageProducer {
     /**
      * @param destination
      * @param message
+     * @throws JMSException
+     * @see javax.jms.MessageProducer#send(javax.jms.Destination,
+     *      javax.jms.Message)
+     */
+    @Override
+    public void send(Destination destination, Message message) throws JMSException {
+        send(destination, message, this.deliveryMode, this.priority, this.timeToLive);
+    }
+
+    /**
+     * @param destination
+     * @param message
      * @param deliveryMode
      * @param priority
      * @param timeToLive


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


[3/3] qpid-jms git commit: add test of TopicSubscriber contract when closed, implement getNoLocal to pass

Posted by ro...@apache.org.
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 <ro...@apache.org>
Authored: Mon Jan 12 10:37:51 2015 +0000
Committer: Robert Gemmell <ro...@apache.org>
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: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[2/3] qpid-jms git commit: ensure the approproate UnsupportedOperation and InvalidDestination exceptions are thrown from producer send methods

Posted by ro...@apache.org.
ensure the approproate UnsupportedOperation and InvalidDestination exceptions are thrown from producer send methods


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

Branch: refs/heads/master
Commit: d53274f604970e8b7a7fb457fe754c6078d130f5
Parents: 23e8a22
Author: Robert Gemmell <ro...@apache.org>
Authored: Mon Jan 12 12:26:33 2015 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Mon Jan 12 12:53:51 2015 +0000

----------------------------------------------------------------------
 .../org/apache/qpid/jms/JmsMessageProducer.java |  21 ++-
 .../apache/qpid/jms/JmsMessageProducerTest.java | 131 +++++++++++++++++++
 2 files changed, 147 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d53274f6/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
index 4d09c04..50e70a8 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
@@ -170,7 +170,7 @@ public class JmsMessageProducer implements MessageProducer {
      */
     @Override
     public void send(Message message) throws JMSException {
-        send(producerInfo.getDestination(), message, this.deliveryMode, this.priority, this.timeToLive);
+        send(message, this.deliveryMode, this.priority, this.timeToLive);
     }
 
     /**
@@ -195,7 +195,13 @@ public class JmsMessageProducer implements MessageProducer {
      */
     @Override
     public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
-        send(producerInfo.getDestination(), message, deliveryMode, priority, timeToLive);
+        checkClosed();
+
+        if (flexibleDestination) {
+            throw new UnsupportedOperationException("Using this method is not supported on producers created without an explicit Destination");
+        }
+
+        sendMessage(producerInfo.getDestination(), message, deliveryMode, priority, timeToLive);
     }
 
     /**
@@ -212,12 +218,17 @@ public class JmsMessageProducer implements MessageProducer {
     public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
         checkClosed();
 
+        if (!flexibleDestination) {
+            throw new UnsupportedOperationException("Using this method is not supported on producers created with an explicit Destination.");
+        }
+
+        sendMessage(destination, message, deliveryMode, priority, timeToLive);
+    }
+
+    private void sendMessage(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
         if (destination == null) {
             throw new InvalidDestinationException("Don't understand null destinations");
         }
-        if (!this.flexibleDestination && !destination.equals(producerInfo.getDestination())) {
-            throw new UnsupportedOperationException("This producer can only send messages to: " + producerInfo.getDestination().getName());
-        }
 
         this.session.send(this, destination, message, deliveryMode, priority, timeToLive, disableMessageId, disableTimestamp);
     }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d53274f6/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsMessageProducerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsMessageProducerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsMessageProducerTest.java
new file mode 100644
index 0000000..1d6a870
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsMessageProducerTest.java
@@ -0,0 +1,131 @@
+/**
+ * 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;
+
+import static org.junit.Assert.fail;
+
+import javax.jms.Destination;
+import javax.jms.InvalidDestinationException;
+import javax.jms.Message;
+
+import org.apache.qpid.jms.meta.JmsProducerId;
+import org.apache.qpid.jms.meta.JmsProducerInfo;
+import org.apache.qpid.jms.meta.JmsResource;
+import org.apache.qpid.jms.provider.Provider;
+import org.apache.qpid.jms.provider.ProviderFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test basic functionality around JmsConnection
+ */
+public class JmsMessageProducerTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JmsMessageProducerTest.class);
+
+    private Provider provider;
+    private JmsConnection connection;
+    private  JmsSession session;
+    private JmsProducerId producerId;
+
+    @Before
+    public void setUp() throws Exception {
+        connection = Mockito.mock(JmsConnection.class);
+        session = Mockito.mock(JmsSession.class);
+        producerId = new JmsProducerId("key");
+
+        Mockito.when(session.getConnection()).thenReturn(connection);
+        Mockito.doAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Throwable {
+                Object[] args = invocation.getArguments();
+                LOG.debug("Handling connection createResource call");
+                if (args[0] instanceof JmsProducerInfo) {
+                    return args[0];
+                }
+
+                throw new IllegalArgumentException("Not implemented");
+            }
+        }).when(connection).createResource(Mockito.any(JmsResource.class));
+    }
+
+    @Test
+    public void testAnonymousProducerThrowsUOEWhenExplictDestinationNotProvided() throws Exception {
+        JmsMessageProducer producer = new JmsMessageProducer(producerId, session, null);
+
+        Message message = Mockito.mock(Message.class);
+        try {
+            producer.send(message);
+            fail("Expected exception not thrown");
+        } catch (UnsupportedOperationException uoe) {
+            // expected
+        }
+
+        try {
+            producer.send(message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+            fail("Expected exception not thrown");
+        } catch (UnsupportedOperationException uoe) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testExplicitProducerThrowsUOEWhenExplictDestinationIsProvided() throws Exception {
+        JmsDestination dest = new JmsQueue("explicitDestination");
+        JmsMessageProducer producer = new JmsMessageProducer(producerId, session, dest);
+
+        Message message = Mockito.mock(Message.class);
+        try {
+            producer.send(dest, message);
+            fail("Expected exception not thrown");
+        } catch (UnsupportedOperationException uoe) {
+            // expected
+        }
+
+        try {
+            producer.send(dest, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+            fail("Expected exception not thrown");
+        } catch (UnsupportedOperationException uoe) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testAnonymousDestinationProducerThrowsIDEWhenNullDestinationIsProvided() throws Exception {
+        JmsMessageProducer producer = new JmsMessageProducer(producerId, session, null);
+
+        Message message = Mockito.mock(Message.class);
+        try {
+            producer.send(null, message);
+            fail("Expected exception not thrown");
+        } catch (InvalidDestinationException ide) {
+            // expected
+        }
+
+        try {
+            producer.send(null, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+            fail("Expected exception not thrown");
+        } catch (InvalidDestinationException ide) {
+            // expected
+        }
+    }
+}


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