froehlich 02/01/27 09:05:36 Modified: simplestore/src/test/org/apache/commons/simplestore TestSoftRefMemoryStore.java Log: applied more patches from Juozas Baliuka [[EMAIL PROTECTED]] Revision Changes Path 1.6 +31 -10 jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSoftRefMemoryStore.java Index: TestSoftRefMemoryStore.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSoftRefMemoryStore.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TestSoftRefMemoryStore.java 26 Jan 2002 16:19:31 -0000 1.5 +++ TestSoftRefMemoryStore.java 27 Jan 2002 17:05:36 -0000 1.6 @@ -19,11 +19,11 @@ * [EMAIL PROTECTED]</a> * @author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - * @version $Id: TestSoftRefMemoryStore.java,v 1.5 2002/01/26 16:19:31 froehlich Exp $ + * @version $Id: TestSoftRefMemoryStore.java,v 1.6 2002/01/27 17:05:36 froehlich Exp $ */ public class TestSoftRefMemoryStore extends TestStore { - private final int ITERATIONS = 2000; + private final int ITERATIONS = 200; private final int MAX_STRONG_REFS = 10; private final int ITEM_SIZE = 0xFFFF; @@ -43,22 +43,21 @@ public Store makeStore() { Swap swap = new Swap(){ - - // this means GC decided memory is low and + // this means GC decided memory is low and // SoftRefMemoryStore decided object is "old" // value wrapper calls this method from finalize // Queue implementation can write object to swap here // It can use JMS to send Object Message - public void add( Object object ){ - System.out.println("Object added to swap " + object.toString().substring(0,20)); + public void add(Object key , Reachable object ){ + System.out.println( key + " Object added to swap " + object.toString().substring(0,20)); } // do nothing at this time, becouse we added no object to Qeue at this time // Queue implementation can add objects to Batch, then this method can be usd to test Queue // It can use Thread in stand alone application to execute Batch - public Object poll( ){ return null; } + }; - SoftRefMemoryStore store = new SoftRefMemoryStore(swap ,MAX_STRONG_REFS ); + SoftRefMemoryStore store = new SoftRefMemoryStore(swap,MAX_STRONG_REFS ); return store; } @@ -68,9 +67,14 @@ char[] testObject = new char[ ITEM_SIZE/2 + 1 ]; java.util.Arrays.fill(testObject,'.'); - - for(int i = 0; i < ITERATIONS; i++) { - store.put(new Integer(i), "(" + new Integer(i) + ")" + new String(testObject)); + Object key = new Integer(0); + Object value = new String(testObject); + ValueObject valueObj = new ValueObject(value); + store.put(key, valueObj ); + for(int i = 1; i < ITERATIONS; i++) { + Object obj = new String(testObject); + obj = new ValueObject(obj); + store.put(new Integer(i),obj ); _testGet(i); } // get something @@ -78,9 +82,26 @@ i < ITERATIONS / 2 ; i++) { _testGet(i); } + assertEquals("Lost Strong Referense in cache", store.get(key), valueObj ); } + + public static class ValueObject implements Reachable{ + Object reference; + Object value; + public ValueObject( Object value){ + this.value = value; + } + Object getValue(){ + return value; + } + public String toString(){ return value != null ? value.toString() : null; } + public void setReference(Object reference) { + this.reference = reference; + } + + } private void _testGet(int lastKey){ if( lastKey >= MAX_STRONG_REFS)
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>