diff --git a/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java new file mode 100644 index 0000000000..25d7dd94f1 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java @@ -0,0 +1,93 @@ +/** + * 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.activemq.store; + +import java.util.concurrent.atomic.AtomicInteger; + +import junit.framework.TestCase; + +import org.apache.activemq.broker.ConnectionContext; +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTextMessage; +import org.apache.activemq.command.Message; +import org.apache.activemq.command.MessageId; + +/** + * + * @author Hiram Chirino + */ +abstract public class PersistenceAdapterTestSupport extends TestCase { + + private PersistenceAdapter pa; + + abstract protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws Exception; + + @Override + protected void setUp() throws Exception { + pa = createPersistenceAdapter(true); + pa.start(); + } + + @Override + protected void tearDown() throws Exception { + if( pa!=null ) { + pa.stop(); + pa=null; + } + } + + public void testStoreCanHandleDupMessages() throws Exception { + + + MessageStore ms = pa.createQueueMessageStore(new ActiveMQQueue("TEST")); + + ActiveMQTextMessage message = new ActiveMQTextMessage(); + message.setText("test"); + message.setMessageId(new MessageId("ID:localhost-56913-1254499826208-0:0:1:1:1")); + ConnectionContext context = new ConnectionContext(); + + ms.addMessage(context, message); + + // here comes the dup... + ms.addMessage(context, message); + + final AtomicInteger recovered = new AtomicInteger(); + ms.recover(new MessageRecoveryListener() { + public boolean hasSpace() { + return true; + } + + public boolean isDuplicate(MessageId ref) { + return false; + } + + public boolean recoverMessage(Message message) throws Exception { + recovered.incrementAndGet(); + return true; + } + + public boolean recoverMessageReference(MessageId ref) throws Exception { + recovered.incrementAndGet(); + return true; + } + }); + + assertEquals(1, recovered.get()); + + } + +} diff --git a/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java b/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java new file mode 100644 index 0000000000..c45c3e5a42 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java @@ -0,0 +1,39 @@ +/** + * 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.activemq.store.kahadb; + +import java.io.File; +import java.io.IOException; + +import org.apache.activemq.store.PersistenceAdapter; +import org.apache.activemq.store.PersistenceAdapterTestSupport; + +/** + * + * @author Hiram Chirino + */ +public class KahaDBPersistenceAdapterTest extends PersistenceAdapterTestSupport { + + protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws IOException { + KahaDBStore kaha = new KahaDBStore(); + kaha.setDirectory(new File("target/activemq-data/kahadb")); + if (delete) { + kaha.deleteAllMessages(); + } + return kaha; + } +}