summaryrefslogtreecommitdiff
path: root/java/broker
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2009-04-01 16:26:50 +0000
committerMartin Ritchie <ritchiem@apache.org>2009-04-01 16:26:50 +0000
commit74d454728cb34f3f492b81c98347375b4426a8ee (patch)
tree72b8e73e2c113384722811e12b73cc9a96235247 /java/broker
parent08308d4404c46de8a2939ca420cc57f8fc6227eb (diff)
downloadqpid-python-74d454728cb34f3f492b81c98347375b4426a8ee.tar.gz
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
Diffstat (limited to 'java/broker')
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/MessageFactory.java12
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/MessageFactoryRecoveryTest.java32
2 files changed, 26 insertions, 18 deletions
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)
{