The original WeakObjectCacheTest
class is almost fully a Refractions Research's work.
See the comments at revision 26198 for a general analysis.
Comments specific to this commit are:
testRemoveSimple()
method has not been ported to SIS. Instead we re-use the
WeakValueHashMapTest
methods, which test additions and removals both as strong
and as weak references.Map.equals(Object)
contract.Command line:
svn diff --extensions "--unified --ignore-space-change --ignore-all-space --ignore-eol-style" -r31617:31618 https://svn.osgeo.org/geotools/trunk/modules/library/metadata/src/test/java/org/geotools/util/WeakObjectCacheTest.java
Revision 31617 | Revision 31618 |
---|---|
assertEquals(value1, cache.get(key1)); assertEquals(null, cache.get(key2)); } @Test public void testConcurrent() throws InterruptedException { ObjectCache cache = new WeakObjectCache(); |
assertEquals(value1, cache.get(key1)); assertEquals(null, cache.get(key2)); //test getKeys() assertEquals(1, cache.getKeys().size()); assertEquals(key1, cache.getKeys().iterator().next()); } @Test public void testRemoveSimple(){ ObjectCache cache = new WeakObjectCache(); assertNotNull(cache); assertEquals(null, cache.get(key1)); cache.writeLock(key1); cache.put(key1, value1); cache.writeUnLock(key1); assertEquals(value1, cache.get(key1)); assertEquals(null, cache.get(key2)); //test getKeys() assertEquals(1, cache.getKeys().size()); assertEquals(key1, cache.getKeys().iterator().next()); //remove the key cache.remove(key1); assertEquals(0, cache.getKeys().size()); } @Test public void testConcurrent() throws InterruptedException { ObjectCache cache = new WeakObjectCache(); |
Object[] values = ((WriterThread) thread1).getValue(); assertEquals(null, values); assertEquals(value2, cache.peek(key1)); //check that a separate write thread can get through cache.writeLock(key2); cache.put(key2, value3); cache.writeUnLock(key2); //unlock try { |
Object[] values = ((WriterThread) thread1).getValue(); assertEquals(null, values); assertEquals(value2, cache.peek(key1)); assertEquals(1,cache.getKeys().size()); //check that a separate write thread can get through cache.writeLock(key2); cache.put(key2, value3); cache.writeUnLock(key2); assertEquals(2,cache.getKeys().size()); //unlock try { |
values = ((WriterThread) thread1).getValue(); assertNotNull(values); assertEquals(value1, values[0]); } private class WriterThread implements Runnable { |
values = ((WriterThread) thread1).getValue(); assertNotNull(values); assertEquals(value1, values[0]); assertEquals(2, cache.getKeys().size()); assertTrue(cache.getKeys().contains(key1)); assertTrue(cache.getKeys().contains(key2)); } private class WriterThread implements Runnable { |