[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/eviction ...

Elias Ross genman at noderunner.net
Sun Nov 26 23:51:24 EST 2006


  User: genman  
  Date: 06/11/26 23:51:24

  Added:       tests/functional/org/jboss/cache/eviction 
                        ExpirationPolicyTest.java
  Log:
  JBCACHE-880 add per node expiration policy
  
  Revision  Changes    Path
  1.1      date: 2006/11/27 04:51:24;  author: genman;  state: Exp;JBossCache/tests/functional/org/jboss/cache/eviction/ExpirationPolicyTest.java
  
  Index: ExpirationPolicyTest.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.eviction;
  
  import junit.framework.TestCase;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.TreeCache;
  import org.jboss.cache.config.Configuration;
  import org.jboss.cache.config.EvictionConfig;
  import org.jboss.cache.factories.XmlConfigurationParser;
  import org.jboss.cache.lock.IsolationLevel;
  import org.jboss.cache.misc.TestingUtil;
  import org.jboss.util.property.Configurable;
  
  /**
   * Unit tests for {@link ExpirationPolicy}.
   *
   * @author Elias Ross
   * @version $Revision: 1.1 $
   */
  public class ExpirationPolicyTest extends TestCase
  {
     private static final Log log = LogFactory.getLog(ExpirationPolicyTest.class);
     
     TreeCache cache;
     int wakeupIntervalMillis = 0;
     final String ROOT_STR = "/test";
     Throwable t1_ex, t2_ex;
     final long DURATION = 10000;
     boolean isTrue;
  
     Fqn fqn1 = Fqn.fromString("/node/1");
     Fqn fqn2 = Fqn.fromString("/node/2");
     Fqn fqn3 = Fqn.fromString("/node/3");
     Fqn fqn4 = Fqn.fromString("/node/4");
     
     Long future;
     Long past;
     
     public void setUp() throws Exception
     {
        super.setUp();
        cache = new TreeCache();
        Configuration conf = new Configuration();
        EvictionConfig econf = new EvictionConfig(ExpirationPolicy.class.getName());
        econf.setWakeupIntervalSeconds(1);
        conf.setEvictionConfig(econf);
        cache.setConfiguration(conf);
        cache.start();
        
        future = Long.valueOf(System.currentTimeMillis() + 3000);
        past = Long.valueOf(System.currentTimeMillis() - 2000);         
     }
  
     public void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
     }
  
     public void testEviction() throws Exception
     {
        cache.put(fqn1, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, future);
        cache.put(fqn2, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, past);
        cache.put(fqn3, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, future);
        cache.put(fqn4, "foo", "bar");
        TestingUtil.sleepThread(2000);
        assertNotNull(cache.get(fqn1));
        assertNull(cache.get(fqn2));
        assertNotNull(cache.get(fqn3));
        assertNotNull(cache.get(fqn4));
        
        log.info("should remove 1 and 3 now");
        TestingUtil.sleepThread(2000);
        assertNull(cache.get(fqn1));
        assertNull(cache.get(fqn3));
     }
     
     public void testUpdate() throws Exception {
        log.info("update 1 from future to past");
        cache.put(fqn1, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, future);
        assertNotNull(cache.get(fqn1));
        cache.put(fqn1, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, past);
        TestingUtil.sleepThread(2000);
        assertNull(cache.get(fqn1));
        cache.remove(Fqn.ROOT);
        
     }
     
     public void testMaxNodes() throws Exception {
        log.info("set max nodes to 2, expire soonest to expire first");
        EvictionPolicyConfig epc = cache.getRegionManager().getAllEvictionRegions().get(0).getEvictionPolicyConfig();
        ExpirationConfiguration ec = (ExpirationConfiguration)epc;
        ec.setMaxNodes(2);
        Long future2 = Long.valueOf(System.currentTimeMillis() + 2100);
        cache.put(fqn1, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, future2);
        cache.put(fqn2, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, future2);
        cache.put(fqn3, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, future);
        cache.put(fqn4, ExpirationConfiguration.DEFAULT_EXPIRATION_KEY, past);
        assertEquals(5, cache.getNumberOfNodes());
        Thread.sleep(1000);
        assertNotNull(cache.get(fqn1));
        assertNotNull(cache.get(fqn2));
        assertNull(cache.get(fqn3));
        assertNull(cache.get(fqn4));
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list