You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2012/07/30 23:20:02 UTC

svn commit: r1367310 - in /activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo: BrokerProtocol.java JMSExclusiveConsumerTest.java JmsTestBase.java OpenwireBrokerProtocol.java StompBrokerProtocol.java

Author: chirino
Date: Mon Jul 30 21:20:02 2012
New Revision: 1367310

URL: http://svn.apache.org/viewvc?rev=1367310&view=rev
Log:
Fixes APLO-228 : JMSExclusiveConsumerTest DispatchExclusive test case is failing

Modified:
    activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/BrokerProtocol.java
    activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JMSExclusiveConsumerTest.java
    activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JmsTestBase.java
    activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/OpenwireBrokerProtocol.java
    activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/StompBrokerProtocol.java

Modified: activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/BrokerProtocol.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/BrokerProtocol.java?rev=1367310&r1=1367309&r2=1367310&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/BrokerProtocol.java (original)
+++ activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/BrokerProtocol.java Mon Jul 30 21:20:02 2012
@@ -110,4 +110,6 @@ abstract public class BrokerProtocol {
     public abstract Topic createTopic(String name);
 
     public abstract void setPrefetch(Connection connection, int value);
+
+    public abstract Destination addExclusiveOptions(Destination name);
 }

Modified: activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JMSExclusiveConsumerTest.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JMSExclusiveConsumerTest.java?rev=1367310&r1=1367309&r2=1367310&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JMSExclusiveConsumerTest.java (original)
+++ activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JMSExclusiveConsumerTest.java Mon Jul 30 21:20:02 2012
@@ -17,7 +17,6 @@
 package org.apache.activemq.apollo;
 
 import junit.framework.Test;
-import org.apache.activemq.command.ActiveMQQueue;
 
 import javax.jms.*;
 
@@ -38,12 +37,6 @@ public class JMSExclusiveConsumerTest ex
         junit.textui.TestRunner.run(suite());
     }
 
-    // TODO: add a way to use exclusive queues via stompjms
-    @Override
-    public void initCombos() {
-        setCombinationValues("protocol",  new Object[] {new OpenwireBrokerProtocol()});
-    }
-
     public void initCombosForTestRoundRobinDispatchOnNonExclusive() {
         addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
     }
@@ -59,7 +52,7 @@ public class JMSExclusiveConsumerTest ex
         // Receive a message with the JMS API
         connection.start();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        ActiveMQQueue destination = new ActiveMQQueue("TEST");
+        Destination destination = createDestination(session, DestinationType.QUEUE_TYPE);
         MessageProducer producer = session.createProducer(destination);
         producer.setDeliveryMode(deliveryMode);
 
@@ -92,12 +85,12 @@ public class JMSExclusiveConsumerTest ex
      * @throws Exception
      */
     // TODO: figure out why this is failing: https://issues.apache.org/jira/browse/APLO-228
