Commits

Anonymous committed 3eaa467

Submitter: Andres March

fixed a few test cases

Comments (0)

Files changed (41)

src/core/java/com/opensymphony/oscache/core/AbstractCacheAdministrator.java

 package com.opensymphony.oscache.core;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
  */
 public abstract class AbstractCacheAdministrator implements
 		java.io.Serializable {
+	public static final String DEFAULT_REGION = "DEFAULT_REGION";
+
 	private static transient final Log log = LogFactory
 			.getLog(AbstractCacheAdministrator.class);
 
 	 */
 	protected int cacheCapacity = -1;
 
-	private Map regions;
+	private Map regions = new HashMap();
 
 	/**
 	 * Create the AbstractCacheAdministrator. This will initialize all values
 	 * @return The cache
 	 * @throws IllegalAccessException 
 	 */
-	public Cache getCache() throws IllegalAccessException {
-		if (regions.size() != 1) throw new IllegalAccessException("More than 1 region configured.  Please use getCache(String regionName)");
-		return (Cache) regions.get("DEFAULT_REGION");
+	public Cache getCache() throws RuntimeException {
+		if (regions.size() != 1) throw new RuntimeException("More than 1 region configured.  Please use getCache(String regionName)");
+		return (Cache) regions.get(DEFAULT_REGION);
+	}
+	
+	public void addCache(String region, Cache cache) {
+		regions.put(region, cache);
+		
 	}
 }

src/core/java/com/opensymphony/oscache/core/BaseCache.java

 import java.util.Properties;
 import java.util.Set;
 
+import com.opensymphony.oscache.algorithm.LRUEvictionAlgorithm;
 import com.opensymphony.oscache.core.EntryRefreshPolicy;
 import com.opensymphony.oscache.core.CacheEntry;
 import com.opensymphony.oscache.events.CacheEntryEvent;
  */
 public abstract class BaseCache implements Cache {
 
-	private EvictionAlgorithm algorithm;
+	private EvictionAlgorithm algorithm = new LRUEvictionAlgorithm();
 
 	private String name;
 
 		Object content = null;
 		if (cacheEntry != null) {
 			content = cacheEntry.getValue();
-			// Check if this entry has expired or has not yet been added to the
-			// cache. If
-			// so, we need to decide whether to block or serve stale content
 			if (this.isStale(cacheEntry, refreshPeriod, cronExpiry)) {
-				remove(key);
 				content = null;
-			} else {
-				algorithm.get(key, cacheEntry);
-
 			}
+			algorithm.get(key, cacheEntry);
 		}
 		return content;
 
 		// fire off a notification message
 		if (oldEntry == null) {
 			fireEvent(newEntry, CacheEvent.ADD);
-		} else {
-			fireEvent(newEntry, CacheEvent.UPDATE);
+			return null;
 		}
+		fireEvent(newEntry, CacheEvent.UPDATE);
 
 		return oldEntry.getValue();
 	}
 	 */
 	public synchronized CacheEntry getEntry(Object key) {
 		CacheEntry cacheEntry = getInternal(key);
-
+		if (cacheEntry != null) {
+			algorithm.get(key, cacheEntry);
+		}
 		return cacheEntry;
 	}
 
 	 * @param group
 	 *            The group to flush
 	 */
-	public void removeGroup(String group) {
+	public void flushGroup(String group) {
 		// Flush all objects in the group
 		Set groupEntries = (Set) groupMap.get(group);
 
 		this.name = name;
 	}
 
-	public void setEvictionPolicy(EvictionAlgorithm policy, Properties props)
+	public void setEvictionAlgorithm(EvictionAlgorithm algorithm)
 			throws IllegalStateException {
+		this.algorithm = algorithm;
 	}
 
 	/**

src/core/java/com/opensymphony/oscache/core/Cache.java

 
 import com.opensymphony.oscache.events.CacheListener;
 
-
 /**
  * DOCUMENT ME!
  * 
  * @version $Revision$
  */
 public interface Cache extends Map {
-	
 
 	/**
 	 * Allows the capacity of the cache to be altered dynamically. Note that
 	 */
 	public abstract void setCapacity(int capacity);
 
-	
 	/**
 	 * Retrieves an object from the cache.
 	 * 
 	 * @return the cached object, or <code>null</code> if the object could not
 	 *         be found and could not be loaded.
 	 */
-	public abstract Object get(Object key, int refreshPeriod,
-			String cronExpiry);
-	
+	public abstract Object get(Object key, int refreshPeriod, String cronExpiry);
+
 	/**
 	 * Retrieves an object from the cache.
 	 * 
 	 *         be found and could not be loaded.
 	 */
 	public abstract Object get(Object key, int refreshPeriod);
-	
+
 	/**
 	 * Retrieve an object from the cache specifying its key.
 	 * 
 	 * 
 	 */
 	public abstract CacheEntry getEntry(Object key);
+	
+	/**
+	 * Store the supplied entry in the cache.
+	 * 
+	 * @param key
+	 *            the key to store the entry under.
+	 * @param value
+	 *            the object to store.
+	 * @return the previous object that was stored under this key, if any.
+	 */
+	public abstract Object put(Object key, Object value, String[] groups,
+			EntryRefreshPolicy policy);
 
+	/**
+	 * Store the supplied entry in the cache.
+	 * 
+	 * @param key
+	 *            the key to store the entry under.
+	 * @param value
+	 *            the object to store.
+	 * @return the previous object that was stored under this key, if any.
+	 */
+	public abstract Object put(Object key, Object value,
+			EntryRefreshPolicy policy);
 
 	/**
+	 * Store the supplied entry in the cache.
+	 * 
+	 * @param key
+	 *            the key to store the entry under.
+	 * @param value
+	 *            the object to store.
+	 * @return the previous object that was stored under this key, if any.
+	 */
+	public abstract Object put(Object key, Object value, String[] groups);
+
+	
+
+	/**
+	 * Flushes all unexpired objects that belong to the supplied group. On
+	 * completion this method fires a <tt>CacheEntryEvent.GROUP_FLUSHED</tt>
+	 * event.
+	 * 
+	 * @param group
+	 *            The group to flush
+	 */
+	public void flushGroup(String group) ;
+	
+	/**
 	 * Flush all entries in the cache on the given date/time.
 	 * 
 	 * @param date
 	 */
 	public abstract void flushAll(Date date);
 
-
 	/**
 	 * Completely clears the cache.
 	 */
 	public abstract void clear();
+
+	/**
+	 * Adds a listener that will receive notifications when cache events occur.
+	 * Listeners will be notified of cache events in the same order as they have
+	 * been added to the cache.
+	 * 
+	 * @param listener
+	 *            the listener to receive the events.
+	 */
+	void addCacheListener(CacheListener listener);
+
+	/**
+	 * Removes a listener from the cache.
+	 * 
+	 * @param listener
+	 *            the listener to remove.
+	 * @return <code>true</code> if the listener was removed successfully,
+	 *         <code>false</code> if the listener could not be found.
+	 */
+	boolean removeCacheListener(CacheListener listener);
 	
-	/**
-	   * Adds a listener that will receive notifications when cache events occur.
-	   * Listeners will be notified of cache events in the same order as they have
-	   * been added to the cache.
-	   *
-	   * @param listener the listener to receive the events.
-	   */
-	  void addCacheListener(CacheListener listener);
-
-	  /**
-	   * Removes a listener from the cache.
-	   *
-	   * @param listener the listener to remove.
-	   * @return <code>true</code> if the listener was removed successfully,
-	   *         <code>false</code> if the listener could not be found.
-	   */
-	  boolean removeCacheListener(CacheListener listener);
+	public void setEvictionAlgorithm(EvictionAlgorithm algorithm);
 
 }

src/core/java/com/opensymphony/oscache/core/CacheEntry.java

 	public CacheEntry(Object key, Object value, EntryRefreshPolicy policy) {
 		this(key, value, null, policy);
 	}
+
 	/**
 	 * Construct a CacheEntry.
 	 * 
 	 *            The object that implements the refresh policy logic. This
 	 *            parameter is optional.
 	 */
-	public CacheEntry(Object key, Object value,  String[] groups) {
+	public CacheEntry(Object key, Object value, String[] groups) {
 		this(key, value, groups, null);
 	}
-	
 
 	public CacheEntry(Object key, Object value, String[] groups,
 			EntryRefreshPolicy policy) {
 		this.key = key;
-		this.groups = new HashSet(Arrays.asList(groups));
+		if (groups != null && groups.length > 0)
+			this.groups = new HashSet(Arrays.asList(groups));
 		this.policy = policy;
 		this.created = System.currentTimeMillis();
 		this.state = STATE_VALID;

src/core/java/com/opensymphony/oscache/general/GeneralCacheAdministrator.java

         createCache();
     }
 
-    /**
-     * Remove an object from the cache
-     *
-     * @param key             The key entered by the user.
-     */
-    public void removeEntry(String key) {
-        getCache().removeEntry(key);
-    }
-
-    /**
-     * Get an object from the cache
-     *
-     * @param key             The key entered by the user.
-     * @return   The object from cache
-     * @throws NeedsRefreshException when no cache entry could be found with the
-     * supplied key, or when an entry was found but is considered out of date. If
-     * the cache entry is a new entry that is currently being constructed this method
-     * will block until the new entry becomes available. Similarly, it will block if
-     * a stale entry is currently being rebuilt by another thread and cache blocking is
-     * enabled (<code>cache.blocking=true</code>).
-     */
-    public Object getFromCache(String key)  {
-        return getCache().get(key);
-    }
-
-    /**
-     * Get an object from the cache
-     *
-     * @param key             The key entered by the user.
-     * @param refreshPeriod   How long the object can stay in cache in seconds. To
-     * allow the entry to stay in the cache indefinitely, supply a value of
-     * {@link CacheEntry#INDEFINITE_EXPIRY}
-     * @return   The object from cache
-     * @throws NeedsRefreshException when no cache entry could be found with the
-     * supplied key, or when an entry was found but is considered out of date. If
-     * the cache entry is a new entry that is currently being constructed this method
-     * will block until the new entry becomes available. Similarly, it will block if
-     * a stale entry is currently being rebuilt by another thread and cache blocking is
-     * enabled (<code>cache.blocking=true</code>).
-     */
-    public Object getFromCache(String key, int refreshPeriod) {
-        return getCache().get(key, refreshPeriod);
-    }
-
-    /**
-     * Get an object from the cache
-     *
-     * @param key             The key entered by the user.
-     * @param refreshPeriod   How long the object can stay in cache in seconds. To
-     * allow the entry to stay in the cache indefinitely, supply a value of
-     * {@link CacheEntry#INDEFINITE_EXPIRY}
-     * @param cronExpression  A cron expression that the age of the cache entry
-     * will be compared to. If the entry is older than the most recent match for the
-     * cron expression, the entry will be considered stale.
-     * @return   The object from cache
-     * @throws NeedsRefreshException when no cache entry could be found with the
-     * supplied key, or when an entry was found but is considered out of date. If
-     * the cache entry is a new entry that is currently being constructed this method
-     * will block until the new entry becomes available. Similarly, it will block if
-     * a stale entry is currently being rebuilt by another thread and cache blocking is
-     * enabled (<code>cache.blocking=true</code>).
-     */
-    public Object getFromCache(String key, int refreshPeriod, String cronExpression) {
-        return getCache().get(key, refreshPeriod, cronExpression);
-    }
-
-    /**
-     * Cancels a pending cache update. This should only be called by a thread
-     * that received a {@link NeedsRefreshException} and was unable to generate
-     * some new cache content.
-     *
-     * @param key The cache entry key to cancel the update of.
-     */
-    public void cancelUpdate(String key) {
-        getCache().cancelUpdate(key);
-    }
 
     /**
      * Shuts down the cache administrator.
      */
     public void destroy() {
-        finalizeListeners(applicationCache);
+//        finalizeListeners(applicationCache);
     }
 
-    // METHODS THAT DELEGATES TO THE CACHE ---------------------
-
-    /**
-     * Flush the entire cache immediately.
-     */
-    public void flushAll() {
-        getCache().flushAll(new Date());
-    }
-
-    /**
-     * Flush the entire cache at the given date.
-     *
-     * @param date The time to flush
-     */
-    public void flushAll(Date date) {
-        getCache().flushAll(date);
-    }
-
-    /**
-     * Flushes a single cache entry.
-     */
-    public void flushEntry(String key) {
-        getCache().flushEntry(key);
-    }
+    
 
     /**
      * Sets the cache capacity (number of items). If the cache contains
      * to bring the cache back down to the new size.
      *
      * @param capacity The new capacity of the cache
+     * @throws IllegalAccessException 
      */
-    public void setCacheCapacity(int capacity) {
-        super.setCacheCapacity(capacity);
+    public void setCacheCapacity(int capacity)  {
         getCache().setCapacity(capacity);
     }
 
     private void createCache() {
         log.info("Creating new cache");
 
-        applicationCache = new MemoryCache(cacheCapacity);
+        Cache applicationCache = new MemoryCache(cacheCapacity);
 
         configureStandardListeners(applicationCache);
+        addCache(DEFAULT_REGION, applicationCache);
     }
+
+	
 }

src/core/test/com/opensymphony/oscache/base/DummyAlwayRefreshEntryPolicy.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.core.CacheEntry;
-import com.opensymphony.oscache.core.EntryRefreshPolicy;
-
-
-/**
- * This is an dummy implementation of an EntryRefreshPolicy. It is just to
- * illustrate how to use it.
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
- */
-public final class DummyAlwayRefreshEntryPolicy implements EntryRefreshPolicy {
-    /**
-     * Dummy implementation of an entry refresh policy. A real implementation
-     * whould do some logic to determine if this entry needs to be refreshed.
-     * It can be calling a bean or checking some files, or even manually manage
-     * the time expiration.
-     *
-     * <p>
-     * @param entry  The entry for wich to determine if a refresh is needed
-     * @return True or false
-     */
-    public boolean needsRefresh(CacheEntry entry) {
-        return true;
-    }
-}

src/core/test/com/opensymphony/oscache/base/GroupConcurrencyProblemTestCase.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.general.GeneralCacheAdministrator;
-
-import junit.framework.TestCase;
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class GroupConcurrencyProblemTestCase extends TestCase {
-    private static GeneralCacheAdministrator cache = new GeneralCacheAdministrator();
-
-    public static void main(String[] args) {
-        System.out.println("START");
-
-        // Create some clients and start them running.
-        for (int i = 0; i < 100; i++) {
-            System.out.println("Creating thread: " + i);
-
-            new Client(i, cache).start();
-        }
-
-        System.out.println("END");
-    }
-}
-
-
-/* Inner class to hammer away at the cache. */
-class Client extends Thread {
-    private static final int MAX_ITERATIONS = 1000;
-    private GeneralCacheAdministrator cache;
-    private int id;
-
-    public Client(int newId, GeneralCacheAdministrator newCache) {
-        super();
-        id = newId;
-        cache = newCache;
-    }
-
-    public void run() {
-        for (int i = 0; i < MAX_ITERATIONS; i++) {
-            /* Put an entry from this Client into the shared group.
-             */
-            cache.putInCache(Integer.toString(id), "Some interesting data", new String[] {
-                    "GLOBAL_GROUP"
-                });
-
-            // Flush that group.
-            cache.flushGroup("GLOBAL_GROUP");
-        }
-    }
-}

src/core/test/com/opensymphony/oscache/base/TestAbstractCacheAdministrator.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.core.AbstractCacheAdministrator;
-import com.opensymphony.oscache.core.MemoryCache;
-
-import junit.framework.TestCase;
-
-/**
- * Test class for the AbstractCacheAdministrator class. It tests some of the
- * public methods of the admin. Some others cannot be tested since they are
- * linked to the property file used for the tests, and since this file
- * will change, the value of some parameters cannot be asserted
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public class TestAbstractCacheAdministrator extends TestCase {
-    // Constants used in the tests
-    private final String CACHE_PATH_PROP = "cache.path";
-    private final String CONTENT = "Content for the abstract cache admin test";
-    private final String ENTRY_KEY = "Test Abstract Admin Key";
-    private final String INVALID_PROP_NAME = "INVALID_PROP_NAME";
-    private final String TEST_LOG = "test log";
-
-   
-
-    public void testGetAndPut() {
-    		AbstractCacheAdministrator admin = getAdmin();
-    		admin.setApplicationCache(new MemoryCache());
-    		Object value = admin.get(ENTRY_KEY);
-    		assertNull(value);
-    		admin.put(ENTRY_KEY, CONTENT);
-    		value = admin.get(ENTRY_KEY);
-    		assertEquals(value, CONTENT);    		
-    }
-    
-    /**
-     * Cannot be tested since CacheContents is an interface
-     */
-    public void testCacheContents() {
-    }
-
-    /**
-     * We cannot test this method because the value depends on the property
-     */
-    public void testGetCachePath() {
-    }
-
-    /**
-     * Validate that the properties retrieved by the admin are the same as the one
-     * specified in the property file. Do not test cache path or memory cache
-     * since it changes with the tests
-     */
-    public void testGetProperty() {
-        // Check if all the default properties are OK
-        assertNull(getAdmin().getProperty(INVALID_PROP_NAME));
-        assertNull(getAdmin().getProperty(""));
-
-        try {
-            assertNull(getAdmin().getProperty(null));
-            fail("NullPointerException expected (property Key null).");
-        } catch (Exception e) {
-        }
-    }
-
-    /**
-     * We cannot test this method because the value depends on the property
-     */
-    public void testIsFileCaching() {
-    }
-
-    /**
-     * We cannot test this method because the value depends on the property
-     */
-    public void testIsMemoryCaching() {
-    }
-
-    /**
-     * Perform a call to the log method. Unfornately, there is no way to check
-     * if the logging is done correctly, we only invoke it
-     */
-    public void testLog() {
-        // Invoke the log
-        // The other log method is not tested since it calls the same as we do
-        //TODO
-
-        /*getAdmin().log(TEST_LOG, System.out);
-        getAdmin().log("", System.out);
-        getAdmin().log(null, System.out);
-        getAdmin().log(TEST_LOG, null);
-          */
-    }
-
-    // Abstract method that returns an instance of an admin
-    protected AbstractCacheAdministrator getAdmin() {
-    		return new AbstractCacheAdministrator() {
-    		};
-    }
-}

src/core/test/com/opensymphony/oscache/base/TestCache.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.core.Cache;
-import com.opensymphony.oscache.core.CacheEntry;
-import com.opensymphony.oscache.general.GeneralCacheAdministrator;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test the public methods of the Cache class
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public class TestCache extends TestCase {
-    // Static variables required thru all the tests
-    private static Cache map = null;
-    private final String CONTENT = "Content for the cache test";
-
-    // Constants needed thru all the tests
-    private final String ENTRY_KEY = "Test cache key";
-    private final int NO_REFRESH_NEEDED = CacheEntry.INDEFINITE_EXPIRY;
-    private final int REFRESH_NEEDED = 0;
-
-    /**
-     * Class constructor.
-     * <p>
-     * @param str The test name (required by JUnit)
-     */
-    public TestCache(String str) {
-        super(str);
-    }
-
-    /**
-     * This method is invoked before each testXXXX methods of the
-     * class. It set ups the variables required for each tests.
-     */
-    public void setUp() {
-        // At first invocation, create a new Cache
-        if (map == null) {
-            GeneralCacheAdministrator admin = new GeneralCacheAdministrator();
-            map = admin.getCache();
-            assertNotNull(map);
-        }
-    }
-
-    /**
-     * This methods returns the name of this test class to JUnit
-     * <p>
-     * @return The name of this class
-     */
-    public static Test suite() {
-        return new TestSuite(TestCache.class);
-    }
-
-    /**
-     * Verify that items may still be flushed by key pattern
-     */
-    public void testFlushPattern() {
-        // Try to flush with a bad pattern and ensure that our data is still there
-        map.put(ENTRY_KEY, CONTENT);
-        map.flushPattern(ENTRY_KEY + "do not flush");
-        getBackContent(map, CONTENT, NO_REFRESH_NEEDED, false);
-
-        // Flush our map for real
-        map.flushPattern(ENTRY_KEY.substring(1, 2));
-        getBackContent(map, CONTENT, NO_REFRESH_NEEDED, true);
-
-        // Check invalid values
-        map.flushPattern("");
-        map.flushPattern(null);
-    }
-
-    /**
-     * Verify that we can put item in the cache and that they are correctly retrieved
-     */
-    public void testPutGetFromCache() {
-        // We put content in the cache and get it back with and without refresh
-        map.put(ENTRY_KEY, CONTENT);
-        getBackContent(map, CONTENT, NO_REFRESH_NEEDED, false);
-        getBackContent(map, CONTENT, REFRESH_NEEDED, true);
-
-        // Test with invalid values
-
-        /** TODO Verify this logic */
-        try {
-            assertNull(map.get("", NO_REFRESH_NEEDED));
-        } catch (NeedsRefreshException nre) {
-            map.cancelUpdate("");
-        } catch (Exception e) {
-        }
-
-        try {
-            assertNull(map.get(null, NO_REFRESH_NEEDED));
-        } catch (NeedsRefreshException nre) {
-            map.cancelUpdate(null);
-        } catch (Exception e) {
-        }
-    }
-
-    /**
-     * Verify that we can put item in the cache and that they are correctly retrieved
-     */
-    public void testPutGetFromCacheWithPolicy() {
-        // We put content in the cache and get it back
-        map.put(ENTRY_KEY + "policy", CONTENT, new DummyAlwayRefreshEntryPolicy());
-
-        // Should get a refresh
-        try {
-            map.get(ENTRY_KEY + "policy", -1);
-            fail("Should have got a refresh.");
-        } catch (NeedsRefreshException nre) {
-            map.cancelUpdate(ENTRY_KEY + "policy");
-        }
-    }
-
-    protected void tearDown() throws Exception {
-        if (map != null) {
-            map.clear();
-        }
-    }
-
-    /**
-     * Retrieve the content in the cache
-     * <p>
-     * @param map       The Cache in which the data is stored
-     * @param content   The content expected to be retrieved
-     * @param refresh   Time interval to determine if the cache object needs refresh
-     * @param exceptionExpected Specify if a NeedsRefreshException is expected
-     */
-    private void getBackContent(Cache map, Object content, int refresh, boolean exceptionExpected) {
-        try {
-            assertEquals(content, map.get(ENTRY_KEY, refresh));
-
-            if (exceptionExpected) {
-                fail("NeedsRefreshException should have been thrown!");
-            }
-        } catch (NeedsRefreshException nre) {
-            map.cancelUpdate(ENTRY_KEY);
-
-            if (!exceptionExpected) {
-                fail("NeedsRefreshException shouldn't have been thrown!");
-            }
-        }
-    }
-}

src/core/test/com/opensymphony/oscache/base/TestCacheEntry.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.core.CacheEntry;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test the public methods of the CacheEntry class
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public class TestCacheEntry extends TestCase {
-    // Static variables required thru the tests
-    static CacheEntry entry = null;
-    static long beforeCreation = 0;
-    static long afterCreation = 0;
-    private final String CONTENT = "Content for the cache entry test";
-
-    // Constants used thru the tests
-    private final String ENTRY_KEY = "Test cache entry key";
-    private final int NO_REFRESH_NEEDED = 1000000;
-    private final int REFRESH_NEEDED = 0;
-
-    /**
-     * Class constructor
-     * <p>
-     * @param str The test name (required by JUnit)
-     */
-    public TestCacheEntry(String str) {
-        super(str);
-    }
-
-    /**
-     * This method is invoked before each testXXXX methods of the
-     * class. It set ups the variables required for each tests.
-     */
-    public void setUp() {
-        // At first invocation, create a cache entry object
-        if (entry == null) {
-            // Log the time before and after to verify the creation time
-            // in one of the tests
-            beforeCreation = System.currentTimeMillis();
-
-            entry = new CacheEntry(ENTRY_KEY);
-            afterCreation = System.currentTimeMillis();
-        }
-    }
-
-    /**
-     * This methods returns the name of this test class to JUnit
-     * <p>
-     * @return The name of this class
-     */
-    public static Test suite() {
-        return new TestSuite(TestCacheEntry.class);
-    }
-
-    /**
-     * Verify the flush
-     */
-    public void testFlush() {
-        // Set the content so it shouldn't need refresh
-        entry.setValue(CONTENT);
-        assertTrue(!entry.needsRefresh(NO_REFRESH_NEEDED));
-
-        // Flush the entry. It should now needs refresh
-        entry.flush();
-        assertTrue(entry.needsRefresh(NO_REFRESH_NEEDED));
-    }
-
-    /**
-     * Verify that the creation time is correct
-     */
-    public void testGetCreated() {
-        assertBetweenOrEquals(beforeCreation, entry.getCreated(), afterCreation);
-    }
-
-    /**
-     * Retrieve the item created by the setup
-     */
-    public void testGetKey() {
-        assertTrue(entry.getKey().equals(ENTRY_KEY));
-    }
-
-    /**
-     * Verify that the last modification time is between the time before and
-     * after the alteration of the item
-     */
-    public void testGetLastUpdate() {
-        // again. Then we ensure that the update time is between our timestamps
-        long before = System.currentTimeMillis();
-        entry.setValue(CONTENT);
-
-        long after = System.currentTimeMillis();
-        assertBetweenOrEquals(before, entry.getLastUpdate(), after);
-    }
-
-    /**
-     * Verify that the "freshness detection" function properly
-     */
-    public void testNeedsRefresh() {
-        // Set the entry content so it shouldn't need refresh
-        // Invoke needsRefresh with no delay, so it should return true.
-        // Then invoke it with a big delay, so it should return false
-        assertTrue(entry.needsRefresh(REFRESH_NEEDED));
-        assertTrue(!entry.needsRefresh(NO_REFRESH_NEEDED));
-    }
-
-    /**
-     * Set the content of the item created by setup and then retrieve it and
-     * validate it
-     */
-    public void testSetGetContent() {
-        entry.setValue(CONTENT);
-        assertTrue(CONTENT.equals(entry.getValue()));
-
-        // Ensure that nulls are allowed
-        entry.setValue(null);
-        assertNull(entry.getValue());
-    }
-
-    /**
-     * Ensure that a value is between two others. Since the execution may be
-     * very fast, equals values are also considered to be between
-     */
-    private void assertBetweenOrEquals(long first, long between, long last) {
-        assertTrue(between >= first);
-        assertTrue(between <= last);
-    }
-}

src/core/test/com/opensymphony/oscache/base/TestCompleteBase.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.base.algorithm.TestCompleteAlgorithm;
-import com.opensymphony.oscache.base.events.TestCompleteEvents;
-import com.opensymphony.oscache.util.TestFastCronParser;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test class for the com.opensymphony.oscache.core package.
- * It invokes all the test suites of all the other classes of the package.
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public final class TestCompleteBase extends TestCase {
-    /**
-     * Constructor for the osCache project main test program
-     */
-    public TestCompleteBase(String str) {
-        super(str);
-    }
-
-    /**
-     * Main method which is called to perform the tests
-     * <p>
-     * @param   args    Arguments received
-     */
-    public static void main(String[] args) {
-        // Run the test suite
-        junit.swingui.TestRunner testRunner = new junit.swingui.TestRunner();
-        testRunner.setLoading(false);
-
-        String[] args2 = {TestCompleteBase.class.getName()};
-        testRunner.start(args2);
-    }
-
-    /**
-     * Test suite required to test this project
-     * <p>
-     * @return  suite   The test suite
-     */
-    public static Test suite() {
-        // Add all the tests suite of all the project classes
-        TestSuite suite = new TestSuite("Test all base cache modules");
-        suite.addTest(TestFastCronParser.suite());
-        suite.addTest(TestCacheEntry.suite());
-        suite.addTest(TestCache.suite());
-        suite.addTest(TestConcurrency.suite());
-        suite.addTest(TestCompleteAlgorithm.suite());
-        suite.addTest(TestCompleteEvents.suite());
-
-        return suite;
-    }
-}

src/core/test/com/opensymphony/oscache/base/TestConcurrency.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base;
-
-import com.opensymphony.oscache.core.AbstractCacheAdministrator;
-import com.opensymphony.oscache.general.GeneralCacheAdministrator;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.BitSet;
-import java.util.Properties;
-
-/**
- * Test the Cache class for any concurrency problems
- * 
- * $Id$
- * 
- * @version $Revision$
- * @author <a href="mailto:chris@chris.com">Chris Miller</a>
- */
-public class TestConcurrency extends TestCase {
-	private static transient final Log log = LogFactory
-			.getLog(GeneralCacheAdministrator.class); // TestConcurrency.class
-
-	// Static variables required thru all the tests
-	private static GeneralCacheAdministrator admin = null;
-
-	// Constants needed in the tests
-	private final String KEY = "key";
-
-	private final String VALUE = "This is some content";
-
-	private final int ITERATION_COUNT = 500; // 500;
-
-	private final int THREAD_COUNT = 600; // 600;
-
-	private final int UNIQUE_KEYS = 1013;
-
-	/**
-	 * Class constructor.
-	 * <p>
-	 * 
-	 * @param str
-	 *            The test name (required by JUnit)
-	 */
-	public TestConcurrency(String str) {
-		super(str);
-	}
-
-	/**
-	 * This method is invoked before each testXXXX methods of the class. It set
-	 * ups the variables required for each tests.
-	 */
-	public void setUp() {
-		// At first invocation, create a new Cache
-		if (admin == null) {
-			Properties config = new Properties();
-			config.setProperty(AbstractCacheAdministrator.CACHE_CAPACITY_KEY,
-					"70");
-			config.setProperty(AbstractCacheAdministrator.CACHE_BLOCKING_KEY,
-					"false");
-			admin = new GeneralCacheAdministrator();
-			assertNotNull(admin);
-		}
-	}
-
-	/**
-	 * This methods returns the name of this test class to JUnit
-	 * <p>
-	 * 
-	 * @return The name of this class
-	 */
-	public static Test suite() {
-		return new TestSuite(TestConcurrency.class);
-	}
-
-	/**
-	 * Check that the cache handles simultaneous attempts to access a new cache
-	 * entry correctly
-	 */
-	public void testNewEntry() {
-		String key = "new";
-
-		try {
-			admin.get(key, -1);
-
-			// Fire off another couple of threads to get the same cache entry
-			GetEntry getEntry = new GetEntry(key, VALUE, -1);
-			Thread thread = new Thread(getEntry);
-			thread.start();
-			getEntry = new GetEntry(key, VALUE, -1);
-			thread = new Thread(getEntry);
-			thread.start();
-
-			// OK, those threads should now be blocked waiting for the new cache
-			// entry to appear. Sleep for a bit to simulate the time taken to
-			// build the cache entry
-			try {
-				Thread.sleep(500);
-			} catch (InterruptedException ie) {
-			}
-
-			// Putting the entry in the cache should unblock the previous
-			// threads
-			admin.put(key, VALUE);
-		} catch (Exception e) {
-			e.printStackTrace();
-			fail("Exception has been thrown");
-		}
-	}
-
-	//
-	// /**
-	// * Check that the cache handles simultaneous attempts to access a
-	// * new cache entry correctly
-	// */
-	// public void testNewEntryCancel() {
-	// String key = "newCancel";
-	// String NEW_VALUE = VALUE + "...";
-	//
-	// try {
-	// admin.getFromCache(key, -1);
-	// fail("NeedsRefreshException should have been thrown");
-	// } catch (NeedsRefreshException nre) {
-	// // Fire off another thread to get the same cache entry
-	// GetEntry getEntry = new GetEntry(key, NEW_VALUE, -1, true);
-	// Thread thread = new Thread(getEntry);
-	// thread.start();
-	//
-	// // The above thread will be blocked waiting for the new content
-	// try {
-	// Thread.sleep(500);
-	// } catch (InterruptedException ie) {
-	// }
-	//
-	// // Now cancel the update (eg because an exception occurred while building
-	// the content).
-	// // This will unblock the other thread and it will receive a
-	// NeedsRefreshException.
-	// admin.cancelUpdate(key);
-	//
-	// // Wait a bit for the other thread to update the cache
-	// try {
-	// Thread.sleep(500);
-	// } catch (InterruptedException ie) {
-	// }
-	//
-	// try {
-	// Object newValue = admin.get(key, -1);
-	// assertEquals(NEW_VALUE, newValue);
-	// } catch (NeedsRefreshException e) {
-	// admin.cancelUpdate(key);
-	// fail("A NeedsRefreshException should not have been thrown");
-	// }
-	// }
-	// }
-
-	/**
-	 * Verify that we can concurrently access the cache without problems
-	 */
-	public void testPut() {
-		Thread[] thread = new Thread[THREAD_COUNT];
-
-		for (int idx = 0; idx < THREAD_COUNT; idx++) {
-			OSGeneralTest runner = new OSGeneralTest();
-			thread[idx] = new Thread(runner);
-			thread[idx].start();
-		}
-
-		boolean stillAlive;
-
-		do {
-			try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				// do nothing
-			}
-
-			stillAlive = false;
-
-			int i = 0;
-
-			while ((i < thread.length) && !stillAlive) {
-				stillAlive |= thread[i++].isAlive();
-			}
-		} while (stillAlive);
-	}
-
-	// /**
-	// * Check that the cache handles simultaneous attempts to access a
-	// * stale cache entry correctly
-	// */
-	// public void testStaleEntry() {
-	// String key = "stale";
-	// assertFalse("The cache should not be in blocking mode for this test.",
-	// admin.isBlocking());
-	//
-	// admin.putInCache(key, VALUE);
-	//
-	// try {
-	// // This should throw a NeedsRefreshException since the refresh
-	// // period is 0
-	// admin.getFromCache(key, 0);
-	// fail("NeedsRefreshException should have been thrown");
-	// } catch (NeedsRefreshException nre) {
-	// // Fire off another thread to get the same cache entry.
-	// // Since blocking mode is currently disabled we should
-	// // immediately get back the stale entry
-	// GetEntry getEntry = new GetEntry(key, VALUE, 0, false);
-	// Thread thread = new Thread(getEntry);
-	// thread.start();
-	//
-	// // Sleep for a bit to simulate the time taken to build the cache entry
-	// try {
-	// Thread.sleep(200);
-	// } catch (InterruptedException ie) {
-	// }
-	//
-	// // Putting the entry in the cache should mean that threads now retrieve
-	// // the updated entry
-	// String newValue = "New value";
-	// admin.put(key, newValue);
-	//
-	// getEntry = new GetEntry(key, newValue, -1, false);
-	// thread = new Thread(getEntry);
-	// thread.start();
-	//
-	// try {
-	// Object fromCache = admin.get(key, -1);
-	// assertEquals(newValue, fromCache);
-	// } catch (NeedsRefreshException e) {
-	// admin.cancelUpdate(key);
-	// fail("Should not have received a NeedsRefreshException");
-	// }
-	//
-	// // Give the GetEntry thread a chance to finish
-	// try {
-	// Thread.sleep(200);
-	// } catch (InterruptedException ie) {
-	// }
-	// }
-	// }
-
-	// /**
-	// * A test for the updating of a stale entry when CACHE.BLOCKING = TRUE
-	// */
-	// public void testStaleEntryBlocking() {
-	// // A test for the case where oscache.blocking = true
-	// admin.destroy();
-	//
-	// Properties p = new Properties();
-	// p.setProperty(AbstractCacheAdministrator.CACHE_BLOCKING_KEY, "true");
-	// admin = new GeneralCacheAdministrator(p);
-	//
-	// assertTrue("The cache should be in blocking mode for this test.",
-	// admin.isBlocking());
-	//
-	// // Use a unique key in case these test entries are being persisted
-	// String key = "blocking";
-	// String NEW_VALUE = VALUE + " abc";
-	// admin.putInCache(key, VALUE);
-	//
-	// try {
-	// // Force a NeedsRefreshException
-	// admin.getFromCache(key, 0);
-	// fail("NeedsRefreshException should have been thrown");
-	// } catch (NeedsRefreshException nre) {
-	// // Fire off another thread to get the same cache entry.
-	// // Since blocking mode is enabled this thread should block
-	// // until the entry has been updated.
-	// GetEntry getEntry = new GetEntry(key, NEW_VALUE, 0, false);
-	// Thread thread = new Thread(getEntry);
-	// thread.start();
-	//
-	// // Sleep for a bit to simulate the time taken to build the cache entry
-	// try {
-	// Thread.sleep(200);
-	// } catch (InterruptedException ie) {
-	// }
-	//
-	// // Putting the entry in the cache should mean that threads now retrieve
-	// // the updated entry
-	// admin.put(key, NEW_VALUE);
-	//
-	// getEntry = new GetEntry(key, NEW_VALUE, -1, false);
-	// thread = new Thread(getEntry);
-	// thread.start();
-	//
-	// try {
-	// Object fromCache = admin.get(key, -1);
-	// assertEquals(NEW_VALUE, fromCache);
-	// } catch (NeedsRefreshException e) {
-	// admin.cancelUpdate(key);
-	// fail("Should not have received a NeedsRefreshException");
-	// }
-	// }
-	// }
-
-	// /**
-	// * Checks whether the cache handles simultaneous attempts to access a
-	// * stable cache entry correctly when the blocking mode is enabled.
-	// *
-	// * Basically N threads are concurrently trying to access a same stale
-	// cache entry and each is cancelling its update. Each thread repeat this
-	// operation M times.
-	// * The test is sucessfull if after some time, all threads are properly
-	// released
-	// */
-	// public void testConcurrentStaleGets() {
-	// GeneralCacheAdministrator staticAdmin = admin;
-	// admin = new GeneralCacheAdministrator(); //avoid poluting other test
-	// cases
-	//
-	// try {
-	// // A test for the case where oscache.blocking = true
-	// //admin.destroy();
-	// Properties p = new Properties();
-	// p.setProperty(AbstractCacheAdministrator.CACHE_BLOCKING_KEY, "true");
-	// admin = new GeneralCacheAdministrator(p);
-	//
-	// assertTrue("The cache should be in blocking mode for this test.",
-	// admin.isBlocking());
-	//
-	// int nbThreads = 50;
-	// int retryByThreads = 10000;
-	//
-	// String key = "new";
-	//
-	// //First put a value
-	// admin.putInCache(key, VALUE);
-	//
-	// try {
-	// //Then test without concurrency that it is reported as stale when
-	// time-to-live is zero
-	// admin.getFromCache(key, 0);
-	// fail("NeedsRefreshException should have been thrown");
-	// } catch (NeedsRefreshException nre) {
-	// //Ok this is was is excpected, we can release the update
-	// admin.cancelUpdate(key);
-	// }
-	//
-	// //Then ask N threads to concurrently try to access this stale resource
-	// and each should receive a NeedsRefreshException, and cancel the update
-	// Thread[] spawnedThreads = new Thread[nbThreads];
-	// BitSet successfullThreadTerminations = new BitSet(nbThreads); //Track
-	// which thread successfully terminated
-	//
-	// for (int threadIndex = 0; threadIndex < nbThreads; threadIndex++) {
-	// GetStaleEntryAndCancelUpdate getEntry = new
-	// GetStaleEntryAndCancelUpdate(key, 0, retryByThreads, threadIndex,
-	// successfullThreadTerminations);
-	// Thread thread = new Thread(getEntry);
-	// spawnedThreads[threadIndex] = thread;
-	// thread.start();
-	// }
-	//
-	// // OK, those threads should now repeatidely be blocked waiting for the
-	// new cache
-	// // entry to appear. Wait for all of them to terminate
-	// int maxWaitingSeconds = 100;
-	// int maxWaitForEachThread = 5;
-	// long waitStartTime = System.currentTimeMillis();
-	//
-	// boolean atLeastOneThreadRunning = false;
-	//
-	// while ((System.currentTimeMillis() - waitStartTime) < (maxWaitingSeconds
-	// * 1000)) {
-	// atLeastOneThreadRunning = false;
-	//
-	// //Wait a bit between each step to avoid consumming all CPU and preventing
-	// other threads from running.
-	// try {
-	// Thread.sleep(500);
-	// } catch (InterruptedException ie) {
-	// }
-	//
-	// //check whether all threads are done.
-	// for (int threadIndex = 0; threadIndex < nbThreads;
-	// threadIndex++) {
-	// Thread inspectedThread = spawnedThreads[threadIndex];
-	//
-	// try {
-	// inspectedThread.join(maxWaitForEachThread * 1000);
-	// } catch (InterruptedException e) {
-	// fail("Thread #" + threadIndex + " was interrupted");
-	// }
-	//
-	// if (inspectedThread.isAlive()) {
-	// atLeastOneThreadRunning = true;
-	// log.error("Thread #" + threadIndex + " did not complete within [" +
-	// ((System.currentTimeMillis() - waitStartTime) / 1000) + "] s ");
-	// }
-	// }
-	//
-	// if (!atLeastOneThreadRunning) {
-	// break; //while loop, test success.
-	// }
-	// }
-	//
-	// assertTrue("at least one thread did not complete within [" +
-	// ((System.currentTimeMillis() - waitStartTime) / 1000) + "] s ",
-	// !atLeastOneThreadRunning);
-	//
-	// for (int threadIndex = 0; threadIndex < nbThreads; threadIndex++) {
-	// assertTrue("thread [" + threadIndex + "] did not successfully complete.
-	// ", successfullThreadTerminations.get(threadIndex));
-	// }
-	// } finally {
-	// admin = staticAdmin;
-	//
-	// //Avoid po
-	// }
-	// }
-
-	private class GetEntry implements Runnable {
-		String key;
-
-		String value;
-
-		boolean expectNRE;
-
-		int time;
-
-		GetEntry(String key, String value, int time) {
-			this.key = key;
-			this.value = value;
-			this.time = time;
-			this.expectNRE = expectNRE;
-		}
-
-public void run() {
-            try {
-                // Get from the cache
-                Object fromCache = admin.get(key, time);
-                assertEquals(value, fromCache);
-            
-                    // Put a new piece of content into the cache
-                    admin.put(key, value);
-                
-            	} catch (Exception e) {
-					e.printStackTrace();
-					fail();
-				}
-        }	
-	}
-
-//	/**
-//	 * Basically requests a stale entry, expects to receive a
-//	 * NeedsRefreshException, and always cancels the update.
-//	 */
-//	private class GetStaleEntryAndCancelUpdate implements Runnable {
-//		String key;
-//
-//		int retries;
-//
-//		int time;
-//
-//		private final BitSet successfullThreadTerminations;
-//
-//		private final int threadIndex;
-//
-//		GetStaleEntryAndCancelUpdate(String key, int time, int retries,
-//				int threadIndex, BitSet successfullThreadTerminations) {
-//			this.key = key;
-//			this.time = time;
-//			this.retries = retries;
-//			this.threadIndex = threadIndex;
-//			this.successfullThreadTerminations = successfullThreadTerminations;
-//		}
-//
-//		public void run() {
-//			for (int retryIndex = 0; retryIndex < retries; retryIndex++) {
-//				try {
-//					// Get from the cache
-//					Object fromCache = admin.getFromCache(key, time);
-//					assertNull("Thread index [" + retryIndex
-//							+ "] expected stale request [" + retryIndex
-//							+ "] to be received, got [" + fromCache + "]",
-//							fromCache);
-//				} catch (NeedsRefreshException nre) {
-//					try {
-//						admin.cancelUpdate(key);
-//					} catch (Throwable t) {
-//						log.error("Thread index [" + retryIndex
-//								+ "]: Unexpectedly caught exception [" + t
-//								+ "]", t);
-//						fail("Thread index [" + retryIndex
-//								+ "] : Unexpectedly caught exception [" + t
-//								+ "]");
-//					}
-//				} catch (Throwable t) {
-//					log.error("Thread index [" + retryIndex
-//							+ "] : Unexpectedly caught exception [" + t + "]",
-//							t);
-//					fail("Thread index [" + retryIndex
-//							+ "] : Unexpectedly caught exception [" + t + "]");
-//				}
-//			}
-//
-//			// Once we successfully terminate, we update the corresponding bit
-//			// to let the Junit know we succeeded.
-//			synchronized (successfullThreadTerminations) {
-//				successfullThreadTerminations.set(threadIndex);
-//			}
-//		}
-//	}
-
-	private class OSGeneralTest implements Runnable {
-		public void doit(int i) {
-			int refreshPeriod = 500 /* millis */;
-			String key = KEY + (i % UNIQUE_KEYS);
-			admin.put(key, VALUE);
-
-			try {
-				// Get from the cache
-				admin.getFromCache(KEY, refreshPeriod);
-			
-				admin.put(KEY, VALUE);
-			} catch (Exception e) {
-				e.printStackTrace();
-				fail();
-			}
-
-			// Flush occasionally
-			if ((i % (UNIQUE_KEYS + 1)) == 0) {
-				admin.getCache().flushEntry(key);
-			}
-		}
-
-		public void run() {
-			int start = (int) (Math.random() * UNIQUE_KEYS);
-			System.out.print(start + " ");
-
-			for (int i = start; i < (start + ITERATION_COUNT); i++) {
-				doit(i);
-			}
-		}
-	}
-}

src/core/test/com/opensymphony/oscache/base/algorithm/TestAbstractCache.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base.algorithm;
-
-import junit.framework.TestCase;
-
-/**
- * Test class for the AbstractCache class. It tests all public methods of
- * the AbstractCache and assert the results. It is design to run under JUnit.
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public abstract class TestAbstractCache extends TestCase {
-    /**
-     * Invalid cache capacity
-     */
-    protected final int INVALID_MAX_ENTRIES = 0;
-
-    /**
-     * Cache capacity
-     */
-    protected final int MAX_ENTRIES = 3;
-
-    /**
-     * Constructor
-     * <p>
-     * @param str The test name (required by JUnit)
-     */
-    protected TestAbstractCache(String str) {
-        super(str);
-    }
-
-    /**
-     * Test the method that verify if the cache contains a specific key
-     */
-    public abstract void testContainsKey();
-
-    /**
-     * Test the get from the cache
-     */
-    public abstract void testGet();
-
-    /**
-     * Test the capacity setting
-     */
-    public void testGetSetMaxEntries() {
-        getCache().setMaxEntries(MAX_ENTRIES);
-        assertEquals(MAX_ENTRIES, getCache().getMaxEntries());
-
-        // Specify an invalid capacity
-        try {
-            getCache().setMaxEntries(INVALID_MAX_ENTRIES);
-            fail("Cache capacity set with an invalid argument");
-        } catch (Exception e) {
-            // This is what we expect
-        }
-    }
-
-    /**
-     * Test the setting of the memory cache
-     */
-    public void testGetSetMemoryCache() {
-        getCache().setMemoryCaching(true);
-        assertTrue(getCache().isMemoryCaching());
-    }
-
-    /**
-     * Test the iterator retrieval
-     */
-    public abstract void testIterator();
-
-    /**
-     * Test the put into the cache
-     */
-    public abstract void testPut();
-
-    /**
-     * Test the remove from the cache
-     */
-    public abstract void testRemove();
-
-    /**
-     * Test the specific details about the cache algorithm
-     */
-    public abstract void testRemoveItem();
-
-    /**
-     * Test the PersistenceListener setter. Since the persistance listener is
-     * an interface, just call the setter with null
-     */
-    public void testSetPersistenceListener() {
-        getCache().setPersistenceListener(null);
-    }
-
-    // Abstract method that returns an instance of an admin
-    protected abstract AbstractConcurrentReadCache getCache();
-}

