From 74d454728cb34f3f492b81c98347375b4426a8ee Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Wed, 1 Apr 2009 16:26:50 +0000 Subject: QPID-1783 : Relax MessageFactory to allow out of order recovery Relax MessageFactory to allow out of order. Updated test git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@760952 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/server/queue/MessageFactory.java | 12 +++----- .../server/queue/MessageFactoryRecoveryTest.java | 32 +++++++++++++++------- 2 files changed, 26 insertions(+), 18 deletions(-) (limited to 'java/broker') diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/MessageFactory.java b/java/broker/src/main/java/org/apache/qpid/server/queue/MessageFactory.java index 9924733178..10e7dca18f 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/queue/MessageFactory.java +++ b/java/broker/src/main/java/org/apache/qpid/server/queue/MessageFactory.java @@ -85,17 +85,13 @@ public class MessageFactory throw new RuntimeException("Unable to create message by ID when not recovering"); } - long currentID = _messageId.get(); - if (messageId <= currentID) + if (messageId < 0L) { - throw new RuntimeException("Message IDs can only increase current id is:" - + currentID + ". Requested:" + messageId); - } - else - { - _messageId.set(messageId); + throw new RuntimeException("Message IDs can only be positive. Requested:" + messageId); } + _messageId.set((int)Math.max(messageId, _messageId.get())); + return createNextMessage(messageId, transactionLog, true); } diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/MessageFactoryRecoveryTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/MessageFactoryRecoveryTest.java index a272da88ac..f8fb9a154c 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/queue/MessageFactoryRecoveryTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/queue/MessageFactoryRecoveryTest.java @@ -41,29 +41,41 @@ public class MessageFactoryRecoveryTest extends TestCase try { - _factory.createMessage(messasgeID, null); - fail("Cannot recreate message with an existing id"); + _factory.createMessage(-1L, null); + fail("Cannot recreate message with a negative id"); } catch (RuntimeException re) { assertEquals("Incorrect exception thrown ", - "Message IDs can only increase current id is:" + messasgeID + ". Requested:" + messasgeID, re.getMessage()); + "Message IDs can only be positive. Requested:-1", re.getMessage()); } - //Check we cannot go backwords with ids. + //Check we CAN go backwords with ids. try { - _factory.createMessage(messasgeID - 1, null); - fail("Cannot recreate message with an old id"); + _factory.createMessage(messasgeID - 1, null); } catch (RuntimeException re) { - assertEquals("Incorrect exception thrown ", - "Message IDs can only increase current id is:" + messasgeID + ". Requested:" + (messasgeID - 1), re.getMessage()); + fail(re.getMessage()); } //Check that we can jump forward in ids during recovery. messasgeID += 100; + Long highestID=messasgeID; + try + { + AMQMessage message = _factory.createMessage(messasgeID, null); + assertEquals("Factory assigned incorrect id.", messasgeID, message.getMessageId()); + } + catch (Exception re) + { + fail("Message with a much higher value should be created"); + } + + + //Check that we can jump backwards in ids during recovery. + messasgeID -= 75; try { AMQMessage message = _factory.createMessage(messasgeID, null); @@ -91,12 +103,12 @@ public class MessageFactoryRecoveryTest extends TestCase // Check that the next message created has the next available id - messasgeID++; + highestID++; try { AMQMessage message = _factory.createMessage(null, false); - assertEquals("Factory assigned incorrect id.", messasgeID, message.getMessageId()); + assertEquals("Factory assigned incorrect id.", highestID, message.getMessageId()); } catch (Exception re) { -- cgit v1.2.1