[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/collection ...
Elias Ross
genman at noderunner.net
Mon Nov 6 18:32:17 EST 2006
User: genman
Date: 06/11/06 18:32:17
Modified: tests-50/functional/org/jboss/cache/pojo/collection
CachedSetTest.java
Log:
JBCACHE-485 - Set.contains() remove() and add() O(1) ops now
Revision Changes Path
1.5 +42 -0 JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/CachedSetTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedSetTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/CachedSetTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- CachedSetTest.java 31 Oct 2006 11:07:16 -0000 1.4
+++ CachedSetTest.java 6 Nov 2006 23:32:17 -0000 1.5
@@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -107,6 +108,47 @@
assertTrue("Should be empty", skills.isEmpty());
}
+ private static class DumbObject
+ {
+ int i;
+ DumbObject(int i) { this.i = i; }
+ public int hashCode()
+ {
+ return 0;
+ }
+ public String toString()
+ {
+ return "" + i;
+ }
+ }
+
+ public void testConflictingHash() throws Exception
+ {
+ Set set = new HashSet();
+ String nulls = null;
+ DumbObject o1 = new DumbObject(1);
+ DumbObject o2 = new DumbObject(2);
+ DumbObject o3 = new DumbObject(3);
+ set.add(o1);
+ set.add(o2);
+ set.add(o3);
+ set.add(nulls);
+ Set set2 = Collections.unmodifiableSet(new HashSet(set));
+
+ cache_.attach("/test", set); // attach
+ set = (Set) cache_.find("/test");
+ assertEquals("Same", set2, set);
+ assertEquals(true, set.remove(o2));
+ assertEquals(true, set.remove(nulls));
+ assertEquals(false, set.remove(o2));
+ assertEquals("Same minus 2 ", set2.size()-2, set.size());
+ assertEquals("set " + set, true, set.add(o2));
+ assertEquals("set " + set, true, set.add(nulls));
+ assertEquals(false, set.add(o2));
+ assertEquals(false, set.add(nulls));
+ assertEquals("Same", set2, set);
+ }
+
public void testAddAndRemoveAll() throws Throwable
{
List list = new ArrayList();
More information about the jboss-cvs-commits
mailing list