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

Brian Stansberry brian.stansberry at jboss.com
Thu Oct 26 14:36:34 EDT 2006


  User: bstansberry
  Date: 06/10/26 14:36:34

  Added:       tests/functional/org/jboss/cache/eviction  Tag:
                        Branch_JBossCache_1_4_0 ConcurrentEvictionTest.java
  Log:
  Test concurrent eviction without passivation
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +91 -0     JBossCache/tests/functional/org/jboss/cache/eviction/ConcurrentEvictionTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConcurrentEvictionTest.java
  ===================================================================
  RCS file: ConcurrentEvictionTest.java
  diff -N ConcurrentEvictionTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ConcurrentEvictionTest.java	26 Oct 2006 18:36:34 -0000	1.1.2.2
  @@ -0,0 +1,91 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
  +package org.jboss.cache.eviction;
  +
  +import java.util.Properties;
  +
  +import junit.framework.Test;
  +import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.PropertyConfigurator;
  +import org.jboss.cache.TreeCache;
  +
  +/**
  + * Tests cache behavior in the presence of concurrent passivation.
  + * 
  + * @author Brian Stansberry
  + * @version $Revision: 1.1.2.2 $
  + */
  +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();
  +      PropertyConfigurator config = new PropertyConfigurator();
  +      config.configure(cache_, "META-INF/local-eviction-cacheloader-service.xml"); // read in generic local xml
  +      cache_.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
  +      cache_.startService();
  +   }
  +
  +   public void tearDown() throws Exception
  +   {
  +      super.tearDown();
  +      cache_.stopService();
  +   }
  +   
  +   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