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

Brian Stansberry brian.stansberry at jboss.com
Thu Oct 26 14:20:38 EDT 2006


  User: bstansberry
  Date: 06/10/26 14:20:38

  Added:       tests/functional/org/jboss/cache/eviction 
                        ConcurrentEvictionTest.java
  Log:
  Test concurrent eviction w/ passivation
  
  Revision  Changes    Path
  1.1      date: 2006/10/26 18:20:38;  author: bstansberry;  state: Exp;JBossCache/tests/functional/org/jboss/cache/eviction/ConcurrentEvictionTest.java
  
  Index: ConcurrentEvictionTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.eviction;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.Fqn;
  import org.jboss.cache.TreeCache;
  import org.jboss.cache.factories.XmlConfigurationParser;
  
  /**
   * Tests cache behavior in the presence of concurrent passivation.
   * 
   * @author Brian Stansberry
   * @version $Revision: 1.1 $
   */
  public class ConcurrentEvictionTest extends TestCase
  {
     private TreeCache cache_;
     private int wakeupIntervalMillis_ = 0;
  
     public ConcurrentEvictionTest(String s)
     {
        super(s);
     }
  
     public void setUp() throws Exception
     {
        super.setUp();
        initCaches();
        wakeupIntervalMillis_ = cache_.getEvictionThreadWakeupIntervalSeconds() * 1000;
        if (wakeupIntervalMillis_ < 0)
           fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
  
     }
  
     void initCaches() throws Exception
     {
        cache_ = new TreeCache();
        cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-eviction-cacheloader-service.xml")); // read in generic local xml
        cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
        cache_.start();
     }
  
     public void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
     
     public void testConcurrentEviction() throws Exception
     {
        Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/eviction");
        
        // Create a bunch of nodes; more than the /org/jboss/test/data
        // region's maxNodes so we know eviction will kick in
        for (int i = 0; i < 1000; i++)
        {      
           cache_.put(new Fqn(base, new Integer(i / 100)), new Integer(i), "value");
        }
        
        // Loop for long enough to have 5 runs of the eviction thread
        long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
        while (System.currentTimeMillis() < loopDone)
        {
           // If any get returns null, that's a failure
           for (int i = 0; i < 1000; i++)
           {
              Fqn fqn = new Fqn(base, new Integer(i / 100));
              Integer key = new Integer(i);
              assertNotNull("found value under Fqn " + fqn + " and key " + key,
                             cache_.get(fqn, key));
           }
        }
     }
  
     public static Test suite()
     {
        return new TestSuite(ConcurrentEvictionTest.class);
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list