-    public void ignoreDispatchExclusive() throws Exception {
+    public void testDispatchExclusive() throws Exception {
 
         // Receive a message with the JMS API
         connection.start();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        ActiveMQQueue destination = new ActiveMQQueue("TEST?consumer.exclusive=true");
+        Destination destination = createDestination(session, DestinationType.QUEUE_TYPE, true);
         MessageProducer producer = session.createProducer(destination);
         producer.setDeliveryMode(deliveryMode);
 
@@ -130,12 +123,13 @@ public class JMSExclusiveConsumerTest ex
     }
 
     public void testMixExclusiveWithNonExclusive() throws Exception {
-        ActiveMQQueue exclusiveQueue = new ActiveMQQueue("TEST.FOO?consumer.exclusive=true");
-        ActiveMQQueue nonExclusiveQueue = new ActiveMQQueue("TEST.FOO?consumer.exclusive=false");
 
         connection.start();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
+        Destination nonExclusiveQueue = createDestination(session, DestinationType.QUEUE_TYPE);
+        Destination exclusiveQueue = protocol.addExclusiveOptions(nonExclusiveQueue);
+
         MessageConsumer nonExCon = session.createConsumer(nonExclusiveQueue);
         MessageConsumer exCon = session.createConsumer(exclusiveQueue);
 

Modified: activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JmsTestBase.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JmsTestBase.java?rev=1367310&r1=1367309&r2=1367310&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JmsTestBase.java (original)
+++ activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/JmsTestBase.java Mon Jul 30 21:20:02 2012
@@ -183,25 +183,36 @@ public class JmsTestBase extends Combina
     //
     // /////////////////////////////////////////////////////////////////
     protected Destination createDestination(Session session, DestinationType type) throws JMSException {
+        return createDestination(session, type, false);
+    }
+
+    protected Destination createDestination(Session session, DestinationType type, boolean exclusive) throws JMSException {
         String testMethod = getName();
         if( testMethod.indexOf(" ")>0 ) {
             testMethod = testMethod.substring(0, testMethod.indexOf(" "));
         }
-        String name = "TEST." + getClass().getName() + "." +testMethod+"."+TEST_COUNTER.getAndIncrement();
+        String name = "TEST." + getClass().getName() + "." + testMethod + "." + TEST_COUNTER.getAndIncrement();
         switch (type) {
         case QUEUE_TYPE:
-            return session.createQueue(name);
+            return makeExclusive(session.createQueue(name), exclusive);
         case TOPIC_TYPE:
-            return session.createTopic(name);
+            return makeExclusive(session.createTopic(name), exclusive);
         case TEMP_QUEUE_TYPE:
-            return session.createTemporaryQueue();
+            return makeExclusive(session.createTemporaryQueue(), exclusive);
         case TEMP_TOPIC_TYPE:
-            return session.createTemporaryTopic();
+            return makeExclusive(session.createTemporaryTopic(), exclusive);
         default:
             throw new IllegalArgumentException("type: " + type);
         }
     }
 
+    private Destination makeExclusive(Destination dest, boolean exclusive) {
+        if( exclusive ) {
+            dest = protocol.addExclusiveOptions(dest);
+        }
+        return dest;
+    }
+
     protected void sendMessages(Destination destination, int count) throws Exception {
         Connection connection = getConnectionFactory().createConnection();
         connection.start();

Modified: activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/OpenwireBrokerProtocol.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/OpenwireBrokerProtocol.java?rev=1367310&r1=1367309&r2=1367310&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/OpenwireBrokerProtocol.java (original)
+++ activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/OpenwireBrokerProtocol.java Mon Jul 30 21:20:02 2012
@@ -18,13 +18,13 @@ package org.apache.activemq.apollo;
 
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.command.ActiveMQDestination;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.command.*;
 
 import static java.lang.String.*;
 
 import javax.jms.*;
+import java.util.HashMap;
+import java.util.Properties;
 
 /**
  * <p>
@@ -65,4 +65,40 @@ public class OpenwireBrokerProtocol exte
     public void setPrefetch(Connection connection, int value) {
         ((ActiveMQConnection)connection).getPrefetchPolicy().setAll(value);
     }
+
+    @Override
+    public Destination addExclusiveOptions(Destination dest) {
+        final HashMap<String, String> o = new HashMap<String, String>();
+        o.put("consumer.exclusive", "true");
+        if( dest instanceof ActiveMQTempTopic ) {
+            return new ActiveMQTopic(((ActiveMQTempTopic)dest).getPhysicalName()) {
+                {
+                    options = o;
+                }
+            };
+        }
+        if( dest instanceof ActiveMQTempQueue ) {
+            return new ActiveMQTempQueue(((ActiveMQTempQueue)dest).getPhysicalName()) {
+                {
+                    options = o;
+                }
+            };
+        }
+        if( dest instanceof ActiveMQTopic ) {
+            return new ActiveMQTopic(((ActiveMQTopic)dest).getPhysicalName()) {
+                {
+                    options = o;
+                }
+            };
+        }
+        if( dest instanceof ActiveMQQueue ) {
+            return new ActiveMQQueue(((ActiveMQQueue)dest).getPhysicalName()) {
+                {
+                    options = o;
+                }
+            };
+        }
+        return dest;
+    }
+
 }

Modified: activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/StompBrokerProtocol.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/StompBrokerProtocol.java?rev=1367310&r1=1367309&r2=1367310&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/StompBrokerProtocol.java (original)
+++ activemq/activemq-apollo/trunk/apollo-itests/src/test/java/org/apache/activemq/apollo/StompBrokerProtocol.java Mon Jul 30 21:20:02 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.activemq.apollo;
 
+import org.apache.activemq.command.ActiveMQDestination;
 import org.fusesource.stomp.jms.*;
 
 import javax.jms.*;
 
+import java.util.HashMap;
+
 import static java.lang.String.format;
 
 /**
@@ -61,4 +64,14 @@ public class StompBrokerProtocol extends
     public void setPrefetch(Connection connection, int value) {
         ((StompJmsConnection)connection).setPrefetch(new StompJmsPrefetch(value));
     }
+
+    @Override
+    public Destination addExclusiveOptions(Destination dest) {
+        HashMap<String, String> headers = new HashMap<String, String>();
+        headers.put("exclusive", "true");
+        final StompJmsQueue copy = ((StompJmsQueue) dest).copy();
+        copy.setSubscribeHeaders(headers);
+        return copy;
+    }
+
 }