froehlich 02/01/26 04:01:07
Modified: simplestore/src/test/org/apache/commons/simplestore
TestSoftRefMemoryStore.java
Log:
applied patches from Juozas Baliuka [[EMAIL PROTECTED]].
- re-factored SoftRefMemoryStore
- added Swapping Simultation and test case
Revision Changes Path
1.4 +29 -23
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestSoftRefMemoryStore.java 21 Jan 2002 22:02:25 -0000 1.3
+++ TestSoftRefMemoryStore.java 26 Jan 2002 12:01:07 -0000 1.4
@@ -17,7 +17,9 @@
/**
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- * @version $Id: TestSoftRefMemoryStore.java,v 1.3 2002/01/21 22:02:25 froehlich
Exp $
+ * @author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
+ * [EMAIL PROTECTED]</a>
+ * @version $Id: TestSoftRefMemoryStore.java,v 1.4 2002/01/26 12:01:07 froehlich
Exp $
*/
public class TestSoftRefMemoryStore extends TestStore
{
@@ -35,33 +37,37 @@
}
public Store makeStore() {
- MRUMemoryStore mrustore = new MRUMemoryStore(10);
- SoftRefMemoryStore softstore = new SoftRefMemoryStore(mrustore,10);
- return softstore;
+ Swap swap = new Swap(){
+
+ // 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);
+ }
+ // 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 ,10);
+ return store;
}
- public void setUp() {
- store = makeStore();
+ public void testSwaping(){
+ byte[] testObject= new byte[100];
+
+ for(int i = 0; i < 10000; i++) {
+ store.put(new Integer(i),new String(testObject));
+ }
}
- public void testNewStore() {
- assertTrue("New store is empty", store.isEmpty());
- assertEquals("New store has size zero", store.size(), 0);
- }
-
- public void testSearch() {
- System.out.println("Testing MRUMemoryStore with WeakReferences");
- store.put("first", "First Item");
- store.put("second", "Second Item");
-
- assertEquals("Top item is 'Second Item'", store.get("first"), "First Item");
- assertEquals("Next Item is 'First Item'", store.get("second"), "Second
Item");
-
- store.remove("first");
- store.remove("second");
-
- assertTrue("Map is empty, now", store.isEmpty());
- assertEquals("Map has size zero, now", store.size(), 0);
+ protected void setUp() throws java.lang.Exception {
+ super.setUp();
+ store = makeStore();
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>