https://issues.apache.org/jira/browse/AMQ-5674 - revisit change - use single redelivey delay attribute for both initial and subsequent delays - resolves regression in BrokerRedeliveryTest

This commit is contained in:
gtully 2015-04-03 14:18:55 +01:00
parent 7741e02622
commit 1d71cb7036
5 changed files with 10 additions and 18 deletions

View File

@ -140,9 +140,10 @@ public class RedeliveryPlugin extends BrokerPluginSupport {
int redeliveryCount = messageReference.getRedeliveryCounter();
if (RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES == maximumRedeliveries || redeliveryCount < maximumRedeliveries) {
long delay = ( redeliveryCount == 0 ?
redeliveryPolicy.getInitialRedeliveryDelay() :
redeliveryPolicy.getNextRedeliveryDelay(getExistingDelay(messageReference)));
long delay = redeliveryPolicy.getInitialRedeliveryDelay();
for (int i = 0; i < redeliveryCount; i++) {
delay = redeliveryPolicy.getNextRedeliveryDelay(delay);
}
scheduleRedelivery(context, messageReference, delay, ++redeliveryCount);
} else if (isSendToDlqIfMaxRetriesExceeded()) {
@ -199,11 +200,4 @@ public class RedeliveryPlugin extends BrokerPluginSupport {
}
}
private int getExistingDelay(MessageReference messageReference) throws IOException {
Object val = messageReference.getMessage().getProperty(REDELIVERY_DELAY);
if (val instanceof Long) {
return ((Long)val).intValue();
}
return 0;
}
}

View File

@ -98,10 +98,7 @@ public class RedeliveryPolicy extends DestinationMapEntry implements Cloneable,
}
public long getNextRedeliveryDelay(long previousDelay) {
long nextDelay = initialRedeliveryDelay;
if (nextDelay == 0) {
nextDelay = redeliveryDelay;
}
long nextDelay = redeliveryDelay;
if (previousDelay > 0 && useExponentialBackOff && backOffMultiplier > 1) {
nextDelay = (long) (previousDelay * backOffMultiplier);

View File

@ -639,6 +639,7 @@ public class ActiveMQActivationSpec implements MessageActivationSpec, Serializab
*/
public void setInitialRedeliveryDelay(long initialRedeliveryDelay) {
lazyCreateRedeliveryPolicy().setInitialRedeliveryDelay(initialRedeliveryDelay);
redeliveryPolicy.setRedeliveryDelay(initialRedeliveryDelay);
}
/**

View File

@ -75,11 +75,11 @@ public class RedeliveryPolicyTest extends JmsTestSupport {
policy.setInitialRedeliveryDelay(500);
long delay = policy.getNextRedeliveryDelay(500);
assertEquals(500, delay);
assertEquals(1000, delay);
delay = policy.getNextRedeliveryDelay(delay);
assertEquals(500, delay);
assertEquals(1000, delay);
delay = policy.getNextRedeliveryDelay(delay);
assertEquals(500, delay);
assertEquals(1000, delay);
}

View File

@ -81,7 +81,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", i == 0 ? initialRedeliveryDelayMillis : redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));
assertEquals("has expiryDelay specified - iteration:" + i, i == 0 ? initialRedeliveryDelayMillis : redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));
consumerSession.rollback();
}