You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/10/02 19:14:26 UTC

svn commit: r821103 - in /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store: PersistenceAdapterTestSupport.java kahadb/KahaDBPersistenceAdapterTest.java

Author: chirino
Date: Fri Oct  2 17:14:25 2009
New Revision: 821103

URL: http://svn.apache.org/viewvc?rev=821103&view=rev
Log:
AMQ-2439: Unit test for the kahadb message store

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java?rev=821103&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/PersistenceAdapterTestSupport.java Fri Oct  2 17:14:25 2009
@@ -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());
+
+    }
+
+}

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java?rev=821103&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapterTest.java Fri Oct  2 17:14:25 2009
@@ -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;
+    }
+}