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

Ben Wang bwang at jboss.com
Tue Jan 2 02:16:52 EST 2007


  User: bwang   
  Date: 07/01/02 02:16:52

  Modified:    tests/functional/org/jboss/cache/aop/loader  Tag:
                        Branch_JBossCache_1_4_0 CacheLoaderTestsBase.java
  Log:
  Update with Collection with cache loader.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.2   +154 -2    JBossCache/tests/functional/org/jboss/cache/aop/loader/Attic/CacheLoaderTestsBase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheLoaderTestsBase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/aop/loader/Attic/CacheLoaderTestsBase.java,v
  retrieving revision 1.9.2.1
  retrieving revision 1.9.2.2
  diff -u -b -r1.9.2.1 -r1.9.2.2
  --- CacheLoaderTestsBase.java	2 Jan 2007 03:23:16 -0000	1.9.2.1
  +++ CacheLoaderTestsBase.java	2 Jan 2007 07:16:51 -0000	1.9.2.2
  @@ -12,12 +12,16 @@
   import java.util.ArrayList;
   import java.util.Map;
   import java.util.HashMap;
  +import java.util.List;
  +import java.util.Set;
  +import java.util.HashSet;
  +import java.util.Iterator;
   
   /**
    * Commons tests for all CacheLoaders. Aop version.
    *
    * @author bwang
  - * @version $Id: CacheLoaderTestsBase.java,v 1.9.2.1 2007/01/02 03:23:16 bwang Exp $
  + * @version $Id: CacheLoaderTestsBase.java,v 1.9.2.2 2007/01/02 07:16:51 bwang Exp $
    */
   abstract public class CacheLoaderTestsBase extends AbstractCacheLoaderTestBase {
      PojoCache cache;
  @@ -27,6 +31,10 @@
   
      protected void setUp() throws Exception {
         super.setUp();
  +      startCache();
  +   }
  +
  +   protected void startCache() throws Exception {
         cache = new PojoCache();
         cache.setCacheMode("local");
         configureCache();
  @@ -53,6 +61,11 @@
         cache.destroyService();
      }
   
  +   protected void stopCache() throws Exception {
  +      cache.stopService();
  +      cache.destroyService();
  +   }
  +
      protected void addDelay() {
         ; // returns immediately in this case.  Subclasses may override where a delay is needed.
      }
  @@ -105,6 +118,34 @@
         assertNull(val);
      }
   
  +   public void testSimpleRestart() throws Exception {
  +      Person test = new Person();
  +      test.setName("Ben");
  +      test.setAge(10);
  +      cache.putObject("/first/second/third", test);   // stored in cache loader
  +      stopCache();
  +      startCache();
  +      assertFalse(cache.exists("/first/second/third"));
  +      Person val = (Person) cache.getObject("/first/second/third"); // should be loaded from cache loader
  +      assertNotNull(val);
  +      assertEquals("Age ", 10, val.getAge());
  +   }
  +
  +   public void testRemoveObject() throws Exception {
  +      Person test = new Person();
  +      test.setName("Ben");
  +      test.setAge(10);
  +      cache.putObject("/first/second/third", test);   // stored in cache loader
  +      addDelay();
  +      cache.removeObject("/first/second/third");
  +      addDelay();
  +      assertFalse(cache.exists("/first/second/third"));
  +      assertTrue(cache.exists("/first/second"));
  +      assertTrue(cache.exists("/first"));
  +      Person val = (Person) cache.getObject("/first/second/third"); // should be loaded from cache loader
  +      assertNull(val);
  +   }
  +
      /**
       * This test illustrates the problem in JBCACHE-477. That is transactional remove under
       * cacheloader using pessimistic locking.
  @@ -138,7 +179,7 @@
         }
      }
   
  -   public void testCollection() throws Exception
  +   public void testMap() throws Exception
      {
         Map map = new HashMap();
         map.put("1", "1");
  @@ -152,11 +193,122 @@
         cache.evict(Fqn.fromString("/test/map"));
         addDelay();
         map = (Map)cache.getObject("/test/map");
  +      assertEquals("Map size ", 3, map.size());
  +      assertEquals("Map 1", "1", map.get("1"));
  +      assertEquals("Map 2", "2", map.get("2"));
  +      assertEquals("Map 3", "3", map.get("3"));
  +   }
  +
  +   public void testMapRestart() throws Exception
  +   {
  +      Map map = new HashMap();
  +      map.put("1", "1");
  +      map.put("2", "2");
  +
  +      cache.putObject("/test/map", map);
  +      map = (Map)cache.getObject("/test/map");
  +      map.put("3", "3");
  +      assertEquals("Map size ", 3, map.size());
  +
  +      stopCache();
  +      startCache();
  +
  +      addDelay();
  +      assertFalse(cache.exists("/test/map"));
  +      map = (Map)cache.getObject("/test/map");
  +      assertEquals("Map size", 3, map.size());
  +
         assertEquals("Map 1", "1", map.get("1"));
         assertEquals("Map 2", "2", map.get("2"));
         assertEquals("Map 3", "3", map.get("3"));
      }
   
  +   public void testList() throws Exception
  +   {
  +      List list = new ArrayList();
  +      list.add("1");
  +      list.add("2");
  +
  +      cache.putObject("/test/list", list);
  +      list = (List)cache.getObject("/test/list");
  +      list.add("3");
  +      assertEquals("List size ", 3, list.size());
  +
  +      cache.evict(Fqn.fromString("/test/list"));
  +      addDelay();
  +      list = (List)cache.getObject("/test/list");
  +      assertEquals("List size ", 3, list.size());
  +      assertEquals("List 1", "1", list.get(0));
  +      assertEquals("List 2", "2", list.get(1));
  +      assertEquals("List 3", "3", list.get(2));
  +   }
  +
  +   public void testListRestart() throws Exception
  +   {
  +      List list = new ArrayList();
  +      list.add("1");
  +      list.add("2");
  +
  +      cache.putObject("/test/list", list);
  +      list = (List)cache.getObject("/test/list");
  +      list.add("3");
  +      assertEquals("List size ", 3, list.size());
  +
  +      stopCache();
  +      startCache();
  +
  +      addDelay();
  +      list = (List)cache.getObject("/test/list");
  +      assertEquals("List size ", 3, list.size());
  +      assertEquals("List 1", "1", list.get(0));
  +      assertEquals("List 2", "2", list.get(1));
  +      assertEquals("List 3", "3", list.get(2));
  +   }
  +
  +   public void testSet() throws Exception
  +   {
  +      Set set = new HashSet();
  +      set.add("1");
  +      set.add("2");
  +
  +      cache.putObject("/test/set", set);
  +      set = (Set)cache.getObject("/test/set");
  +      set.add("3");
  +      assertEquals("Set size ", 3, set.size());
  +
  +      cache.evict(Fqn.fromString("/test/set"));
  +      addDelay();
  +      set = (Set)cache.getObject("/test/set");
  +      assertEquals("Set size ", 3, set.size());
  +      Iterator it = set.iterator();
  +      assertEquals("Set 1", "3", it.next());
  +      assertEquals("Set 2", "2", it.next());
  +      assertEquals("Set 3", "1", it.next());
  +   }
  +
  +   public void testSetRestart() throws Exception
  +   {
  +      Set set = new HashSet();
  +      set.add("1");
  +      set.add("2");
  +
  +      cache.putObject("/test/set", set);
  +      set = (Set)cache.getObject("/test/set");
  +      set.add("3");
  +      assertEquals("Set size ", 3, set.size());
  +
  +      stopCache();
  +      startCache();
  +
  +      addDelay();
  +      set = (Set)cache.getObject("/test/set");
  +      assertEquals("Set size ", 3, set.size());
  +      Iterator it = set.iterator();
  +      assertEquals("Set 1", "3", it.next());
  +      assertEquals("Set 2", "2", it.next());
  +      assertEquals("Set 3", "1", it.next());
  +   }
  +
      public static Test suite() {
         return new TestSuite(CacheLoaderTestsBase.class);
      }
  
  
  



More information about the jboss-cvs-commits mailing list