Commits

Anonymous committed f92fdae

Submitter: Andres March

fixed a few test cases

Comments (0)

Files changed (10)

src/core/java/com/opensymphony/oscache/algorithm/FIFOEvictionAlgorithm.java

 	public void evaluateRemove(Object key) {
 		elements.remove(key);
 	}
+
+	public void setCapacity(int max_entries) {
+		this.maxSize = max_entries;
+		
+	}
+
+	public int getCapacity() {
+		return this.maxSize;
+	}
 }

src/core/java/com/opensymphony/oscache/algorithm/LRUEvictionAlgorithm.java

 		}
 		return toEvict;
 	}
+
+	public void setCapacity(int max_entries) {
+		this.maxSize = max_entries;
+	}
+	
+	public int getCapacity() {
+		return this.maxSize;
+	}
 }

src/core/java/com/opensymphony/oscache/algorithm/UnlimitedEvictionAlgorithm.java

 
 import java.util.Properties;
 
-import com.opensymphony.oscache.core.CacheEntry;
 import com.opensymphony.oscache.core.EvictionAlgorithm;
 
 /**
 	public Object evict() {
 		return null;
 	}
+
+	public void setCapacity(int max_entries) {
+		// TODO Auto-generated method stub
+		
+	}
+	
+	
+	public int getCapacity() {
+		return -1;
+	}
 }

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

 
 	/**
 	 * Allows the capacity of the cache to be altered dynamically. Note that
-	 * some cache implementations may choose to ignore this setting (eg the
+	 * some eviction algorithms may choose to ignore this setting (eg the
 	 * {@link UnlimitedCache} ignores this call).
 	 * 
 	 * @param capacity

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

 /**
  * Controls the behaviour for evicting cache entries.
  */
-public interface EvictionAlgorithm  {
-  /**
-   * Configures the eviction policy using the supplied properties.
-   *
-   * @param params the configuration parameters for the eviction policy.
-   */
-  void init(Properties params);
+public interface EvictionAlgorithm {
+	/**
+	 * Configures the eviction policy using the supplied properties.
+	 * 
+	 * @param params
+	 *            the configuration parameters for the eviction policy.
+	 */
+	void init(Properties params);
 
-  /**
-   * Called whenever an object is placed in the cache. The implementation
-   * of this method may want to use this information to update its
-   * eviction data.
-   *
-   * @param entry   the entry of the object that was put in the cache.
-   * @return entry evicted due to the put action
-   */
-  Object evaluatePut(Object key);
+	/**
+	 * Called whenever an object is placed in the cache. The implementation of
+	 * this method may want to use this information to update its eviction data.
+	 * 
+	 * @param entry
+	 *            the entry of the object that was put in the cache.
+	 * @return entry evicted due to the put action
+	 */
+	Object evaluatePut(Object key);
 
-  /**
-   * Called whenever an object was retrieved from the cache. The
-   * implementation of this method may want to use this information
-   * to update its eviction data.
-   *
-   * @param key   the key of the object that was retrieved from the cache.
-   * @param value the value of the object that was retrieved from the cache.
-   */
-  void evaluateGet(Object key);
+	/**
+	 * Called whenever an object was retrieved from the cache. The
+	 * implementation of this method may want to use this information to update
+	 * its eviction data.
+	 * 
+	 * @param key
+	 *            the key of the object that was retrieved from the cache.
+	 * @param value
+	 *            the value of the object that was retrieved from the cache.
+	 */
+	void evaluateGet(Object key);
 
-  /**
-   * Called whenever an object is removed from the cache. The
-   * implementation of this method may want to use this information
-   * to update its eviction data.
-   *
-   * @param key   the key of the object that was removed from the cache.
-   * @param value the value of the object that was removed from the cache.
-   */
-  void evaluateRemove(Object key);
+	/**
+	 * Called whenever an object is removed from the cache. The implementation
+	 * of this method may want to use this information to update its eviction
+	 * data.
+	 * 
+	 * @param key
+	 *            the key of the object that was removed from the cache.
+	 * @param value
+	 *            the value of the object that was removed from the cache.
+	 */
+	void evaluateRemove(Object key);
 
-  /**
-   * Causes the eviction policy to evict a cache entry if required.
-   *
-   * @return the cache entry that was evicted, or <code>null</code>
-   *         if no eviction took place.
-   */
-  Object evict();
+	/**
+	 * Causes the eviction policy to evict a cache entry if required.
+	 * 
+	 * @return the cache entry that was evicted, or <code>null</code> if no
+	 *         eviction took place.
+	 */
+	Object evict();
+
+	void setCapacity(int max_entries);
+
+	int getCapacity();
 }
-

src/core/java/com/opensymphony/oscache/web/tag/CacheTag.java

                     } else {
                         String[] groupArray = new String[groups.size()];
                         groups.toArray(groupArray);
-                        cache.putInCache(actualKey, body, groupArray, policy, null);
+                        cache.put(actualKey, body, groupArray, policy);
                     }
                 }
             }
     }
 
     public void doFinally() {
-        if (cancelUpdateRequired && (actualKey != null)) {
-            cache.cancelUpdate(actualKey);
-        }
 
         // reset all states, CACHE-144
         groups = null;

src/core/java/com/opensymphony/oscache/web/tag/FlushTag.java

      */
     String key = null;
 
-    /**
-     * if pattern value is specified, all keys that contain the pattern are flushed.
-     */
-    String pattern = null;
     String scope = null;
     int cacheScope = -1;
 
         this.language = value;
     }
 
