Save This Page
Home » oscache-2.4.1-full » com.opensymphony.oscache » base » algorithm » [javadoc | source]
    1   /*
    2    * Copyright (c) 2002-2003 by OpenSymphony
    3    * All rights reserved.
    4    */
    5   package com.opensymphony.oscache.base.algorithm;
    6   
    7   import junit.framework.Test;
    8   import junit.framework.TestSuite;
    9   
   10   /**
   11    * Test class for the LRUCache class. It only tests that the algorithm reacts as
   12    * expected when entries are removed. All the other tests related to the LRU
   13    * algorithm are in the TestNonQueueCache class, since those tests are shared
   14    * with the TestUnlimitedCache class.
   15    *
   16    * $Id: TestLRUCache.java,v 1.1 2005/06/17 05:07:08 dres Exp $
   17    * @version        $Revision: 1.1 $
   18    * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
   19    */
   20   public final class TestLRUCache extends TestQueueCache {
   21       /**
   22        * LRU Cache object
   23        */
   24       private static LRUCache cache = null;
   25   
   26       /**
   27        * Constructor
   28        * <p>
   29        * @param str The test name (required by JUnit)
   30        */
   31       public TestLRUCache(String str) {
   32           super(str);
   33       }
   34   
   35       /**
   36        * This methods returns the name of this test class to JUnit
   37        * <p>
   38        * @return The test for this class
   39        */
   40       public static Test suite() {
   41           return new TestSuite(TestLRUCache.class);
   42       }
   43   
   44       /**
   45        * Abstract method used by the TestAbstractCache class
   46        * <p>
   47        * @return  A cache instance
   48        */
   49       public AbstractConcurrentReadCache getCache() {
   50           return cache;
   51       }
   52   
   53       /**
   54        * This method is invoked before each testXXXX methods of the
   55        * class. It set ups the variables required for each tests.
   56        */
   57       public void setUp() {
   58           // Create a cache instance on first invocation
   59           if (cache == null) {
   60               cache = new LRUCache();
   61               assertNotNull(cache);
   62           }
   63       }
   64   
   65       /**
   66        * Test the cache algorithm
   67        */
   68       public void testRemoveItem() {
   69           // Add 3 elements
   70           cache.itemPut(KEY);
   71           cache.itemPut(KEY + 1);
   72           cache.itemPut(KEY + 2);
   73   
   74           // Get the last element
   75           cache.itemRetrieved(KEY);
   76   
   77           // The least recently used item is key + 1
   78           assertTrue((KEY + 1).equals(cache.removeItem()));
   79       }
   80   }

Save This Page
Home » oscache-2.4.1-full » com.opensymphony.oscache » base » algorithm » [javadoc | source]