summaryrefslogtreecommitdiff
path: root/java/broker/test/src
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2006-10-19 10:11:47 +0000
committerGordon Sim <gsim@apache.org>2006-10-19 10:11:47 +0000
commit0c7aaaaab89dff7f0843cbcdf40791e4d17255bb (patch)
tree6eecd25a9ba32c11fdffe69f7508b222e486814a /java/broker/test/src
parent025451b1e26c48ca58c388921827929d11c9459c (diff)
downloadqpid-python-0c7aaaaab89dff7f0843cbcdf40791e4d17255bb.tar.gz
Further fixes and some extra tests for transactions.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@465549 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker/test/src')
-rw-r--r--java/broker/test/src/org/apache/qpid/server/ack/TxAckTest.java186
-rw-r--r--java/broker/test/src/org/apache/qpid/server/ack/UnitTests.java34
-rw-r--r--java/broker/test/src/org/apache/qpid/server/queue/AckTest.java37
-rw-r--r--java/broker/test/src/org/apache/qpid/server/util/OrderedMapHelperTest.java95
-rw-r--r--java/broker/test/src/org/apache/qpid/server/util/UnitTests.java2
5 files changed, 240 insertions, 114 deletions
diff --git a/java/broker/test/src/org/apache/qpid/server/ack/TxAckTest.java b/java/broker/test/src/org/apache/qpid/server/ack/TxAckTest.java
new file mode 100644
index 0000000000..4bf23ec25a
--- /dev/null
+++ b/java/broker/test/src/org/apache/qpid/server/ack/TxAckTest.java
@@ -0,0 +1,186 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.server.ack;
+
+import junit.framework.JUnit4TestAdapter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Ignore;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.server.queue.AMQMessage;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public class TxAckTest
+{
+ private Scenario individual;
+ private Scenario multiple;
+ private Scenario combined;
+
+ @Before
+ public void setup() throws Exception
+ {
+ //ack only 5th msg
+ individual = new Scenario(10, Arrays.asList(5l), Arrays.asList(1l, 2l, 3l, 4l, 6l, 7l, 8l, 9l, 10l));
+ individual.update(5, false);
+
+ //ack all up to and including 5th msg
+ multiple = new Scenario(10, Arrays.asList(1l, 2l, 3l, 4l, 5l), Arrays.asList(6l, 7l, 8l, 9l, 10l));
+ multiple.update(5, true);
+
+ //leave only 8th and 9th unacked
+ combined = new Scenario(10, Arrays.asList(1l, 2l, 3l, 4l, 5l, 6l, 7l, 10l), Arrays.asList(8l, 9l));
+ combined.update(3, false);
+ combined.update(5, true);
+ combined.update(7, true);
+ combined.update(2, true);//should be ignored
+ combined.update(1, false);//should be ignored
+ combined.update(10, false);
+ }
+
+ @Test
+ public void prepare() throws AMQException
+ {
+ individual.prepare();
+ multiple.prepare();
+ combined.prepare();
+ }
+
+ @Test
+ public void undoPrepare() throws AMQException
+ {
+ individual.undoPrepare();
+ multiple.undoPrepare();
+ combined.undoPrepare();
+ }
+
+ @Test
+ public void commit() throws AMQException
+ {
+ individual.commit();
+ multiple.commit();
+ combined.commit();
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(TxAckTest.class);
+ }
+
+ private class Scenario
+ {
+ private final LinkedHashMap<Long, UnacknowledgedMessage> _messages = new LinkedHashMap<Long, UnacknowledgedMessage>();
+ private final UnacknowledgedMessageMap _map = new UnacknowledgedMessageMapImpl(_messages, _messages);
+ private final TxAck _op = new TxAck(_map);
+ private final List<Long> _acked;
+ private final List<Long> _unacked;
+
+ Scenario(int messageCount, List<Long> acked, List<Long> unacked)
+ {
+ for(int i = 0; i < messageCount; i++)
+ {
+ long deliveryTag = i + 1;
+ _messages.put(deliveryTag, new UnacknowledgedMessage(null, new TestMessage(deliveryTag), null, deliveryTag));
+ }
+ _acked = acked;
+ _unacked = unacked;
+ }
+
+ void update(long deliverytag, boolean multiple)
+ {
+ _op.update(deliverytag, multiple);
+ }
+
+ private void assertCount(List<Long> tags, int expected)
+ {
+ for(long tag : tags)
+ {
+ UnacknowledgedMessage u = _messages.get(tag);
+ assertTrue("Message not found for tag " + tag, u != null);
+ ((TestMessage) u.message).assertCountEquals(expected);
+ }
+ }
+
+ void prepare() throws AMQException
+ {
+ _op.consolidate();
+ _op.prepare();
+
+ assertCount(_acked, -1);
+ assertCount(_unacked, 0);
+
+ }
+ void undoPrepare()
+ {
+ _op.consolidate();
+ _op.undoPrepare();
+
+ assertCount(_acked, 1);
+ assertCount(_unacked, 0);
+ }
+
+ void commit()
+ {
+ _op.consolidate();
+ _op.commit();
+
+
+ //check acked messages are removed from map
+ HashSet<Long> keys = new HashSet<Long>(_messages.keySet());
+ keys.retainAll(_acked);
+ assertTrue("Expected messages with following tags to have been removed from map: " + keys, keys.isEmpty());
+ //check unacked messages are still in map
+ keys = new HashSet<Long>(_unacked);
+ keys.removeAll(_messages.keySet());
+ assertTrue("Expected messages with following tags to still be in map: " + keys, keys.isEmpty());
+ }
+ }
+
+ private class TestMessage extends AMQMessage
+ {
+ private final long _tag;
+ private int _count;
+
+ TestMessage(long tag)
+ {
+ super(new TestableMemoryMessageStore(), null);
+ _tag = tag;
+ }
+
+ public void incrementReference()
+ {
+ _count++;
+ }
+
+ public void decrementReference()
+ {
+ _count--;
+ }
+
+ void assertCountEquals(int expected)
+ {
+ assertEquals("Wrong count for message with tag " + _tag, expected, _count);
+ }
+ }
+}
diff --git a/java/broker/test/src/org/apache/qpid/server/ack/UnitTests.java b/java/broker/test/src/org/apache/qpid/server/ack/UnitTests.java
new file mode 100644
index 0000000000..3d7db01365
--- /dev/null
+++ b/java/broker/test/src/org/apache/qpid/server/ack/UnitTests.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.server.ack;
+
+import junit.framework.JUnit4TestAdapter;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TxAckTest.class
+})
+public class UnitTests
+{
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(UnitTests.class);
+ }
+}
diff --git a/java/broker/test/src/org/apache/qpid/server/queue/AckTest.java b/java/broker/test/src/org/apache/qpid/server/queue/AckTest.java
index 8ce006b3ae..f22ccb8caf 100644
--- a/java/broker/test/src/org/apache/qpid/server/queue/AckTest.java
+++ b/java/broker/test/src/org/apache/qpid/server/queue/AckTest.java
@@ -26,6 +26,7 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.framing.BasicPublishBody;
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.ack.UnacknowledgedMessage;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
import org.apache.qpid.server.util.TestApplicationRegistry;
@@ -93,15 +94,15 @@ public class AckTest
final int msgCount = 10;
publishMessages(msgCount);
- Map<Long, AMQChannel.UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
+ Map<Long, UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
assertTrue(map.size() == msgCount);
- Iterator<Map.Entry<Long, AMQChannel.UnacknowledgedMessage>> it = map.entrySet().iterator();
+ Iterator<Map.Entry<Long, UnacknowledgedMessage>> it = map.entrySet().iterator();
for (int i = 1; i <= map.size(); i++)
{
- Map.Entry<Long, AMQChannel.UnacknowledgedMessage> entry = it.next();
+ Map.Entry<Long, UnacknowledgedMessage> entry = it.next();
assertTrue(entry.getKey() == i);
- AMQChannel.UnacknowledgedMessage unackedMsg = entry.getValue();
+ UnacknowledgedMessage unackedMsg = entry.getValue();
assertTrue(unackedMsg.queue == _queue);
}
assertTrue(_messageStore.getMessageMap().size() == msgCount);
@@ -118,7 +119,7 @@ public class AckTest
final int msgCount = 10;
publishMessages(msgCount);
- Map<Long, AMQChannel.UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
+ Map<Long, UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
assertTrue(map.size() == 0);
assertTrue(_messageStore.getMessageMap().size() == 0);
}
@@ -135,16 +136,16 @@ public class AckTest
publishMessages(msgCount);
_channel.acknowledgeMessage(5, false);
- Map<Long, AMQChannel.UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
+ Map<Long, UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
assertTrue(map.size() == msgCount - 1);
- Iterator<Map.Entry<Long, AMQChannel.UnacknowledgedMessage>> it = map.entrySet().iterator();
+ Iterator<Map.Entry<Long, UnacknowledgedMessage>> it = map.entrySet().iterator();
int i = 1;
while (i <= map.size())
{
- Map.Entry<Long, AMQChannel.UnacknowledgedMessage> entry = it.next();
+ Map.Entry<Long, UnacknowledgedMessage> entry = it.next();
assertTrue(entry.getKey() == i);
- AMQChannel.UnacknowledgedMessage unackedMsg = entry.getValue();
+ UnacknowledgedMessage unackedMsg = entry.getValue();
assertTrue(unackedMsg.queue == _queue);
// 5 is the delivery tag of the message that *should* be removed
if (++i == 5)
@@ -166,16 +167,16 @@ public class AckTest
publishMessages(msgCount);
_channel.acknowledgeMessage(5, true);
- Map<Long, AMQChannel.UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
+ Map<Long, UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
assertTrue(map.size() == 5);
- Iterator<Map.Entry<Long, AMQChannel.UnacknowledgedMessage>> it = map.entrySet().iterator();
+ Iterator<Map.Entry<Long, UnacknowledgedMessage>> it = map.entrySet().iterator();
int i = 1;
while (i <= map.size())
{
- Map.Entry<Long, AMQChannel.UnacknowledgedMessage> entry = it.next();
+ Map.Entry<Long, UnacknowledgedMessage> entry = it.next();
assertTrue(entry.getKey() == i + 5);
- AMQChannel.UnacknowledgedMessage unackedMsg = entry.getValue();
+ UnacknowledgedMessage unackedMsg = entry.getValue();
assertTrue(unackedMsg.queue == _queue);
++i;
}
@@ -193,16 +194,16 @@ public class AckTest
publishMessages(msgCount);
_channel.acknowledgeMessage(0, true);
- Map<Long, AMQChannel.UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
+ Map<Long, UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
assertTrue(map.size() == 0);
- Iterator<Map.Entry<Long, AMQChannel.UnacknowledgedMessage>> it = map.entrySet().iterator();
+ Iterator<Map.Entry<Long, UnacknowledgedMessage>> it = map.entrySet().iterator();
int i = 1;
while (i <= map.size())
{
- Map.Entry<Long, AMQChannel.UnacknowledgedMessage> entry = it.next();
+ Map.Entry<Long, UnacknowledgedMessage> entry = it.next();
assertTrue(entry.getKey() == i + 5);
- AMQChannel.UnacknowledgedMessage unackedMsg = entry.getValue();
+ UnacknowledgedMessage unackedMsg = entry.getValue();
assertTrue(unackedMsg.queue == _queue);
++i;
}
@@ -221,7 +222,7 @@ public class AckTest
// at this point we should have sent out only 5 messages with a further 5 queued
// up in the channel which should be suspended
assertTrue(_subscription.isSuspended());
- Map<Long, AMQChannel.UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
+ Map<Long, UnacknowledgedMessage> map = _channel.getUnacknowledgedMessageMap();
assertTrue(map.size() == 5);
_channel.acknowledgeMessage(5, true);
assertTrue(!_subscription.isSuspended());
diff --git a/java/broker/test/src/org/apache/qpid/server/util/OrderedMapHelperTest.java b/java/broker/test/src/org/apache/qpid/server/util/OrderedMapHelperTest.java
deleted file mode 100644
index 74340e98c0..0000000000
--- a/java/broker/test/src/org/apache/qpid/server/util/OrderedMapHelperTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.qpid.server.util;
-
-import junit.framework.JUnit4TestAdapter;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.Ignore;
-import org.apache.qpid.AMQException;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class OrderedMapHelperTest
-{
- private final Object lock = new Object();
- private final Map<Integer, String> map = new LinkedHashMap<Integer, String>();
- private final OrderedMapHelper<Integer, String> helper = new OrderedMapHelper<Integer, String>(map, lock, 0);
-
- @Before
- public void setup() throws Exception
- {
- map.put(1, "One");
- map.put(2, "Two");
- map.put(5, "Five");
- map.put(8, "Eight");
- map.put(10, "Ten");
- }
-
- @Test
- public void specific()
- {
- Map<Integer, String> slice = helper.getValues(5, false);
- assertEquals(1, slice.size());
- assertTrue(slice.containsKey(5));
- assertTrue(slice.containsValue("Five"));
- assertEquals("Five", slice.get(5));
- }
-
- @Test
- public void multiple()
- {
- Map<Integer, String> slice = helper.getValues(5, true);
- assertEquals(3, slice.size());
-
- assertTrue(slice.containsKey(1));
- assertTrue(slice.containsKey(2));
- assertTrue(slice.containsKey(5));
-
- assertEquals("One", slice.get(1));
- assertEquals("Two", slice.get(2));
- assertEquals("Five", slice.get(5));
- }
-
- @Test
- public void all()
- {
- Map<Integer, String> slice = helper.getValues(0/*the 'wildcard'*/, true);
- assertEquals(5, slice.size());
-
- assertTrue(slice.containsKey(1));
- assertTrue(slice.containsKey(2));
- assertTrue(slice.containsKey(5));
- assertTrue(slice.containsKey(8));
- assertTrue(slice.containsKey(10));
-
- assertEquals("One", slice.get(1));
- assertEquals("Two", slice.get(2));
- assertEquals("Five", slice.get(5));
- assertEquals("Eight", slice.get(8));
- assertEquals("Ten", slice.get(10));
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(OrderedMapHelperTest.class);
- }
-}
diff --git a/java/broker/test/src/org/apache/qpid/server/util/UnitTests.java b/java/broker/test/src/org/apache/qpid/server/util/UnitTests.java
index 5c2242fb0d..d6cc471413 100644
--- a/java/broker/test/src/org/apache/qpid/server/util/UnitTests.java
+++ b/java/broker/test/src/org/apache/qpid/server/util/UnitTests.java
@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({LoggingProxyTest.class, OrderedMapHelperTest.class})
+@Suite.SuiteClasses({LoggingProxyTest.class})
public class UnitTests
{
public static junit.framework.Test suite()