-    /**
-     *  The key pattern to be flushed.
-     * If specified, all entries that contain the pattern will be flushed.
-     *  @param value The key of the specific entry to flush.
-     */
-    public void setPattern(String value) {
-        this.pattern = value;
-    }
 
     /**
      * Set the scope of this flush.
             } else {
                 throw new JspTagException("A cache group was specified for flushing, but the scope wasn't supplied or was invalid");
             }
-        } else if (pattern != null) // We're flushing keys which contain the pattern
-         {
-            if (cacheScope >= 0) {
-                Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
-                cache.flushPattern(pattern);
-            } else {
-                throw new JspTagException("A pattern was specified for flushing, but the scope wasn't supplied or was invalid");
-            }
         } else if (key == null) // we're flushing a whole scope
          {
             if (cacheScope >= 0) {
                 String actualKey = admin.generateEntryKey(key, (HttpServletRequest) pageContext.getRequest(), cacheScope, language);
 
                 Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
-                cache.flushEntry(actualKey);
+                cache.remove(actualKey);
             } else {
                 throw new JspTagException("A cache key was specified for flushing, but the scope wasn't supplied or was invalid");
             }

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

     public abstract void testRemoveItem();
 
 
-    // Abstract method that returns an instance of an admin
     protected abstract EvictionAlgorithm getAlgorithm();
 }

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

 
 import com.opensymphony.oscache.algorithm.FIFOEvictionAlgorithm;
 import com.opensymphony.oscache.core.Cache;
+import com.opensymphony.oscache.core.EvictionAlgorithm;
 import com.opensymphony.oscache.core.MemoryCache;
 
 /**
 	/**
 	 * FIFO Cache object
 	 */
-	private static FIFOEvictionAlgorithm cache = null;
+	private static FIFOEvictionAlgorithm algorithm = null;
 
 	/**
 	 * Constructor
 	 * 
 	 * @return A cache instance
 	 */
