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 2006/09/05 15:51:15 UTC

svn commit: r440342 [2/2] - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/kaha/impl/ main/java/org/apache/activemq/kaha/impl/container/ main/java/org/apache/activemq/kaha/impl/data/ main/java/org/apache/activemq/kaha/imp...

Copied: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java (from r440186, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/VMIndexLinkedList.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java?view=diff&rev=440342&p1=incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/VMIndexLinkedList.java&r1=440186&p2=incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java&r2=440342
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/VMIndexLinkedList.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java Tue Sep  5 06:51:13 2006
@@ -15,7 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.kaha.impl;
+package org.apache.activemq.kaha.impl.index;
 
 /**
  * A linked list used by IndexItems

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/CachedListContainerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/CachedListContainerImplTest.java?view=auto&rev=440342
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/CachedListContainerImplTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/CachedListContainerImplTest.java Tue Sep  5 06:51:13 2006
@@ -0,0 +1,172 @@
+/**
+ * 
+ * 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;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+import org.apache.activemq.kaha.StoreFactory;
+import org.apache.activemq.kaha.impl.KahaStore;
+import org.apache.activemq.kaha.impl.container.ContainerId;
+import org.apache.activemq.kaha.impl.container.ListContainerImpl;
+import org.apache.activemq.kaha.impl.data.DataManager;
+import org.apache.activemq.kaha.impl.index.IndexItem;
+import org.apache.activemq.kaha.impl.index.IndexManager;
+/**
+ * Junit tests for CachedListContainerImpl
+ * 
+ * @version $Revision: 439552 $
+ */
+public class CachedListContainerImplTest extends TestCase{
+    protected String name;
+    protected KahaStore store;
+    protected int MAX_CACHE_SIZE=10;
+
+    protected KahaStore getStore() throws IOException{
+        KahaStore store = new KahaStore(name,"rw");
+        store.initialize();
+        return store;
+    }
+
+    public void testAdds() throws Exception{
+        ListContainerImpl list=getStoreList("test");
+        List data=getDataList(100);
+        list.addAll(data);
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        List cached=getCachedList(MAX_CACHE_SIZE);
+        for(int i=0;i<cached.size();i++){
+            list.add(i,cached.get(i));
+        }
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        for(int i=0;i<cached.size();i++){
+            assertEquals(cached.get(i),list.getCacheList().get(i));
+        }
+    }
+
+    public void testAddsIntoCacheSpace() throws Exception{
+        ListContainerImpl list=getStoreList("test");
+        int initialDataSize=50;
+        List data=getDataList(initialDataSize);
+        list.addAll(data);
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        List cached=getCachedList(MAX_CACHE_SIZE);
+        for(int i=MAX_CACHE_SIZE/2;i<cached.size();i++){
+            list.add(i,cached.get(i));
+        }
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        for(int i=0;i<MAX_CACHE_SIZE/2;i++){
+            assertEquals(data.get(i),list.getCacheList().get(i));
+        }
+        for(int i=MAX_CACHE_SIZE/2;i<MAX_CACHE_SIZE;i++){
+            assertEquals(cached.get(i),list.getCacheList().get(i));
+        }
+    }
+
+    public void testRemoves() throws Exception{
+        ListContainerImpl list=getStoreList("test");
+        int initialDataSize=10;
+        List data=getDataList(initialDataSize);
+        list.addAll(data);
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        List cached=getCachedList(MAX_CACHE_SIZE);
+        list.addAll(cached);
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        for(int i=0;i<cached.size();i++){
+            assertNotSame(cached.get(i),list.getCacheList().get(i));
+        }
+        for(int i=0;i<initialDataSize;i++){
+            list.remove(0);
+        }
+        assertEquals(0,list.getCacheList().size());
+        // repopulate the cache
+        for(int i=0;i<MAX_CACHE_SIZE;i++){
+            list.get(i);
+        }
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        for(int i=0;i<cached.size();i++){
+            assertEquals(cached.get(i),list.getCacheList().get(i));
+        }
+    }
+
+    public void testCacheSize() throws Exception{
+        ListContainerImpl list=getStoreList("test");
+        List data=getDataList(100);
+        list.addAll(data);
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+    }
+
+    public void testInserts() throws Exception{
+        ListContainerImpl list=getStoreList("test");
+        List data=getDataList(100);
+        list.addAll(data);
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        List cached=getCachedList(MAX_CACHE_SIZE);
+        for(int i=0;i<cached.size();i++){
+            list.set(i,cached.get(i));
+        }
+        assertEquals(MAX_CACHE_SIZE,list.getCacheList().size());
+        for(int i=0;i<cached.size();i++){
+            assertEquals(cached.get(i),list.getCacheList().get(i));
+        }
+    }
+
+    protected ListContainerImpl getStoreList(Object id) throws Exception{
+        String containerName="test";
+        DataManager dm=store.getDataManager(containerName);
+        IndexManager im=store.getIndexManager(dm,containerName);
+        ContainerId containerId=new ContainerId();
+        containerId.setKey(id);
+        containerId.setDataContainerName(containerName);
+        IndexItem root=store.listsContainer.addRoot(containerId);
+        ListContainerImpl result=new ListContainerImpl(containerId,root,store.rootIndexManager,im,dm);
+        result.expressDataInterest();
+        result.setMaximumCacheSize(MAX_CACHE_SIZE);
+        return result;
+    }
+
+    protected List getDataList(int num){
+        List result=new ArrayList();
+        for(int i=0;i<num;i++){
+            result.add("data:"+i);
+        }
+        return result;
+    }
+
+    protected List getCachedList(int num){
+        List result=new ArrayList();
+        for(int i=0;i<num;i++){
+            result.add("cached:"+i);
+        }
+        return result;
+    }
+
+    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);
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedListTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedListTest.java?view=auto&rev=440342
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedListTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedListTest.java Tue Sep  5 06:51:13 2006
@@ -0,0 +1,253 @@
+/**
+ *
+ * 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.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.kaha.impl.index.IndexItem;
+import org.apache.activemq.kaha.impl.index.IndexLinkedList;
+
+/** 
+* @version $Revision: 1.2 $
+*/
+public class VMIndexLinkedListTest extends TestCase{
+    static final int NUMBER = 10;
+    private IndexItem root;
+    private List testData = new ArrayList();
+    private IndexLinkedList list;
+    protected void setUp() throws Exception{
+        super.setUp();
+        for (int i =0; i < NUMBER; i++){
+            testData.add(new IndexItem());
+        }
+        root = new IndexItem();
+        list = new VMIndexLinkedList(root);
+    }
+
+    protected void tearDown() throws Exception{
+        super.tearDown();
+        testData.clear();
+        list = null;
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getFirst()'
+     */
+    public void testGetFirst(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.getFirst()==testData.get(0));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getLast()'
+     */
+    public void testGetLast(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.getLast()==testData.get(testData.size()-1));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.removeFirst()'
+     */
+    public void testRemoveFirst(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.removeFirst()==testData.get(0));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.removeLast()'
+     */
+    public void testRemoveLast(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.removeLast()==testData.get(testData.size()-1));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.addFirst(IndexItem)'
+     */
+    public void testAddFirst(){
+        for (int i =0; i < testData.size(); i++){
+            list.addFirst((IndexItem) testData.get(i));
+        }
+        int count = 0;
+        for (int i =testData.size()-1; i>=0; i--){
+            assertTrue(testData.get(i)==list.get(count++));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.addLast(IndexItem)'
+     */
+    public void testAddLast(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(testData.get(i)==list.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.size()'
+     */
+    public void testSize(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+            assertTrue(list.size()==i+1);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.isEmpty()'
+     */
+    public void testIsEmpty(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+            assertTrue(list.size()==i+1);
+        }
+        list.clear();
+        assertTrue(list.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.add(IndexItem)'
+     */
+    public void testAddIndexItem(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(testData.get(i)==list.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.clear()'
+     */
+    public void testClear(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+            assertTrue(list.size()==i+1);
+        }
+        list.clear();
+        assertTrue(list.isEmpty());
+    }
+
+    
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.add(int, IndexItem)'
+     */
+    public void testAddIntIndexItem(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(testData.get(i)==list.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.remove(int)'
+     */
+    public void testRemoveInt(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            list.remove(0);
+        }
+        assertTrue(list.isEmpty());
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            list.remove(list.size()-1);
+        }
+        assertTrue(list.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.indexOf(IndexItem)'
+     */
+    public void testIndexOf(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(list.indexOf((IndexItem) testData.get(i))==i);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getNextEntry(IndexItem)'
+     */
+    public void testGetNextEntry(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        IndexItem next = list.getFirst();
+        int count = 0;
+        while (next != null){
+            assertTrue(next==testData.get(count++));
+            next = list.getNextEntry(next);
+            assertTrue(next != root);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.getPrevEntry(IndexItem)'
+     */
+    public void testGetPrevEntry(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        IndexItem next = list.getLast();
+        int count = testData.size()-1;
+        while (next != null){
+            assertTrue(next==testData.get(count--));
+            next = list.getPrevEntry(next);
+            assertTrue(next != root);
+        }
+    }
+
+    
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.VMIndexLinkedList.remove(IndexItem)'
+     */
+    public void testRemoveIndexItem(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            list.remove((IndexItem)testData.get(i));
+            assertTrue(list.size()==testData.size()-i-1);
+        }
+    }
+}