From cf9ef821887400816f30c83e84c4f6027cf26bd5 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Thu, 14 Aug 2014 23:20:43 +0000 Subject: QPID-3978 : [Java Broker] Add unit test for UnacknowledgedMessageMap git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1618082 13f79535-47bb-0310-9956-ffa450edef68 --- .../v0_8/UnacknowledgedMessageMapTest.java | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java (limited to 'qpid/java/broker-plugins') diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java new file mode 100644 index 0000000000..ca52173e66 --- /dev/null +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java @@ -0,0 +1,84 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.protocol.v0_8; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collection; + +import junit.framework.TestCase; + +import org.apache.qpid.server.message.MessageInstance; + +public class UnacknowledgedMessageMapTest extends TestCase +{ + public void testDeletedMessagesCantBeAcknowledged() + { + UnacknowledgedMessageMap map = new UnacknowledgedMessageMapImpl(100); + final int expectedSize = 5; + MessageInstance[] msgs = populateMap(map,expectedSize); + assertEquals(expectedSize,map.size()); + Collection acknowledged = map.acknowledge(100, true); + assertEquals(expectedSize, acknowledged.size()); + assertEquals(0,map.size()); + for(int i = 0; i < expectedSize; i++) + { + assertTrue("Message " + i + " is missing", acknowledged.contains(msgs[i])); + } + + map = new UnacknowledgedMessageMapImpl(100); + msgs = populateMap(map,expectedSize); + // simulate some messages being ttl expired + when(msgs[2].lockAcquisition()).thenReturn(Boolean.FALSE); + when(msgs[4].lockAcquisition()).thenReturn(Boolean.FALSE); + + assertEquals(expectedSize,map.size()); + + + acknowledged = map.acknowledge(100, true); + assertEquals(expectedSize-2, acknowledged.size()); + assertEquals(0,map.size()); + for(int i = 0; i < expectedSize; i++) + { + assertEquals(i != 2 && i != 4, acknowledged.contains(msgs[i])); + } + + } + + public MessageInstance[] populateMap(final UnacknowledgedMessageMap map, int size) + { + MessageInstance[] msgs = new MessageInstance[size]; + for(int i = 0; i < size; i++) + { + msgs[i] = createMessageInstance(i); + map.add((long)i,msgs[i]); + } + return msgs; + } + + private MessageInstance createMessageInstance(final int id) + { + MessageInstance instance = mock(MessageInstance.class); + when(instance.lockAcquisition()).thenReturn(Boolean.TRUE); + return instance; + } +} -- cgit v1.2.1