hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjungb...@apache.org
Subject svn commit: r1387533 [7/10] - in /hama/trunk: ./ core/ core/src/main/java/org/apache/hama/bsp/ graph/ graph/src/main/java/org/apache/hama/graph/ jdbm/ jdbm/src/ jdbm/src/main/ jdbm/src/main/java/ jdbm/src/main/java/org/ jdbm/src/main/java/org/apache/ j...
Date Wed, 19 Sep 2012 11:52:24 GMT
Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigable2Test.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigable2Test.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigable2Test.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigable2Test.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,421 @@
+/**
+ * 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.hama.jdbm;
+
+import java.util.AbstractMap;
+import java.util.ConcurrentModificationException;
+import java.util.NavigableMap;
+import java.util.NavigableSet;
+import java.util.Set;
+import java.util.SortedMap;
+
+public class BTreeMapNavigable2Test extends TestCaseWithTestFile {
+  static NavigableMap<Integer, String> map;
+
+  @Override
+  public void setUp() throws Exception {
+    map = newDBNoCache().createTreeMap("test");
+
+    map.put(1, "one");
+    map.put(2, "two");
+    map.put(3, "three");
+    map.put(4, "four");
+
+    map.put(7, "seven");
+    map.put(8, "eight");
+    map.put(9, "nine");
+    map.put(10, "ten");
+  }
+
+  public void testSize() {
+    int i = 8;
+    assertEquals(map.size(), i);
+    while (!map.isEmpty()) {
+      map.remove(map.firstKey());
+      assertEquals(map.size(), --i);
+    }
+  }
+
+  public void testContainsKey() {
+    assertTrue(map.containsKey(1));
+    assertTrue(map.containsKey(2));
+    assertTrue(map.containsKey(3));
+    assertTrue(map.containsKey(4));
+    assertFalse(map.containsKey(5));
+    assertFalse(map.containsKey(6));
+    assertTrue(map.containsKey(7));
+    assertTrue(map.containsKey(8));
+    assertTrue(map.containsKey(9));
+    assertTrue(map.containsKey(10));
+
+    assertFalse(map.containsKey(999));
+    assertFalse(map.containsKey(-1));
+  }
+
+  public void testContainsValue() {
+    assertTrue(map.containsValue("one"));
+    assertTrue(map.containsValue("two"));
+    assertTrue(map.containsValue("three"));
+    assertTrue(map.containsValue("four"));
+    assertFalse(map.containsValue("five"));
+    assertFalse(map.containsValue("six"));
+    assertTrue(map.containsValue("seven"));
+    assertTrue(map.containsValue("eight"));
+    assertTrue(map.containsValue("nine"));
+    assertTrue(map.containsValue("ten"));
+
+    assertFalse(map.containsValue("aaaa"));
+  }
+
+  public void testPut() {
+    assertFalse(map.containsKey(40));
+    assertFalse(map.containsValue("forty"));
+    map.put(40, "forty");
+    assertTrue(map.containsKey(40));
+    assertTrue(map.containsValue("forty"));
+  }
+
+  public void testLowerEntry() {
+    AbstractMap.Entry<Integer, String> e = map.lowerEntry(4);
+    assertEquals(e.getKey(), (Integer) 3);
+  }
+
+  public void testLowerKey() {
+    Integer key = map.lowerKey(4);
+    assertEquals(key, (Integer) 3);
+  }
+
+  public void testFloorEntry() {
+    AbstractMap.Entry<Integer, String> e = map.floorEntry(6);
+    assertEquals(e.getKey(), (Integer) 4);
+
+    e = map.floorEntry(7);
+    assertEquals(e.getKey(), (Integer) 7);
+  }
+
+  public void testFloorKey() {
+    Integer key = map.floorKey(6);
+    assertEquals(key, (Integer) 4);
+
+    key = map.floorKey(7);
+    assertEquals(key, (Integer) 7);
+  }
+
+  public void testCeilingEntry() {
+    AbstractMap.Entry<Integer, String> e = map.ceilingEntry(6);
+    assertEquals(e.getKey(), (Integer) 7);
+
+    e = map.ceilingEntry(7);
+    assertEquals(e.getKey(), (Integer) 7);
+  }
+
+  public void testCeilingKey() {
+    Integer key = map.ceilingKey(6);
+    assertEquals(key, (Integer) 7);
+
+    key = map.ceilingKey(7);
+    assertEquals(key, (Integer) 7);
+  }
+
+  public void testHigherEntry() {
+    AbstractMap.Entry<Integer, String> e = map.higherEntry(4);
+    assertEquals(e.getKey(), (Integer) 7);
+
+    e = map.higherEntry(7);
+    assertEquals(e.getKey(), (Integer) 8);
+  }
+
+  public void testHigherKey() {
+    Integer key = map.higherKey(4);
+    assertEquals(key, (Integer) 7);
+
+    key = map.higherKey(7);
+    assertEquals(key, (Integer) 8);
+  }
+
+  public void testFirstEntry() {
+    assertEquals(map.firstEntry().getKey(), (Integer) 1);
+  }
+
+  public void testLastEntry() {
+    assertEquals(map.lastEntry().getKey(), (Integer) 10);
+  }
+
+  public void testPollFirstEntry() {
+    int size0 = map.size();
+    AbstractMap.Entry<Integer, String> e = map.pollFirstEntry();
+    int size1 = map.size();
+    assertEquals(size0 - 1, size1);
+
+    assertNull(map.get(1));
+    assertEquals(e.getKey(), (Integer) 1);
+    assertEquals(e.getValue(), "one");
+  }
+
+  public void testPollLastEntry() {
+    int size0 = map.size();
+    AbstractMap.Entry<Integer, String> e = map.pollLastEntry();
+    int size1 = map.size();
+    assertEquals(size0 - 1, size1);
+
+    assertNull(map.get(10));
+    assertEquals(e.getKey(), (Integer) 10);
+    assertEquals(e.getValue(), "ten");
+  }
+
+  //
+  // TODO implement this
+  // public void testDescendingMap()
+  // {
+  // NavigableMap<Integer, String> desMap = map.descendingMap();
+  // Set<AbstractMap.Entry<Integer,String>> entrySet1 = map.entrySet();
+  // Set<AbstractMap.Entry<Integer,String>> entrySet2 = desMap.entrySet();
+  // AbstractMap.Entry<Integer,String>[] arr1 = entrySet1.toArray(new
+  // AbstractMap.Entry[0]);
+  // AbstractMap.Entry<Integer,String>[] arr2 = entrySet2.toArray(new
+  // AbstractMap.Entry[0]);
+  //
+  // int size = arr1.length;
+  // assertEquals(arr1.length, arr2.length);
+  // for (int i = 0; i < arr1.length; i++)
+  // {
+  // assertEquals(arr1[i], arr2[size-1-i]);
+  // }
+  // }
+
+  public void testNavigableKeySet() {
+    int size0 = map.size();
+    NavigableSet<Integer> keySet = map.navigableKeySet();
+    int size1 = keySet.size();
+    assertEquals(size0, size1);
+
+    keySet.remove(2);
+    size0 = map.size();
+    size1 = keySet.size();
+    assertEquals(size0, size1);
+    assertNull(map.get(2));
+  }
+
+  // TODO implement this
+  //
+  // public void testDescendingKeySet()
+  // {
+  // Set<Integer> keySet1 = map.keySet();
+  // Set<Integer> keySet2 = map.descendingKeySet();
+  //
+  // Integer[] arr1 = keySet1.toArray(new Integer[0]);
+  // Integer[] arr2 = keySet2.toArray(new Integer[0]);
+  // int size = arr1.length;
+  // assertEquals(arr1.length, arr2.length);
+  // for (int i = 0; i < size; i++)
+  // {
+  // assertEquals(arr1[i],arr2[size-1-i]);
+  // }
+  // }
+
+  public void testSubMap() {
+    SortedMap<Integer, String> subMap = map.subMap(3, 8);
+    assertNotNull(subMap.get(3));
+    assertEquals(subMap.get(3), "three");
+    assertEquals(subMap.get(4), "four");
+    assertNull(subMap.get(5));
+    assertNull(subMap.get(6));
+    assertEquals(subMap.get(7), "seven");
+
+    assertNull(subMap.get(8));
+    assertNull(subMap.get(2));
+    assertNull(subMap.get(9));
+    try {
+      subMap.put(11, "eleven");
+      fail("Inserted entry outside of submap range");
+    } catch (IllegalArgumentException e) {
+      assertNull(subMap.get(11));
+    }
+  }
+
+  public void testSubMap2() {
+    NavigableMap<Integer, String> subMap = map.subMap(3, true, 8, false);
+    assertNotNull(subMap.get(3));
+    assertEquals(subMap.get(3), "three");
+    assertEquals(subMap.get(4), "four");
+    assertNull(subMap.get(5));
+    assertNull(subMap.get(6));
+    assertEquals(subMap.get(7), "seven");
+
+    assertNull(subMap.get(8));
+    assertNull(subMap.get(2));
+    assertNull(subMap.get(9));
+    try {
+      subMap.put(11, "eleven");
+      fail("Inserted entry outside of submap range");
+    } catch (IllegalArgumentException e) {
+      assertNull(subMap.get(11));
+    }
+  }
+
+  public void testSubMap3() {
+    NavigableMap<Integer, String> subMap = map.subMap(2, false, 8, false);
+    assertNotNull(subMap.get(3));
+    assertEquals(subMap.get(3), "three");
+    assertEquals(subMap.get(4), "four");
+    assertNull(subMap.get(5));
+    assertNull(subMap.get(6));
+    assertEquals(subMap.get(7), "seven");
+
+    assertNull(subMap.get(8));
+    assertNull(subMap.get(2));
+    assertNull(subMap.get(9));
+    try {
+      subMap.put(11, "eleven");
+      fail("Inserted entry outside of submap range");
+    } catch (IllegalArgumentException e) {
+      assertNull(subMap.get(11));
+    }
+  }
+
+  public void testSubMap4() {
+    NavigableMap<Integer, String> subMap = map.subMap(3, true, 7, true);
+    assertNotNull(subMap.get(3));
+    assertEquals(subMap.get(3), "three");
+    assertEquals(subMap.get(4), "four");
+    assertNull(subMap.get(5));
+    assertNull(subMap.get(6));
+    assertEquals(subMap.get(7), "seven");
+
+    assertNull(subMap.get(8));
+    assertNull(subMap.get(2));
+    assertNull(subMap.get(9));
+    try {
+      subMap.put(11, "eleven");
+      fail("Inserted entry outside of submap range");
+    } catch (IllegalArgumentException e) {
+      assertNull(subMap.get(11));
+    }
+  }
+
+  public void testHeadMap() {
+    SortedMap<Integer, String> subMap = map.headMap(5);
+    assertEquals(subMap.size(), 4);
+    assertNull(subMap.get(5));
+    assertEquals(subMap.get(1), "one");
+    try {
+      subMap.put(5, "five");
+      fail("Inseted data out of bounds of submap.");
+    } catch (IllegalArgumentException e) {
+      assertNull(subMap.get(5));
+    }
+  }
+
+  public void testHeadMap2() {
+    NavigableMap<Integer, String> subMap = map.headMap(5, false);
+    assertEquals(subMap.size(), 4);
+    assertNull(subMap.get(5));
+    assertEquals(subMap.get(1), "one");
+    try {
+      subMap.put(5, "five");
+      fail("Inseted data out of bounds of submap.");
+    } catch (IllegalArgumentException e) {
+      assertNull(subMap.get(5));
+    }
+  }
+
+  public void testHeadMap3() {
+    NavigableMap<Integer, String> subMap = map.headMap(5, true);
+    assertEquals(subMap.size(), 4);
+    assertNull(subMap.get(5));
+    assertEquals(subMap.get(1), "one");
+    try {
+      subMap.put(5, "five");
+      assertEquals(subMap.get(5), "five");
+    } catch (IllegalArgumentException e) {
+      fail("It was not possible to insert a legal value in a submap.");
+    }
+  }
+
+  public void testHeadMap4() {
+    NavigableMap<Integer, String> subMap = map.headMap(8, true);
+    assertEquals(subMap.size(), 6);
+    assertEquals(subMap.get(8), "eight");
+    assertEquals(subMap.get(1), "one");
+    try {
+      subMap.put(5, "five");
+      assertEquals(subMap.get(5), "five");
+    } catch (IllegalArgumentException e) {
+      fail("It was not possible to insert a legal value in a submap.");
+    }
+  }
+
+  public void testTailMap() {
+    SortedMap<Integer, String> subMap = map.tailMap(5);
+    assertEquals(subMap.size(), 4);
+    assertEquals(subMap.firstKey(), (Integer) 7);
+    assertEquals(subMap.lastKey(), (Integer) 10);
+  }
+
+  public void testTailMap2() {
+    SortedMap<Integer, String> subMap = map.tailMap(7);
+    assertEquals(subMap.size(), 4);
+    assertEquals(subMap.firstKey(), (Integer) 7);
+    assertEquals(subMap.lastKey(), (Integer) 10);
+  }
+
+  public void testTailMap3() {
+    NavigableMap<Integer, String> subMap = map.tailMap(7, false);
+    assertEquals(subMap.size(), 3);
+    assertEquals(subMap.firstKey(), (Integer) 8);
+    assertEquals(subMap.lastKey(), (Integer) 10);
+  }
+
+  public void testTailMap4() {
+    NavigableMap<Integer, String> subMap = map.tailMap(7, true);
+    assertEquals(subMap.size(), 4);
+    assertEquals(subMap.firstKey(), (Integer) 7);
+    assertEquals(subMap.lastKey(), (Integer) 10);
+  }
+
+  public void testIsEmpty() {
+    assertFalse(map.isEmpty());
+    map.clear();
+    assertTrue(map.isEmpty());
+  }
+
+  public void testClearSubmap() {
+    NavigableMap<Integer, String> subMap = map.subMap(7, true, 9, true);
+    subMap.clear();
+    assertEquals(subMap.size(), 0);
+    assertTrue(map.size() == 5);
+    assertNull(map.get(7));
+    assertNull(map.get(8));
+    assertNull(map.get(9));
+  }
+
+  public void testConcurrentModification() {
+    Set<AbstractMap.Entry<Integer, String>> entrySet = map.entrySet();
+    assertTrue(entrySet.size() > 0);
+    try {
+
+      for (AbstractMap.Entry<Integer, String> e : entrySet)
+        entrySet.remove(e);
+
+      fail("No concurrentModificationException was thrown");
+    } catch (ConcurrentModificationException ex) {
+    }
+
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapExclusiveTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapExclusiveTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapExclusiveTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapExclusiveTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,37 @@
+/**
+ * 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.hama.jdbm;
+
+public class BTreeMapNavigableSubMapExclusiveTest extends
+    BTreeMapNavigable2Test {
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    map.put(-1, "-one");
+    map.put(0, "zero");
+    map.put(11, "eleven");
+    map.put(12, "twelve");
+    map = map.subMap(0, false, 11, false);
+  }
+
+  @Override
+  public void testPut() {
+    // this test is not run on submaps
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapInclusiveTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapInclusiveTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapInclusiveTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableSubMapInclusiveTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.hama.jdbm;
+
+public class BTreeMapNavigableSubMapInclusiveTest extends
+    BTreeMapNavigable2Test {
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    map.put(0, "zero");
+    map.put(11, "eleven");
+    map = map.subMap(1, true, 10, true);
+  }
+
+  @Override
+  public void testPut() {
+    // this test is not run on submaps
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeMapNavigableTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,309 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.NavigableSet;
+import java.util.SortedMap;
+
+/**
+ * to test {@link NavigableMap} implementation
+ * 
+ */
+public class BTreeMapNavigableTest extends TestCaseWithTestFile {
+
+  private static final String MUST_NOT_CONTAINS_KD = "must not contains 'kd'";
+
+  private static final String MUST_NOT_CONTAINS_KA = "must not contains 'ka'";
+
+  private static final String BAD_FIRST_ENTRY_KEY = "bad first entry key";
+
+  private static final String MUST_NOT_BE_EMPTY = "must not be empty";
+
+  private static final String BAD_SIZE = "bad size";
+
+  private static final String MUST_CONTAINS_KC = "must contains 'kc'";
+
+  private static final String MUST_CONTAINS_KB = "must contains 'kb'";
+
+  private static final String MUST_CONTAINS_KA = "must contains 'ka'";
+
+  private NavigableMap<String, String> navigableMap;
+
+  public void setUp() throws IOException {
+    navigableMap = newDBCache().createTreeMap("test");
+  }
+
+  public void testLowerEntry() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    final Entry<String, String> lowerEntry = navigableMap.lowerEntry("kb");
+    assertEquals("bad lower entry value", "xx", lowerEntry.getValue());
+    assertEquals("bad lower entry key", "ka", lowerEntry.getKey());
+  }
+
+  public void testLowerKey() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    assertEquals("bad lower key", "ka", navigableMap.lowerKey("kb"));
+  }
+
+  public void testFloorEntry() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kc", "aa");
+    navigableMap.put("kd", "zz");
+    Entry<String, String> floorEntry = navigableMap.floorEntry("ka");
+    assertEquals("bad floor entry value", "xx", floorEntry.getValue());
+    assertEquals("bad floor entry key", "ka", floorEntry.getKey());
+    floorEntry = navigableMap.floorEntry("kb");
+    assertEquals("bad floor entry value", "xx", floorEntry.getValue());
+    assertEquals("bad floor entry key", "ka", floorEntry.getKey());
+  }
+
+  public void testFloorKey() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kc", "aa");
+    navigableMap.put("kd", "zz");
+    assertEquals("bad floor key", "ka", navigableMap.floorKey("ka"));
+    assertEquals("bad floor key", "ka", navigableMap.floorKey("kb"));
+  }
+
+  public void testCeilingEntry() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kd", "zz");
+    Entry<String, String> ceilingEntry = navigableMap.ceilingEntry("kd");
+    assertEquals("bad ceiling entry value", "zz", ceilingEntry.getValue());
+    assertEquals("bad ceiling entry key", "kd", ceilingEntry.getKey());
+    ceilingEntry = navigableMap.ceilingEntry("kc");
+    assertEquals("bad ceiling entry value", "zz", ceilingEntry.getValue());
+    assertEquals("bad ceiling entry key", "kd", ceilingEntry.getKey());
+  }
+
+  public void testCeilingKey() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kd", "zz");
+    assertEquals("bad ceiling key", "kd", navigableMap.ceilingKey("kd"));
+    assertEquals("bad ceiling key", "kd", navigableMap.ceilingKey("kc"));
+  }
+
+  public void testHigherEntry() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    final Entry<String, String> higherEntry = navigableMap.higherEntry("kb");
+    assertEquals("bad higher entry value", "zz", higherEntry.getValue());
+    assertEquals("bad higher entry key", "kc", higherEntry.getKey());
+  }
+
+  public void testHigherKey() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    assertEquals("bad higher key", "kc", navigableMap.higherKey("kb"));
+  }
+
+  public void testFirstEntry() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    final Entry<String, String> firstEntry = navigableMap.firstEntry();
+    assertEquals("bad first entry value", "xx", firstEntry.getValue());
+    assertEquals(BAD_FIRST_ENTRY_KEY, "ka", firstEntry.getKey());
+  }
+
+  public void testLastEntry() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    final Entry<String, String> lastEntry = navigableMap.lastEntry();
+    assertEquals("bad last entry value", "zz", lastEntry.getValue());
+    assertEquals("bad last entry key", "kc", lastEntry.getKey());
+  }
+
+  public void testPollFirstEntry() {
+    assertNull("must not have first entry", navigableMap.pollFirstEntry());
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    assertEquals("must have 3 entries", 3, navigableMap.size());
+    final Entry<String, String> firstEntry = navigableMap.pollFirstEntry();
+    assertNotNull("must have first entry", firstEntry);
+    assertEquals("bad first entry value", "xx", firstEntry.getValue());
+    assertEquals(BAD_FIRST_ENTRY_KEY, "ka", firstEntry.getKey());
+    assertEquals("must have 2 entries", 2, navigableMap.size());
+  }
+
+  public void testPollLastEntry() {
+    assertNull("must not have last entry", navigableMap.pollLastEntry());
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    assertEquals("must have 3 entries", 3, navigableMap.size());
+    final Entry<String, String> lastEntry = navigableMap.pollLastEntry();
+    assertNotNull("must have last entry", lastEntry);
+    assertEquals("bad last entry value", "zz", lastEntry.getValue());
+    assertEquals("bad last entry key", "kc", lastEntry.getKey());
+    assertEquals("must have 2 entries", 2, navigableMap.size());
+  }
+
+  // TODO implement this
+  //
+  // public void testDescendingMap() {
+  // navigableMap.put("ka", "xx");
+  // navigableMap.put("kb", "aa");
+  // navigableMap.put("kc", "zz");
+  // final NavigableMap<String, String> descendingMap = navigableMap
+  // .descendingMap();
+  //
+  // assertEquals(BAD_SIZE, 3, descendingMap.size());
+  // assertFalse(MUST_NOT_BE_EMPTY, descendingMap.isEmpty());
+  //
+  // final Entry<String, String> firstEntry = descendingMap.firstEntry();
+  // assertEquals("bad first entry value", "zz", firstEntry.getValue());
+  // assertEquals(BAD_FIRST_ENTRY_KEY, "kc", firstEntry.getKey());
+  //
+  // final Entry<String, String> lastEntry = descendingMap.lastEntry();
+  // assertEquals("bad last entry value", "xx", lastEntry.getValue());
+  // assertEquals("bad last entry key", "ka", lastEntry.getKey());
+  //
+  // final Set<Entry<String, String>> entrySet = descendingMap.entrySet();
+  // final Iterator<Entry<String, String>> iterator = entrySet.iterator();
+  // assertTrue("must have first entry", iterator.hasNext());
+  // assertEquals(BAD_FIRST_ENTRY_KEY, "kc", iterator.next().getKey());
+  // assertTrue("must have second entry", iterator.hasNext());
+  // assertEquals("bad second entry key", "kb", iterator.next().getKey());
+  // assertTrue("must have third entry", iterator.hasNext());
+  // assertEquals("bad third entry key", "ka", iterator.next().getKey());
+  // assertFalse("must not have fourth entry", iterator.hasNext());
+  //
+  // descendingMap.remove("kb");
+  // assertEquals(BAD_SIZE, 2, descendingMap.size());
+  // assertFalse(MUST_NOT_BE_EMPTY, descendingMap.isEmpty());
+  //
+  // assertEquals(BAD_SIZE, 2, navigableMap.size());
+  // assertFalse(MUST_NOT_BE_EMPTY, navigableMap.isEmpty());
+  // assertTrue("must contains key 'ka'", navigableMap.containsKey("ka"));
+  // assertFalse("must not contains key 'kb'", navigableMap
+  // .containsKey("kb"));
+  // assertTrue("must contains key 'kc'", navigableMap.containsKey("kc"));
+  // }
+
+  public void testNavigableKeySet() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    final NavigableSet<String> navigableSet = navigableMap.navigableKeySet();
+    assertEquals("bad first element", "ka", navigableSet.first());
+    assertEquals("bad last element", "kc", navigableSet.last());
+    assertTrue(MUST_CONTAINS_KA, navigableSet.contains("ka"));
+    assertTrue(MUST_CONTAINS_KB, navigableSet.contains("kb"));
+    assertTrue(MUST_CONTAINS_KC, navigableSet.contains("kc"));
+
+    navigableSet.remove("kb");
+    assertEquals(BAD_SIZE, 2, navigableMap.size());
+    assertFalse(MUST_NOT_BE_EMPTY, navigableMap.isEmpty());
+    assertTrue("must contains key 'ka'", navigableMap.containsKey("ka"));
+    assertFalse("must not contains key 'kb'", navigableMap.containsKey("kb"));
+    assertTrue("must contains key 'kc'", navigableMap.containsKey("kc"));
+  }
+
+  // TODO implement this
+  // public void testDescendingKeySet() {
+  // navigableMap.put("ka", "xx");
+  // navigableMap.put("kb", "aa");
+  // navigableMap.put("kc", "zz");
+  // final NavigableSet<String> navigableSet = navigableMap
+  // .descendingKeySet();
+  // assertEquals("bad first element", "kc", navigableSet.first());
+  // assertEquals("bad last element", "ka", navigableSet.last());
+  // assertTrue(MUST_CONTAINS_KA, navigableSet.contains("ka"));
+  // assertTrue(MUST_CONTAINS_KB, navigableSet.contains("kb"));
+  // assertTrue(MUST_CONTAINS_KC, navigableSet.contains("kc"));
+  //
+  // navigableSet.remove("kb");
+  // assertEquals(BAD_SIZE, 2, navigableMap.size());
+  // assertFalse(MUST_NOT_BE_EMPTY, navigableMap.isEmpty());
+  // assertTrue("must contains key 'ka'", navigableMap.containsKey("ka"));
+  // assertFalse("must not contains key 'kb'", navigableMap
+  // .containsKey("kb"));
+  // assertTrue("must contains key 'kc'", navigableMap.containsKey("kc"));
+  // }
+
+  public void testSubMap() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    navigableMap.put("kd", "uu");
+
+    SortedMap<String, String> sortedMap = navigableMap.subMap("kb", "kd");
+    assertFalse(MUST_NOT_CONTAINS_KA, sortedMap.containsKey("ka"));
+    assertTrue(MUST_CONTAINS_KB, sortedMap.containsKey("kb"));
+    assertTrue(MUST_CONTAINS_KC, sortedMap.containsKey("kc"));
+    assertFalse(MUST_NOT_CONTAINS_KD, sortedMap.containsKey("kd"));
+
+    sortedMap = navigableMap.subMap("ka", false, "kc", true);
+    assertFalse(MUST_NOT_CONTAINS_KA, sortedMap.containsKey("ka"));
+    assertTrue(MUST_CONTAINS_KB, sortedMap.containsKey("kb"));
+    assertTrue(MUST_CONTAINS_KC, sortedMap.containsKey("kc"));
+    assertFalse(MUST_NOT_CONTAINS_KD, sortedMap.containsKey("kd"));
+  }
+
+  public void testHeadMap() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    navigableMap.put("kd", "uu");
+
+    SortedMap<String, String> sortedMap = navigableMap.headMap("kc");
+    assertTrue(MUST_CONTAINS_KA, sortedMap.containsKey("ka"));
+    assertTrue(MUST_CONTAINS_KB, sortedMap.containsKey("kb"));
+    assertFalse("must not contains 'kc'", sortedMap.containsKey("kc"));
+    assertFalse(MUST_NOT_CONTAINS_KD, sortedMap.containsKey("kd"));
+
+    sortedMap = navigableMap.headMap("kb", true);
+    assertTrue(MUST_CONTAINS_KA, sortedMap.containsKey("ka"));
+    assertTrue(MUST_CONTAINS_KB, sortedMap.containsKey("kb"));
+    assertFalse("must not contains 'kc'", sortedMap.containsKey("kc"));
+    assertFalse(MUST_NOT_CONTAINS_KD, sortedMap.containsKey("kd"));
+  }
+
+  public void testTailMap() {
+    navigableMap.put("ka", "xx");
+    navigableMap.put("kb", "aa");
+    navigableMap.put("kc", "zz");
+    navigableMap.put("kd", "uu");
+
+    SortedMap<String, String> sortedMap = navigableMap.tailMap("kc");
+    assertFalse(MUST_NOT_CONTAINS_KA, sortedMap.containsKey("ka"));
+    assertFalse("must not contains 'kb'", sortedMap.containsKey("kb"));
+    assertTrue(MUST_CONTAINS_KC, sortedMap.containsKey("kc"));
+    assertTrue("must contains 'kd'", sortedMap.containsKey("kd"));
+
+    sortedMap = navigableMap.tailMap("kb", false);
+    assertFalse(MUST_NOT_CONTAINS_KA, sortedMap.containsKey("ka"));
+    assertFalse("must not contains 'kb'", sortedMap.containsKey("kb"));
+    assertTrue(MUST_CONTAINS_KC, sortedMap.containsKey("kc"));
+    assertTrue("must contains 'kd'", sortedMap.containsKey("kd"));
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeNodeTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeNodeTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeNodeTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeNodeTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,69 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+
+/**
+ * This class contains all Unit tests for {@link BTreeNode}.
+ */
+public class BTreeNodeTest extends TestCaseWithTestFile {
+
+  /**
+   * Basic tests
+   */
+  public void testBasics() throws IOException {
+    DBAbstract db;
+    String test, test1, test2, test3;
+
+    test = "test";
+    test1 = "test1";
+    test2 = "test2";
+    test3 = "test3";
+
+    db = newDBCache();
+
+    BTree tree = BTree.createInstance(db);
+
+    BTreeNode node = new BTreeNode(tree, test, test);
+
+    BTree.BTreeTupleBrowser browser;
+    BTree.BTreeTuple tuple = new BTree.BTreeTuple();
+
+    // test insertion
+    node.insert(1, test2, test2, false);
+    node.insert(1, test3, test3, false);
+    node.insert(1, test1, test1, false);
+
+    // test binary search
+    browser = node.find(1, test2, true);
+    if (browser.getNext(tuple) == false) {
+      throw new IllegalStateException("Browser didn't have 'test2'");
+    }
+    if (!tuple.key.equals(test2)) {
+      throw new IllegalStateException("Tuple key is not 'test2'");
+    }
+    if (!tuple.value.equals(test2)) {
+      throw new IllegalStateException("Tuple value is not 'test2'");
+    }
+
+    db.close();
+    db = null;
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeSetTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeSetTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeSetTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/BTreeSetTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,316 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.SortedSet;
+
+/**
+ * Tests for TreeSet which comes with JDBM. Original code comes from Apache
+ * Harmony, Modified by Jan Kotek for use in JDBM
+ */
+public class BTreeSetTest extends TestCaseWithTestFile {
+
+  private DB db;
+
+  public static class ReversedIntegerComparator implements Comparator,
+      Serializable {
+    public int compare(Object o1, Object o2) {
+      return -(((Integer) o1).compareTo((Integer) o2));
+    }
+
+    public boolean equals(Object o1, Object o2) {
+      return ((Integer) o1).compareTo((Integer) o2) == 0;
+    }
+
+  }
+
+  SortedSet<Object> ts;
+
+  Object objArray[] = new Object[1000];
+
+  /**
+   * @tests java.util.TreeSet#TreeSet()
+   */
+  public void test_Constructor() {
+    // Test for method java.util.TreeSet()
+    assertTrue("Did not construct correct TreeSet", db.createTreeSet("test")
+        .isEmpty());
+  }
+
+  /**
+   * @tests java.util.TreeSet#TreeSet(java.util.Comparator)
+   */
+  public void test_ConstructorLjava_util_Comparator() {
+    // Test for method java.util.TreeSet(java.util.Comparator)
+    SortedSet myTreeSet = db.createTreeSet("test",
+        new ReversedIntegerComparator(), null);
+    assertTrue("Did not construct correct TreeSet", myTreeSet.isEmpty());
+    myTreeSet.add(new Integer(1));
+    myTreeSet.add(new Integer(2));
+    assertTrue(
+        "Answered incorrect first element--did not use custom comparator ",
+        myTreeSet.first().equals(new Integer(2)));
+    assertTrue(
+        "Answered incorrect last element--did not use custom comparator ",
+        myTreeSet.last().equals(new Integer(1)));
+  }
+
+  /**
+   * @tests java.util.TreeSet#TreeSet(java.util.SortedSet)
+   */
+  public void test_ConstructorLjava_util_SortedSet() {
+    // Test for method java.util.TreeSet(java.util.SortedSet)
+    ReversedIntegerComparator comp = new ReversedIntegerComparator();
+    SortedSet myTreeSet = db.createTreeSet("test", comp, null);
+    for (int i = 0; i < objArray.length; i++)
+      myTreeSet.add(objArray[i]);
+    SortedSet anotherTreeSet = db.getTreeSet("test");
+    anotherTreeSet.addAll(myTreeSet);
+    assertTrue("TreeSet is not correct size",
+        anotherTreeSet.size() == objArray.length);
+    for (int counter = 0; counter < objArray.length; counter++)
+      assertTrue("TreeSet does not contain correct elements",
+          anotherTreeSet.contains(objArray[counter]));
+    assertEquals("TreeSet does not answer correct comparator", anotherTreeSet
+        .comparator().getClass(), comp.getClass());
+    assertEquals("TreeSet does not use comparator", anotherTreeSet.first(),
+        objArray[objArray.length - 1]);
+  }
+
+  /**
+   * @tests java.util.TreeSet#add(java.lang.Object)
+   */
+  public void test_addLjava_lang_Object() {
+    // Test for method boolean java.util.TreeSet.add(java.lang.Object)
+    ts.add(new Integer(-8));
+    assertTrue("Failed to add Object", ts.contains(new Integer(-8)));
+    ts.add(objArray[0]);
+    assertTrue("Added existing element", ts.size() == objArray.length + 1);
+
+  }
+
+  /**
+   * @tests java.util.TreeSet#addAll(java.util.Collection)
+   */
+  public void test_addAllLjava_util_Collection() {
+    // Test for method boolean
+    // java.util.TreeSet.addAll(java.util.Collection)
+    SortedSet s = db.createTreeSet("test");
+    s.addAll(ts);
+    assertTrue("Incorrect size after add", s.size() == ts.size());
+    Iterator i = ts.iterator();
+    while (i.hasNext())
+      assertTrue("Returned incorrect set", s.contains(i.next()));
+
+  }
+
+  /**
+   * @tests java.util.TreeSet#clear()
+   */
+  public void test_clear() {
+    // Test for method void java.util.TreeSet.clear()
+    ts.clear();
+    assertEquals("Returned non-zero size after clear", 0, ts.size());
+    assertTrue("Found element in cleared set", !ts.contains(objArray[0]));
+  }
+
+  /**
+   * @tests java.util.TreeSet#comparator()
+   */
+  public void test_comparator() {
+    // Test for method java.util.Comparator java.util.TreeSet.comparator()
+    ReversedIntegerComparator comp = new ReversedIntegerComparator();
+    SortedSet myTreeSet = db.createTreeSet("test", comp, null);
+    assertTrue("Answered incorrect comparator", myTreeSet.comparator() == comp);
+  }
+
+  /**
+   * @tests java.util.TreeSet#contains(java.lang.Object)
+   */
+  public void test_containsLjava_lang_Object() {
+    // Test for method boolean java.util.TreeSet.contains(java.lang.Object)
+    assertTrue("Returned false for valid Object",
+        ts.contains(objArray[objArray.length / 2]));
+    assertTrue("Returned true for invalid Object",
+        !ts.contains(new Integer(-9)));
+  }
+
+  /**
+   * @tests java.util.TreeSet#first()
+   */
+  public void test_first() {
+
+    // Test for method java.lang.Object java.util.TreeSet.first()
+    assertEquals("Returned incorrect first element", ts.first(), objArray[0]);
+  }
+
+  /**
+   * @tests java.util.TreeSet#headSet(java.lang.Object)
+   */
+  public void test_headSetLjava_lang_Object() {
+    // Test for method java.util.SortedSet
+    // java.util.TreeSet.headSet(java.lang.Object)
+    Set s = ts.headSet(new Integer(100));
+    assertEquals("Returned set of incorrect size", 100, s.size());
+    for (int i = 0; i < 100; i++)
+      assertTrue("Returned incorrect set", s.contains(objArray[i]));
+  }
+
+  /**
+   * @tests java.util.TreeSet#isEmpty()
+   */
+  public void test_isEmpty() {
+    // Test for method boolean java.util.TreeSet.isEmpty()
+    assertTrue("Empty set returned false", db.createTreeSet("test").isEmpty());
+    assertTrue("Non-Empty returned true", !ts.isEmpty());
+  }
+
+  /**
+   * @tests java.util.TreeSet#iterator()
+   */
+  public void test_iterator() {
+    // Test for method java.util.Iterator java.util.TreeSet.iterator()
+    SortedSet s = db.createTreeSet("test");
+    s.addAll(ts);
+    Iterator i = ts.iterator();
+    Set as = new HashSet(Arrays.asList(objArray));
+    while (i.hasNext())
+      as.remove(i.next());
+    assertEquals("Returned incorrect iterator", 0, as.size());
+
+  }
+
+  /**
+   * @tests java.util.TreeSet#last()
+   */
+  public void test_last() {
+    // Test for method java.lang.Object java.util.TreeSet.last()
+    assertEquals("Returned incorrect last element", ts.last(),
+        objArray[objArray.length - 1]);
+  }
+
+  /**
+   * @tests java.util.TreeSet#remove(java.lang.Object)
+   */
+  public void test_removeLjava_lang_Object() {
+    // Test for method boolean java.util.TreeSet.remove(java.lang.Object)
+    ts.remove(objArray[0]);
+    assertTrue("Failed to remove object", !ts.contains(objArray[0]));
+    assertTrue("Failed to change size after remove",
+        ts.size() == objArray.length - 1);
+  }
+
+  /**
+   * @tests java.util.TreeSet#size()
+   */
+  public void test_size() {
+    // Test for method int java.util.TreeSet.size()
+    assertTrue("Returned incorrect size", ts.size() == objArray.length);
+  }
+
+  /**
+   * @tests java.util.TreeSet#subSet(java.lang.Object, java.lang.Object)
+   */
+  public void test_subSetLjava_lang_ObjectLjava_lang_Object() {
+    // Test for method java.util.SortedSet
+    // java.util.TreeSet.subSet(java.lang.Object, java.lang.Object)
+    final int startPos = objArray.length / 4;
+    final int endPos = 3 * objArray.length / 4;
+    SortedSet aSubSet = ts.subSet(objArray[startPos], objArray[endPos]);
+    assertTrue("Subset has wrong number of elements",
+        aSubSet.size() == (endPos - startPos));
+    for (int counter = startPos; counter < endPos; counter++)
+      assertTrue("Subset does not contain all the elements it should",
+          aSubSet.contains(objArray[counter]));
+
+    int result;
+    try {
+      ts.subSet(objArray[3], objArray[0]);
+      result = 0;
+    } catch (IllegalArgumentException e) {
+      result = 1;
+    }
+    assertEquals("end less than start should throw", 1, result);
+  }
+
+  /**
+   * @tests java.util.TreeSet#tailSet(java.lang.Object)
+   */
+  public void test_tailSetLjava_lang_Object() {
+    // Test for method java.util.SortedSet
+    // java.util.TreeSet.tailSet(java.lang.Object)
+    Set s = ts.tailSet(new Integer(900));
+    assertEquals("Returned set of incorrect size", 100, s.size());
+    for (int i = 900; i < objArray.length; i++)
+      assertTrue("Returned incorrect set", s.contains(objArray[i]));
+  }
+
+  /**
+   * Tests equals() method. Tests that no ClassCastException will be thrown in
+   * all cases. Regression test for HARMONY-1639.
+   */
+  public void test_equals() throws Exception {
+    // comparing TreeSets with different object types
+    Set s1 = db.createTreeSet("test1");
+    Set s2 = db.createTreeSet("test2");
+    s1.add("key1");
+    s1.add("key2");
+    s2.add(new Integer(1));
+    s2.add(new Integer(2));
+    assertFalse("Sets should not be equal 1", s1.equals(s2));
+    assertFalse("Sets should not be equal 2", s2.equals(s1));
+
+    // comparing TreeSet with HashSet
+    s1 = db.createTreeSet("test");
+    s2 = new HashSet();
+    s1.add("key");
+    s2.add(new Object());
+    assertFalse("Sets should not be equal 3", s1.equals(s2));
+    assertFalse("Sets should not be equal 4", s2.equals(s1));
+
+  }
+
+  /**
+   * Sets up the fixture, for example, open a network connection. This method is
+   * called before a test is executed.
+   */
+  public void setUp() throws Exception {
+    super.setUp();
+    db = newDBNoCache();
+    ts = db.createTreeSet("testBTreeSet");
+    for (int i = 0; i < objArray.length; i++) {
+      Object x = objArray[i] = new Integer(i);
+      ts.add(x);
+    }
+  }
+
+  /**
+   * Tears down the fixture, for example, close a network connection. This
+   * method is called after a test is executed.
+   */
+  public void tearDown() throws Exception {
+    db.close();
+    super.tearDown();
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ByteArrayComparator.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ByteArrayComparator.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ByteArrayComparator.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ByteArrayComparator.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,98 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Comparator for byte arrays.
+ * 
+ */
+public final class ByteArrayComparator implements Comparator<byte[]>,
+    Serializable {
+
+  /**
+   * Version id for serialization.
+   */
+  final static long serialVersionUID = 1L;
+
+  /**
+   * Compare two objects.
+   * 
+   * @param obj1 First object
+   * @param obj2 Second object
+   * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2, and a
+   *         negative integer if obj1 < obj2
+   */
+  public int compare(byte[] obj1, byte[] obj2) {
+    if (obj1 == null) {
+      throw new IllegalArgumentException("Argument 'obj1' is null");
+    }
+
+    if (obj2 == null) {
+      throw new IllegalArgumentException("Argument 'obj2' is null");
+    }
+
+    return compareByteArray(obj1, obj2);
+  }
+
+  /**
+   * Compare two byte arrays.
+   */
+  public static int compareByteArray(byte[] thisKey, byte[] otherKey) {
+    int len = Math.min(thisKey.length, otherKey.length);
+
+    // compare the byte arrays
+    for (int i = 0; i < len; i++) {
+      if (thisKey[i] >= 0) {
+        if (otherKey[i] >= 0) {
+          // both positive
+          if (thisKey[i] < otherKey[i]) {
+            return -1;
+          } else if (thisKey[i] > otherKey[i]) {
+            return 1;
+          }
+        } else {
+          // otherKey is negative => greater (because MSB is 1)
+          return -1;
+        }
+      } else {
+        if (otherKey[i] >= 0) {
+          // thisKey is negative => greater (because MSB is 1)
+          return 1;
+        } else {
+          // both negative
+          if (thisKey[i] < otherKey[i]) {
+            return -1;
+          } else if (thisKey[i] > otherKey[i]) {
+            return 1;
+          }
+        }
+      }
+    }
+    if (thisKey.length == otherKey.length) {
+      return 0;
+    }
+    if (thisKey.length < otherKey.length) {
+      return -1;
+    }
+    return 1;
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/CompactTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/CompactTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/CompactTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/CompactTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,94 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class CompactTest extends TestCaseWithTestFile {
+
+  final int MAX = 1000 * 1000;
+
+  public void testHashCompaction() throws IOException {
+
+    String f = newTestFile();
+
+    DB db0 = DBMaker.openFile(f).disableTransactions().make();
+    Map<String, String> db = db0.createHashMap("db");
+
+    System.out.println("Adding");
+    for (int i = 0; i < MAX; i++) {
+      db.put("key" + i, "value" + i);
+    }
+
+    db0.close();
+    db0 = DBMaker.openFile(f).disableTransactions().make();
+    db = db0.getHashMap("db");
+
+    System.out.println("Deleting");
+    for (int i = 0; i < MAX; i++) {
+      db.remove("key" + i);
+    }
+
+    db0.close();
+    db0 = DBMaker.openFile(f).disableTransactions().make();
+    db = db0.getHashMap("db");
+
+    System.out.println("Adding");
+    for (int i = 0; i < MAX; i++) {
+      db.put("key" + i, "value" + i);
+    }
+    System.out.println("Closing");
+    db0.close();
+  }
+
+  public void testBTreeCompaction() throws IOException {
+
+    String f = newTestFile();
+
+    DB db0 = DBMaker.openFile(f).disableTransactions().make();
+    Map<String, String> db = db0.createTreeMap("db");
+
+    System.out.println("Adding");
+    for (int i = 0; i < MAX; i++) {
+      db.put("key" + i, "value" + i);
+    }
+
+    db0.close();
+    db0 = DBMaker.openFile(f).disableTransactions().make();
+    db = db0.getTreeMap("db");
+
+    System.out.println("Deleting");
+    for (int i = 0; i < MAX; i++) {
+      db.remove("key" + i);
+    }
+
+    db0.close();
+    db0 = DBMaker.openFile(f).disableTransactions().make();
+    db = db0.getTreeMap("db");
+
+    System.out.println("Adding");
+    for (int i = 0; i < MAX; i++) {
+      db.put("key" + i, "value" + i);
+    }
+
+    System.out.println("Closing");
+    db0.close();
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ConcurrentBTreeReadTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ConcurrentBTreeReadTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ConcurrentBTreeReadTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/ConcurrentBTreeReadTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,139 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Random;
+
+public class ConcurrentBTreeReadTest extends TestCaseWithTestFile {
+
+  public static class Dummy implements Serializable {
+
+    private static final long serialVersionUID = -5567451291089724793L;
+    private long key;
+    @SuppressWarnings("unused")
+    private byte space[] = new byte[1024];
+
+    public Dummy() {
+    }
+
+    public Dummy(long key) {
+      this.key = key;
+    }
+
+    @Override
+    public int hashCode() {
+      return (int) key;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (!(obj instanceof Dummy))
+        return false;
+      Dummy other = (Dummy) obj;
+      if (key != other.key)
+        return false;
+      return true;
+    }
+
+  }
+
+  private DBAbstract db;
+
+  private BTree btree;
+
+  private int entries = 20000;
+
+  private int readers = 5;
+
+  public void setUp() throws Exception {
+    super.setUp();
+    db = newDBCache();
+    btree = BTree.createInstance(db, (Comparator) Collections.reverseOrder(),
+        null, null, true);
+    System.err.println(db.getClass());
+  }
+
+  public void testConcurrent() throws Exception {
+    Runnable read = new Runnable() {
+
+      public void run() {
+        read();
+      }
+
+    };
+    Thread t[] = new Thread[readers];
+    int c = 0;
+    for (int i = 0; i < entries; i++) {
+      btree.insert((long) i, new Dummy(i), false);
+      if (i % 1000 == 0) {
+        System.err.println("count " + i);
+        commit();
+      }
+    }
+    System.err.println("done!");
+    commit();
+    System.gc();
+    Thread.sleep(1000);
+
+    for (int i = 0; i < readers; i++) {
+      t[c++] = new Thread(read);
+    }
+
+    System.err.println("start readers");
+    long start = System.currentTimeMillis();
+    for (int i = 0; i < t.length; i++) {
+      t[i].start();
+    }
+    for (int i = 0; i < t.length; i++) {
+      t[i].join();
+    }
+    long end = System.currentTimeMillis();
+    System.err.println("done " + (end - start) + "ms");
+  }
+
+  private Object fetch(Long id) throws IOException {
+    try {
+      return btree.get(id);
+    } catch (IOException e) {
+      System.out.println("ERR " + id);
+      e.printStackTrace();
+      return null;
+    }
+  }
+
+  private void commit() throws IOException {
+    db.commit();
+  }
+
+  private void read() {
+    Random r = new Random();
+    for (int i = 0; i < entries; i++) {
+      try {
+        fetch((long) r.nextInt(entries));
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    System.err.println("done read");
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheMRUTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheMRUTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheMRUTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheMRUTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,58 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class DBCacheMRUTest extends TestCaseWithTestFile {
+
+  public void testPurgeEntryClearsCache() throws IOException {
+    DBCacheMRU d = (DBCacheMRU) newDBCache();
+
+    for (long i = 0; i < 1e3; i++)
+      d.addEntry(newEntry(i));
+
+    for (long i = 0; i < 1e3; i++)
+      d.purgeEntry();
+
+    assertEquals(d._hash.size(), 0);
+  }
+
+  DBCacheMRU.CacheEntry newEntry(long i) {
+    return new DBCacheMRU.CacheEntry(i, i);
+  }
+
+  public void testCacheMaxSize() throws IOException {
+
+    DBCacheMRU d = (DBCacheMRU) DBMaker.openFile(newTestFile())
+        .setMRUCacheSize(100).make();
+
+    ArrayList<Long> recids = new ArrayList<Long>();
+    for (int i = 0; i < 1e5; i++) {
+      recids.add(d.insert("aa" + i));
+    }
+    d.commit();
+    for (int i = 0; i < 1e5; i++) {
+      d.fetch(recids.get(i));
+    }
+
+    assert (d._hash.size() <= 100);
+
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBCacheTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,74 @@
+/**
+ * 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.hama.jdbm;
+
+import java.util.Map;
+import java.util.Set;
+
+public class DBCacheTest extends TestCaseWithTestFile {
+
+  // https://github.com/jankotek/JDBM3/issues/11
+  public void test_Issue_11_soft_cache_record_disappear() {
+    long MAX = (long) 1e6;
+
+    String file = newTestFile();
+    DB d = DBMaker.openFile(file).disableTransactions().enableSoftCache()
+        .make();
+
+    Set<Integer> set = d.createHashSet("1");
+
+    for (Integer i = 0; i < MAX; i++) {
+      set.add(i);
+    }
+
+    d.close();
+
+    d = DBMaker.openFile(file).disableTransactions().enableSoftCache().make();
+
+    set = d.getHashSet("1");
+    for (Integer i = 0; i < MAX; i++) {
+      assertTrue(set.contains(i));
+    }
+
+  }
+
+  public void test_issue_xyz() {
+    org.apache.hama.jdbm.DB db = DBMaker.openFile(newTestFile()).enableSoftCache()
+        .make();
+    Map m = db.createTreeMap("test");
+
+    for (int i = 0; i < 1e5; i++) {
+      m.put("test" + i, "test" + i);
+    }
+    db.close();
+    //
+    // problem in cache, throws;
+    // java.lang.IllegalArgumentException: Argument 'recid' is invalid: 0
+    // at org.apache.jdbm.DBStore.fetch(DBStore.java:356)
+    // at org.apache.jdbm.DBCache.fetch(DBCache.java:292)
+    // at org.apache.jdbm.BTreeNode.loadNode(BTreeNode.java:833)
+    // at org.apache.jdbm.BTreeNode.insert(BTreeNode.java:391)
+    // at org.apache.jdbm.BTreeNode.insert(BTreeNode.java:392)
+    // at org.apache.jdbm.BTreeNode.insert(BTreeNode.java:392)
+    // at org.apache.jdbm.BTree.insert(BTree.java:281)
+    // at org.apache.jdbm.BTreeMap.put(BTreeMap.java:285)
+    // at org.apache.jdbm.DBCacheTest.test_some_random_shit(DBCacheTest.java:48)
+    //
+
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBMakerTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBMakerTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBMakerTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBMakerTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+import java.util.Set;
+
+public class DBMakerTest extends TestCaseWithTestFile {
+
+  public void testMemory() throws IOException {
+    DBStore db = (DBStore) DBMaker.openMemory().disableCache().make();
+
+    long recid = db.insert("aaa");
+    db.commit();
+    db.update(recid, "bbb");
+    db.rollback();
+    assertEquals("aaa", db.fetch(recid));
+
+    db.close();
+
+    db = (DBStore) DBMaker.openMemory().disableCache().make();
+
+    // this will fail if 'test' already exists
+    try {
+      db.fetch(recid);
+      fail("record should not exist");
+    } catch (Throwable e) {
+      // ignore
+    }
+
+  }
+
+  public void testDisk() throws IOException {
+    DBStore db = (DBStore) DBMaker.openFile(newTestFile()).disableCache()
+        .make();
+
+    long recid = db.insert("aaa");
+    db.commit();
+    db.update(recid, "bbb");
+    db.rollback();
+    assertEquals("aaa", db.fetch(recid));
+
+    db.close();
+  }
+
+  public void testEncrypt() {
+    String file = newTestFile();
+    DB db = DBMaker.openFile(file).enableEncryption("password", false).make();
+
+    Set l = db.createHashSet("test");
+    for (int i = 0; i < 10000; i++) {
+      l.add("aa" + i);
+    }
+    db.commit();
+    db.close();
+    db = DBMaker.openFile(file).enableEncryption("password", false).make();
+    l = db.getHashSet("test");
+    for (int i = 0; i < 10000; i++) {
+      assertTrue(l.contains("aa" + i));
+    }
+    db.close();
+
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DBTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,462 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.File;
+import java.io.IOError;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * This class contains all Unit tests for {@link DBAbstract}.
+ */
+public class DBTest extends TestCaseWithTestFile {
+
+  /**
+   * Test constructor
+   */
+  public void testCtor() throws Exception {
+    DB db;
+
+    db = newDBCache();
+    db.close();
+  }
+
+  /**
+   * Test basics
+   */
+  public void testBasics() throws Exception {
+
+    DBAbstract db = newDBCache();
+
+    // insert a 10,000 byte record.
+    byte[] data = UtilTT.makeRecord(10000, (byte) 1);
+    long rowid = db.insert(data);
+    assertTrue("check data1",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid), 10000, (byte) 1));
+
+    // update it as a 20,000 byte record.
+    data = UtilTT.makeRecord(20000, (byte) 2);
+    db.update(rowid, data);
+    assertTrue("check data2",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid), 20000, (byte) 2));
+
+    // insert a third record.
+    data = UtilTT.makeRecord(20, (byte) 3);
+    long rowid2 = db.insert(data);
+    assertTrue("check data3",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid2), 20, (byte) 3));
+
+    // now, grow the first record again
+    data = UtilTT.makeRecord(30000, (byte) 4);
+    db.update(rowid, data);
+    assertTrue("check data4",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid), 30000, (byte) 4));
+
+    // delete the record
+    db.delete(rowid);
+
+    // close the file
+    db.close();
+  }
+
+  /**
+   * Test delete and immediate reuse. This attempts to reproduce a bug in the
+   * stress test involving 0 record lengths.
+   */
+  public void testDeleteAndReuse() throws Exception {
+
+    DBAbstract db = newDBCache();
+
+    // insert a 1500 byte record.
+    byte[] data = UtilTT.makeRecord(1500, (byte) 1);
+    long rowid = db.insert(data);
+    assertTrue("check data1",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid), 1500, (byte) 1));
+
+    // delete the record
+    db.delete(rowid);
+
+    // insert a 0 byte record. Should have the same rowid.
+    data = UtilTT.makeRecord(0, (byte) 2);
+    long rowid2 = db.insert(data);
+    assertEquals("old and new rowid", rowid, rowid2);
+    assertTrue("check data2",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid2), 0, (byte) 2));
+
+    // now make the record a bit bigger
+    data = UtilTT.makeRecord(10000, (byte) 3);
+    db.update(rowid, data);
+    assertTrue("check data3",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid), 10000, (byte) 3));
+
+    // .. and again
+    data = UtilTT.makeRecord(30000, (byte) 4);
+    db.update(rowid, data);
+    assertTrue("check data3",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid), 30000, (byte) 4));
+
+    // close the file
+    db.close();
+  }
+
+  /**
+   * Test rollback sanity. Attemts to add a new record, rollback and add the
+   * same record. We should obtain the same record id for both operations.
+   */
+  public void testRollback() throws Exception {
+
+    // Note: We start out with an empty file
+    DBAbstract db = newDBCache();
+
+    db.insert(""); // first insert an empty record, to make sure serializer is
+                   // initialized
+    db.commit();
+    // insert a 150000 byte record.
+    byte[] data1 = UtilTT.makeRecord(150000, (byte) 1);
+    long rowid1 = db.insert(data1);
+    assertTrue("check data1",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid1), 150000, (byte) 1));
+
+    // rollback transaction, should revert to previous state
+    db.rollback();
+
+    // insert same 150000 byte record.
+    byte[] data2 = UtilTT.makeRecord(150000, (byte) 1);
+    long rowid2 = db.insert(data2);
+    assertTrue("check data2",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid2), 150000, (byte) 1));
+
+    assertEquals("old and new rowid", rowid1, rowid2);
+
+    db.commit();
+
+    // insert a 150000 byte record.
+    data1 = UtilTT.makeRecord(150000, (byte) 2);
+    rowid1 = db.insert(data1);
+    assertTrue("check data1",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid1), 150000, (byte) 2));
+
+    // rollback transaction, should revert to previous state
+    db.rollback();
+
+    // insert same 150000 byte record.
+    data2 = UtilTT.makeRecord(150000, (byte) 2);
+    rowid2 = db.insert(data2);
+    assertTrue("check data2",
+        UtilTT.checkRecord((byte[]) db.fetch(rowid2), 150000, (byte) 2));
+
+    assertEquals("old and new rowid", rowid1, rowid2);
+
+    // close the file
+    db.close();
+  }
+
+  public void testNonExistingRecid() throws IOException {
+    DBAbstract db = newDBCache();
+
+    Object obj = db.fetch(6666666);
+    assertTrue(obj == null);
+
+    try {
+      db.update(6666666, obj);
+      db.commit();
+      fail();
+    } catch (IOError expected) {
+
+    } catch (IOException expected) {
+
+    }
+
+  }
+
+  final static AtomicInteger i = new AtomicInteger(0);
+
+  public static class Serial implements Serializer<String>, Serializable {
+
+    public String deserialize(DataInput in) throws IOException,
+        ClassNotFoundException {
+      i.incrementAndGet();
+      return in.readUTF();
+    }
+
+    public void serialize(DataOutput out, String obj) throws IOException {
+      i.incrementAndGet();
+      out.writeUTF(obj);
+    }
+  }
+
+  public void testTreeMapValueSerializer() throws Exception {
+    i.set(0);
+    Serializer<String> ser = new Serial();
+
+    DB db = newDBCache();
+    Map<Long, String> t = db.<Long, String> createTreeMap("test", null, null,
+        ser);
+    t.put(1l, "hopsa hejsa1");
+    t.put(2l, "hopsa hejsa2");
+    db.commit();
+    assertEquals(t.get(2l), "hopsa hejsa2");
+    assertTrue(i.intValue() > 0);
+  }
+
+  public void testCountRecid() throws Exception {
+    DBStore db = newDBNoCache();
+    db.insert(""); // first insert an empty record, to make sure serializer is
+                   // initialized
+    long baseCount = db.countRecords();
+    for (int i = 1; i < 3000; i++) {
+      Object val = "qjiodjqwoidjqwiodoi";
+
+      db.insert(val);
+      if (i % 1000 == 0)
+        db.commit();
+
+      assertEquals(db.countRecords(), i + baseCount);
+    }
+
+  }
+
+  public void testGetCollections() throws IOException {
+    DB db = newDBCache();
+    db.createTreeMap("treemap");
+    db.createHashMap("hashmap");
+    db.createTreeSet("treeset");
+    db.createHashSet("hashset");
+
+    db.createLinkedList("linkedlist");
+    Map<String, Object> cols = db.getCollections();
+    assertTrue(cols.get("treemap") instanceof SortedMap);
+    assertTrue(cols.get("hashmap") instanceof Map);
+
+    assertTrue(cols.get("treeset") instanceof SortedSet);
+    assertTrue(cols.get("hashset") instanceof Set);
+    assertTrue(cols.get("linkedlist") instanceof List);
+  }
+
+  public void testRegisterShutdown() {
+    DB d = DBMaker.openFile(newTestFile()).closeOnExit().make();
+    // do nothing
+  }
+
+  public void testDeleteAfterExit() {
+    String f = newTestFile();
+    File f1 = new File(StorageDiskMapped.makeFileName(f, 1, 0));
+    File f2 = new File(StorageDiskMapped.makeFileName(f, -1, 0));
+
+    assertFalse(f1.exists());
+    assertFalse(f2.exists());
+
+    DB d = DBMaker.openFile(f).deleteFilesAfterClose().make();
+    d.createHashSet("test");
+    assertTrue(f1.exists());
+    assertTrue(f2.exists());
+    d.close();
+    assertFalse(f1.exists());
+    assertFalse(f2.exists());
+
+  }
+
+  public void testDeleteAfterExitRAF() {
+    String f = newTestFile();
+    File f1 = new File(StorageDiskMapped.makeFileName(f, 1, 0));
+    File f2 = new File(StorageDiskMapped.makeFileName(f, -1, 0));
+
+    assertFalse(f1.exists());
+    assertFalse(f2.exists());
+
+    DB d = DBMaker.openFile(f).deleteFilesAfterClose().useRandomAccessFile()
+        .make();
+    d.createHashSet("test");
+    assertTrue(f1.exists());
+    assertTrue(f2.exists());
+    d.close();
+    assertFalse(f1.exists());
+    assertFalse(f2.exists());
+
+  }
+
+  public void testDeleteLinkedList() throws IOException {
+    DBStore d = newDBNoCache();
+    d.createHashMap("testXX").put("aa", "bb"); // make sure serializer and name
+                                               // map are initilaized
+    d.commit();
+    long recCount = d.countRecords();
+    List l = d.createLinkedList("test");
+    l.add("1");
+    l.add("2");
+    d.commit();
+    assertFalse(recCount == d.countRecords());
+    d.deleteCollection("test");
+    assertEquals(recCount, d.countRecords());
+
+  }
+
+  public void testDeleteTreeMap() throws IOException {
+    DBStore d = newDBNoCache();
+    d.createHashMap("testXX").put("aa", "bb"); // make sure serializer and name
+                                               // map are initilaized
+    d.commit();
+    long recCount = d.countRecords();
+    Map l = d.createTreeMap("test");
+    l.put("1", "b");
+    l.put("2", "b");
+    d.commit();
+    assertFalse(recCount == d.countRecords());
+    d.deleteCollection("test");
+    assertEquals(recCount, d.countRecords());
+
+  }
+
+  public void testDeleteHashMap() throws IOException {
+    DBStore d = newDBNoCache();
+    d.createHashMap("testXX").put("aa", "bb"); // make sure serializer and name
+                                               // map are initilaized
+    d.commit();
+    long recCount = d.countRecords();
+    Map l = d.createHashMap("test");
+    l.put("1", "b");
+    l.put("2", "b");
+    d.commit();
+    assertFalse(recCount == d.countRecords());
+    d.deleteCollection("test");
+    assertEquals(recCount, d.countRecords());
+
+  }
+
+  public void testDeleteEmptyLinkedList() throws IOException {
+    DBStore d = newDBNoCache();
+    d.createHashMap("testXX").put("aa", "bb"); // make sure serializer and name
+                                               // map are initilaized
+    d.commit();
+    long recCount = d.countRecords();
+    List l = d.createLinkedList("test");
+    d.commit();
+    assertFalse(recCount == d.countRecords());
+    d.deleteCollection("test");
+    assertEquals(recCount, d.countRecords());
+
+  }
+
+  public void testDeleteEmptyTreeMap() throws IOException {
+    DBStore d = newDBNoCache();
+    d.createHashMap("testXX").put("aa", "bb"); // make sure serializer and name
+                                               // map are initilaized
+    d.commit();
+    long recCount = d.countRecords();
+    Map l = d.createTreeMap("test");
+    d.commit();
+    assertFalse(recCount == d.countRecords());
+    d.deleteCollection("test");
+    assertEquals(recCount, d.countRecords());
+
+  }
+
+  public void testDeleteEmptyHashMap() throws IOException {
+    DBStore d = newDBNoCache();
+    d.createHashMap("testXX").put("aa", "bb"); // make sure serializer and name
+                                               // map are initilaized
+    d.commit();
+    long recCount = d.countRecords();
+    Map l = d.createHashMap("test");
+    d.commit();
+    assertFalse(recCount == d.countRecords());
+    d.deleteCollection("test");
+    assertEquals(recCount, d.countRecords());
+
+  }
+
+  public void testHugeRecord() throws IOException {
+    DBStore s = newDBNoCache();
+    try {
+      s.insert(new byte[50 * 1000 * 1000]);
+      s.commit();
+      fail();
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+
+  }
+
+  public void testCompressRecid() {
+    for (long l = Magic.PAGE_HEADER_SIZE; l < Storage.PAGE_SIZE; l += 6) {
+      assertEquals(l, DBStore.decompressRecid(DBStore.compressRecid(l)));
+    }
+
+    for (long l = Magic.PAGE_HEADER_SIZE + Storage.PAGE_SIZE * 5; l < Storage.PAGE_SIZE * 6; l += 6) {
+      assertEquals(l, DBStore.decompressRecid(DBStore.compressRecid(l)));
+    }
+
+  }
+
+  public void testCollectionSize() throws IOException {
+    DB d = newDBNoCache();
+
+    Map tm = d.createTreeMap("t1");
+    tm.put(1, 1);
+    tm.put(2, 2);
+    assertEquals(d.collectionSize(tm), 2);
+
+    tm = d.createHashMap("t2");
+    tm.put(1, 1);
+    tm.put(2, 2);
+    assertEquals(d.collectionSize(tm), 2);
+
+    Collection c = d.createLinkedList("t3");
+    c.add(1);
+    c.add(2);
+    assertEquals(d.collectionSize(c), 2);
+
+    c = d.createTreeSet("t4");
+    c.add(1);
+    c.add(2);
+    assertEquals(d.collectionSize(c), 2);
+
+    c = d.createHashSet("t5");
+    c.add(1);
+    c.add(2);
+    assertEquals(d.collectionSize(c), 2);
+
+  }
+
+  public void testDeleteAndPutCollection() throws IOException {
+    DB db = newDBNoCache();
+    db = DBMakerTest.newDBCache();
+    Map toAdd = new HashMap();
+    toAdd.put("description", "test");
+    toAdd.put("descriptio1", "test");
+    Map<String, Object> map = db.createHashMap("test");
+    map.putAll(toAdd);
+    db.commit();
+    db.deleteCollection("test");
+    map = db.getHashMap("test");
+    assertNull(map);
+
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DataInputOutputTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DataInputOutputTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DataInputOutputTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DataInputOutputTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,83 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class DataInputOutputTest extends TestCase {
+
+  final DataInputOutput d = new DataInputOutput();
+
+  public void testInt() throws IOException {
+    int i = 123129049;
+    d.writeInt(i);
+    d.reset();
+    assertEquals(i, d.readInt());
+  }
+
+  public void testLong() throws IOException {
+    long i = 1231290495545446485L;
+    d.writeLong(i);
+    d.reset();
+    assertEquals(i, d.readLong());
+  }
+
+  public void testBooelean() throws IOException {
+    d.writeBoolean(true);
+    d.reset();
+    assertEquals(true, d.readBoolean());
+    d.reset();
+    d.writeBoolean(false);
+    d.reset();
+    assertEquals(false, d.readBoolean());
+
+  }
+
+  public void testByte() throws IOException {
+
+    for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
+      d.writeByte(i);
+      d.reset();
+      assertEquals(i, d.readByte());
+      d.reset();
+    }
+  }
+
+  public void testUnsignedByte() throws IOException {
+
+    for (int i = 0; i <= 255; i++) {
+      d.write(i);
+      d.reset();
+      assertEquals(i, d.readUnsignedByte());
+      d.reset();
+    }
+  }
+
+  public void testLongPacker() throws IOException {
+
+    for (int i = 0; i < 1e7; i++) {
+      LongPacker.packInt(d, i);
+      d.reset();
+      assertEquals(i, LongPacker.unpackInt(d));
+      d.reset();
+    }
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DefragTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DefragTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DefragTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/DefragTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,106 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class DefragTest extends TestCaseWithTestFile {
+
+  public void testDefrag1() throws IOException {
+    String file = newTestFile();
+    DBStore m = new DBStore(file, false, false, false);
+    long loc = m.insert("123");
+    m.defrag(true);
+    m.close();
+    m = new DBStore(file, false, false, false);
+    assertEquals(m.fetch(loc), "123");
+  }
+
+  public void testDefrag2() throws IOException {
+    String file = newTestFile();
+    DBStore m = new DBStore(file, false, false, false);
+    TreeMap<Long, String> map = new TreeMap<Long, String>();
+    for (int i = 0; i < 10000; i++) {
+      long loc = m.insert("" + i);
+      map.put(loc, "" + i);
+    }
+
+    m.defrag(true);
+    m.close();
+    m = new DBStore(file, false, false, false);
+    for (Long l : map.keySet()) {
+      String val = map.get(l);
+      assertEquals(val, m.fetch(l));
+    }
+  }
+
+  public void testDefragBtree() throws IOException {
+    String file = newTestFile();
+    DBStore m = new DBStore(file, false, false, false);
+    Map t = m.createTreeMap("aa");
+    TreeMap t2 = new TreeMap();
+    for (int i = 0; i < 10000; i++) {
+      t.put(i, "" + i);
+      t2.put(i, "" + i);
+    }
+
+    m.defrag(true);
+    m.close();
+    m = new DBStore(file, false, false, false);
+    t = m.getTreeMap("aa");
+    assertEquals(t, t2);
+  }
+
+  public void testDefragLinkedList() throws Exception {
+    String file = newTestFile();
+    DBStore r = new DBStore(file, false, false, false);
+    List l = r.createLinkedList("test");
+    Map<Long, Double> junk = new LinkedHashMap<Long, Double>();
+
+    for (int i = 0; i < 1e4; i++) {
+      // insert some junk
+      Double d = Math.random();
+      l.add(d);
+      junk.put(r.insert(d), d);
+    }
+    r.commit();
+    // make copy of linked list
+    List l2 = new ArrayList(l);
+    long oldRecCount = r.countRecords();
+    r.defrag(true);
+
+    r.close();
+    r = new DBStore(file, false, false, false);
+    assertEquals(oldRecCount, r.countRecords());
+
+    // compare that list was unchanged
+    assertEquals(l2, new ArrayList(r.getLinkedList("test")));
+
+    // and check that random junk still have the same recids
+    for (Long recid : junk.keySet()) {
+      assertEquals(junk.get(recid), r.fetch(recid));
+    }
+
+    r.close();
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileHeaderTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileHeaderTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileHeaderTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileHeaderTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,58 @@
+/**
+ * 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.hama.jdbm;
+
+import junit.framework.TestCase;
+
+public class FileHeaderTest extends TestCase {
+
+  /**
+   * Test set, write, read
+   */
+  public void testSetWriteRead() throws Exception {
+    PageIo b = new PageIo(0, new byte[1000]);
+    b.fileHeaderCheckHead(true);
+    for (int i = 0; i < Magic.NLISTS; i++) {
+      b.fileHeaderSetFirstOf(i, 100 * i);
+      b.fileHeaderSetLastOf(i, 200 * i);
+    }
+
+    b.fileHeaderCheckHead(false);
+    for (int i = 0; i < Magic.NLISTS; i++) {
+      assertEquals("first " + i, i * 100, b.fileHeaderGetFirstOf(i));
+      assertEquals("last " + i, i * 200, b.fileHeaderGetLastOf(i));
+    }
+  }
+
+  /**
+   * Test root rowids
+   */
+  public void testRootRowids() throws Exception {
+    PageIo b = new PageIo(0, new byte[Storage.PAGE_SIZE]);
+    b.fileHeaderCheckHead(true);
+    for (int i = 0; i < Magic.FILE_HEADER_NROOTS; i++) {
+      b.fileHeaderSetRoot(i, 100 * i);
+    }
+
+    b.fileHeaderCheckHead(false);
+    for (int i = 0; i < Magic.FILE_HEADER_NROOTS; i++) {
+      assertEquals("root " + i, i * 100, b.fileHeaderGetRoot(i));
+    }
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileLockTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileLockTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileLockTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/FileLockTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.hama.jdbm;
+
+import java.io.IOError;
+import java.io.IOException;
+
+public class FileLockTest extends TestCaseWithTestFile {
+
+  public void testLock() throws IOException {
+    String file = newTestFile();
+
+    DB db1 = DBMaker.openFile(file).make();
+    // now open same file second time, exception should be thrown
+    try {
+      DB db2 = DBMaker.openFile(file).make();
+      fail("Exception should be thrown if file was locked");
+    } catch (IOError e) {
+      // expected
+    }
+
+    db1.close();
+
+    // after close lock should be released, reopen
+    DB db3 = DBMaker.openFile(file).make();
+    db3.close();
+  }
+}



Mime
View raw message