o added a setter for reclaimer threshold
authorKiran Ayyagari <kayyagari@apache.org>
Thu, 2 Apr 2015 10:15:42 +0000 (10:15 +0000)
committerKiran Ayyagari <kayyagari@apache.org>
Thu, 2 Apr 2015 10:15:42 +0000 (10:15 +0000)
o added a test for reclaimer (in progress)

mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java [new file with mode: 0644]

index 62c388c..abfa120 100644 (file)
@@ -3992,6 +3992,18 @@ public class RecordManager extends AbstractTransactionManager
 
 
     /**
+     * sets the threshold of the number of commits to be performed before
+     * reclaiming the free pages.
+     * 
+     * @param spaceReclaimerThreshold the number of commits before the reclaimer runs
+     */
+    public void setSpaceReclaimerThreshold( int spaceReclaimerThreshold )
+    {
+        this.spaceReclaimerThreshold = spaceReclaimerThreshold;
+    }
+
+
+    /**
      * @see Object#toString()
      */
     public String toString()
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java b/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java
new file mode 100644 (file)
index 0000000..aa22048
--- /dev/null
@@ -0,0 +1,110 @@
+/*\r
+ *   Licensed to the Apache Software Foundation (ASF) under one\r
+ *   or more contributor license agreements.  See the NOTICE file\r
+ *   distributed with this work for additional information\r
+ *   regarding copyright ownership.  The ASF licenses this file\r
+ *   to you under the Apache License, Version 2.0 (the\r
+ *   "License"); you may not use this file except in compliance\r
+ *   with the License.  You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *   Unless required by applicable law or agreed to in writing,\r
+ *   software distributed under the License is distributed on an\r
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ *   KIND, either express or implied.  See the License for the\r
+ *   specific language governing permissions and limitations\r
+ *   under the License.\r
+ *\r
+ */\r
+package org.apache.directory.mavibot.btree;\r
+\r
+\r
+import java.io.File;\r
+\r
+import org.apache.directory.mavibot.btree.serializer.IntSerializer;\r
+import org.apache.directory.mavibot.btree.serializer.StringSerializer;\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.TemporaryFolder;\r
+import static org.junit.Assert.*;\r
+\r
+/**\r
+ * Tests for free page reclaimer.\r
+ *\r
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>\r
+ */\r
+public class SpaceReclaimerTest\r
+{\r
+    private static final String TREE_NAME = "uid-tree";\r
+\r
+    private RecordManager rm;\r
+\r
+    private PersistedBTree<Integer, String> uidTree;\r
+    \r
+    @Rule\r
+    public TemporaryFolder tmpDir;\r
+\r
+    private File dbFile;\r
+\r
+\r
+    @Before\r
+    public void setup() throws Exception\r
+    {\r
+        tmpDir = new TemporaryFolder();\r
+        tmpDir.create();\r
+        \r
+        dbFile = tmpDir.newFile( "spacereclaimer.db" );\r
+\r
+        rm = new RecordManager( dbFile.getAbsolutePath() );\r
+        rm.setSpaceReclaimerThreshold( 10 );\r
+        \r
+        uidTree = ( PersistedBTree<Integer, String> ) rm.addBTree( TREE_NAME, IntSerializer.INSTANCE, StringSerializer.INSTANCE, false );\r
+    }\r
+\r
+\r
+    @After\r
+    public void cleanup() throws Exception\r
+    {\r
+        rm.close();\r
+        dbFile.delete();\r
+        tmpDir.delete();\r
+    }\r
+\r
+    \r
+    private void closeAndReopenRM() throws Exception\r
+    {\r
+        uidTree.close();\r
+        rm.close();\r
+        rm = new RecordManager( dbFile.getAbsolutePath() );\r
+        uidTree = ( PersistedBTree ) rm.getManagedTree( TREE_NAME );\r
+    }\r
+\r
+    \r
+    @Test\r
+    public void testReclaimer() throws Exception\r
+    {\r
+        int total = 11;\r
+        System.out.println( dbFile.length() );\r
+        for ( int i=0; i < total; i++ )\r
+        {\r
+            uidTree.insert( i, String.valueOf( i ) );\r
+            System.out.println( dbFile.length() );\r
+        }\r
+    \r
+        closeAndReopenRM();\r
+        \r
+        System.out.println( dbFile.length() );\r
+        \r
+        int count = 0;\r
+        TupleCursor<Integer, String> cursor = uidTree.browse();\r
+        while ( cursor.hasNext() )\r
+        {\r
+            count++;\r
+        }\r
+        \r
+        assertEquals( count, total );\r
+    }\r
+}\r