activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1454330 - in /activemq/trunk: activemq-broker/src/main/java/org/apache/activemq/broker/util/ activemq-client/src/main/java/org/apache/activemq/ activemq-unit-tests/src/test/java/org/apache/activemq/broker/
Date Fri, 08 Mar 2013 11:43:47 GMT
Author: gtully
Date: Fri Mar  8 11:43:46 2013
New Revision: 1454330

URL: http://svn.apache.org/r1454330
Log:
https://issues.apache.org/jira/browse/AMQ-4362 - Broker-based redelivery plugin - support
for maximumRedeliveries="-1"

Modified:
    activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/util/RedeliveryPlugin.java
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java

Modified: activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/util/RedeliveryPlugin.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/util/RedeliveryPlugin.java?rev=1454330&r1=1454329&r2=1454330&view=diff
==============================================================================
--- activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/util/RedeliveryPlugin.java
(original)
+++ activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/util/RedeliveryPlugin.java
Fri Mar  8 11:43:46 2013
@@ -135,8 +135,9 @@ public class RedeliveryPlugin extends Br
                 Destination regionDestination = (Destination) messageReference.getRegionDestination();
                 final RedeliveryPolicy redeliveryPolicy = redeliveryPolicyMap.getEntryFor(regionDestination.getActiveMQDestination());
                 if (redeliveryPolicy != null) {
+                    final int maximumRedeliveries = redeliveryPolicy.getMaximumRedeliveries();
                     int redeliveryCount = messageReference.getRedeliveryCounter();
-                    if (redeliveryCount < redeliveryPolicy.getMaximumRedeliveries()) {
+                    if (RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES == maximumRedeliveries ||
redeliveryCount < maximumRedeliveries) {
 
                         long delay = ( redeliveryCount == 0 ?
                                 redeliveryPolicy.getInitialRedeliveryDelay() :
@@ -146,7 +147,7 @@ public class RedeliveryPlugin extends Br
                     } else if (isSendToDlqIfMaxRetriesExceeded()) {
                         super.sendToDeadLetterQueue(context, messageReference, subscription);
                     } else {
-                        LOG.debug("Discarding message that exceeds max redelivery count,
" + messageReference.getMessageId());
+                        LOG.debug("Discarding message that exceeds max redelivery count(
" + maximumRedeliveries + "), " + messageReference.getMessageId());
                     }
                 } else if (isFallbackToDeadLetter()) {
                     super.sendToDeadLetterQueue(context, messageReference, subscription);

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java?rev=1454330&r1=1454329&r2=1454330&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
(original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
Fri Mar  8 11:43:46 2013
@@ -32,11 +32,13 @@ import org.apache.activemq.util.Introspe
 public class RedeliveryPolicy extends DestinationMapEntry implements Cloneable, Serializable
{
 
     public static final int NO_MAXIMUM_REDELIVERIES = -1;
+    public static final int DEFAULT_MAXIMUM_REDELIVERIES = 6;
+
     private static Random randomNumberGenerator;
 
     // +/-15% for a 30% spread -cgs
     protected double collisionAvoidanceFactor = 0.15d;
-    protected int maximumRedeliveries = 6;
+    protected int maximumRedeliveries = DEFAULT_MAXIMUM_REDELIVERIES;
     protected long maximumRedeliveryDelay = -1;
     protected long initialRedeliveryDelay = 1000L;
     protected boolean useCollisionAvoidance;

Modified: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java?rev=1454330&r1=1454329&r2=1454330&view=diff
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
(original)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
Fri Mar  8 11:43:46 2013
@@ -40,10 +40,20 @@ public class BrokerRedeliveryTest extend
     final ActiveMQQueue destination = new ActiveMQQueue("Redelivery");
     final String data = "hi";
     final long redeliveryDelayMillis = 2000;
-    final int maxBrokerRedeliveries = 2;
+    int maxBrokerRedeliveries = 2;
 
     public void testScheduledRedelivery() throws Exception {
+        doTestScheduledRedelivery(maxBrokerRedeliveries, true);
+    }
+
+    public void testInfiniteRedelivery() throws Exception {
+        maxBrokerRedeliveries = RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES;
+        doTestScheduledRedelivery(RedeliveryPolicy.DEFAULT_MAXIMUM_REDELIVERIES + 1, false);
+    }
 
+    public void doTestScheduledRedelivery(int maxBrokerRedeliveriesToValidate, boolean validateDLQ)
throws Exception {
+
+        startBroker(true);
         sendMessage(0);
 
         ActiveMQConnection consumerConnection = (ActiveMQConnection) createConnection();
@@ -59,7 +69,7 @@ public class BrokerRedeliveryTest extend
         LOG.info("got: " + message);
         consumerSession.rollback();
 
-        for (int i=0;i<maxBrokerRedeliveries;i++) {
+        for (int i=0;i<maxBrokerRedeliveriesToValidate;i++) {
             Message shouldBeNull = consumer.receive(500);
             assertNull("did not get message after redelivery count exceeded: " + shouldBeNull,
shouldBeNull);
 
@@ -74,15 +84,25 @@ public class BrokerRedeliveryTest extend
             consumerSession.rollback();
         }
 
-        // validate DLQ
-        MessageConsumer dlqConsumer = consumerSession.createConsumer(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
-        Message dlqMessage = dlqConsumer.receive(2000);
-        assertNotNull("Got message from dql", dlqMessage);
-        assertEquals("message matches", message.getStringProperty("data"), dlqMessage.getStringProperty("data"));
-        consumerSession.commit();
+        if (validateDLQ) {
+            MessageConsumer dlqConsumer = consumerSession.createConsumer(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
+            Message dlqMessage = dlqConsumer.receive(2000);
+            assertNotNull("Got message from dql", dlqMessage);
+            assertEquals("message matches", message.getStringProperty("data"), dlqMessage.getStringProperty("data"));
+            consumerSession.commit();
+        } else {
+            // consume/commit ok
+            message = consumer.receive(3000);
+            assertNotNull("got message", message);
+            assertEquals("redeliveries accounted for", maxBrokerRedeliveriesToValidate +
2, message.getLongProperty("JMSXDeliveryCount"));
+            consumerSession.commit();
+        }
+
+        consumerConnection.close();
     }
 
     public void testNoScheduledRedeliveryOfExpired() throws Exception {
+        startBroker(true);
         ActiveMQConnection consumerConnection = (ActiveMQConnection) createConnection();
         consumerConnection.start();
         Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -156,12 +176,6 @@ public class BrokerRedeliveryTest extend
     }
 
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        startBroker(true);
-    }
-
-    @Override
     protected void tearDown() throws Exception {
         stopBroker();
         super.tearDown();



Mime
View raw message