You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ka...@apache.org on 2009/01/06 21:25:59 UTC
svn commit: r732099 [2/2] - in /labs/bananadb: ./ trunk/ trunk/src/
trunk/src/main/ trunk/src/main/java/ trunk/src/main/java/org/
trunk/src/main/java/org/apache/ trunk/src/main/java/org/apache/labs/
trunk/src/main/java/org/apache/labs/bananadb/ trunk/s...
Added: labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java?rev=732099&view=auto
==============================================================================
--- labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java (added)
+++ labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java Tue Jan 6 12:25:58 2009
@@ -0,0 +1,107 @@
+package org.apache.labs.bananadb.hashtable;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+import org.apache.labs.bananadb.hashtable.handlers.IntegerHandler;
+import org.apache.labs.bananadb.hashtable.handlers.StringValueHandler;
+
+import java.io.File;
+
+/**
+ * User: kalle
+ * Date: 2009-jan-03
+ * Time: 05:43:56
+ */
+public class TestHashtable extends TestCase {
+
+ public void test() throws Exception {
+
+ File path = new File("target/" + Hashtable.class.getSimpleName() + "/" + System.currentTimeMillis());
+ path.mkdirs();
+
+ Hashtable<Integer, String> map;
+
+ map = new Hashtable<Integer, String>(path, 1000000, new IntegerHandler(), new StringValueHandler());
+
+ assertEquals(0, map.size());
+
+ HashtableAccessor accessor = map.createAccessor(false);
+
+ assertNull(map.get(accessor, 0));
+
+ String v = "hello world";
+
+ assertNull(map.put(accessor, 0, v));
+ assertEquals(1, map.size());
+ assertEquals(v, map.get(accessor, 0));
+
+ assertNull(map.put(accessor, 1, v));
+ assertEquals(2, map.size());
+
+ String v2 = map.get(accessor, 1);
+ assertEquals(v, v2);
+
+
+ accessor.close();
+
+ //
+
+ map = new Hashtable<Integer, String>(path, 100, new IntegerHandler(), new StringValueHandler());
+
+ assertEquals(2, map.size());
+
+ accessor = map.createAccessor(false);
+ Hashtable<Integer, String>.Cursor cursor = map.new Cursor(accessor);
+
+ assertTrue(cursor.next());
+ assertEquals(0, (int) cursor.key());
+ assertEquals(v, cursor.value());
+
+ assertTrue(cursor.next());
+ assertEquals(1, (int) cursor.key());
+ assertEquals(v, cursor.value());
+
+ assertFalse(cursor.next());
+
+ v = map.remove(accessor, 0);
+ assertEquals(1, map.size());
+ assertEquals(v2, v);
+ assertNull(map.get(accessor, 0));
+
+ accessor.close();
+
+ //
+
+ map = new Hashtable<Integer, String>(path, 100, new IntegerHandler(), new StringValueHandler());
+
+ accessor = map.createAccessor(false);
+
+ assertNull(map.get(accessor, 0));
+
+ assertNotNull(map.get(accessor, 1));
+ assertEquals(1, map.size());
+
+ for (int i = 2; i < 100; i++) {
+ map.put(accessor, i, v);
+ assertEquals(v, map.get(accessor, i));
+ }
+
+ accessor.close();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org