AMQ-2439: Unit test for the kahadb message store

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@821103 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2009-10-02 17:14:25 +00:00
parent bdd9e2a8cd
commit 1d5bcaf274
2 changed files with 132 additions and 0 deletions

View File

@ -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 <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
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());
}
}

View File

@ -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 <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
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;
}
}