-	public Cache getCache() {
-		return cache;
+	public EvictionAlgorithm getAlgorithm() {
+		return algorithm;
 	}
 
 	/**
 	 */
 	public void setUp() {
 		// Create a cache instance on first invocation
-		if (cache == null) {
-			FIFOEvictionAlgorithm alg = new FIFOEvictionAlgorithm();
-			cache = new MemoryCache();
-			cache.setEvictionAlgorithm(alg);
-			assertNotNull(cache);
+		if (algorithm == null) {
+			algorithm = new FIFOEvictionAlgorithm();
+			assertNotNull(algorithm);
 		}
 	}
 
 		// Add 2 elements in the cache and ensure that the one to remove is the
 		// first
 		// inserted
-		cache.itemPut(KEY);
-		cache.itemPut(KEY + 1);
-		assertTrue(KEY.equals(cache.removeItem()));
+		algorithm.evaluatePut(KEY);
+		algorithm.evaluatePut(KEY + 1);
+		assertTrue(KEY.equals(algorithm.evict()));
 	}
 }

src/core/test/com/opensymphony/oscache/core/algorithm/TestLRUCache.java

  * expected when entries are removed. All the other tests related to the LRU
  * algorithm are in the TestNonQueueCache class, since those tests are shared
  * with the TestUnlimitedCache class.
- *
+ * 
  * $Id$
- * @version        $Revision$
+ * 
+ * @version $Revision$
  * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
  */
 public final class TestLRUCache extends TestQueueCache {
-    /**
-     * LRU Cache object
-     */
-    private static Cache cache = null;
+	/**
+	 * LRU Cache object
+	 */
 	private EvictionAlgorithm algorithm;
 
-    /**
-     * Constructor
-     * <p>
-     * @param str The test name (required by JUnit)
-     */
-    public TestLRUCache(String str) {
-        super(str);
-    }
+	/**
+	 * Constructor
+	 * <p>
+	 * 
+	 * @param str
+	 *            The test name (required by JUnit)
+	 */
+	public TestLRUCache(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(TestLRUCache.class);
-    }
+	/**
+	 * 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(TestLRUCache.class);
+	}
 
-    /**
-     * Abstract method used by the TestAbstractCache class
-     * <p>
-     * @return  A cache instance
-     */
-    public Cache getCache() {
-        return cache;
-    }
-    
-    /**
-     * Abstract method used by the TestAbstractCache class
-     * <p>
-     * @return  A cache instance
-     */
-    public EvictionAlgorithm getAlgorithm() {
-        return algorithm;
-    }
+	/**
+	 * Abstract method used by the TestAbstractCache class
+	 * <p>
+	 * 
+	 * @return A cache instance
+	 */
+	public EvictionAlgorithm getAlgorithm() {
+		return algorithm;
+	}
 
-    /**
-     * This method is invoked before each testXXXX methods of the
-     * class. It set ups the variables required for each tests.
-     */
-    public void setUp() {
-        // Create a cache instance on first invocation
-        if (cache == null) {
-        	cache = new MemoryCache();
-        algorithm = new LRUEvictionAlgorithm();
-        	cache.setEvictionAlgorithm(algorithm);
-        }
-    }
+	/**
+	 * This method is invoked before each testXXXX methods of the class. It set
+	 * ups the variables required for each tests.
+	 */
+	public void setUp() {
+		// Create a cache instance on first invocation
+		if (algorithm == null) {
+			algorithm = new LRUEvictionAlgorithm();
+		}
+	}
 
-    /**
-     * Test the cache algorithm
-     */
-    public void testRemoveItem() {
-        // Add 3 elements
-    	algorithm.put(KEY, KEY);
-    	algorithm.put(KEY + 1, KEY);
-    	algorithm.put(KEY + 2, KEY);
+	/**
+	 * Test the cache algorithm
+	 */
+	public void testRemoveItem() {
+		// Add 3 elements
+		algorithm.evaluatePut(KEY);
+		algorithm.evaluatePut(KEY + 1);
+		algorithm.evaluatePut(KEY + 2);
 
-        // Get the last element
-    	algorithm.get(KEY, KEY);
+		// Get the last element
+		algorithm.evaluateGet(KEY);
 
-        // The least recently used item is key + 1
-        assertTrue((KEY + 1).equals(algorithm.evict()));
-    }
+		// The least recently used item is key + 1
+		assertTrue((KEY + 1).equals(algorithm.evict()));
+	}
 }