src/core/test/com/opensymphony/oscache/base/algorithm/TestCompleteAlgorithm.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base.algorithm;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test class for the com.opensymphony.oscache.core.algorithm package.
- * It invokes all the test suites of all the other classes of the package,
- * except abstract ones because they are tested via final ones.
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public final class TestCompleteAlgorithm extends TestCase {
-    /**
-     * Constructor for the oscache project main test program
-     */
-    public TestCompleteAlgorithm(String str) {
-        super(str);
-    }
-
-    /**
-     * Main method which is called to perform the tests
-     * <p>
-     * @param   args    Arguments received
-     */
-    public static void main(String[] args) {
-        // Run the test suite
-        junit.swingui.TestRunner testRunner = new junit.swingui.TestRunner();
-        testRunner.setLoading(false);
-
-        String[] args2 = {TestCompleteAlgorithm.class.getName()};
-        testRunner.start(args2);
-    }
-
-    /**
-     * Test suite required to test this project
-     * <p>
-     * @return  suite   The test suite
-     */
-    public static Test suite() {
-        // Add all the tests suite of all the project classes
-        TestSuite suite = new TestSuite("Test all base algorithm cache modules");
-        suite.addTest(TestFIFOCache.suite());
-        suite.addTest(TestLRUCache.suite());
-        suite.addTest(TestUnlimitedCache.suite());
-
-        return suite;
-    }
-}

src/core/test/com/opensymphony/oscache/base/algorithm/TestFIFOCache.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.base.algorithm;
-
-import com.opensymphony.oscache.algorithm.FIFOCache;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test class for the FIFOCache class. It tests that the algorithm reacts as
- * expected when entries are removed
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public final class TestFIFOCache extends TestQueueCache {
-    /**
-     * FIFO Cache object
-     */
-    private static FIFOCache cache = null;
-
-    /**
-     * Constructor
-     * <p>
-     * @param str The test name (required by JUnit)
-     */
-    public TestFIFOCache(String str) {
-        super(str);
-    }
-
-    /**
-     * This methods returns the name of this test class to JUnit
-     * <p>
-     * @return The test for this class
-     */
-    public static Test suite() {
-        return new TestSuite(TestFIFOCache.class);
-    }
-
-    /**
-     * Abstract method used by the TestAbstractCache class
-     * <p>
-     * @return  A cache instance
-     */
-    public AbstractConcurrentReadCache getCache() {
-        return cache;
-    }
-
-    /**
-     * This method is invoked before each testXXXX methods of the
-     * class. It set ups the variables required for each tests.