froehlich 02/01/26 08:19:31
Modified: simplestore/src/test/org/apache/commons/simplestore
TestSoftRefMemoryStore.java
Log:
applied more patches from Juozas Baliuka [[EMAIL PROTECTED]]
Revision Changes Path
1.5 +65 -28
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestSoftRefMemoryStore.java 26 Jan 2002 12:01:07 -0000 1.4
+++ TestSoftRefMemoryStore.java 26 Jan 2002 16:19:31 -0000 1.5
@@ -19,51 +19,88 @@
* [EMAIL PROTECTED]</a>
* @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 $
+ * @version $Id: TestSoftRefMemoryStore.java,v 1.5 2002/01/26 16:19:31 froehlich
Exp $
*/
-public class TestSoftRefMemoryStore extends TestStore
-{
+public class TestSoftRefMemoryStore extends TestStore {
+
+ private final int ITERATIONS = 2000;
+ private final int MAX_STRONG_REFS = 10;
+ private final int ITEM_SIZE = 0xFFFF;
+
+
public TestSoftRefMemoryStore(String testName) {
super(testName);
}
-
+
public static Test suite() {
return new TestSuite(TestSoftRefMemoryStore.class);
}
-
+
public static void main(String args[]) {
String[] testCaseName = { TestSoftRefMemoryStore.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
-
+
public Store makeStore() {
- 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);
+ 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.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 );
return store;
}
-
+
public void testSwaping(){
- byte[] testObject= new byte[100];
-
- for(int i = 0; i < 10000; i++) {
- store.put(new Integer(i),new String(testObject));
+
+ assertTrue("try to set ITERATIONS > MAX_STRONG_REFS ", ITERATIONS >
MAX_STRONG_REFS );
+
+ 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));
+ _testGet(i);
+ }
+ // get something
+ for( int i = ITERATIONS / ( MAX_STRONG_REFS == 0 ? 10 : MAX_STRONG_REFS );
+ i < ITERATIONS / 2 ; i++) {
+ _testGet(i);
+ }
+
+
+ }
+ private void _testGet(int lastKey){
+
+ if( lastKey >= MAX_STRONG_REFS)
+ System.out.println("GET ... ");
+
+ for( int i = lastKey - MAX_STRONG_REFS ;
+ ( i < lastKey ) && ( i > 0 );
+ i += ( MAX_STRONG_REFS / 2 + 1 ) ) {
+
+ Object key = new Integer(i);
+ Object object = store.get(key);
+
+ if(object == null){
+ System.out.println( key + " removed from memory ");
+ }else{
+ System.out.println( object.toString().substring(0,20) );
+ }
}
}
+
protected void setUp() throws java.lang.Exception {
super.setUp();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>