activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AMQ-5087 fix and test
Date Thu, 06 Mar 2014 22:40:15 GMT
Repository: activemq
Updated Branches:
  refs/heads/trunk f555d90e9 -> 33b88d34a


https://issues.apache.org/jira/browse/AMQ-5087 fix and test


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/33b88d34
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/33b88d34
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/33b88d34

Branch: refs/heads/trunk
Commit: 33b88d34a9c242787c5878c9192f77bbb163e446
Parents: f555d90
Author: gtully <gary.tully@gmail.com>
Authored: Thu Mar 6 22:39:16 2014 +0000
Committer: gtully <gary.tully@gmail.com>
Committed: Thu Mar 6 22:40:01 2014 +0000

----------------------------------------------------------------------
 .../org/apache/activemq/RedeliveryPolicy.java   |  8 ++---
 .../apache/activemq/RedeliveryPolicyTest.java   | 33 ++++++++++++++++----
 .../activemq/broker/BrokerRedeliveryTest.java   |  5 +--
 3 files changed, 32 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/33b88d34/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java b/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
index c6824f7..91f2b71 100644
--- a/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
+++ b/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java
@@ -98,18 +98,14 @@ public class RedeliveryPolicy extends DestinationMapEntry implements Cloneable,
     }
 
     public long getNextRedeliveryDelay(long previousDelay) {
-        long nextDelay;
+        long nextDelay = redeliveryDelay;
 
-        if (previousDelay == 0) {
-            nextDelay = redeliveryDelay;
-        } else if (useExponentialBackOff && backOffMultiplier > 1) {
+        if (previousDelay > 0 && useExponentialBackOff && backOffMultiplier
> 1) {
             nextDelay = (long) (previousDelay * backOffMultiplier);
             if(maximumRedeliveryDelay != -1 && nextDelay > maximumRedeliveryDelay)
{
                 // in case the user made max redelivery delay less than redelivery delay
for some reason.
                 nextDelay = Math.max(maximumRedeliveryDelay, redeliveryDelay);
             }
-        } else {
-            nextDelay = previousDelay;
         }
 
         if (useCollisionAvoidance) {

http://git-wip-us.apache.org/repos/asf/activemq/blob/33b88d34/activemq-unit-tests/src/test/java/org/apache/activemq/RedeliveryPolicyTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/RedeliveryPolicyTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/RedeliveryPolicyTest.java
index f77e4ba..02db378 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/RedeliveryPolicyTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/RedeliveryPolicyTest.java
@@ -43,6 +43,27 @@ public class RedeliveryPolicyTest extends JmsTestSupport {
         junit.textui.TestRunner.run(suite());
     }
 
+
+    public void testGetNext() throws Exception {
+
+        RedeliveryPolicy policy = new RedeliveryPolicy();
+        policy.setInitialRedeliveryDelay(0);
+        policy.setRedeliveryDelay(500);
+        policy.setBackOffMultiplier((short) 2);
+        policy.setUseExponentialBackOff(true);
+
+        long delay = policy.getNextRedeliveryDelay(0);
+        assertEquals(500, delay);
+        delay = policy.getNextRedeliveryDelay(delay);
+        assertEquals(500*2, delay);
+        delay = policy.getNextRedeliveryDelay(delay);
+        assertEquals(500*4, delay);
+
+        policy.setUseExponentialBackOff(false);
+        delay = policy.getNextRedeliveryDelay(delay);
+        assertEquals(500, delay);
+    }
+
     /**
      * @throws Exception
      */
@@ -185,7 +206,7 @@ public class RedeliveryPolicyTest extends JmsTestSupport {
         assertEquals("1st", m.getText());
         session.rollback();
 
-        m = (TextMessage)consumer.receive(1000);
+        m = (TextMessage)consumer.receive(2000);
         assertNotNull(m);
         assertEquals("1st", m.getText());
         session.rollback();
@@ -245,27 +266,27 @@ public class RedeliveryPolicyTest extends JmsTestSupport {
         assertEquals("1st", m.getText());
         session.rollback();
 
-        m = (TextMessage)consumer.receive(1000);
+        m = (TextMessage)consumer.receive(2000);
         assertNotNull(m);
         assertEquals("1st", m.getText());
         session.rollback();
 
-        m = (TextMessage)consumer.receive(1000);
+        m = (TextMessage)consumer.receive(2000);
         assertNotNull(m);
         assertEquals("1st", m.getText());
         session.rollback();
 
-        m = (TextMessage)consumer.receive(1000);
+        m = (TextMessage)consumer.receive(2000);
         assertNotNull(m);
         assertEquals("1st", m.getText());
         session.rollback();
 
-        m = (TextMessage)consumer.receive(1000);
+        m = (TextMessage)consumer.receive(2000);
         assertNotNull(m);
         assertEquals("1st", m.getText());
         session.commit();
 
-        m = (TextMessage)consumer.receive(1000);
+        m = (TextMessage)consumer.receive(2000);
         assertNotNull(m);
         assertEquals("2nd", m.getText());
         session.commit();

http://git-wip-us.apache.org/repos/asf/activemq/blob/33b88d34/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
index c61a5ee..1bec479 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerRedeliveryTest.java
@@ -40,6 +40,7 @@ public class BrokerRedeliveryTest extends org.apache.activemq.TestSupport
{
     final ActiveMQQueue destination = new ActiveMQQueue("Redelivery");
     final String data = "hi";
     final long redeliveryDelayMillis = 2000;
+    final long initialRedeliveryDelayMillis = 4000;
     int maxBrokerRedeliveries = 2;
 
     public void testScheduledRedelivery() throws Exception {
@@ -79,7 +80,7 @@ public class BrokerRedeliveryTest extends org.apache.activemq.TestSupport
{
             LOG.info("got: " + brokerRedeliveryMessage);
             assertNotNull("got message via broker redelivery after delay", brokerRedeliveryMessage);
             assertEquals("message matches", message.getStringProperty("data"), brokerRedeliveryMessage.getStringProperty("data"));
-            assertEquals("has expiryDelay specified", redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));
+            assertEquals("has expiryDelay specified", i == 0 ? initialRedeliveryDelayMillis
: redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));
 
             consumerSession.rollback();
         }
@@ -149,7 +150,7 @@ public class BrokerRedeliveryTest extends org.apache.activemq.TestSupport
{
 
         RedeliveryPolicy brokerRedeliveryPolicy = new RedeliveryPolicy();
         brokerRedeliveryPolicy.setRedeliveryDelay(redeliveryDelayMillis);
-        brokerRedeliveryPolicy.setInitialRedeliveryDelay(redeliveryDelayMillis);
+        brokerRedeliveryPolicy.setInitialRedeliveryDelay(initialRedeliveryDelayMillis);
         brokerRedeliveryPolicy.setMaximumRedeliveries(maxBrokerRedeliveries);
 
         RedeliveryPolicyMap redeliveryPolicyMap = new RedeliveryPolicyMap();


Mime
View raw message