You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/11/15 01:36:56 UTC

svn commit: r1409621 [1/2] - in /activemq/trunk: activemq-amq-store/src/test/java/org/apache/activemq/kaha/ activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/ activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/ activemq-a...

Author: tabish
Date: Thu Nov 15 00:36:53 2012
New Revision: 1409621

URL: http://svn.apache.org/viewvc?rev=1409621&view=rev
Log:
move the Kaha store tests into the activemq-amq-store module 

Added:
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/ListContainerTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/LoadTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/Loader.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/MapContainerTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/StoreTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/VolumeTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/DataFileAppenderTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/LocationTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/NioDataFileAppenderTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedListTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedListTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/hash/
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashIndexBenchMark.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashTest.java   (with props)
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/tree/
    activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java   (with props)
Removed:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/ListContainerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/ListContainerTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/ListContainerTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/ListContainerTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,326 @@
+/**
+ * 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.kaha;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import junit.framework.TestCase;
+
+public class ListContainerTest extends TestCase {
+    
+    protected static final int COUNT = 10;
+
+    protected String name = "test";
+    protected Store store;
+    protected ListContainer<Object> container;
+    protected LinkedList<Object> testList;
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.ListContainer.size()'
+     */
+    public void testSize() throws Exception {
+        container.addAll(testList);
+        assertEquals(container.size(), testList.size());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.ListContainer.addFirst(Object)'
+     */
+    public void testAddFirst() throws Exception {
+        container.addAll(testList);
+        assertEquals(container.size(), testList.size());
+        String first = "first";
+        container.addFirst(first);
+        assertEquals(first, container.get(0));
+        assertEquals(container.size(), testList.size() + 1);
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.ListContainer.addLast(Object)'
+     */
+    public void testAddLast() throws Exception {
+        container.addAll(testList);
+        assertEquals(container.size(), testList.size());
+        String last = "last";
+        container.addLast(last);
+        assertEquals(last, container.get(testList.size()));
+        assertEquals(container.size(), testList.size() + 1);
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.ListContainer.removeFirst()'
+     */
+    public void testRemoveFirst() throws Exception {
+        container.addAll(testList);
+        assertEquals(container.size(), testList.size());
+        assertEquals(testList.get(0), container.removeFirst());
+        assertEquals(container.size(), testList.size() - 1);
+        for (int i = 1; i < testList.size(); i++) {
+            assertEquals(testList.get(i), container.get(i - 1));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.ListContainer.removeLast()'
+     */
+    public void testRemoveLast() throws Exception {
+        container.addAll(testList);
+        assertEquals(container.size(), testList.size());
+        assertEquals(testList.get(testList.size() - 1), container.removeLast());
+        assertEquals(container.size(), testList.size() - 1);
+        for (int i = 0; i < testList.size() - 1; i++) {
+            assertEquals(testList.get(i), container.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'java.util.List.iterator()'
+     */
+    public void testIterator() throws Exception {
+        container.addAll(testList);
+        Iterator<Object> j = container.iterator();
+        for (Iterator<Object> i = testList.iterator(); i.hasNext();) {
+            assertEquals(i.next(), j.next());
+        }
+        for (Iterator<Object> i = container.iterator(); i.hasNext();) {
+            i.next();
+            i.remove();
+        }
+        assert container.isEmpty();
+    }
+
+    /*
+     * Test method for 'java.util.List.isEmpty()'
+     */
+    public void testIsEmpty() throws Exception {
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'java.util.List.contains(Object)'
+     */
+    public void testContains() throws Exception {
+        container.addAll(testList);
+        for (Iterator<Object> i = testList.iterator(); i.hasNext();) {
+            assertTrue(container.contains(i.next()));
+        }
+    }
+
+    /*
+     * Test method for 'java.util.List.toArray()'
+     */
+    public void testToArray() throws Exception {
+        container.addAll(testList);
+        Object[] a = testList.toArray();
+        Object[] b = container.toArray();
+        assertEquals(a.length, b.length);
+        for (int i = 0; i < a.length; i++) {
+            assertEquals(a[i], b[i]);
+        }
+    }
+
+    /*
+     * Test method for 'java.util.List.remove(Object)'
+     */
+    public void testRemoveObject() throws Exception {
+        container.addAll(testList);
+        assertEquals(container.size(), testList.size());
+        for (int i = 0; i < testList.size(); i++) {
+            container.remove(testList.get(i));
+        }
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'java.util.List.containsAll(Collection<?>)'
+     */
+    public void testContainsAll() throws Exception {
+        container.addAll(testList);
+        assertTrue(container.containsAll(testList));
+    }
+
+    /*
+     * Test method for 'java.util.List.removeAll(Collection<?>)'
+     */
+    public void testRemoveAll() throws Exception {
+        container.addAll(testList);
+        assertEquals(testList.size(), container.size());
+        container.removeAll(testList);
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'java.util.List.retainAll(Collection<?>)'
+     */
+    public void testRetainAll() throws Exception {
+        container.addAll(testList);
+        assertEquals(testList.size(), container.size());
+        testList.remove(0);
+        container.retainAll(testList);
+        assertEquals(testList.size(), container.size());
+    }
+
+    /*
+     * Test method for 'java.util.List.clear()'
+     */
+    public void testClear() throws Exception {
+        container.addAll(testList);
+        assertEquals(testList.size(), container.size());
+        container.clear();
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'java.util.List.get(int)'
+     */
+    public void testGet() throws Exception {
+        container.addAll(testList);
+        for (int i = 0; i < testList.size(); i++) {
+            assertEquals(container.get(i), testList.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'java.util.List.set(int, E)'
+     */
+    public void testSet() throws Exception {
+        container.addAll(testList);
+    }
+
+    /*
+     * Test method for 'java.util.List.add(int, E)'
+     */
+    public void testAddIntE() throws Exception {
+        container.addAll(testList);
+        assertTrue(container.equals(testList));
+        Object testObj = "testObj";
+        int index = 0;
+        testList.set(index, testObj);
+        container.set(index, testObj);
+        assertTrue(container.equals(testList));
+        index = testList.size() - 1;
+        testList.set(index, testObj);
+        container.set(index, testObj);
+        assertTrue(container.equals(testList));
+    }
+
+    /*
+     * Test method for 'java.util.List.remove(int)'
+     */
+    public void testRemoveInt() throws Exception {
+        container.addAll(testList);
+        assertTrue(container.equals(testList));
+        testList.remove(0);
+        container.remove(0);
+        assertTrue(container.equals(testList));
+        int pos = testList.size() - 1;
+        testList.remove(pos);
+        container.remove(pos);
+        assertTrue(container.equals(testList));
+    }
+
+    /*
+     * Test method for 'java.util.List.indexOf(Object)'
+     */
+    public void testIndexOf() throws Exception {
+        container.addAll(testList);
+        assertTrue(container.equals(testList));
+        for (int i = 0; i < testList.size(); i++) {
+            Object o = testList.get(i);
+            assertEquals(i, container.indexOf(o));
+        }
+    }
+
+    /*
+     * Test method for 'java.util.List.listIterator()'
+     */
+    public void testListIterator() throws Exception {
+        container.addAll(testList);
+        ListIterator<Object> containerIter = container.listIterator();
+        ListIterator<Object> testIter = testList.listIterator();
+        assertTrue(testIter.hasNext());
+        assertTrue(containerIter.hasNext());
+        while (testIter.hasNext()) {
+            Object o1 = testIter.next();
+            Object o2 = containerIter.next();
+            assertEquals(o1, o2);
+            testIter.remove();
+            containerIter.remove();
+        }
+        assertTrue(testList.isEmpty());
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'java.util.List.listIterator(int)'
+     */
+    public void testListIteratorInt() throws Exception {
+        container.addAll(testList);
+        int start = testList.size() / 2;
+        ListIterator<Object> containerIter = container.listIterator(start);
+        ListIterator<Object> testIter = testList.listIterator(start);
+        assertTrue(testIter.hasNext());
+        assertTrue(containerIter.hasNext());
+        while (testIter.hasNext()) {
+            Object o1 = testIter.next();
+            Object o2 = containerIter.next();
+            assertEquals(o1, o2);
+        }
+    }
+
+    /*
+     * Test method for 'java.util.List.subList(int, int)'
+     */
+    public void testSubList() throws Exception {
+        container.addAll(testList);
+        int start = testList.size() / 2;
+        List<Object> l1 = testList.subList(start, testList.size());
+        List<Object> l2 = container.subList(start, testList.size());
+        assertEquals(l1.size(), l2.size());
+        assertEquals(l1, l2);
+    }
+
+    protected Store getStore() throws IOException {
+        return StoreFactory.open(name, "rw");
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        name = System.getProperty("basedir", ".") + "/target/activemq-data/list-container.db";
+        StoreFactory.delete(name);
+        store = getStore();
+        store.deleteListContainer(name);
+        container = store.getListContainer(name);
+        container.load();
+        testList = new LinkedList<Object>();
+        for (int i = 0; i < COUNT; i++) {
+            String value = "value:" + i;
+            testList.add(value);
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (store != null) {
+            store.close();
+        }
+        assertTrue(StoreFactory.delete(name));
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/ListContainerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/LoadTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/LoadTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/LoadTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/LoadTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,66 @@
+/**
+ * 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.kaha;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+
+import junit.framework.TestCase;
+import org.apache.activemq.kaha.impl.KahaStore;
+
+/**
+ * Store test
+ * 
+ * 
+ */
+public class LoadTest extends TestCase {
+    static final int COUNT = 10000;
+    static final int NUM_LOADERS = 5;
+    protected String name = "load.db";
+    protected KahaStore store;
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.Store.close()'
+     */
+    public void testLoad() throws Exception {
+        CountDownLatch start = new CountDownLatch(NUM_LOADERS);
+        CountDownLatch stop = new CountDownLatch(NUM_LOADERS);
+        for (int i = 0; i < NUM_LOADERS; i++) {
+            Loader loader = new Loader("loader:" + i, store, COUNT, start, stop);
+            loader.start();
+        }
+        stop.await();
+    }
+
+    protected KahaStore getStore() throws IOException {
+        return (KahaStore)StoreFactory.open(name, "rw");
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        name = System.getProperty("basedir", ".") + "/target/activemq-data/load.db";
+        StoreFactory.delete(name);
+        store = getStore();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        store.clear();
+        store.close();
+        assertTrue(StoreFactory.delete(name));
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/LoadTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/Loader.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/Loader.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/Loader.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/Loader.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,116 @@
+/**
+ * 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.kaha;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Store test
+ * 
+ * 
+ */
+class Loader extends Thread {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Loader.class);
+
+    private String name;
+    private Store store;
+    private int count;
+    private CountDownLatch start;
+    private CountDownLatch stop;
+
+    public Loader(String name, Store store, int count, CountDownLatch start, CountDownLatch stop) {
+        this.name = name;
+        this.store = store;
+        this.count = count;
+        this.start = start;
+        this.stop = stop;
+    }
+
+    public void run() {
+        try {
+            start.countDown();
+            start.await();
+            Marshaller<String> keyMarshaller = new StringMarshaller();
+            Marshaller<Object> valueMarshaller = new BytesMarshaller();
+            MapContainer<String, Object> container = store.getMapContainer(name, store.getDefaultContainerName(), true);
+
+            container.setKeyMarshaller(keyMarshaller);
+            container.setValueMarshaller(valueMarshaller);
+            container.load();
+            // set data
+            Object value = getData(1024);
+            long startTime = System.currentTimeMillis();
+            long startLoad = System.currentTimeMillis();
+            for (int i = 0; i < count; i++) {
+                String key = "key:" + i;
+                container.put(key, value);
+            }
+            long finishLoad = System.currentTimeMillis();
+            long totalLoadTime = finishLoad - startLoad;
+            LOG.info("name " + name + " load time = " + totalLoadTime + "(ms)");
+
+            Set<String> keys = container.keySet();
+            long startExtract = System.currentTimeMillis();
+
+            for (Iterator<String> i = keys.iterator(); i.hasNext();) {
+                byte[] data = (byte[])container.get(i.next());
+            }
+            long finishExtract = System.currentTimeMillis();
+            long totalExtractTime = finishExtract - startExtract;
+            LOG.info("name " + name + " extract time = " + totalExtractTime + "(ms)");
+
+            long startRemove = System.currentTimeMillis();
+            for (Iterator<String> i = keys.iterator(); i.hasNext();) {
+                container.remove(i.next());
+            }
+            long finishRemove = System.currentTimeMillis();
+            long totalRemoveTime = finishRemove - startRemove;
+            LOG.info("name " + name + " remove time = " + totalRemoveTime + "(ms)");
+            // re-insert data of longer length
+            startLoad = System.currentTimeMillis();
+            value = getData(2048);
+            for (int i = 0; i < count; i++) {
+                // System.out.println(this + " Container size = " +
+                // container.size());
+                String key = "key:" + i;
+                container.put(key, value);
+            }
+            finishLoad = System.currentTimeMillis();
+            totalLoadTime = finishLoad - startLoad;
+            LOG.info("name " + name + " 2nd load time = " + totalLoadTime + "(ms)");
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            stop.countDown();
+        }
+    }
+
+    byte[] getData(int size) {
+        byte[] result = new byte[size];
+        for (int i = 0; i < size; i++) {
+            result[i] = 'a';
+        }
+        return result;
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/Loader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/MapContainerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/MapContainerTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/MapContainerTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/MapContainerTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,280 @@
+/**
+ * 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.kaha;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.activemq.kaha.impl.container.BaseContainerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.TestCase;
+
+public class MapContainerTest extends TestCase {
+    private static final Logger LOG = LoggerFactory.getLogger(MapContainerTest.class);
+    protected static final int COUNT = 10;
+
+    protected String name = "test";
+    protected Store store;
+    protected MapContainer<String, String> container;
+    protected Map<String, String> testMap;
+
+    public void testBasicAllocations() throws Exception {
+        String key = "key";
+        Object value = testMap;
+        MapContainer<String, Object> test = store.getMapContainer("test", "test");
+        test.put(key, value);
+        store.close();
+        store = getStore();
+        assertFalse(store.getMapContainerIds().isEmpty());
+        test = store.getMapContainer("test", "test");
+        assertEquals(value, test.get(key));
+
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.size()'
+     */
+    public void testSize() throws Exception {
+        container.putAll(testMap);
+        assertTrue(container.size() == testMap.size());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.isEmpty()'
+     */
+    public void testIsEmpty() throws Exception {
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.clear()'
+     */
+    public void testClear() throws Exception {
+        container.putAll(testMap);
+        assertTrue(container.size() == testMap.size());
+        container.clear();
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.activemq.kaha.MapContainer.containsKey(Object)'
+     */
+    public void testContainsKeyObject() throws Exception {
+        container.putAll(testMap);
+        for (Iterator i = testMap.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Entry)i.next();
+            assertTrue(container.containsKey(entry.getKey()));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.get(Object)'
+     */
+    public void testGetObject() throws Exception {
+        container.putAll(testMap);
+        for (Iterator i = testMap.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Entry)i.next();
+            Object value = container.get(entry.getKey());
+            assertNotNull(value);
+            assertTrue(value.equals(entry.getValue()));
+        }
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.activemq.kaha.MapContainer.containsValue(Object)'
+     */
+    public void testContainsValueObject() throws Exception {
+        container.putAll(testMap);
+        for (Iterator i = testMap.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Entry)i.next();
+            assertTrue(container.containsValue(entry.getValue()));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.putAll(Map)'
+     */
+    public void testPutAllMap() throws Exception {
+        container.putAll(testMap);
+        for (Iterator i = testMap.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Entry)i.next();
+            assertTrue(container.containsValue(entry.getValue()));
+            assertTrue(container.containsKey(entry.getKey()));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.keySet()'
+     */
+    public void testKeySet() throws Exception {
+        container.putAll(testMap);
+        Set<String> keys = container.keySet();
+        assertTrue(keys.size() == testMap.size());
+        for (Iterator<String> i = testMap.keySet().iterator(); i.hasNext();) {
+            Object key = i.next();
+            assertTrue(keys.contains(key));
+            keys.remove(key);
+        }
+        assertTrue(container.isEmpty());
+
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.values()'
+     */
+    public void testValues() throws Exception {
+        container.putAll(testMap);
+        Collection<String> values = container.values();
+        assertTrue(values.size() == testMap.size());
+        for (Iterator<String> i = testMap.values().iterator(); i.hasNext();) {
+            Object value = i.next();
+            assertTrue(values.contains(value));
+            assertTrue(values.remove(value));
+        }
+        assertTrue(container.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.entrySet()'
+     */
+    public void testEntrySet() throws Exception {
+        container.putAll(testMap);
+        Set entries = container.entrySet();
+        assertTrue(entries.size() == testMap.size());
+        for (Iterator i = entries.iterator(); i.hasNext();) {
+            Map.Entry entry = (Entry)i.next();
+            assertTrue(testMap.containsKey(entry.getKey()));
+            assertTrue(testMap.containsValue(entry.getValue()));
+
+        }
+
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.MapContainer.remove(Object)'
+     */
+    public void testRemoveObject() throws Exception {
+        container.putAll(testMap);
+        for (Iterator<String> i = testMap.keySet().iterator(); i.hasNext();) {
+            container.remove(i.next());
+        }
+        assertTrue(container.isEmpty());
+    }
+
+    
+    public void testDuplicatesOk() throws Exception {
+        StoreEntry first, entry; 
+        
+        container.put("M1", "DD");
+        first = container.getFirst();
+        LOG.info("First=" + first);
+        assertEquals(-1, first.getNextItem());
+        
+        // add duplicate
+        String old = container.put("M1", "DD");
+        assertNotNull(old);
+        assertEquals(1, container.size());
+        
+        entry = container.getFirst();
+        LOG.info("New First=" + entry);
+        assertEquals(-1, entry.getNextItem());
+
+        assertEquals(first, entry);
+        
+        container.remove("M1");
+        
+        entry = container.getFirst();
+        assertNull(entry);
+    }
+
+    
+    public void testDuplicatesFreeListShared() throws Exception {
+        StoreEntry batchEntry; 
+        
+        MapContainer other = store.getMapContainer(getName()+"2", "test", true);
+        other.load();
+        other.put("M1", "DD");
+             
+        container.put("M1", "DD");
+        batchEntry = container.getFirst();
+        LOG.info("First=" + batchEntry);
+        assertEquals(-1, batchEntry.getNextItem());
+        
+        // have something on free list before duplicate
+        other.remove("M1");
+        
+        // add duplicate
+        String old = container.put("M1", "DD");
+        assertNotNull(old);
+        assertEquals(1, container.size());
+
+        // entry now on free list on its own
+        batchEntry = container.refresh(batchEntry);
+        assertEquals(-1, batchEntry.getNextItem());
+        LOG.info("refreshed=" + batchEntry);
+        
+        // ack
+        container.remove("M1");   
+        
+        //container is valid  (empty)
+        assertNull(container.getFirst());
+
+        // batchEntry now has next as there is another on the free list
+        batchEntry = container.refresh(batchEntry);
+        LOG.info("refreshed=" + batchEntry);
+        
+        assertTrue(batchEntry.getNextItem() != -1);        
+    }
+
+    protected Store getStore() throws IOException {
+        return StoreFactory.open(name, "rw");
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        name = System.getProperty("basedir", ".") + "/target/activemq-data/map-container.db";
+        store = getStore();
+        container = store.getMapContainer(getName(), "test", true);
+        container.load();
+        testMap = new HashMap<String, String>();
+        for (int i = 0; i < COUNT; i++) {
+            String key = "key:" + i;
+            String value = "value:" + i;
+            testMap.put(key, value);
+        }
+
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (store != null) {
+            store.close();
+            store = null;
+        }
+        assertTrue(StoreFactory.delete(name));
+    }
+
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/MapContainerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/StoreTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/StoreTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/StoreTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/StoreTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,212 @@
+/**
+ * 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.kaha;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import org.apache.activemq.kaha.impl.StoreLockedExcpetion;
+
+/**
+ * Store test
+ * 
+ * 
+ */
+public class StoreTest extends TestCase {
+
+    protected String name;
+    protected Store store;
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.Store.close()'
+     */
+    public void testClose() throws Exception {
+        store.close();
+        try {
+            // access should throw an exception
+            store.getListContainer("fred");
+            assertTrue("Should have got a enception", false);
+        } catch (Exception e) {
+
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.Store.clear()'
+     */
+    public void testClear() throws Exception {
+        int count = 100;
+        ListContainer list = store.getListContainer("testClear");
+        list.load();
+        for (int i = 0; i < count; i++) {
+            list.add("test " + i);
+        }
+        assertEquals(count, list.size());
+        store.clear();
+        assertTrue(list.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.Store.getMapContainer(Object)'
+     */
+    public void testGetMapContainer() throws Exception {
+        String containerId = "test";
+        MapContainer<Object, String> container = store.getMapContainer(containerId);
+        container.load();
+        assertNotNull(container);
+        store.close();
+        store = getStore();
+        container = store.getMapContainer(containerId);
+        assertNotNull(container);
+
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.activemq.kaha.Store.deleteMapContainer(Object)'
+     */
+    public void testDeleteMapContainer() throws Exception {
+        String containerId = "test";
+        MapContainer<Object, String> container = store.getMapContainer(containerId);
+        assertNotNull(container);
+        store.deleteMapContainer(containerId);
+        assertFalse(store.doesMapContainerExist(containerId));
+        store.close();
+        store = getStore();
+        assertFalse(store.doesMapContainerExist(containerId));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.Store.getListContainer(Object)'
+     */
+    public void testGetListContainer() throws Exception {
+        String containerId = "test";
+        ListContainer container = store.getListContainer(containerId);
+        assertNotNull(container);
+        store.close();
+        store = getStore();
+        container = store.getListContainer(containerId);
+        assertNotNull(container);
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.activemq.kaha.Store.deleteListContainer(Object)'
+     */
+    public void testDeleteListContainer() throws Exception {
+        String containerId = "test";
+        ListContainer container = store.getListContainer(containerId);
+        assertNotNull(container);
+        store.deleteListContainer(containerId);
+        assertFalse(store.doesListContainerExist(containerId));
+        store.close();
+        store = getStore();
+        assertFalse(store.doesListContainerExist(containerId));
+    }
+
+    public void testBasicAllocations() throws Exception {
+        Map<Object, String> testMap = new HashMap<Object, String>();
+        int count = 1000;
+        for (int i = 0; i < count; i++) {
+            String key = "key:" + i;
+            String value = "value:" + i;
+            testMap.put(key, value);
+        }
+        List testList = new ArrayList();
+        for (int i = 0; i < count; i++) {
+            testList.add("value:" + i);
+        }
+        String listId = "testList";
+        String mapId1 = "testMap";
+        String mapId2 = "testMap2";
+        MapContainer<Object, String> mapContainer1 = store.getMapContainer(mapId1);
+        mapContainer1.load();
+        mapContainer1.putAll(testMap);
+
+        MapContainer<Object, String> mapContainer2 = store.getMapContainer(mapId2, mapId2);
+        mapContainer2.load();
+        mapContainer2.putAll(testMap);
+
+        ListContainer listContainer = store.getListContainer(listId);
+        listContainer.load();
+
+        listContainer.addAll(testList);
+        store.close();
+        store = getStore();
+        mapContainer1 = store.getMapContainer(mapId1);
+        mapContainer1.load();
+        mapContainer2 = store.getMapContainer(mapId2, mapId2);
+        mapContainer2.load();
+        listContainer = store.getListContainer(listId);
+        listContainer.load();
+        for (Iterator<Object> i = testMap.keySet().iterator(); i.hasNext();) {
+            Object key = i.next();
+            Object value = testMap.get(key);
+            assertTrue(mapContainer1.containsKey(key));
+            assertEquals(value, mapContainer1.get(key));
+        }
+        for (Iterator<Object> i = testMap.keySet().iterator(); i.hasNext();) {
+            Object key = i.next();
+            Object value = testMap.get(key);
+            assertTrue(mapContainer2.containsKey(key));
+            assertEquals(value, mapContainer2.get(key));
+        }
+        assertEquals(testList.size(), listContainer.size());
+        Iterator j = listContainer.iterator();
+        for (Iterator i = testList.iterator(); i.hasNext();) {
+            assertEquals(i.next(), j.next());
+        }
+    }
+
+    public void testLock() throws Exception {
+        store.doesListContainerExist("fred");
+        Store s = getStore();
+        try {
+            s.doesListContainerExist("fred");
+        } catch (StoreLockedExcpetion e) {
+            return;
+        } finally {
+            s.close();
+        }
+        fail("Expected to catch an exception");
+    }
+
+    protected Store getStore() throws IOException {
+        return StoreFactory.open(name, "rw");
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        name = System.getProperty("basedir", ".") + "/target/activemq-data/store-test.db";
+        store = getStore();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (store != null) {
+            store.close();
+            store = null;
+        }
+        boolean rc = StoreFactory.delete(name);
+        assertTrue(rc);
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/StoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/VolumeTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/VolumeTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/VolumeTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/VolumeTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,79 @@
+/**
+ * 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.kaha;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class VolumeTest extends TestCase {
+
+    protected static final int NUMBER = 1;
+    private static final transient Logger LOG = LoggerFactory.getLogger(VolumeTest.class);
+
+    protected Store store;
+    protected String name;
+
+    /*
+     * dump a large number of messages into a list - then retreive them
+     */
+    public void testListVolume() throws Exception {
+        ListContainer container = store.getListContainer("volume");
+        container.setMarshaller(Store.BYTES_MARSHALLER);
+        byte[] data = new byte[10];
+        for (int i = 0; i < NUMBER; i++) {
+            container.add(data);
+            if (i % 100000 == 0) {
+                LOG.error("persisted " + i);
+            }
+
+        }
+        int count = 0;
+
+        for (Iterator i = container.iterator(); i.hasNext();) {
+            assertNotNull(i.next());
+            count++;
+            if (count % 100000 == 0) {
+                LOG.error("retrived  " + count);
+            }
+        }
+        assertEquals("Different retrieved to stored", NUMBER, count);
+    }
+
+    protected Store getStore() throws IOException {
+        return StoreFactory.open(name, "rw");
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        name = System.getProperty("basedir", ".") + "/target/activemq-data/volume-container.db";
+        StoreFactory.delete(name);
+        store = StoreFactory.open(name, "rw");
+
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (store != null) {
+            store.close();
+        }
+        assertTrue(StoreFactory.delete(name));
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/VolumeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/DataFileAppenderTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/DataFileAppenderTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/DataFileAppenderTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/DataFileAppenderTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,133 @@
+/**
+ * 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.kaha.impl.async;
+
+import java.io.File;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.util.ByteSequence;
+
+public class DataFileAppenderTest extends TestCase {
+    AsyncDataManager dataManager;
+    File dir;
+    
+    @Override
+    public void setUp() throws Exception {
+        dir = new File("target/tests/DataFileAppenderTest");
+        dir.mkdirs();
+        dataManager = new AsyncDataManager();
+        dataManager.setDirectory(dir);
+        configure(dataManager);
+        dataManager.start();
+    }
+    
+    protected void configure(AsyncDataManager dataManager) {
+        dataManager.setUseNio(false);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        dataManager.close();
+        deleteFilesInDirectory(dir);
+        dir.delete();
+    }
+
+    private void deleteFilesInDirectory(File directory) {
+        File[] files = directory.listFiles();
+        for (int i=0; i<files.length; i++) {
+            File f = files[i];
+            if (f.isDirectory()) {
+                deleteFilesInDirectory(f);
+            }   
+            f.delete();
+        }  
+    }  
+
+    public void testBatchWriteCallbackCompleteAfterTimeout() throws Exception {
+        final int iterations = 10;
+        final CountDownLatch latch = new CountDownLatch(iterations);
+        ByteSequence data = new ByteSequence("DATA".getBytes());
+        for (int i=0; i < iterations; i++) {
+            dataManager.write(data, new Runnable() {
+                public void run() {
+                    latch.countDown();                 
+                }
+            });
+        }
+        // at this point most probably dataManager.getInflightWrites().size() >= 0
+        // as the Thread created in DataFileAppender.enqueue() may not have caught up.
+        assertTrue("queued data is written", latch.await(5, TimeUnit.SECONDS));
+    }
+
+    public void testBatchWriteCallbackCompleteAfterClose() throws Exception {
+        final int iterations = 10;
+        final CountDownLatch latch = new CountDownLatch(iterations);
+        ByteSequence data = new ByteSequence("DATA".getBytes());
+        for (int i=0; i<iterations; i++) {
+            dataManager.write(data, new Runnable() {
+                public void run() {
+                    latch.countDown();                 
+                }
+            });
+        }
+        dataManager.close();
+        assertTrue("queued data is written", dataManager.getInflightWrites().isEmpty());
+        assertEquals("none written", 0, latch.getCount());
+    }
+    
+    public void testBatchWriteCompleteAfterClose() throws Exception {
+        ByteSequence data = new ByteSequence("DATA".getBytes());
+        final int iterations = 10;
+        for (int i=0; i<iterations; i++) {
+            dataManager.write(data, false);
+        }
+        dataManager.close();
+        assertTrue("queued data is written:" + dataManager.getInflightWrites().size(), dataManager.getInflightWrites().isEmpty());
+    }
+    
+    public void testBatchWriteToMaxMessageSize() throws Exception {
+        final int iterations = 4;
+        final CountDownLatch latch = new CountDownLatch(iterations);
+        Runnable done = new Runnable() {
+            public void run() {
+                latch.countDown();                 
+            }
+        };
+        int messageSize = DataFileAppender.DEFAULT_MAX_BATCH_SIZE / iterations;
+        byte[] message = new byte[messageSize];
+        ByteSequence data = new ByteSequence(message);
+        
+        for (int i=0; i< iterations; i++) {
+            dataManager.write(data, done);
+        }
+        
+        // write may take some time
+        assertTrue("all callbacks complete", latch.await(10, TimeUnit.SECONDS));
+    }
+    
+    public void testNoBatchWriteWithSync() throws Exception {
+        ByteSequence data = new ByteSequence("DATA".getBytes());
+        final int iterations = 10;
+        for (int i=0; i<iterations; i++) {
+            dataManager.write(data, true);
+            assertTrue("queued data is written", dataManager.getInflightWrites().isEmpty());
+        }
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/DataFileAppenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,217 @@
+/**
+ * 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.kaha.impl.async;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import org.apache.activeio.journal.InvalidRecordLocationException;
+import org.apache.activeio.journal.RecordLocation;
+import org.apache.activeio.packet.ByteArrayPacket;
+import org.apache.activeio.packet.Packet;
+import org.apache.activemq.kaha.impl.async.JournalFacade.RecordLocationFacade;
+import org.apache.activemq.util.ByteSequence;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests the AsyncDataManager based Journal
+ * 
+ * 
+ */
+public class JournalImplTest extends TestCase {
+
+    Logger log = LoggerFactory.getLogger(JournalImplTest.class);
+
+    int size = 1024 * 10;
+    int logFileCount = 2;
+    File logDirectory = new File("target/dm-data2");
+    private JournalFacade journal;
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        if (logDirectory.exists()) {
+            deleteDir(logDirectory);
+        }
+        assertTrue("Could not delete directory: " + logDirectory.getCanonicalPath(), !logDirectory.exists());
+        AsyncDataManager dm = new AsyncDataManager();
+        dm.setDirectory(logDirectory);
+        dm.setMaxFileLength(1024 * 64);
+        dm.start();
+        journal = new JournalFacade(dm);
+    }
+
+    /**
+     */
+    private void deleteDir(File f) {
+        File[] files = f.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            File file = files[i];
+            file.delete();
+        }
+        f.delete();
+    }
+
+    protected void tearDown() throws Exception {
+        journal.close();
+        if (logDirectory.exists()) {
+            deleteDir(logDirectory);
+        }
+        // assertTrue( !logDirectory.exists() );
+    }
+
+    public void testLogFileCreation() throws IOException {
+        RecordLocation mark = journal.getMark();
+        assertNull(mark);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testAppendAndRead() throws InvalidRecordLocationException, InterruptedException, IOException {
+
+        Packet data1 = createPacket("Hello World 1");
+        RecordLocation location1 = journal.write(data1, false);
+        Packet data2 = createPacket("Hello World 2");
+        RecordLocation location2 = journal.write(data2, false);
+        Packet data3 = createPacket("Hello World 3");
+        RecordLocation location3 = journal.write(data3, false);
+
+        // Thread.sleep(1000);
+
+        // Now see if we can read that data.
+        Packet data;
+        data = journal.read(location2);
+        assertEquals(data2, data);
+        data = journal.read(location1);
+        assertEquals(data1, data);
+        data = journal.read(location3);
+        assertEquals(data3, data);
+
+        // Can we cursor the data?
+        RecordLocation l = journal.getNextRecordLocation(null);
+        int t = l.compareTo(location1);
+        assertEquals(0, t);
+        data = journal.read(l);
+        assertEquals(data1, data);
+
+        l = journal.getNextRecordLocation(l);
+        assertEquals(0, l.compareTo(location2));
+        data = journal.read(l);
+        assertEquals(data2, data);
+
+        l = journal.getNextRecordLocation(l);
+        assertEquals(0, l.compareTo(location3));
+        data = journal.read(l);
+        assertEquals(data3, data);
+
+        l = journal.getNextRecordLocation(l);
+        assertNull(l);
+
+        log.info(journal.toString());
+    }
+
+    public void testReadOnlyRead() throws InvalidRecordLocationException, InterruptedException, IOException {
+    	
+    	Packet data1 = createPacket("Hello World 1");
+        RecordLocation location1 = journal.write(data1, false);
+        Packet data2 = createPacket("Hello World 2");
+        RecordLocation location2 = journal.write(data2, false);
+        Packet data3 = createPacket("Hello World 3");
+        RecordLocation location3 = journal.write(data3, false);
+        
+        Packet packet;
+        packet = journal.read(location2);
+        assertEquals(data2, packet);
+        packet = journal.read(location1);
+        assertEquals(data1, packet);
+        packet = journal.read(location3);
+        assertEquals(data3, packet);
+    	
+        ArrayList<File> data = new ArrayList<File>();
+        data.add(logDirectory);
+        ReadOnlyAsyncDataManager rodm = new ReadOnlyAsyncDataManager(data);
+        rodm.start();
+        try {
+            for (Location curr = rodm.getFirstLocation(); curr != null; curr = rodm.getNextLocation(curr)) {
+                ByteSequence bs = rodm.read(curr);
+                assertNotNull(bs);
+            }
+        } finally {
+    	    rodm.close();
+        }
+    }
+
+    public void testCanReadFromArchivedLogFile() throws InvalidRecordLocationException, InterruptedException, IOException {
+
+        Packet data1 = createPacket("Hello World 1");
+        RecordLocationFacade location1 = (RecordLocationFacade)journal.write(data1, false);
+
+        RecordLocationFacade pos;
+        int counter = 0;
+        do {
+
+            Packet p = createPacket("<<<data>>>");
+            pos = (RecordLocationFacade)journal.write(p, false);
+            if (counter++ % 1000 == 0) {
+                journal.setMark(pos, false);
+            }
+
+        } while (pos.getLocation().getDataFileId() < 5);
+
+        // Now see if we can read that first packet.
+        Packet data;
+        data = journal.read(location1);
+        assertEquals(data1, data);
+
+    }
+
+    /**
+     * @param string
+     * @return
+     */
+    private Packet createPacket(String string) {
+        return new ByteArrayPacket(string.getBytes());
+    }
+
+    public static void assertEquals(Packet arg0, Packet arg1) {
+        assertEquals(arg0.sliceAsBytes(), arg1.sliceAsBytes());
+    }
+
+    public static void assertEquals(byte[] arg0, byte[] arg1) {
+
+        // System.out.println("Comparing: "+new String(arg0)+" and "+new
+        // String(arg1));
+        if (arg0 == null ^ arg1 == null) {
+            fail("Not equal: " + arg0 + " != " + arg1);
+        }
+        if (arg0 == null) {
+            return;
+        }
+        if (arg0.length != arg1.length) {
+            fail("Array lenght not equal: " + arg0.length + " != " + arg1.length);
+        }
+        for (int i = 0; i < arg0.length; i++) {
+            if (arg0[i] != arg1[i]) {
+                fail("Array item not equal at index " + i + ": " + arg0[i] + " != " + arg1[i]);
+            }
+        }
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/LocationTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/LocationTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/LocationTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/LocationTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,62 @@
+/**
+ * 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.kaha.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+import org.apache.activemq.kaha.impl.async.JournalFacade.RecordLocationFacade;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests the Location Class
+ * 
+ * 
+ */
+public class LocationTest extends TestCase {
+    private static final transient Logger LOG = LoggerFactory.getLogger(LocationTest.class);
+
+    @SuppressWarnings("unchecked")
+    public synchronized void testRecordLocationImplComparison() throws IOException {
+        Location l1 = new Location();
+        l1.setDataFileId(0);
+        l1.setOffset(5);
+        Location l2 = new Location(l1);
+        l2.setOffset(10);
+        Location l3 = new Location(l2);
+        l3.setDataFileId(2);
+        l3.setOffset(0);
+
+        assertTrue(l1.compareTo(l2) < 0);
+
+        // Sort them using a list. Put them in the wrong order.
+        ArrayList<RecordLocationFacade> l = new ArrayList<RecordLocationFacade>();
+        l.add(new RecordLocationFacade(l2));
+        l.add(new RecordLocationFacade(l3));
+        l.add(new RecordLocationFacade(l1));
+        Collections.sort(l);
+
+        // Did they get sorted to the correct order?
+        LOG.debug(l.get(0).toString());
+        assertSame(l.get(0).getLocation(), l1);
+        assertSame(l.get(1).getLocation(), l2);
+        assertSame(l.get(2).getLocation(), l3);
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/LocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/NioDataFileAppenderTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/NioDataFileAppenderTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/NioDataFileAppenderTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/NioDataFileAppenderTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,25 @@
+/**
+ * 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.kaha.impl.async;
+
+public class NioDataFileAppenderTest extends DataFileAppenderTest {
+
+    @Override
+    protected void configure(AsyncDataManager dataManager) {
+        dataManager.setUseNio(true);
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/async/NioDataFileAppenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedListTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedListTest.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedListTest.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedListTest.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,132 @@
+/**
+ * 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.kaha.impl.index;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.activemq.kaha.impl.DataManager;
+import org.apache.activemq.kaha.impl.data.DataManagerImpl;
+import org.apache.activemq.kaha.impl.data.Item;
+import org.apache.activemq.util.IOHelper;
+
+
+public class DiskIndexLinkedListTest extends VMIndexLinkedListTest {
+
+    private IndexManager im;
+    protected IndexLinkedList createList(IndexItem root) throws IOException {
+        String dirName = System.getProperty("basedir", ".") + "/target/activemq-data/testIndex";
+        File file = new File(dirName);
+        file.mkdirs();
+        IOHelper.deleteChildren(file);
+        DataManager dm = new DataManagerImpl(file,"test",new AtomicLong());
+        im = new IndexManager(file,"test","rw",dm,new AtomicLong());
+        root = im.createNewIndex();
+        im.storeIndex(root);
+        return new DiskIndexLinkedList(im,root);
+    }
+    
+    IndexItem createIndex(IndexLinkedList indexList,int offset) throws IOException {
+        IndexItem result =  im.createNewIndex();
+        im.storeIndex(result);
+        return result;
+    }
+    
+    protected void addToList(IndexLinkedList list,IndexItem item) throws IOException {
+        IndexItem root = list.getRoot();
+        IndexItem prev = list.getLast();
+        prev = prev != null ? prev : root;
+        IndexItem next = list.getNextEntry(prev);
+        prev.setNextItem(item.getOffset());
+        item.setPreviousItem(prev.getOffset());
+        im.updateIndexes(prev);
+        if (next != null) {
+            next.setPreviousItem(item.getOffset());
+            item.setNextItem(next.getOffset());
+            im.updateIndexes(next);
+        }
+        im.storeIndex(item);
+        list.add(item);
+    }
+    
+    protected void insertToList(IndexLinkedList list,int pos,IndexItem item) throws IOException {
+        IndexItem root = list.getRoot();
+        IndexItem prev = null;
+        IndexItem next = null;
+        if (pos <= 0) {
+            prev = root;
+            next = list.getNextEntry(root);
+        } else if (pos >= list.size()) {
+            prev = list.getLast();
+            if (prev==null) {
+                prev=root;
+            }
+            next = null;
+        } else {
+            prev = list.get(pos);
+            prev = prev != null ? prev : root;
+            next = list.getNextEntry(prev);
+        }
+        prev.setNextItem(item.getOffset());
+        item.setPreviousItem(prev.getOffset());
+        im.updateIndexes(prev);
+        if (next != null) {
+            next.setPreviousItem(item.getOffset());
+            item.setNextItem(next.getOffset());
+            im.updateIndexes(next);
+        }
+        im.storeIndex(item);
+        list.setRoot(root);
+        list.add(pos,item);
+    }
+    
+    protected void insertFirst(IndexLinkedList list,IndexItem item) throws IOException {
+        IndexItem root = list.getRoot();
+        IndexItem prev = root;
+        IndexItem next = list.getNextEntry(prev);
+        prev.setNextItem(item.getOffset());
+        item.setPreviousItem(prev.getOffset());
+        im.updateIndexes(prev);
+        if (next != null) {
+            next.setPreviousItem(item.getOffset());
+            item.setNextItem(next.getOffset());
+            im.updateIndexes(next);
+        }
+        im.storeIndex(item);
+        list.addFirst(item);
+    }
+    
+    protected synchronized void remove(IndexLinkedList list,IndexItem item) throws IOException {
+        IndexItem root = list.getRoot();
+        IndexItem prev = list.getPrevEntry(item);
+        IndexItem next = list.getNextEntry(item);
+        list.remove(item);
+
+        prev = prev == null ? root : prev;
+        next = (next == null || !next.equals(root)) ? next : null;
+       
+        if (next != null) {
+            prev.setNextItem(next.getOffset());
+            next.setPreviousItem(prev.getOffset());
+            im.updateIndexes(next);
+        } else {
+            prev.setNextItem(Item.POSITION_NOT_SET);
+        }
+        im.updateIndexes(prev);
+    }
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedListTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java?rev=1409621&view=auto
==============================================================================
--- activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java (added)
+++ activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java Thu Nov 15 00:36:53 2012
@@ -0,0 +1,231 @@
+/**
+ * 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.kaha.impl.index;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+import junit.framework.TestCase;
+import org.apache.activemq.kaha.StoreEntry;
+import org.apache.activemq.util.IOHelper;
+
+/**
+ * @author chirino
+ */
+public abstract class IndexBenchmark extends TestCase {
+
+    // Slower machines might need to make this bigger.
+    private static final long SAMPLE_DURATION = Integer.parseInt(System.getProperty("SAMPLES_DURATION", "" + 1000 * 5));
+    // How many times do we sample?
+    private static final long SAMPLES = Integer.parseInt(System.getProperty("SAMPLES", "" + 60 * 1000 / SAMPLE_DURATION)); // Take
+                                                                                                                            // enough
+                                                                                                                            // samples
+                                                                                                                            // to
+                                                                                                                            // run
+                                                                                                                            // for
+                                                                                                                            // a
+                                                                                                                            // minute.
+
+    // How many indexes will we be benchmarking concurrently?
+    private static final int INDEX_COUNT = Integer.parseInt(System.getProperty("INDEX_COUNT", "" + 1));
+    // Indexes tend to perform worse when they get big.. so how many items
+    // should we put into the index before we start sampling.
+    private static final int INDEX_PRE_LOAD_COUNT = Integer.parseInt(System.getProperty("INDEX_PRE_LOAD_COUNT", "" + 10000 / INDEX_COUNT));
+
+    protected File ROOT_DIR;
+    protected final HashMap<String, Index> indexes = new HashMap<String, Index>();
+    protected IndexManager indexManager;
+
+    public void setUp() throws Exception {
+        ROOT_DIR = new File(IOHelper.getDefaultDataDirectory());
+        IOHelper.mkdirs(ROOT_DIR);
+        IOHelper.deleteChildren(ROOT_DIR);
+        indexManager = new IndexManager(ROOT_DIR, getClass().getName(), "rw", null, new AtomicLong());
+    }
+
+    protected void tearDown() throws Exception {
+        for (Index i : indexes.values()) {
+            try {
+                i.unload();
+            } catch (Throwable ignore) {
+            }
+        }
+        indexManager.close();
+    }
+
+    abstract protected Index createIndex(File root, String name) throws Exception;
+
+    synchronized private Index openIndex(String name) throws Exception {
+        Index index = indexes.get(name);
+        if (index == null) {
+            index = createIndex(ROOT_DIR, name);
+            index.load();
+            indexes.put(name, index);
+        }
+        return index;
+    }
+
+    class Producer extends Thread {
+        private final String name;
+        AtomicBoolean shutdown = new AtomicBoolean();
+
+        public Producer(String name) {
+            super("Producer: " + name);
+            this.name = name;
+        }
+
+        public void shutdown() {
+            shutdown.set(true);
+        }
+
+        @Override
+        public void run() {
+            try {
+
+                IndexItem value = indexManager.createNewIndex();
+                indexManager.storeIndex(value);
+
+                Index index = openIndex(name);
+                long counter = 0;
+                while (!shutdown.get()) {
+                    long c = counter;
+
+                    String key = "a-long-message-id-like-key-" + c;
+                    index.store(key, value);
+                    onProduced(counter++);
+                }
+
+            } catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+
+        public void onProduced(long counter) {
+        }
+    }
+
+    class Consumer extends Thread {
+        private final String name;
+        AtomicBoolean shutdown = new AtomicBoolean();
+
+        public Consumer(String name) {
+            super("Consumer: " + name);
+            this.name = name;
+        }
+
+        public void shutdown() {
+            shutdown.set(true);
+        }
+
+        @Override
+        public void run() {
+            try {
+                Index index = openIndex(name);
+                long counter = 0;
+                while (!shutdown.get()) {
+                    long c = counter;
+                    String key = "a-long-message-id-like-key-" + c;
+                    StoreEntry record;
+                    record = index.get(key);
+                    if (record != null) {
+                        index.remove(key);
+                        onConsumed(counter++);
+                    } else {
+                        Thread.sleep(0);
+                    }
+                }
+            } catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+
+        public void onConsumed(long counter) {
+        }
+    }
+
+    public void testLoad() throws Exception {
+
+        final Producer producers[] = new Producer[INDEX_COUNT];
+        final Consumer consumers[] = new Consumer[INDEX_COUNT];
+        final CountDownLatch preloadCountDown = new CountDownLatch(INDEX_COUNT);
+        final AtomicLong producedRecords = new AtomicLong();
+        final AtomicLong consumedRecords = new AtomicLong();
+
+        System.out.println("Starting: " + INDEX_COUNT + " producers");
+        for (int i = 0; i < INDEX_COUNT; i++) {
+            producers[i] = new Producer("test-" + i) {
+                private boolean prelaodDone;
+
+                public void onProduced(long counter) {
+                    if (!prelaodDone && counter >= INDEX_PRE_LOAD_COUNT) {
+                        prelaodDone = true;
+                        preloadCountDown.countDown();
+                    }
+                    producedRecords.incrementAndGet();
+                }
+            };
+            producers[i].start();
+        }
+
+        long start = System.currentTimeMillis();
+        System.out.println("Waiting for each producer create " + INDEX_PRE_LOAD_COUNT + " records before starting the consumers.");
+        preloadCountDown.await();
+        long end = System.currentTimeMillis();
+        System.out.println("Preloaded " + INDEX_PRE_LOAD_COUNT * INDEX_COUNT + " records at " + (INDEX_PRE_LOAD_COUNT * INDEX_COUNT * 1000f / (end - start)) + " records/sec");
+
+        System.out.println("Starting: " + INDEX_COUNT + " consumers");
+        for (int i = 0; i < INDEX_COUNT; i++) {
+            consumers[i] = new Consumer("test-" + i) {
+                public void onConsumed(long counter) {
+                    consumedRecords.incrementAndGet();
+                }
+            };
+            consumers[i].start();
+        }
+
+        long sample_start = System.currentTimeMillis();
+        System.out.println("Taking " + SAMPLES + " performance samples every " + SAMPLE_DURATION + " ms");
+        System.out.println("time (s), produced, produce rate (r/s), consumed, consume rate (r/s), used memory (k)");
+        producedRecords.set(0);
+        consumedRecords.set(0);
+        for (int i = 0; i < SAMPLES; i++) {
+            start = System.currentTimeMillis();
+            Thread.sleep(SAMPLE_DURATION);
+            end = System.currentTimeMillis();
+            long p = producedRecords.getAndSet(0);
+            long c = consumedRecords.getAndSet(0);
+
+            long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+
+            System.out.println(((end-sample_start)/1000f)+", "+p+", "+(p * 1000f / (end - start)) + ", "+ c+", " + (c * 1000f / (end - start))+", "+(usedMemory/(1024)) );
+        }
+        System.out.println("Samples done... Shutting down the producers and consumers...");
+        for (int i = 0; i < INDEX_COUNT; i++) {
+            producers[i].shutdown();
+            consumers[i].shutdown();
+        }
+        for (int i = 0; i < INDEX_COUNT; i++) {
+            producers[i].join(1000 * 5);
+            consumers[i].join(1000 * 5);
+        }
+        System.out.println("Shutdown.");
+    }
+
+}

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-amq-store/src/test/java/org/apache/activemq/kaha/impl/index/IndexBenchmark.java
------------------------------------------------------------------------------
    svn:executable = *