You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/10/19 22:19:05 UTC

qpid-jms git commit: QPIDJMS-126 Add some support for throwing more explicit error types from send failing for use in testing message producers under certian cases.

Repository: qpid-jms
Updated Branches:
  refs/heads/master c4c79e5c5 -> 69cb3e699


QPIDJMS-126 Add some support for throwing more explicit error types from
send failing for use in testing message producers under certian cases. 

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

Branch: refs/heads/master
Commit: 69cb3e699e56ad4d7ec69b0a88b646e157921304
Parents: c4c79e5
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Oct 19 16:18:53 2015 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Oct 19 16:18:53 2015 -0400

----------------------------------------------------------------------
 .../qpid/jms/provider/amqp/AmqpSupport.java     |  3 +++
 .../jms/producer/JmsAnonymousProducerTest.java  | 22 ++++++++++++++++++++
 .../jms/producer/JmsMessageProducerTest.java    | 15 +++++++++++++
 3 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/69cb3e69/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
index 1ec2bfa..12604b4 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
@@ -23,6 +23,7 @@ import javax.jms.InvalidClientIDException;
 import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 import javax.jms.JMSSecurityException;
+import javax.jms.ResourceAllocationException;
 import javax.jms.TransactionRolledBackException;
 
 import org.apache.qpid.jms.provider.ProviderRedirectedException;
@@ -98,6 +99,8 @@ public class AmqpSupport {
 
             if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                 remoteError = new JMSSecurityException(message);
+            } else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
+                remoteError = new ResourceAllocationException(message);
             } else if (error.equals(AmqpError.NOT_FOUND)) {
                 remoteError = new InvalidDestinationException(message);
             } else if (error.equals(TransactionErrors.TRANSACTION_ROLLBACK)) {

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/69cb3e69/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsAnonymousProducerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsAnonymousProducerTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsAnonymousProducerTest.java
index ff5db03..76afd57 100644
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsAnonymousProducerTest.java
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsAnonymousProducerTest.java
@@ -19,10 +19,13 @@ package org.apache.qpid.jms.producer;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.jms.JMSException;
+import javax.jms.JMSSecurityException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
@@ -148,4 +151,23 @@ public class JmsAnonymousProducerTest extends AmqpTestSupport {
             }
         }
     }
+
+    // TODO - Should only get JMSSecurityException on ActiveMQ 5.12.2+
+    @Test(timeout = 30000)
+    public void testAnonymousProducerNotAuthorized() throws Exception {
+        connection = createAmqpConnection("guest", "password");
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue queue = session.createQueue("USERS.txQueue");
+        MessageProducer producer = session.createProducer(null);
+
+        try {
+            producer.send(queue, session.createTextMessage());
+            fail("Should not be able to produce here.");
+        } catch (JMSSecurityException jmsSE) {
+            LOG.info("Caught expected exception");
+        } catch (JMSException jms) {
+            LOG.info("Caught expected exception");
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/69cb3e69/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
index ad50d6f..8a2b78d 100644
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
@@ -20,12 +20,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.util.Arrays;
 import java.util.concurrent.TimeUnit;
 
 import javax.jms.BytesMessage;
 import javax.jms.DeliveryMode;
+import javax.jms.JMSSecurityException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
@@ -59,6 +61,19 @@ public class JmsMessageProducerTest extends AmqpTestSupport {
         assertEquals(0, proxy.getQueueSize());
     }
 
+    @Test(timeout = 30000)
+    public void testProducerNotAuthorized() throws Exception {
+        connection = createAmqpConnection("guest", "password");
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue queue = session.createQueue("USERS.txQueue");
+        try {
+            session.createProducer(queue);
+            fail("Should not be able to produce here.");
+        } catch (JMSSecurityException jmsSE) {
+            LOG.info("Caught expected exception");
+        }
+    }
+
     @Test(timeout = 20000)
     public void testSendMultipleMessagesPersistent() throws Exception {
         connection = createAmqpConnection();


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