hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjungb...@apache.org
Subject svn commit: r1387533 [10/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/ ...
Date Wed, 19 Sep 2012 11:52:24 GMT
Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerialClassInfoTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerialClassInfoTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerialClassInfoTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerialClassInfoTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,264 @@
+/**
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class SerialClassInfoTest extends TestCaseWithTestFile {
+
+  public SerialClassInfoTest() {
+  }
+
+  static class Bean1 implements Serializable {
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o)
+        return true;
+      if (o == null || getClass() != o.getClass())
+        return false;
+
+      Bean1 bean1 = (Bean1) o;
+
+      if (Double.compare(bean1.doubleField, doubleField) != 0)
+        return false;
+      if (Float.compare(bean1.floatField, floatField) != 0)
+        return false;
+      if (intField != bean1.intField)
+        return false;
+      if (longField != bean1.longField)
+        return false;
+      if (field1 != null ? !field1.equals(bean1.field1) : bean1.field1 != null)
+        return false;
+      if (field2 != null ? !field2.equals(bean1.field2) : bean1.field2 != null)
+        return false;
+
+      return true;
+    }
+
+    protected String field1 = null;
+    protected String field2 = null;
+
+    protected int intField = Integer.MAX_VALUE;
+    protected long longField = Long.MAX_VALUE;
+    protected double doubleField = Double.MAX_VALUE;
+    protected float floatField = Float.MAX_VALUE;
+
+    transient int getCalled = 0;
+    transient int setCalled = 0;
+
+    public String getField2() {
+      getCalled++;
+      return field2;
+    }
+
+    public void setField2(String field2) {
+      setCalled++;
+      this.field2 = field2;
+    }
+
+    Bean1() {
+
+    }
+
+    Bean1(String field1, String field2) {
+      this.field1 = field1;
+      this.field2 = field2;
+    }
+
+  }
+
+  static class Bean2 extends Bean1 {
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o)
+        return true;
+      if (o == null || getClass() != o.getClass())
+        return false;
+      if (!super.equals(o))
+        return false;
+
+      Bean2 bean2 = (Bean2) o;
+
+      if (field3 != null ? !field3.equals(bean2.field3) : bean2.field3 != null)
+        return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return field3 != null ? field3.hashCode() : 0;
+    }
+
+    private String field3 = null;
+
+    Bean2() {
+    }
+
+    Bean2(String field1, String field2, String field3) {
+      super(field1, field2);
+      this.field3 = field3;
+    }
+
+  }
+
+  SerialClassInfo s;
+
+  @Override
+  public void setUp() throws IOException {
+    s = new Serialization();
+  }
+
+  Bean1 b = new Bean1("aa", "bb");
+  Bean2 b2 = new Bean2("aa", "bb", "cc");
+
+  public void testGetFieldValue1() throws Exception {
+    assertEquals("aa", s.getFieldValue("field1", b));
+  }
+
+  public void testGetFieldValue2() throws Exception {
+    assertEquals("bb", s.getFieldValue("field2", b));
+    assertEquals(1, b.getCalled);
+  }
+
+  public void testGetFieldValue3() throws Exception {
+    assertEquals("aa", s.getFieldValue("field1", b2));
+  }
+
+  public void testGetFieldValue4() throws Exception {
+    assertEquals("bb", s.getFieldValue("field2", b2));
+    assertEquals(1, b2.getCalled);
+  }
+
+  public void testGetFieldValue5() throws Exception {
+    assertEquals("cc", s.getFieldValue("field3", b2));
+  }
+
+  public void testSetFieldValue1() {
+    s.setFieldValue("field1", b, "zz");
+    assertEquals("zz", b.field1);
+  }
+
+  public void testSetFieldValue2() {
+    s.setFieldValue("field2", b, "zz");
+    assertEquals("zz", b.field2);
+    assertEquals(1, b.setCalled);
+  }
+
+  public void testSetFieldValue3() {
+    s.setFieldValue("field1", b2, "zz");
+    assertEquals("zz", b2.field1);
+  }
+
+  public void testSetFieldValue4() {
+    s.setFieldValue("field2", b2, "zz");
+    assertEquals("zz", b2.field2);
+    assertEquals(1, b2.setCalled);
+  }
+
+  public void testSetFieldValue5() {
+    s.setFieldValue("field3", b2, "zz");
+    assertEquals("zz", b2.field3);
+  }
+
+  public void testGetPrimitiveField() {
+    assertEquals(Integer.MAX_VALUE, s.getFieldValue("intField", b2));
+    assertEquals(Long.MAX_VALUE, s.getFieldValue("longField", b2));
+    assertEquals(Double.MAX_VALUE, s.getFieldValue("doubleField", b2));
+    assertEquals(Float.MAX_VALUE, s.getFieldValue("floatField", b2));
+  }
+
+  public void testSetPrimitiveField() {
+    s.setFieldValue("intField", b2, -1);
+    assertEquals(-1, s.getFieldValue("intField", b2));
+    s.setFieldValue("longField", b2, -1L);
+    assertEquals(-1L, s.getFieldValue("longField", b2));
+    s.setFieldValue("doubleField", b2, -1D);
+    assertEquals(-1D, s.getFieldValue("doubleField", b2));
+    s.setFieldValue("floatField", b2, -1F);
+    assertEquals(-1F, s.getFieldValue("floatField", b2));
+  }
+
+  <E> E serialize(E e) throws ClassNotFoundException, IOException {
+    Serialization s2 = new Serialization();
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    s2.serialize(new DataOutputStream(out), e);
+
+    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+    return (E) s2.deserialize(new DataInputStream(in));
+
+  }
+
+  public void testSerializable() throws Exception {
+
+    assertEquals(serialize(b), b);
+  }
+
+  public void testRecursion3() throws Exception {
+    ArrayList l = new ArrayList();
+    l.add("123");
+    l.add(l);
+
+    ArrayList l2 = serialize(l);
+
+    assertTrue(l.size() == 2);
+    assertEquals(l.get(0), "123");
+    assertTrue(l.get(1) == l);
+  }
+
+  public void testPersistedSimple() throws Exception {
+
+    String f = newTestFile();
+    DBAbstract r1 = (DBAbstract) DBMaker.openFile(f).make();
+    long recid = r1.insert("AA");
+    r1.commit();
+    r1.close();
+
+    DBAbstract r2 = (DBAbstract) DBMaker.openFile(f).make();
+
+    String a2 = r2.fetch(recid);
+    r2.close();
+    assertEquals("AA", a2);
+
+  }
+
+  public void testPersisted() throws Exception {
+    Bean1 b1 = new Bean1("abc", "dcd");
+    String f = newTestFile();
+    DBAbstract r1 = (DBAbstract) DBMaker.openFile(f).make();
+    long recid = r1.insert(b1);
+    r1.commit();
+    r1.close();
+
+    DBAbstract r2 = (DBAbstract) DBMaker.openFile(f).make();
+
+    Bean1 b2 = (Bean1) r2.fetch(recid);
+    r2.close();
+    assertEquals(b1, b2);
+
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Bean.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Bean.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Bean.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Bean.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,113 @@
+/**
+ * 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;
+
+public class Serialization2Bean implements Serializable {
+  // =========================== Constants ===============================
+  private static final long serialVersionUID = 2757814409580877461L;
+
+  // =========================== Attributes ==============================
+  private String id = "test";
+  private String f1 = "";
+  private String f2 = "";
+  private String f3 = null;
+  private String f4 = "";
+  private String f5 = null;
+  private String f6 = "";
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((f1 == null) ? 0 : f1.hashCode());
+    result = prime * result + ((f2 == null) ? 0 : f2.hashCode());
+    result = prime * result + ((f3 == null) ? 0 : f3.hashCode());
+    result = prime * result + ((f4 == null) ? 0 : f4.hashCode());
+    result = prime * result + ((f5 == null) ? 0 : f5.hashCode());
+    result = prime * result + ((f6 == null) ? 0 : f6.hashCode());
+    result = prime * result + ((id == null) ? 0 : id.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    }
+    if (obj == null) {
+      return false;
+    }
+    if (getClass() != obj.getClass()) {
+      return false;
+    }
+    Serialization2Bean other = (Serialization2Bean) obj;
+    if (f1 == null) {
+      if (other.f1 != null) {
+        return false;
+      }
+    } else if (!f1.equals(other.f1)) {
+      return false;
+    }
+    if (f2 == null) {
+      if (other.f2 != null) {
+        return false;
+      }
+    } else if (!f2.equals(other.f2)) {
+      return false;
+    }
+    if (f3 == null) {
+      if (other.f3 != null) {
+        return false;
+      }
+    } else if (!f3.equals(other.f3)) {
+      return false;
+    }
+    if (f4 == null) {
+      if (other.f4 != null) {
+        return false;
+      }
+    } else if (!f4.equals(other.f4)) {
+      return false;
+    }
+    if (f5 == null) {
+      if (other.f5 != null) {
+        return false;
+      }
+    } else if (!f5.equals(other.f5)) {
+      return false;
+    }
+    if (f6 == null) {
+      if (other.f6 != null) {
+        return false;
+      }
+    } else if (!f6.equals(other.f6)) {
+      return false;
+    }
+    if (id == null) {
+      if (other.id != null) {
+        return false;
+      }
+    } else if (!id.equals(other.id)) {
+      return false;
+    }
+    return true;
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Test.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Test.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Test.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialization2Test.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,87 @@
+/**
+ * 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.Map;
+
+public class Serialization2Test extends TestCaseWithTestFile {
+
+  public void test2() throws IOException {
+    DB db = newDBNoCache();
+
+    Serialization2Bean processView = new Serialization2Bean();
+
+    Map<Object, Object> map = db.createHashMap("test2");
+
+    map.put("abc", processView);
+
+    db.commit();
+
+    Serialization2Bean retProcessView = (Serialization2Bean) map.get("abc");
+    assertEquals(processView, retProcessView);
+
+    db.close();
+  }
+
+  public void test3() throws IOException {
+
+    String file = newTestFile();
+
+    Serialized2DerivedBean att = new Serialized2DerivedBean();
+    DB db = DBMaker.openFile(file).disableCache().make();
+
+    Map<Object, Object> map = db.createHashMap("test");
+
+    map.put("att", att);
+    db.commit();
+    db.close();
+    db = DBMaker.openFile(file).disableCache().make();
+    map = db.getHashMap("test");
+
+    Serialized2DerivedBean retAtt = (Serialized2DerivedBean) map.get("att");
+    assertEquals(att, retAtt);
+  }
+
+  static class AAA implements Serializable {
+    String test = "aa";
+  }
+
+  public void testReopenWithDefrag() {
+
+    String f = newTestFile();
+
+    DB db = DBMaker.openFile(f).disableTransactions().make();
+
+    Map<Integer, AAA> map = db.createTreeMap("test");
+    map.put(1, new AAA());
+
+    db.defrag(true);
+    db.close();
+
+    db = DBMaker.openFile(f).disableTransactions().make();
+
+    map = db.getTreeMap("test");
+    assertNotNull(map.get(1));
+    assertEquals(map.get(1).test, "aa");
+
+    db.close();
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationHeaderTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationHeaderTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationHeaderTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationHeaderTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,40 @@
+/**
+ * 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.lang.reflect.Field;
+import java.util.Set;
+import java.util.TreeSet;
+
+import junit.framework.TestCase;
+
+public class SerializationHeaderTest extends TestCase {
+
+  public void testUnique() throws IllegalAccessException {
+    Class c = SerializationHeader.class;
+    Set<Integer> s = new TreeSet<Integer>();
+    for (Field f : c.getDeclaredFields()) {
+      f.setAccessible(true);
+      int value = f.getInt(null);
+
+      assertTrue("Value already used: " + value, !s.contains(value));
+      s.add(value);
+    }
+    assertTrue(!s.isEmpty());
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/SerializationTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,465 @@
+/*******************************************************************************
+ * Copyright 2010 Cees De Groot, Alex Boisvert, Jan Kotek
+ *
+ * Licensed 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 static java.util.Arrays.asList;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.AbstractMap.SimpleEntry;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+@SuppressWarnings("unchecked")
+public class SerializationTest extends TestCase {
+
+  Serialization ser;
+
+  public SerializationTest() throws IOException {
+    ser = new Serialization();
+  }
+
+  public void testInt() throws IOException, ClassNotFoundException {
+    int[] vals = { Integer.MIN_VALUE, -Short.MIN_VALUE * 2,
+        -Short.MIN_VALUE + 1, -Short.MIN_VALUE, -10, -9, -8, -7, -6, -5, -4,
+        -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 127, 254, 255, 256,
+        Short.MAX_VALUE, Short.MAX_VALUE + 1, Short.MAX_VALUE * 2,
+        Integer.MAX_VALUE };
+    for (int i : vals) {
+      byte[] buf = ser.serialize(i);
+      Object l2 = ser.deserialize(buf);
+      assertTrue(l2.getClass() == Integer.class);
+      assertEquals(l2, i);
+    }
+  }
+
+  public void testShort() throws IOException, ClassNotFoundException {
+    short[] vals = { (short) (-Short.MIN_VALUE + 1), (short) -Short.MIN_VALUE,
+        -10, -9, -8, -7, -6, -5, -4, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 127,
+        254, 255, 256, Short.MAX_VALUE, Short.MAX_VALUE - 1, Short.MAX_VALUE };
+    for (short i : vals) {
+      byte[] buf = ser.serialize(i);
+      Object l2 = ser.deserialize(buf);
+      assertTrue(l2.getClass() == Short.class);
+      assertEquals(l2, i);
+    }
+  }
+
+  public void testDouble() throws IOException, ClassNotFoundException {
+    double[] vals = { 1f, 0f, -1f, Math.PI, 255, 256, Short.MAX_VALUE,
+        Short.MAX_VALUE + 1, -100 };
+    for (double i : vals) {
+      byte[] buf = ser.serialize(i);
+      Object l2 = ser.deserialize(buf);
+      assertTrue(l2.getClass() == Double.class);
+      assertEquals(l2, i);
+    }
+  }
+
+  public void testFloat() throws IOException, ClassNotFoundException {
+    float[] vals = { 1f, 0f, -1f, (float) Math.PI, 255, 256, Short.MAX_VALUE,
+        Short.MAX_VALUE + 1, -100 };
+    for (float i : vals) {
+      byte[] buf = ser.serialize(i);
+      Object l2 = ser.deserialize(buf);
+      assertTrue(l2.getClass() == Float.class);
+      assertEquals(l2, i);
+    }
+  }
+
+  public void testChar() throws IOException, ClassNotFoundException {
+    char[] vals = { 'a', ' ' };
+    for (char i : vals) {
+      byte[] buf = ser.serialize(i);
+      Object l2 = ser.deserialize(buf);
+      assertTrue(l2.getClass() == Character.class);
+      assertEquals(l2, i);
+    }
+  }
+
+  public void testLong() throws IOException, ClassNotFoundException {
+    long[] vals = { Long.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE - 1,
+        Integer.MIN_VALUE + 1, -Short.MIN_VALUE * 2, -Short.MIN_VALUE + 1,
+        -Short.MIN_VALUE, -10, -9, -8, -7, -6, -5, -4, -1, 0, 1, 2, 3, 4, 5, 6,
+        7, 8, 9, 10, 127, 254, 255, 256, Short.MAX_VALUE, Short.MAX_VALUE + 1,
+        Short.MAX_VALUE * 2, Integer.MAX_VALUE, Integer.MAX_VALUE + 1,
+        Long.MAX_VALUE };
+    for (long i : vals) {
+      byte[] buf = ser.serialize(i);
+      Object l2 = ser.deserialize(buf);
+      assertTrue(l2.getClass() == Long.class);
+      assertEquals(l2, i);
+    }
+  }
+
+  public void testBoolean1() throws IOException, ClassNotFoundException {
+    byte[] buf = ser.serialize(true);
+    Object l2 = ser.deserialize(buf);
+    assertTrue(l2.getClass() == Boolean.class);
+    assertEquals(l2, true);
+
+    byte[] buf2 = ser.serialize(false);
+    Object l22 = ser.deserialize(buf2);
+    assertTrue(l22.getClass() == Boolean.class);
+    assertEquals(l22, false);
+
+  }
+
+  public void testString() throws IOException, ClassNotFoundException {
+    byte[] buf = ser.serialize("Abcd");
+    String l2 = (String) ser.deserialize(buf);
+    assertEquals(l2, "Abcd");
+  }
+
+  public void testBigString() throws IOException, ClassNotFoundException {
+    String bigString = "";
+    for (int i = 0; i < 1e4; i++)
+      bigString += i % 10;
+    byte[] buf = ser.serialize(bigString);
+    String l2 = (String) ser.deserialize(buf);
+    assertEquals(l2, bigString);
+  }
+
+  public void testNoArgumentConstructorInJavaSerialization()
+      throws ClassNotFoundException, IOException {
+    SimpleEntry a = new SimpleEntry(1, "11");
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    new ObjectOutputStream(out).writeObject(a);
+    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
+        out.toByteArray()));
+    SimpleEntry a2 = (SimpleEntry) in.readObject();
+    assertEquals(a, a2);
+  }
+
+  public void testArrayList() throws ClassNotFoundException, IOException {
+    Collection c = new ArrayList();
+    for (int i = 0; i < 200; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testLinkedList() throws ClassNotFoundException, IOException {
+    Collection c = new java.util.LinkedList();
+    for (int i = 0; i < 200; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testVector() throws ClassNotFoundException, IOException {
+    Collection c = new Vector();
+    for (int i = 0; i < 200; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testTreeSet() throws ClassNotFoundException, IOException {
+    Collection c = new TreeSet();
+    for (int i = 0; i < 200; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testHashSet() throws ClassNotFoundException, IOException {
+    Collection c = new HashSet();
+    for (int i = 0; i < 200; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testLinkedHashSet() throws ClassNotFoundException, IOException {
+    Collection c = new LinkedHashSet();
+    for (int i = 0; i < 200; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.add(i);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testHashMap() throws ClassNotFoundException, IOException {
+    Map c = new HashMap();
+    for (int i = 0; i < 200; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testTreeMap() throws ClassNotFoundException, IOException {
+    Map c = new TreeMap();
+    for (int i = 0; i < 200; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testLinkedHashMap() throws ClassNotFoundException, IOException {
+    Map c = new LinkedHashMap();
+    for (int i = 0; i < 200; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testHashtable() throws ClassNotFoundException, IOException {
+    Map c = new Hashtable();
+    for (int i = 0; i < 200; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testProperties() throws ClassNotFoundException, IOException {
+    Properties c = new Properties();
+    for (int i = 0; i < 200; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+    for (int i = 0; i < 2000; i++)
+      c.put(i, i + 10000);
+    assertEquals(c, ser.deserialize(ser.serialize(c)));
+  }
+
+  public void testClass() throws IOException, ClassNotFoundException {
+    byte[] buf = ser.serialize(String.class);
+    Class l2 = (Class) ser.deserialize(buf);
+    assertEquals(l2, String.class);
+  }
+
+  public void testClass2() throws IOException, ClassNotFoundException {
+    byte[] buf = ser.serialize(long[].class);
+    Class l2 = (Class) ser.deserialize(buf);
+    assertEquals(l2, long[].class);
+  }
+
+  public void testUnicodeString() throws ClassNotFoundException, IOException {
+    String s = "Ciudad Bolíva";
+    byte[] buf = ser.serialize(s);
+    assertTrue("text is not unicode", buf.length != s.length());
+    Object l2 = ser.deserialize(buf);
+    assertEquals(l2, s);
+  }
+
+  public void testSerializationHeader() throws IOException {
+    ByteArrayOutputStream b = new ByteArrayOutputStream();
+    new java.io.ObjectOutputStream(b).writeObject("lalala");
+    ByteArrayInputStream i = new ByteArrayInputStream(b.toByteArray());
+    final int header1 = i.read();
+
+    ByteArrayOutputStream b2 = new ByteArrayOutputStream();
+    new java.io.ObjectOutputStream(b2).writeObject(new Integer(1));
+    ByteArrayInputStream i2 = new ByteArrayInputStream(b2.toByteArray());
+    final int header2 = i2.read();
+
+    assertEquals(header1, header2);
+    assertEquals(header1, SerializationHeader.JAVA_SERIALIZATION);
+  }
+
+  public void testPackedLongCollection() throws ClassNotFoundException,
+      IOException {
+    ArrayList l1 = new ArrayList();
+    l1.add(0L);
+    l1.add(1L);
+    l1.add(0L);
+    assertEquals(l1, ser.deserialize(ser.serialize(l1)));
+    l1.add(-1L);
+    assertEquals(l1, ser.deserialize(ser.serialize(l1)));
+  }
+
+  public void testNegativeLongsArray() throws ClassNotFoundException,
+      IOException {
+    long[] l = new long[] { -12 };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (long[]) deserialize));
+  }
+
+  public void testNegativeIntArray() throws ClassNotFoundException, IOException {
+    int[] l = new int[] { -12 };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (int[]) deserialize));
+  }
+
+  public void testNegativeShortArray() throws ClassNotFoundException,
+      IOException {
+    short[] l = new short[] { -12 };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (short[]) deserialize));
+  }
+
+  public void testBooleanArray() throws ClassNotFoundException, IOException {
+    boolean[] l = new boolean[] { true, false };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (boolean[]) deserialize));
+  }
+
+  public void testDoubleArray() throws ClassNotFoundException, IOException {
+    double[] l = new double[] { Math.PI, 1D };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (double[]) deserialize));
+  }
+
+  public void testFloatArray() throws ClassNotFoundException, IOException {
+    float[] l = new float[] { 1F, 1.234235F };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (float[]) deserialize));
+  }
+
+  public void testByteArray() throws ClassNotFoundException, IOException {
+    byte[] l = new byte[] { 1, 34, -5 };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (byte[]) deserialize));
+  }
+
+  public void testCharArray() throws ClassNotFoundException, IOException {
+    char[] l = new char[] { '1', 'a', '&' };
+    Object deserialize = ser.deserialize(ser.serialize(l));
+    assertTrue(Arrays.equals(l, (char[]) deserialize));
+  }
+
+  public void testDate() throws IOException, ClassNotFoundException {
+    Date d = new Date(6546565565656L);
+    assertEquals(d, ser.deserialize(ser.serialize(d)));
+    d = new Date(System.currentTimeMillis());
+    assertEquals(d, ser.deserialize(ser.serialize(d)));
+  }
+
+  public void testBigDecimal() throws IOException, ClassNotFoundException {
+    BigDecimal d = new BigDecimal("445656.7889889895165654423236");
+    assertEquals(d, ser.deserialize(ser.serialize(d)));
+    d = new BigDecimal("-53534534534534445656.7889889895165654423236");
+    assertEquals(d, ser.deserialize(ser.serialize(d)));
+  }
+
+  public void testBigInteger() throws IOException, ClassNotFoundException {
+    BigInteger d = new BigInteger("4456567889889895165654423236");
+    assertEquals(d, ser.deserialize(ser.serialize(d)));
+    d = new BigInteger("-535345345345344456567889889895165654423236");
+    assertEquals(d, ser.deserialize(ser.serialize(d)));
+  }
+
+  public void testLocale() throws Exception {
+    assertEquals(Locale.FRANCE, ser.deserialize(ser.serialize(Locale.FRANCE)));
+    assertEquals(Locale.CANADA_FRENCH,
+        ser.deserialize(ser.serialize(Locale.CANADA_FRENCH)));
+    assertEquals(Locale.SIMPLIFIED_CHINESE,
+        ser.deserialize(ser.serialize(Locale.SIMPLIFIED_CHINESE)));
+
+  }
+
+  enum Order {
+    ASCENDING, DESCENDING
+  }
+
+  public void testEnum() throws Exception {
+    Order o = Order.ASCENDING;
+    o = (Order) ser.deserialize(ser.serialize(o));
+    assertEquals(o, Order.ASCENDING);
+    assertEquals(o.ordinal(), Order.ASCENDING.ordinal());
+    assertEquals(o.name(), Order.ASCENDING.name());
+
+    o = Order.DESCENDING;
+    o = (Order) ser.deserialize(ser.serialize(o));
+    assertEquals(o, Order.DESCENDING);
+    assertEquals(o.ordinal(), Order.DESCENDING.ordinal());
+    assertEquals(o.name(), Order.DESCENDING.name());
+
+  }
+
+  static class Extr implements Externalizable {
+
+    int aaa = 11;
+    String l = "agfa";
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+      out.writeObject(l);
+      out.writeInt(aaa);
+
+    }
+
+    public void readExternal(ObjectInput in) throws IOException,
+        ClassNotFoundException {
+      l = (String) in.readObject();
+      aaa = in.readInt() + 1;
+
+    }
+  }
+
+  public void testExternalizable() throws Exception {
+    Extr e = new Extr();
+    e.aaa = 15;
+    e.l = "pakla";
+
+    e = (Extr) ser.deserialize(ser.serialize(e));
+    assertEquals(e.aaa, 16); // was incremented during serialization
+    assertEquals(e.l, "pakla");
+
+  }
+
+  public void testObjectArrayArray() throws IOException, ClassNotFoundException {
+    Object[][] arr = new Object[][] { { (int) 25, (short) 20, (short) 32,
+        (short) 16, (short) 20 }, };
+    Object[][] arr2 = (Object[][]) ser.deserialize(ser.serialize(arr));
+
+    for (int i = 0; i < arr.length; i++)
+      assertEquals(asList(arr[i]), asList(arr2[i]));
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialized2DerivedBean.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialized2DerivedBean.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialized2DerivedBean.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/Serialized2DerivedBean.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,85 @@
+/**
+ * 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 Serialized2DerivedBean extends Serialization2Bean {
+  private static final long serialVersionUID = 2071817382135925585L;
+
+  private String d1 = "1";
+  private String d2 = "2";
+  private String d3 = null;
+  private String d4 = "4";
+  private String d5 = null;
+  private String d6 = "6";
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = super.hashCode();
+    result = prime * result + ((d1 == null) ? 0 : d1.hashCode());
+    result = prime * result + ((d2 == null) ? 0 : d2.hashCode());
+    result = prime * result + ((d3 == null) ? 0 : d3.hashCode());
+    result = prime * result + ((d4 == null) ? 0 : d4.hashCode());
+    result = prime * result + ((d5 == null) ? 0 : d5.hashCode());
+    result = prime * result + ((d6 == null) ? 0 : d6.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (!super.equals(obj))
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Serialized2DerivedBean other = (Serialized2DerivedBean) obj;
+    if (d1 == null) {
+      if (other.d1 != null)
+        return false;
+    } else if (!d1.equals(other.d1))
+      return false;
+    if (d2 == null) {
+      if (other.d2 != null)
+        return false;
+    } else if (!d2.equals(other.d2))
+      return false;
+    if (d3 == null) {
+      if (other.d3 != null)
+        return false;
+    } else if (!d3.equals(other.d3))
+      return false;
+    if (d4 == null) {
+      if (other.d4 != null)
+        return false;
+    } else if (!d4.equals(other.d4))
+      return false;
+    if (d5 == null) {
+      if (other.d5 != null)
+        return false;
+    } else if (!d5.equals(other.d5))
+      return false;
+    if (d6 == null) {
+      if (other.d6 != null)
+        return false;
+    } else if (!d6.equals(other.d6))
+      return false;
+    return true;
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StorageDiskMappedTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StorageDiskMappedTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StorageDiskMappedTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StorageDiskMappedTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,29 @@
+/**
+ * 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 StorageDiskMappedTest extends TestCase {
+
+  public void testNumberOfPages() {
+
+    assertTrue(StorageDiskMapped.PAGES_PER_FILE * Storage.PAGE_SIZE < Integer.MAX_VALUE);
+
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StreamCorrupted.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StreamCorrupted.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StreamCorrupted.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/StreamCorrupted.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,90 @@
+/**
+ * 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;
+
+/**
+ * Contributed test case for BTree by Christof Dallermassl (cdaller iicm.edu):
+ * <p/>
+ * -= quote from original message posted on jdbm-general =-
+ * 
+ * <pre>
+ * 
+ * I tried to insert a couple of elements into a BTree and then remove
+ * them one by one. After a number or removals, there is always (if more
+ * than 20 elements in btree) a java.io.StreamCorruptedException thrown.
+ * 
+ * The strange thing is, that on 50 elements, the exception is thrown
+ * after removing 22, on 200 it is thrown after 36, on 1000 it is thrown
+ * after 104, on 10000 it is thrown after 1003....
+ * 
+ * The full stackTrace is here:
+ * ---------------------- snip ------- snap -------------------------
+ * java.io.StreamCorruptedException: Caught EOFException while reading the
+ * stream header
+ *   at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:845)
+ *   at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
+ *   at jdbm.db.DB.byteArrayToObject(DB.java:296)
+ *   at jdbm.db.DB.fetchObject(DB.java:239)
+ *   at jdbm.helper.ObjectCache.fetchObject(ObjectCache.java:104)
+ *   at jdbm.btree.BPage.loadBPage(BPage.java:670)
+ *   at jdbm.btree.BPage.remove(BPage.java:492)
+ *   at jdbm.btree.BPage.remove(BPage.java:437)
+ *   at jdbm.btree.BTree.remove(BTree.java:313)
+ *   at JDBMTest.main(JDBMTest.java:41)
+ * 
+ * </pre>
+ */
+public class StreamCorrupted extends TestCaseWithTestFile {
+
+  /**
+   * Basic tests
+   */
+  public void testStreamCorrupted() throws IOException {
+    DBAbstract db;
+    BTree btree;
+    int iterations;
+
+    iterations = 100; // 23 works :-(((((
+
+    // open database
+    db = newDBCache();
+
+    // create a new B+Tree data structure
+    btree = BTree.createInstance(db);
+    db.setNamedObject("testbtree", btree.getRecid());
+
+    // action:
+
+    // insert data
+    for (int count = 0; count < iterations; count++) {
+      btree.insert("num" + count, new Integer(count), true);
+    }
+
+    // delete data
+    for (int count = 0; count < iterations; count++) {
+      btree.remove("num" + count);
+    }
+
+    // close database
+    db.close();
+    db = null;
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestCaseWithTestFile.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestCaseWithTestFile.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestCaseWithTestFile.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestCaseWithTestFile.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+/**
+ * Subclass from this class if you have any test cases that need to do file I/O.
+ * The setUp() and tearDown() methods here will take care of cleanup on disk.
+ */
+abstract class TestCaseWithTestFile extends TestCase {
+
+  public static final String testFolder = System.getProperty("java.io.tmpdir",
+      ".") + "/_testdb";
+
+  // public static final String testFileName = "test";
+
+  public void setUp() throws Exception {
+    File f = new File(testFolder);
+    if (!f.exists())
+      f.mkdirs();
+  }
+
+  public void tearDown() throws Exception {
+    File f = new File(testFolder);
+    if (f.exists()) {
+      for (File f2 : f.listFiles()) {
+        f2.deleteOnExit();
+        f2.delete();
+      }
+    }
+  }
+
+  static public String newTestFile() {
+    return testFolder + File.separator + "test" + System.nanoTime();
+  }
+
+  static public PageFile newRecordFile() throws IOException {
+    return new PageFile(newTestFile());
+  }
+
+  static public DBAbstract newDBCache() throws IOException {
+    return (DBAbstract) DBMaker.openFile(newTestFile()).make();
+  }
+
+  static public DBStore newDBNoCache() throws IOException {
+    return (DBStore) DBMaker.openFile(newTestFile()).disableCache().make();
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertPerf.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertPerf.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertPerf.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertPerf.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,52 @@
+/**
+ * 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;
+
+/**
+ * Test BTree insert performance.
+ */
+public class TestInsertPerf extends TestCaseWithTestFile {
+
+  int _numberOfObjects = 1000;
+
+  public void testInsert() throws IOException {
+
+    long start, finish;
+    DBAbstract db = newDBCache();
+    BTree btree = BTree.createInstance(db);
+
+    // Note: One can use specialized serializers for better performance /
+    // database size
+    // btree = BTree.createInstance( db, new LongComparator(),
+    // LongSerializer.INSTANCE, IntegerSerializer.INSTANCE );
+
+    start = System.currentTimeMillis();
+    for (int i = 0; i < _numberOfObjects; i++) {
+      btree.insert(new Long(i), new Integer(i), false);
+    }
+    db.commit();
+    finish = System.currentTimeMillis();
+
+    System.out.println("It took " + (finish - start) + " ms to insert "
+        + _numberOfObjects + " objects.");
+
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertUpdate.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertUpdate.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertUpdate.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestInsertUpdate.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,47 @@
+/**
+ * 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;
+
+import org.junit.Test;
+
+public class TestInsertUpdate extends TestCaseWithTestFile {
+
+  /**
+   * Test that the object is not modified by serialization.
+   * 
+   * @throws IOException
+   */
+  @Test
+  public void testInsertUpdateWithCustomSerializer() throws IOException {
+    DB db = newDBCache();
+    Serializer<Long> serializer = new HTreeBucketTest.LongSerializer();
+
+    Map<Long, Long> map = db.createHashMap("custom", serializer, serializer);
+
+    map.put(new Long(1), new Long(1));
+    map.put(new Long(2), new Long(2));
+    db.commit();
+    map.put(new Long(2), new Long(3));
+    db.commit();
+    db.close();
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestIssues.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestIssues.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestIssues.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestIssues.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,68 @@
+/**
+ * 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 TestIssues extends TestCaseWithTestFile {
+
+  /*
+   * test this issue http://code.google.com/p/jdbm2/issues/detail?id=2
+   */
+  public void testHTreeClear() throws IOException {
+    final DBAbstract db = newDBCache();
+    final HTree<String, String> tree = (HTree) db.createHashMap("name");
+
+    for (int i = 0; i < 1001; i++) {
+      tree.put(String.valueOf(i), String.valueOf(i));
+    }
+    db.commit();
+    System.out.println("finished adding");
+
+    tree.clear();
+    db.commit();
+    System.out.println("finished clearing");
+    assertTrue(tree.isEmpty());
+  }
+
+  public void testBTreeClear() throws IOException {
+    final DB db = newDBCache();
+    final Map<String, String> treeMap = db.createTreeMap("test");
+
+    for (int i = 0; i < 1001; i++) {
+      treeMap.put(String.valueOf(i), String.valueOf(i));
+    }
+    db.commit();
+    System.out.println("finished adding");
+
+    treeMap.clear();
+    db.commit();
+    System.out.println("finished clearing");
+    assertTrue(treeMap.isEmpty());
+  }
+
+  public void test_issue_84_reopen_after_close() {
+    String f = newTestFile();
+    DB db = DBMaker.openFile(f).make();
+    db.close();
+
+    db = DBMaker.openFile(f).readonly().make();
+    db.close();
+  }
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLargeData.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLargeData.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLargeData.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLargeData.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,76 @@
+/**
+ * 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.Arrays;
+
+public class TestLargeData extends TestCaseWithTestFile {
+
+  public void testLargeData() throws IOException {
+
+    DBAbstract db = new DBStore(newTestFile(), false, false, false);
+
+    byte[] data = UtilTT.makeRecord(1000000, (byte) 12);
+    final long id = db.insert(data);
+    data = (byte[]) db.fetch(id);
+    UtilTT.checkRecord(data, 1000000, (byte) 12);
+    db.commit();
+
+    data = UtilTT.makeRecord(2000000, (byte) 13);
+    db.update(id, data);
+    db.commit();
+    data = (byte[]) db.fetch(id);
+    UtilTT.checkRecord(data, 2000000, (byte) 13);
+    db.commit();
+
+    data = UtilTT.makeRecord(1500000, (byte) 14);
+    db.update(id, data);
+    data = (byte[]) db.fetch(id);
+    UtilTT.checkRecord(data, 1500000, (byte) 14);
+    db.commit();
+
+    data = UtilTT.makeRecord(2500000, (byte) 15);
+    db.update(id, data);
+    db.rollback();
+    data = (byte[]) db.fetch(id);
+    UtilTT.checkRecord(data, 1500000, (byte) 14);
+    db.commit();
+
+    data = UtilTT.makeRecord(1, (byte) 20);
+    db.update(id, data);
+    data = (byte[]) db.fetch(id);
+    UtilTT.checkRecord(data, 1, (byte) 20);
+    db.commit();
+  }
+
+  public void testAllSizes() throws IOException {
+    // use in memory store to make it faster
+    DBStore db = (DBStore) DBMaker.openFile(newTestFile()).disableCache()
+        .disableTransactions().make();
+    for (int i = 1; i < RecordHeader.MAX_RECORD_SIZE - 100; i += 111111) {
+      // System.out.println(i);
+      byte[] rec = UtilTT.makeRecord(i, (byte) 11);
+      long recid = db.insert(rec);
+      byte[] rec2 = db.fetch(recid);
+      assertTrue("error at size: " + i, Arrays.equals(rec, rec2));
+      db.delete(recid);
+    }
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLazyRecordsInTree.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLazyRecordsInTree.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLazyRecordsInTree.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestLazyRecordsInTree.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,73 @@
+/**
+ * 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 TestLazyRecordsInTree extends TestCaseWithTestFile {
+
+  String makeString(int size) {
+    StringBuilder s = new StringBuilder(size);
+    for (int i = 0; i < size; i++) {
+      s.append('a');
+    }
+    return s.toString();
+  }
+
+  void doIt(DBStore r, Map<Integer, String> m) throws IOException {
+    m.put(1, "");
+    long counter = r.countRecords();
+    // number of records should increase after inserting big record
+    m.put(1, makeString(1000));
+    assertEquals(counter + 1, r.countRecords());
+    assertEquals(m.get(1), makeString(1000));
+
+    // old record should be disposed when replaced with big record
+    m.put(1, makeString(1001));
+    assertEquals(counter + 1, r.countRecords());
+    assertEquals(m.get(1), makeString(1001));
+
+    // old record should be disposed when replaced with small record
+    m.put(1, "aa");
+    assertEquals(counter, r.countRecords());
+    assertEquals(m.get(1), "aa");
+
+    // old record should be disposed after deleting
+    m.put(1, makeString(1001));
+    assertEquals(counter + 1, r.countRecords());
+    assertEquals(m.get(1), makeString(1001));
+    m.remove(1);
+    assertTrue(counter >= r.countRecords());
+    assertEquals(m.get(1), null);
+
+  }
+
+  public void testBTree() throws IOException {
+    DBStore r = newDBNoCache();
+    Map<Integer, String> m = r.createTreeMap("test");
+    doIt(r, m);
+  }
+
+  public void testHTree() throws IOException {
+    DBStore r = newDBNoCache();
+    Map<Integer, String> m = r.createHashMap("test");
+    doIt(r, m);
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestRollback.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestRollback.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestRollback.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestRollback.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,130 @@
+/**
+ * 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;
+
+/**
+ * Test cases for HTree rollback
+ */
+public class TestRollback extends TestCaseWithTestFile {
+
+  /**
+   * Test case courtesy of Derek Dick (mailto:ddick users.sourceforge.net)
+   */
+  public void testRollback1() throws Exception {
+
+    // Note: We start out with an empty file
+    DBAbstract db = newDBCache();
+
+    HTree tree = (HTree) db.createHashMap("test");
+
+    tree.put("Foo", "Bar");
+    tree.put("Fo", "Fum");
+
+    db.commit();
+
+    tree.put("Hello", "World");
+
+    db.rollback();
+
+    assertTrue(tree.get("Foo").equals("Bar"));
+    assertTrue(tree.get("Fo").equals("Fum"));
+    assertTrue(tree.get("Hello") == null);
+  }
+
+  /**
+   * Test case courtesy of Derek Dick (mailto:ddick users.sourceforge.net)
+   */
+  public void testRollback2() throws Exception {
+
+    DBAbstract db = newDBCache();
+
+    HTree tree = (HTree) db.createHashMap("test");
+
+    tree.put("hello", "world");
+    tree.put("goodnight", "gracie");
+    db.commit();
+
+    tree.put("derek", "dick");
+    db.rollback();
+
+    assertTrue(tree.get("derek") == null);
+    assertTrue(tree.get("goodnight").equals("gracie"));
+    assertTrue(tree.get("hello").equals("world"));
+  }
+
+  /**
+   * Test case courtesy of Derek Dick (mailto:ddick users.sourceforge.net)
+   */
+  public void testRollback1b() throws Exception {
+
+    // Note: We start out with an empty file
+    DBAbstract db = newDBCache();
+
+    HTree<Object, Object> tree = (HTree<Object, Object>) db
+        .createHashMap("test");
+
+    tree.put("Foo", "Bar");
+    tree.put("Fo", "Fum");
+
+    db.commit();
+
+    tree.put("Hello", "World");
+
+    db.rollback();
+
+    assertTrue(tree.get("Foo").equals("Bar"));
+    assertTrue(tree.get("Fo").equals("Fum"));
+    assertTrue(tree.get("Hello") == null);
+  }
+
+  /**
+   * Test case courtesy of Derek Dick (mailto:ddick users.sourceforge.net)
+   */
+  public void testRollback2b() throws Exception {
+    DBAbstract db;
+    long root;
+
+    // Note: We start out with an empty file
+    db = newDBCache();
+
+    root = db.getNamedObject("xyz");
+
+    BTree tree = null;
+    if (root == 0) {
+      // create a new one
+      tree = BTree.createInstance(db);
+      root = tree.getRecid();
+      db.setNamedObject("xyz", root);
+      db.commit();
+    } else {
+      tree = BTree.load(db, root);
+    }
+
+    tree.insert("hello", "world", true);
+    tree.insert("goodnight", "gracie", true);
+    db.commit();
+
+    tree.insert("derek", "dick", true);
+    db.rollback();
+
+    assertTrue(tree.get("derek") == null);
+    assertTrue(tree.get("goodnight").equals("gracie"));
+    assertTrue(tree.get("hello").equals("world"));
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestStress.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestStress.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestStress.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/TestStress.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,215 @@
+/**
+ * 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.Random;
+
+/**
+ * This class contains stress tests for this package.
+ */
+public class TestStress extends TestCaseWithTestFile {
+
+  // test parameters
+  final int RECORDS = 10000;
+  final int MAXSIZE = 500;
+  final int ROUNDS = 1 * 1000 * 1000;
+
+  final int RPPROMILLE = ROUNDS / 1000;
+
+  Random rnd = new Random(42);
+
+  // holder for record data so we can compare
+  class RecordData {
+    long rowid;
+    int size;
+    byte b;
+
+    RecordData(long rowid, int size, byte b) {
+      this.rowid = rowid;
+      this.size = size;
+      this.b = b;
+    }
+
+    public String toString() {
+      return "slot(" + rowid + ",sz=" + size + ",b=" + b + ")";
+    }
+  }
+
+  private int getRandomAllocatedSlot(RecordData[] d) {
+    int slot = rnd.nextInt(RECORDS);
+    while (d[slot] == null) {
+      slot++;
+      if (slot == RECORDS)
+        slot = 0; // wrap
+    }
+    return slot;
+  }
+
+  // holder for root records
+  long[] roots = new long[Magic.FILE_HEADER_NROOTS];
+
+  private int getRandomAllocatedRoot() {
+    int slot = rnd.nextInt(Magic.FILE_HEADER_NROOTS);
+    while (roots[slot] == 0) {
+      slot++;
+      if (slot == Magic.FILE_HEADER_NROOTS)
+        slot = 0; // wrap
+    }
+    return slot;
+  }
+
+  /**
+   * Test basics
+   */
+  public void testBasics() throws Exception {
+
+    String file = newTestFile();
+    DBStore db = new DBStore(file, false, false, false);
+
+    // as this code is meant to test data structure calculcations
+    // and stuff like that, we may want to disable transactions
+    // that just slow us down.
+    // mgr.disableTransactions();
+
+    RecordData[] d = new RecordData[RECORDS];
+    int recordCount = 0, rootCount = 0;
+    int inserts = 0, updates = 0, deletes = 0, fetches = 0;
+    int rootgets = 0, rootsets = 0;
+    int slot = -1;
+
+    try {
+
+      for (int i = 0; i < ROUNDS; i++) {
+        if ((i % RPPROMILLE) == 0)
+          System.out.print("\rComplete: " + i / RPPROMILLE + "/1000th");
+
+        // close and re-open a couple of times during the
+        // test, in order to check flushing etcetera.
+        if ((i % (ROUNDS / 5)) == 0) {
+          System.out.print(" (reopened at round " + i / RPPROMILLE + ")");
+          db.close();
+          db = new DBStore(file, false, false, false);
+          // db.disableTransactions();
+        }
+
+        // generate a random number and assign ranges to operations:
+        // 0-10 = insert, 20 = delete, 30-50 = update, 51 = set root,
+        // 52 = get root, rest = fetch.
+        int op = rnd.nextInt(100);
+        if (op <= 10) {
+          // INSERT RECORD
+          if (recordCount == RECORDS) {
+            i -= 1;
+            continue;
+          }
+
+          slot = 0;
+          while (d[slot] != null)
+            slot++;
+
+          d[slot] = new RecordData(0, rnd.nextInt(MAXSIZE),
+              (byte) rnd.nextInt());
+          d[slot].rowid = db.insert(UtilTT.makeRecord(d[slot].size, d[slot].b));
+          recordCount++;
+          inserts++;
+        } else if (op == 20) {
+          // DELETE RECORD
+          if (recordCount == 0) {
+            i -= 1;
+            continue;
+          }
+
+          slot = getRandomAllocatedSlot(d);
+          db.delete(d[slot].rowid);
+          d[slot] = null;
+          recordCount--;
+          deletes++;
+        } else if (op <= 50) {
+          // UPDATE RECORD
+          if (recordCount == 0) {
+            i -= 1;
+            continue;
+          }
+
+          slot = getRandomAllocatedSlot(d);
+          d[slot].size = rnd.nextInt(MAXSIZE);
+          d[slot].b = (byte) rnd.nextInt();
+          db.update(d[slot].rowid, UtilTT.makeRecord(d[slot].size, d[slot].b));
+          updates++;
+        } else if (op == 51) {
+
+          // SET ROOT
+          int root = rnd.nextInt(Magic.FILE_HEADER_NROOTS);
+          if (root > 10) { // DONT do this for reserved roots
+            roots[root] = rnd.nextLong();
+            db.setRoot((byte) root, roots[root]);
+            rootsets++;
+          }
+        } else if (op == 52) {
+          // GET ROOT
+          if (rootCount == 0) {
+            i -= 1;
+            continue;
+          }
+
+          int root = getRandomAllocatedRoot();
+          if (root > 10) { // DONT do this for reserved roots
+            assertEquals("root", roots[root], db.getRoot((byte) root));
+            rootgets++;
+          }
+        } else {
+          // FETCH RECORD
+          if (recordCount == 0) {
+            i -= 1;
+            continue;
+          }
+
+          slot = getRandomAllocatedSlot(d);
+          byte[] data = (byte[]) db.fetch(d[slot].rowid);
+          assertTrue("fetch round=" + i + ", slot=" + slot + ", " + d[slot],
+              UtilTT.checkRecord(data, d[slot].size, d[slot].b));
+          fetches++;
+        }
+      }
+      db.close();
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw new RuntimeException("aborting test at slot " + slot + ": ", e);
+    } finally {
+      System.out.println("records : " + recordCount);
+      System.out.println("deletes : " + deletes);
+      System.out.println("inserts : " + inserts);
+      System.out.println("updates : " + updates);
+      System.out.println("fetches : " + fetches);
+      System.out.println("rootget : " + rootgets);
+      System.out.println("rootset : " + rootsets);
+      int totalSize = 0;
+      for (int i = 0; i < RECORDS; i++)
+        if (d[i] != null)
+          totalSize += d[i].size;
+      System.out.println("total outstanding size: " + totalSize);
+
+      // System.out.println("---");
+      // for (int i = 0; i < RECORDS; i++)
+      // if (d[i] != null)
+      // System.out.println("slot " + i + ": " + d[i]);
+    }
+
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilTT.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilTT.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilTT.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilTT.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,47 @@
+/**
+ * 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.Assert;
+
+/**
+ * This class contains some test utilities.
+ */
+public class UtilTT {
+  /**
+   * Creates a "record" containing "length" repetitions of the indicated byte.
+   */
+  public static byte[] makeRecord(int length, byte b) {
+    byte[] retval = new byte[length];
+    for (int i = 0; i < length; i++)
+      retval[i] = b;
+    return retval;
+  }
+
+  /**
+   * Checks whether the record has the indicated length and data
+   */
+  public static boolean checkRecord(byte[] data, int length, byte b) {
+    Assert.assertEquals("lenght does not match", length, data.length);
+    for (int i = 0; i < length; i++)
+      Assert.assertEquals("byte " + i, b, data[i]);
+
+    return true;
+  }
+
+}

Added: hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilsTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilsTest.java?rev=1387533&view=auto
==============================================================================
--- hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilsTest.java (added)
+++ hama/trunk/jdbm/src/test/java/org/apache/hama/jdbm/UtilsTest.java Wed Sep 19 11:52:20 2012
@@ -0,0 +1,30 @@
+/**
+ * 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 UtilsTest extends TestCase {
+
+  public void testFormatSpaceUsage() {
+    assertEquals("100B", JDBMUtils.formatSpaceUsage(100L));
+    assertEquals("1024B", JDBMUtils.formatSpaceUsage(1024L));
+    assertEquals("10KB", JDBMUtils.formatSpaceUsage(10024L));
+    assertEquals("15MB", JDBMUtils.formatSpaceUsage(15000000));
+  }
+}

Modified: hama/trunk/pom.xml
URL: http://svn.apache.org/viewvc/hama/trunk/pom.xml?rev=1387533&r1=1387532&r2=1387533&view=diff
==============================================================================
--- hama/trunk/pom.xml (original)
+++ hama/trunk/pom.xml Wed Sep 19 11:52:20 2012
@@ -248,6 +248,7 @@
     <module>examples</module>
     <module>yarn</module>
     <module>ml</module>
+    <module>jdbm</module>
     <module>dist</module>
   </modules>
 

Modified: hama/trunk/src/assemble/bin.xml
URL: http://svn.apache.org/viewvc/hama/trunk/src/assemble/bin.xml?rev=1387533&r1=1387532&r2=1387533&view=diff
==============================================================================
--- hama/trunk/src/assemble/bin.xml (original)
+++ hama/trunk/src/assemble/bin.xml Wed Sep 19 11:52:20 2012
@@ -74,6 +74,19 @@
       </excludes>
       <outputDirectory>../hama-${project.version}/</outputDirectory>
     </fileSet>
+    <fileSet>
+      <directory>../jdbm/target</directory>
+      <includes>
+        <include>hama-*.jar</include>
+      </includes>
+      <excludes>
+        <exclude>*sources.jar</exclude>
+        <exclude>*tests.jar</exclude>
+        <exclude>*javadoc.jar</exclude>
+      </excludes>
+      <outputDirectory>../hama-${project.version}/</outputDirectory>
+    </fileSet>
+
  
     <fileSet>
       <directory>../</directory>



Mime
View raw message