diff options
Diffstat (limited to 'qpid/java')
5 files changed, 296 insertions, 11 deletions
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java index b23890b10c..6b6d62378e 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java @@ -28,7 +28,6 @@ import java.util.UUID; import org.apache.log4j.Logger; import org.apache.qpid.server.message.EnqueableMessage; -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; @@ -72,7 +71,7 @@ public abstract class MessageStoreQuotaEventsTestBase extends QpidTestCase imple _store = createStore(); ((DurableConfigurationStore)_store).configureConfigStore(vhost, null); - _store.configureMessageStore(vhost, null, null); + _store.configureMessageStore(vhost, mock(MessageStoreRecoveryHandler.class), null); _transactionResource = UUID.randomUUID(); _events = new ArrayList<Event>(); @@ -122,7 +121,7 @@ public abstract class MessageStoreQuotaEventsTestBase extends QpidTestCase imple protected EnqueableMessage addMessage(long id) { StorableMessageMetaData metaData = createMetaData(id, MESSAGE_DATA.length); - StoredMessage handle = _store.addMessage(metaData); + StoredMessage<?> handle = _store.addMessage(metaData); handle.addContent(0, ByteBuffer.wrap(MESSAGE_DATA)); TestMessage message = new TestMessage(id, handle); return message; @@ -130,14 +129,7 @@ public abstract class MessageStoreQuotaEventsTestBase extends QpidTestCase imple 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; + return new TestMessageMetaData(id, length); } @Override diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaData.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaData.java new file mode 100644 index 0000000000..d99adb91fe --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaData.java @@ -0,0 +1,72 @@ +package org.apache.qpid.server.store; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.apache.qpid.framing.EncodingUtils; +import org.apache.qpid.server.plugin.MessageMetaDataType; +import org.apache.qpid.server.store.StorableMessageMetaData; +import org.apache.qpid.server.util.ByteBufferOutputStream; + +public class TestMessageMetaData implements StorableMessageMetaData +{ + public static final MessageMetaDataType.Factory<TestMessageMetaData> FACTORY = new TestMessageMetaDataFactory(); + + private static final TestMessageMetaDataType TYPE = new TestMessageMetaDataType(); + + private int _contentSize; + private long _messageId; + + public TestMessageMetaData(long messageId, int contentSize) + { + _contentSize = contentSize; + _messageId = messageId; + } + + @Override + public int getContentSize() + { + return _contentSize; + } + + @Override + public int getStorableSize() + { + int storeableSize = 8 + //message id, long, 8bytes/64bits + 4; //content size, int, 4bytes/32bits + + return storeableSize; + } + + @Override + public MessageMetaDataType getType() + { + return TYPE; + } + + @Override + public boolean isPersistent() + { + return true; + } + + @Override + public int writeToBuffer(int offsetInMetaData, ByteBuffer dest) + { + int oldPosition = dest.position(); + try + { + DataOutputStream dataOutputStream = new DataOutputStream(new ByteBufferOutputStream(dest)); + EncodingUtils.writeLong(dataOutputStream, _messageId); + EncodingUtils.writeInteger(dataOutputStream, _contentSize); + } + catch (IOException e) + { + // This shouldn't happen as we are not actually using anything that can throw an IO Exception + throw new RuntimeException(e); + } + + return dest.position() - oldPosition; + }; +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaDataFactory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaDataFactory.java new file mode 100644 index 0000000000..8acdd25e97 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaDataFactory.java @@ -0,0 +1,51 @@ +/* + * + * 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 java.io.DataInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.apache.qpid.framing.EncodingUtils; +import org.apache.qpid.server.plugin.MessageMetaDataType; +import org.apache.qpid.util.ByteBufferInputStream; + +public class TestMessageMetaDataFactory implements MessageMetaDataType.Factory<TestMessageMetaData> +{ + public TestMessageMetaData createMetaData(ByteBuffer buf) + { + try + { + ByteBufferInputStream bbis = new ByteBufferInputStream(buf); + DataInputStream dais = new DataInputStream(bbis); + + long id = EncodingUtils.readLong(dais); + int size = EncodingUtils.readInteger(dais); + + return new TestMessageMetaData(id, size); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + + } +}
\ No newline at end of file diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaDataType.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaDataType.java new file mode 100644 index 0000000000..25f1df7a20 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMessageMetaDataType.java @@ -0,0 +1,151 @@ +/* + * + * 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 java.nio.ByteBuffer; + +import org.apache.qpid.server.message.AMQMessageHeader; +import org.apache.qpid.server.message.MessageReference; +import org.apache.qpid.server.message.ServerMessage; +import org.apache.qpid.server.plugin.MessageMetaDataType; +import org.apache.qpid.server.protocol.AmqpProtocolVersion; + +public class TestMessageMetaDataType implements MessageMetaDataType<TestMessageMetaData> +{ + //largest metadata type value the BDBMessageStore can store (it uses a byte) + private static final byte TYPE = 7; + + @Override + public int ordinal() + { + return TYPE; + } + + @Override + public TestMessageMetaData createMetaData(ByteBuffer buf) + { + return TestMessageMetaData.FACTORY.createMetaData(buf); + } + + @Override + public ServerMessage<TestMessageMetaData> createMessage(StoredMessage<TestMessageMetaData> msg) + { + return new TestServerMessage(msg); + } + + public int hashCode() + { + return ordinal(); + } + + public boolean equals(Object o) + { + return o != null && o.getClass() == getClass(); + } + + @Override + public String getType() + { + return AmqpProtocolVersion.v0_8.toString(); + } + + + private static class TestServerMessage implements ServerMessage<TestMessageMetaData> + { + private StoredMessage<TestMessageMetaData> _storedMsg; + + public TestServerMessage(StoredMessage<TestMessageMetaData> storedMsg) + { + _storedMsg = storedMsg; + } + @Override + public long getArrivalTime() + { + return 0; + } + + @Override + public int getContent(ByteBuffer buf, int offset) + { + return 0; + } + + @Override + public ByteBuffer getContent(int offset, int size) + { + return null; + } + + @Override + public long getExpiration() + { + return 0; + } + + @Override + public AMQMessageHeader getMessageHeader() + { + return null; + } + + @Override + public long getMessageNumber() + { + return 0; + } + + @Override + public String getRoutingKey() + { + return null; + } + + @Override + public long getSize() + { + return 0; + } + + @Override + public StoredMessage<TestMessageMetaData> getStoredMessage() + { + return _storedMsg; + } + + @Override + public boolean isImmediate() + { + return false; + } + + @Override + public boolean isPersistent() + { + return false; + } + + @Override + public MessageReference newReference() + { + return null; + } + } +} diff --git a/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.MessageMetaDataType b/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.MessageMetaDataType new file mode 100644 index 0000000000..5edf3448f9 --- /dev/null +++ b/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.MessageMetaDataType @@ -0,0 +1,19 @@ +# +# 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. +# +org.apache.qpid.server.store.TestMessageMetaDataType |
