From 403007b67551a262b62ada16429f4f305c2d93fd Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Tue, 16 Jul 2013 09:23:02 +0000 Subject: QPID-4659 : [Java Broker] reduce unnecessary usage of 0-8 classes in tests git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1503625 13f79535-47bb-0310-9956-ffa450edef68 --- .../subjects/SubscriptionLogSubjectTest.java | 105 +++++++++++++ .../protocol/v0_8/ExtractResendAndRequeueTest.java | 4 - .../qpid/server/protocol/v0_8/MockAMQMessage.java | 40 +++++ .../protocol/v0_8/MockMessagePublishInfo.java | 52 +++++++ .../server/protocol/v0_8/MockStoredMessage.java | 115 +++++++++++++++ .../protocol/v0_8/ReferenceCountingTest.java | 162 +++++++++++++++++++++ .../protocol/v0_8/SubscriptionLogSubjectTest.java | 115 --------------- .../apache/qpid/server/queue/MockAMQMessage.java | 42 ------ .../org/apache/qpid/server/queue/MockAMQQueue.java | 1 - .../qpid/server/queue/MockMessagePublishInfo.java | 52 ------- .../apache/qpid/server/queue/MockQueueEntry.java | 1 - .../qpid/server/queue/MockStoredMessage.java | 116 --------------- .../qpid/server/queue/QueueEntryListTestBase.java | 25 ++-- .../AbstractDurableConfigurationStoreTestCase.java | 5 +- .../store/MessageStoreQuotaEventsTestBase.java | 35 ++--- .../qpid/server/store/ReferenceCountingTest.java | 162 --------------------- 16 files changed, 507 insertions(+), 525 deletions(-) create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockAMQMessage.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockMessagePublishInfo.java create mode 100755 qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockStoredMessage.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java delete mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/SubscriptionLogSubjectTest.java delete mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java delete mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockMessagePublishInfo.java delete mode 100755 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockStoredMessage.java delete mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java (limited to 'qpid/java') diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java new file mode 100644 index 0000000000..b9efac1ae8 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java @@ -0,0 +1,105 @@ +/* + * + * 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.logging.subjects; + +import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.queue.MockAMQQueue; +import org.apache.qpid.server.subscription.Subscription; +import org.apache.qpid.server.util.BrokerTestHelper; +import org.apache.qpid.server.virtualhost.VirtualHost; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Validate SubscriptionLogSubjects are logged as expected + */ +public class SubscriptionLogSubjectTest extends AbstractTestLogSubject +{ + + private static final long SUBSCRIPTION_ID = 1; + private AMQQueue _queue; + private VirtualHost _testVhost; + private Subscription _subscription; + + @Override + public void setUp() throws Exception + { + super.setUp(); + + _testVhost = BrokerTestHelper.createVirtualHost("test"); + + _queue = new MockAMQQueue("SubscriptionLogSubjectTest"); + ((MockAMQQueue) _queue).setVirtualHost(_testVhost); + + _subscription = mock(Subscription.class); + when(_subscription.getQueue()).thenReturn(_queue); + when(_subscription.getSubscriptionID()).thenReturn(SUBSCRIPTION_ID); + + _subject = new SubscriptionLogSubject(_subscription); + } + + @Override + public void tearDown() throws Exception + { + if (_testVhost != null) + { + _testVhost.close(); + } + super.tearDown(); + } + + /** + * Validate that the logged Subject message is as expected: + * MESSAGE [Blank][sub:0(vh(/test)/qu(SubscriptionLogSubjectTest))] + * + * @param message the message whos format needs validation + */ + @Override + protected void validateLogStatement(String message) + { + String subscriptionSlice = getSlice("sub:" + + _subscription.getSubscriptionID(), + message); + + assertNotNull("Unable to locate subscription 'sub:" + + _subscription.getSubscriptionID() + "'"); + + + + // Pull out the qu(..) section from the subscription message + // Split it into three parts + // MESSAGE [Blank][sub:0(vh(/ + // test)/ + // qu(SubscriptionLogSubjectTest))] + // Take the last bit and drop off the extra )] + String[] parts = message.split("/"); + assertEquals("Message part count wrong", 3, parts.length); + String subscription = parts[2].substring(0, parts[2].indexOf(")") + 1); + + // Adding the ')' is a bit ugly but SubscriptionLogSubject is the only + // Subject that nests () and so the simple parser of checking for the + // next ')' falls down. + verifyVirtualHost(subscriptionSlice+ ")", _queue.getVirtualHost()); + + verifyQueue(subscription, _queue); + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ExtractResendAndRequeueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ExtractResendAndRequeueTest.java index 2da93d2d99..7f36b4a081 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ExtractResendAndRequeueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ExtractResendAndRequeueTest.java @@ -23,11 +23,7 @@ package org.apache.qpid.server.protocol.v0_8; import junit.framework.TestCase; import org.apache.qpid.AMQException; -import org.apache.qpid.server.protocol.v0_8.UnacknowledgedMessageMapImpl; -import org.apache.qpid.server.protocol.v0_8.AMQMessage; -import org.apache.qpid.server.protocol.v0_8.ExtractResendAndRequeue; import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.MockAMQMessage; import org.apache.qpid.server.queue.MockAMQQueue; import org.apache.qpid.server.queue.QueueEntry; import org.apache.qpid.server.queue.QueueEntryIterator; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockAMQMessage.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockAMQMessage.java new file mode 100644 index 0000000000..1cc3607298 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockAMQMessage.java @@ -0,0 +1,40 @@ +/* + * + * 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; + +public class MockAMQMessage extends AMQMessage +{ + public MockAMQMessage(long messageId) + { + super(new MockStoredMessage(messageId)); + } + + public MockAMQMessage(long messageId, String headerName, Object headerValue) + { + super(new MockStoredMessage(messageId, headerName, headerValue)); + } + + @Override + public long getSize() + { + return 0l; + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockMessagePublishInfo.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockMessagePublishInfo.java new file mode 100644 index 0000000000..ab29e58a6c --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockMessagePublishInfo.java @@ -0,0 +1,52 @@ +/* + * + * 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 org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.abstraction.MessagePublishInfo; + +public class MockMessagePublishInfo implements MessagePublishInfo +{ + public AMQShortString getExchange() + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void setExchange(AMQShortString exchange) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isImmediate() + { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isMandatory() + { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + public AMQShortString getRoutingKey() + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockStoredMessage.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockStoredMessage.java new file mode 100755 index 0000000000..15573a871f --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/MockStoredMessage.java @@ -0,0 +1,115 @@ +/* +* +* 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 org.apache.qpid.framing.BasicContentHeaderProperties; +import org.apache.qpid.framing.ContentHeaderBody; +import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.framing.abstraction.MessagePublishInfo; +import org.apache.qpid.server.store.StoreFuture; +import org.apache.qpid.server.store.StoredMessage; + +import java.nio.ByteBuffer; + +public class MockStoredMessage implements StoredMessage +{ + private long _messageId; + private MessageMetaData _metaData; + private final ByteBuffer _content; + + public MockStoredMessage(long messageId) + { + this(messageId, (String)null, null); + } + + public MockStoredMessage(long messageId, String headerName, Object headerValue) + { + this(messageId, new MockMessagePublishInfo(), new ContentHeaderBody(new BasicContentHeaderProperties(), 60), headerName, headerValue); + } + + public MockStoredMessage(long messageId, MessagePublishInfo info, ContentHeaderBody chb) + { + this(messageId, info, chb, null, null); + } + + public MockStoredMessage(long messageId, MessagePublishInfo info, ContentHeaderBody chb, String headerName, Object headerValue) + { + _messageId = messageId; + if (headerName != null) + { + FieldTable headers = new FieldTable(); + headers.setString(headerName, headerValue == null? null :String.valueOf(headerValue)); + ((BasicContentHeaderProperties)chb.getProperties()).setHeaders(headers); + } + _metaData = new MessageMetaData(info, chb, 0); + _content = ByteBuffer.allocate(_metaData.getContentSize()); + } + + public MessageMetaData getMetaData() + { + return _metaData; + } + + public long getMessageNumber() + { + return _messageId; + } + + public void addContent(int offsetInMessage, ByteBuffer src) + { + src = src.duplicate(); + ByteBuffer dst = _content.duplicate(); + dst.position(offsetInMessage); + dst.put(src); + } + + public int getContent(int offset, ByteBuffer dst) + { + ByteBuffer src = _content.duplicate(); + src.position(offset); + src = src.slice(); + if(dst.remaining() < src.limit()) + { + src.limit(dst.remaining()); + } + dst.put(src); + return src.limit(); + } + + + + public ByteBuffer getContent(int offsetInMessage, int size) + { + ByteBuffer buf = ByteBuffer.allocate(size); + getContent(offsetInMessage, buf); + buf.position(0); + return buf; + } + + public StoreFuture flushToStore() + { + return StoreFuture.IMMEDIATE_FUTURE; + } + + public void remove() + { + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java new file mode 100644 index 0000000000..87fbcfa9b3 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java @@ -0,0 +1,162 @@ +/* + * + * 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 org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.BasicContentHeaderProperties; +import org.apache.qpid.framing.ContentHeaderBody; +import org.apache.qpid.framing.abstraction.MessagePublishInfo; +import org.apache.qpid.server.message.MessageReference; +import org.apache.qpid.server.store.StoredMessage; +import org.apache.qpid.server.store.TestableMemoryMessageStore; +import org.apache.qpid.test.utils.QpidTestCase; + +/** + * Tests that reference counting works correctly with AMQMessage and the message store + */ +public class ReferenceCountingTest extends QpidTestCase +{ + private TestableMemoryMessageStore _store; + + + protected void setUp() throws Exception + { + _store = new TestableMemoryMessageStore(); + } + + /** + * Check that when the reference count is decremented the message removes itself from the store + */ + public void testMessageGetsRemoved() throws AMQException + { + ContentHeaderBody chb = createPersistentContentHeader(); + + MessagePublishInfo info = new MessagePublishInfo() + { + + public AMQShortString getExchange() + { + return null; + } + + public void setExchange(AMQShortString exchange) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isImmediate() + { + return false; + } + + public boolean isMandatory() + { + return false; + } + + public AMQShortString getRoutingKey() + { + return null; + } + }; + + + + MessageMetaData mmd = new MessageMetaData(info, chb, 0); + StoredMessage storedMessage = _store.addMessage(mmd); + + + AMQMessage message = new AMQMessage(storedMessage); + + MessageReference ref = message.newReference(); + + assertEquals(1, _store.getMessageCount()); + + ref.release(); + + assertEquals(0, _store.getMessageCount()); + } + + private ContentHeaderBody createPersistentContentHeader() + { + ContentHeaderBody chb = new ContentHeaderBody(); + BasicContentHeaderProperties bchp = new BasicContentHeaderProperties(); + bchp.setDeliveryMode((byte)2); + chb.setProperties(bchp); + return chb; + } + + public void testMessageRemains() throws AMQException + { + + MessagePublishInfo info = new MessagePublishInfo() + { + + public AMQShortString getExchange() + { + return null; + } + + public void setExchange(AMQShortString exchange) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isImmediate() + { + return false; + } + + public boolean isMandatory() + { + return false; + } + + public AMQShortString getRoutingKey() + { + return null; + } + }; + + final ContentHeaderBody chb = createPersistentContentHeader(); + + MessageMetaData mmd = new MessageMetaData(info, chb, 0); + StoredMessage storedMessage = _store.addMessage(mmd); + + AMQMessage message = new AMQMessage(storedMessage); + + + MessageReference ref = message.newReference(); + // we call routing complete to set up the handle + // message.routingComplete(_store, _storeContext, new MessageHandleFactory()); + + assertEquals(1, _store.getMessageCount()); + MessageReference ref2 = message.newReference(); + ref.release(); + assertEquals(1, _store.getMessageCount()); + } + + public static junit.framework.Test suite() + { + return new junit.framework.TestSuite(ReferenceCountingTest.class); + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/SubscriptionLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/SubscriptionLogSubjectTest.java deleted file mode 100644 index c44fdebc03..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/v0_8/SubscriptionLogSubjectTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * 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 org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject; -import org.apache.qpid.server.logging.subjects.SubscriptionLogSubject; -import org.apache.qpid.server.flow.LimitlessCreditManager; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.MockAMQQueue; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.util.BrokerTestHelper; -import org.apache.qpid.server.virtualhost.VirtualHost; - -/** - * Validate SubscriptionLogSubjects are logged as expected - */ -public class SubscriptionLogSubjectTest extends AbstractTestLogSubject -{ - - private AMQQueue _queue; - private VirtualHost _testVhost; - private int _channelID = 1; - private Subscription _subscription; - - @Override - public void setUp() throws Exception - { - super.setUp(); - - InternalTestProtocolSession session = BrokerTestHelper_0_8.createProtocolSession(); - _testVhost = session.getVirtualHost(); - - _queue = new MockAMQQueue("SubscriptionLogSubjectTest"); - ((MockAMQQueue) _queue).setVirtualHost(_testVhost); - - AMQChannel channel = new AMQChannel(session, _channelID, _testVhost.getMessageStore()); - - session.addChannel(channel); - - SubscriptionFactory factory = new SubscriptionFactoryImpl(); - - _subscription = factory.createSubscription(_channelID, session, new AMQShortString("cTag"), - false, null, false, - new LimitlessCreditManager()); - - _subscription.setQueue(_queue, false); - - _subject = new SubscriptionLogSubject(_subscription); - } - - @Override - public void tearDown() throws Exception - { - if (_testVhost != null) - { - _testVhost.close(); - } - super.tearDown(); - } - - /** - * Validate that the logged Subject message is as expected: - * MESSAGE [Blank][sub:0(vh(/test)/qu(SubscriptionLogSubjectTest))] - * - * @param message the message whos format needs validation - */ - @Override - protected void validateLogStatement(String message) - { - String subscriptionSlice = getSlice("sub:" - + _subscription.getSubscriptionID(), - message); - - assertNotNull("Unable to locate subscription 'sub:" + - _subscription.getSubscriptionID() + "'"); - - - - // Pull out the qu(..) section from the subscription message - // Split it into three parts - // MESSAGE [Blank][sub:0(vh(/ - // test)/ - // qu(SubscriptionLogSubjectTest))] - // Take the last bit and drop off the extra )] - String[] parts = message.split("/"); - assertEquals("Message part count wrong", 3, parts.length); - String subscription = parts[2].substring(0, parts[2].indexOf(")") + 1); - - // Adding the ')' is a bit ugly but SubscriptionLogSubject is the only - // Subject that nests () and so the simple parser of checking for the - // next ')' falls down. - verifyVirtualHost(subscriptionSlice+ ")", _queue.getVirtualHost()); - - verifyQueue(subscription, _queue); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java deleted file mode 100644 index 0e1c2d59de..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * 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.queue; - -import org.apache.qpid.server.protocol.v0_8.AMQMessage; - -public class MockAMQMessage extends AMQMessage -{ - public MockAMQMessage(long messageId) - { - super(new MockStoredMessage(messageId)); - } - - public MockAMQMessage(long messageId, String headerName, Object headerValue) - { - super(new MockStoredMessage(messageId, headerName, headerValue)); - } - - @Override - public long getSize() - { - return 0l; - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java index 358246330a..b677ece408 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java @@ -24,7 +24,6 @@ import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.logging.LogSubject; import org.apache.qpid.server.message.ServerMessage; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockMessagePublishInfo.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockMessagePublishInfo.java deleted file mode 100644 index bcf4c7efc6..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockMessagePublishInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * 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.queue; - -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.abstraction.MessagePublishInfo; - -public class MockMessagePublishInfo implements MessagePublishInfo -{ - public AMQShortString getExchange() - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - public void setExchange(AMQShortString exchange) - { - //To change body of implemented methods use File | Settings | File Templates. - } - - public boolean isImmediate() - { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - public boolean isMandatory() - { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - public AMQShortString getRoutingKey() - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java index c3485f6140..f5d4f1219d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java @@ -21,7 +21,6 @@ package org.apache.qpid.server.queue; import org.apache.qpid.AMQException; -import org.apache.qpid.server.protocol.v0_8.AMQMessage; import org.apache.qpid.server.message.AMQMessageHeader; import org.apache.qpid.server.message.ServerMessage; import org.apache.qpid.server.subscription.Subscription; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockStoredMessage.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockStoredMessage.java deleted file mode 100755 index 6d1ad22a39..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockStoredMessage.java +++ /dev/null @@ -1,116 +0,0 @@ -/* -* -* 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.queue; - -import org.apache.qpid.framing.BasicContentHeaderProperties; -import org.apache.qpid.framing.ContentHeaderBody; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.framing.abstraction.MessagePublishInfo; -import org.apache.qpid.server.protocol.v0_8.MessageMetaData; -import org.apache.qpid.server.store.StoreFuture; -import org.apache.qpid.server.store.StoredMessage; - -import java.nio.ByteBuffer; - -public class MockStoredMessage implements StoredMessage -{ - private long _messageId; - private MessageMetaData _metaData; - private final ByteBuffer _content; - - public MockStoredMessage(long messageId) - { - this(messageId, (String)null, null); - } - - public MockStoredMessage(long messageId, String headerName, Object headerValue) - { - this(messageId, new MockMessagePublishInfo(), new ContentHeaderBody(new BasicContentHeaderProperties(), 60), headerName, headerValue); - } - - public MockStoredMessage(long messageId, MessagePublishInfo info, ContentHeaderBody chb) - { - this(messageId, info, chb, null, null); - } - - public MockStoredMessage(long messageId, MessagePublishInfo info, ContentHeaderBody chb, String headerName, Object headerValue) - { - _messageId = messageId; - if (headerName != null) - { - FieldTable headers = new FieldTable(); - headers.setString(headerName, headerValue == null? null :String.valueOf(headerValue)); - ((BasicContentHeaderProperties)chb.getProperties()).setHeaders(headers); - } - _metaData = new MessageMetaData(info, chb, 0); - _content = ByteBuffer.allocate(_metaData.getContentSize()); - } - - public MessageMetaData getMetaData() - { - return _metaData; - } - - public long getMessageNumber() - { - return _messageId; - } - - public void addContent(int offsetInMessage, ByteBuffer src) - { - src = src.duplicate(); - ByteBuffer dst = _content.duplicate(); - dst.position(offsetInMessage); - dst.put(src); - } - - public int getContent(int offset, ByteBuffer dst) - { - ByteBuffer src = _content.duplicate(); - src.position(offset); - src = src.slice(); - if(dst.remaining() < src.limit()) - { - src.limit(dst.remaining()); - } - dst.put(src); - return src.limit(); - } - - - - public ByteBuffer getContent(int offsetInMessage, int size) - { - ByteBuffer buf = ByteBuffer.allocate(size); - getContent(offsetInMessage, buf); - buf.position(0); - return buf; - } - - public StoreFuture flushToStore() - { - return StoreFuture.IMMEDIATE_FUTURE; - } - - public void remove() - { - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryListTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryListTestBase.java index 25ab115748..beb5bda7ff 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryListTestBase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryListTestBase.java @@ -71,19 +71,12 @@ public abstract class QueueEntryListTestBase extends TestCase * Test to add a generic mock message. * @see QueueEntryListTestBase#getTestList() * @see QueueEntryListTestBase#getExpectedListLength() - * @see MockAMQMessage * @throws AMQException */ public void testAddGenericMessage() throws AMQException { final QueueEntryList list = getTestList(); - final ServerMessage message = mock(ServerMessage.class); - when(message.getMessageNumber()).thenReturn((long)666); - MessageReference ref = mock(MessageReference.class); - AMQMessageHeader hdr = mock(AMQMessageHeader.class); - when(ref.getMessage()).thenReturn(message); - when(message.newReference()).thenReturn(ref); - when(message.getMessageHeader()).thenReturn(hdr); + final ServerMessage message = createServerMessage(666l); list.add(message); final QueueEntryIterator iter = list.iterator(); @@ -97,6 +90,18 @@ public abstract class QueueEntryListTestBase extends TestCase } + private ServerMessage createServerMessage(long number) + { + final ServerMessage message = mock(ServerMessage.class); + when(message.getMessageNumber()).thenReturn(number); + MessageReference ref = mock(MessageReference.class); + AMQMessageHeader hdr = mock(AMQMessageHeader.class); + when(ref.getMessage()).thenReturn(message); + when(message.newReference()).thenReturn(ref); + when(message.getMessageHeader()).thenReturn(hdr); + return message; + } + /** * Test for getting the next element in a queue list. * @see QueueEntryListTestBase#getTestList() @@ -213,8 +218,8 @@ public abstract class QueueEntryListTestBase extends TestCase QueueEntryList list = getTestList(true); int i = 0; - QueueEntry queueEntry1 = list.add(new MockAMQMessage(i++)); - QueueEntry queueEntry2 = list.add(new MockAMQMessage(i++)); + QueueEntry queueEntry1 = list.add(createServerMessage(i++)); + QueueEntry queueEntry2 = list.add(createServerMessage(i++)); assertSame(queueEntry2, list.next(queueEntry1)); assertNull(list.next(queueEntry2)); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java index c6d166bc4c..62c731b2ec 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java @@ -48,7 +48,6 @@ import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.MockStoredMessage; import org.apache.qpid.server.store.MessageStoreRecoveryHandler.StoredMessageRecoveryHandler; import org.apache.qpid.server.store.Transaction.Record; import org.apache.qpid.test.utils.QpidTestCase; @@ -445,7 +444,9 @@ public abstract class AbstractDurableConfigurationStoreTestCase extends QpidTest EnqueableMessage message1 = mock(EnqueableMessage.class); when(message1.isPersistent()).thenReturn(true); when(message1.getMessageNumber()).thenReturn(messageNumber); - when(message1.getStoredMessage()).thenReturn(new MockStoredMessage(messageNumber)); + final StoredMessage storedMessage = mock(StoredMessage.class); + when(storedMessage.getMessageNumber()).thenReturn(messageNumber); + when(message1.getStoredMessage()).thenReturn(storedMessage); Record enqueueRecord = new TestRecord(queue1, message1); return enqueueRecord; } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java index facc231bca..4a246b018b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java @@ -27,15 +27,8 @@ import java.util.List; import java.util.UUID; import org.apache.log4j.Logger; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.BasicContentHeaderProperties; -import org.apache.qpid.framing.ContentHeaderBody; -import org.apache.qpid.framing.MethodRegistry; -import org.apache.qpid.framing.ProtocolVersion; -import org.apache.qpid.framing.abstraction.MessagePublishInfo; -import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl; import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.protocol.v0_8.MessageMetaData; +import org.apache.qpid.server.plugin.MessageMetaDataType; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.test.utils.QpidTestCase; import org.apache.qpid.util.FileUtils; @@ -115,23 +108,25 @@ public abstract class MessageStoreQuotaEventsTestBase extends QpidTestCase imple protected EnqueableMessage addMessage(long id) { - MessagePublishInfo pubInfoBody = new MessagePublishInfoImpl(new AMQShortString(getName()), false, false, - new AMQShortString(getName())); - BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - props.setDeliveryMode(Integer.valueOf(BasicContentHeaderProperties.PERSISTENT).byteValue()); - props.setContentType(getTestName()); - - MethodRegistry methodRegistry = MethodRegistry.getMethodRegistry(ProtocolVersion.v0_9); - int classForBasic = methodRegistry.createBasicQosOkBody().getClazz(); - ContentHeaderBody contentHeaderBody = new ContentHeaderBody(classForBasic, 1, props, MESSAGE_DATA.length); - - MessageMetaData metaData = new MessageMetaData(pubInfoBody, contentHeaderBody, 1); - StoredMessage handle = _store.addMessage(metaData); + StorableMessageMetaData metaData = createMetaData(id, MESSAGE_DATA.length); + StoredMessage handle = _store.addMessage(metaData); handle.addContent(0, ByteBuffer.wrap(MESSAGE_DATA)); TestMessage message = new TestMessage(id, handle); return message; } + private StorableMessageMetaData createMetaData(long id, int length) + { + StorableMessageMetaData metaData = mock(StorableMessageMetaData.class); + when(metaData.isPersistent()).thenReturn(true); + when(metaData.getContentSize()).thenReturn(length); + when(metaData.getStorableSize()).thenReturn(0); + MessageMetaDataType type = mock(MessageMetaDataType.class); + when(type.ordinal()).thenReturn(-1); + when(metaData.getType()).thenReturn(type); + return metaData; + } + @Override public void event(Event event) { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java deleted file mode 100644 index d50df47998..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * - * 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.store; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.BasicContentHeaderProperties; -import org.apache.qpid.framing.ContentHeaderBody; -import org.apache.qpid.framing.abstraction.MessagePublishInfo; -import org.apache.qpid.server.protocol.v0_8.AMQMessage; -import org.apache.qpid.server.protocol.v0_8.MessageMetaData; -import org.apache.qpid.server.message.MessageReference; -import org.apache.qpid.test.utils.QpidTestCase; - -/** - * Tests that reference counting works correctly with AMQMessage and the message store - */ -public class ReferenceCountingTest extends QpidTestCase -{ - private TestableMemoryMessageStore _store; - - - protected void setUp() throws Exception - { - _store = new TestableMemoryMessageStore(); - } - - /** - * Check that when the reference count is decremented the message removes itself from the store - */ - public void testMessageGetsRemoved() throws AMQException - { - ContentHeaderBody chb = createPersistentContentHeader(); - - MessagePublishInfo info = new MessagePublishInfo() - { - - public AMQShortString getExchange() - { - return null; - } - - public void setExchange(AMQShortString exchange) - { - //To change body of implemented methods use File | Settings | File Templates. - } - - public boolean isImmediate() - { - return false; - } - - public boolean isMandatory() - { - return false; - } - - public AMQShortString getRoutingKey() - { - return null; - } - }; - - - - MessageMetaData mmd = new MessageMetaData(info, chb, 0); - StoredMessage storedMessage = _store.addMessage(mmd); - - - AMQMessage message = new AMQMessage(storedMessage); - - MessageReference ref = message.newReference(); - - assertEquals(1, _store.getMessageCount()); - - ref.release(); - - assertEquals(0, _store.getMessageCount()); - } - - private ContentHeaderBody createPersistentContentHeader() - { - ContentHeaderBody chb = new ContentHeaderBody(); - BasicContentHeaderProperties bchp = new BasicContentHeaderProperties(); - bchp.setDeliveryMode((byte)2); - chb.setProperties(bchp); - return chb; - } - - public void testMessageRemains() throws AMQException - { - - MessagePublishInfo info = new MessagePublishInfo() - { - - public AMQShortString getExchange() - { - return null; - } - - public void setExchange(AMQShortString exchange) - { - //To change body of implemented methods use File | Settings | File Templates. - } - - public boolean isImmediate() - { - return false; - } - - public boolean isMandatory() - { - return false; - } - - public AMQShortString getRoutingKey() - { - return null; - } - }; - - final ContentHeaderBody chb = createPersistentContentHeader(); - - MessageMetaData mmd = new MessageMetaData(info, chb, 0); - StoredMessage storedMessage = _store.addMessage(mmd); - - AMQMessage message = new AMQMessage(storedMessage); - - - MessageReference ref = message.newReference(); - // we call routing complete to set up the handle - // message.routingComplete(_store, _storeContext, new MessageHandleFactory()); - - assertEquals(1, _store.getMessageCount()); - MessageReference ref2 = message.newReference(); - ref.release(); - assertEquals(1, _store.getMessageCount()); - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(ReferenceCountingTest.class); - } -} -- cgit v1.2.1