[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/collection ...

Ben Wang bwang at jboss.com
Thu Nov 9 11:54:33 EST 2006


  User: bwang   
  Date: 06/11/09 11:54:33

  Modified:    tests-50/functional/org/jboss/cache/pojo/collection     
                        ReplicatedSyncSetTest.java
                        ReplicatedSyncMapTest.java CachedListImplTest.java
                        ReplicatedSyncListTest.java
  Added:       tests-50/functional/org/jboss/cache/pojo/collection     
                        CachedMapImplTest.java
  Log:
  Added detection for Collection hashCode recursion.
  
  Revision  Changes    Path
  1.6       +14 -0     JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/ReplicatedSyncSetTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedSyncSetTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/ReplicatedSyncSetTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- ReplicatedSyncSetTest.java	6 Nov 2006 13:44:26 -0000	1.5
  +++ ReplicatedSyncSetTest.java	9 Nov 2006 16:54:33 -0000	1.6
  @@ -199,6 +199,20 @@
         assertFalse("element 2 is removed", set2.contains("element 2"));
      }
   
  +
  +   /* This test won't pass since the recursive set will fail during replication as well
  +   because of HashSet that calls out to HashMap hashCode. This causes the recursion.
  +   public void testRecursion2() throws Exception
  +   {
  +      Set set = new HashSet();
  +      set.add("1");
  +      set.add("2");
  +      set.add(set);
  +
  +      cache1.attach("set", set);
  +   }
  +   */
  +
      public static Test suite() throws Exception
      {
         return new TestSuite(ReplicatedSyncSetTest.class);
  
  
  
  1.6       +29 -0     JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/ReplicatedSyncMapTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedSyncMapTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/ReplicatedSyncMapTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- ReplicatedSyncMapTest.java	6 Nov 2006 13:44:27 -0000	1.5
  +++ ReplicatedSyncMapTest.java	9 Nov 2006 16:54:33 -0000	1.6
  @@ -10,6 +10,7 @@
   import org.jboss.cache.pojo.test.Address;
   import org.jboss.cache.pojo.test.Person;
   import org.jboss.cache.Fqn;
  +import org.jboss.aop.proxy.ClassProxy;
   
   import java.util.Collection;
   import java.util.HashMap;
  @@ -258,6 +259,34 @@
   
      }
   
  +   public void testRecursion1() throws Exception
  +   {
  +      Map map = new HashMap();
  +      map.put("1", "1");
  +      map.put("2", "2");
  +      cache1.attach("map", map);
  +
  +      map = (Map)cache1.find("map");
  +      map.put("map", map);
  +
  +      assertEquals("size ", 3, map.size());
  +      Map m2 = (Map)map.get("map");
  +      assertTrue("Instance of AopProxy", m2 instanceof ClassProxy);
  +//      assertEquals("ClassProxy instance", list, l2);
  +   }
  +
  +   public void testRecursion2() throws Exception
  +   {
  +      Map map = new HashMap();
  +      map.put("1", "1");
  +      map.put("2", "2");
  +      map.put("map", map);
  +
  +      cache1.attach("map", map);
  +
  +      Map m2 = (Map)cache2.find("map");
  +      m2.toString();
  +   }
   
      public static Test suite() throws Exception
      {
  
  
  
  1.5       +25 -5     JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/CachedListImplTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CachedListImplTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/CachedListImplTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- CachedListImplTest.java	31 Oct 2006 11:07:16 -0000	1.4
  +++ CachedListImplTest.java	9 Nov 2006 16:54:33 -0000	1.5
  @@ -7,6 +7,10 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.pojo.PojoCache;
   import org.jboss.cache.pojo.PojoCacheFactory;
  +import org.jboss.cache.Fqn;
  +
  +import java.util.List;
  +import java.util.ArrayList;
   
   /**
    * List implementation testing.
  @@ -17,7 +21,7 @@
   public class CachedListImplTest extends TestCase
   {
      Log log = LogFactory.getLog(CachedListImplTest.class);
  -   PojoCache cache_;
  +   PojoCache cache_, cache1_;
   
      public CachedListImplTest(String name)
      {
  @@ -29,20 +33,36 @@
      {
         super.setUp();
         log.info("setUp() ....");
  -      String configFile = "META-INF/local-service.xml";
  -      boolean toStart = false;
  +      String configFile = "META-INF/replSync-service.xml";
  +      boolean toStart = true;
         cache_ = PojoCacheFactory.createCache(configFile, toStart);
  -      cache_.start();
  +
  +      cache1_ = PojoCacheFactory.createCache(configFile, toStart);
      }
   
      protected void tearDown() throws Exception
      {
         super.tearDown();
         cache_.stop();
  +      cache1_.stop();
      }
   
  -   public void testDummy()
  +   public void testSimpleRepl()
      {
  +      List list = new ArrayList();
  +      list.add("1");
  +      list.add("2");
  +
  +      cache_.attach("list", list);
  +
  +      // proxy now
  +      list = (List)cache_.find("list");
  +
  +      // test repl
  +      cache_.getCache().put(Fqn.fromString("test"), "1", list);
  +
  +      ArrayList l1 = (ArrayList)cache1_.getCache().get(Fqn.fromString("test"), "1");
  +      System.out.println(" list : " +l1);
      }
   
      public static Test suite() throws Exception
  
  
  
  1.6       +30 -0     JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedSyncListTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- ReplicatedSyncListTest.java	6 Nov 2006 13:44:27 -0000	1.5
  +++ ReplicatedSyncListTest.java	9 Nov 2006 16:54:33 -0000	1.6
  @@ -10,6 +10,7 @@
   import org.jboss.cache.pojo.test.Address;
   import org.jboss.cache.pojo.test.Person;
   import org.jboss.cache.Fqn;
  +import org.jboss.aop.proxy.ClassProxy;
   
   import java.util.ArrayList;
   import java.util.List;
  @@ -242,6 +243,35 @@
   
      }
   
  +   public void testRecursion1() throws Exception
  +   {
  +      List list = new ArrayList();
  +      list.add("1");
  +      list.add("2");
  +      cache1.attach("list", list);
  +      
  +      list = (List)cache1.find("list");
  +      list.add(list);
  +
  +      assertEquals("size ", 3, list.size());
  +      List l2 = (List)list.get(2);
  +      assertTrue("Instance of AopProxy", l2 instanceof ClassProxy);
  +//      assertEquals("ClassProxy instance", list, l2);
  +   }
  +
  +   public void testRecursion2() throws Exception
  +   {
  +      List list = new ArrayList();
  +      list.add("1");
  +      list.add("2");
  +      list.add(list);
  +
  +      cache1.attach("list", list);
  +
  +      list = (List)cache1.find("list");
  +      list.toString();
  +   }
  +
      public static Test suite() throws Exception
      {
         return new TestSuite(ReplicatedSyncListTest.class);
  
  
  
  1.1      date: 2006/11/09 16:54:33;  author: bwang;  state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/collection/CachedMapImplTest.java
  
  Index: CachedMapImplTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.TestCase;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.Fqn;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * List implementation testing.
   *
   * @author Ben Wang
   */
  
  public class CachedMapImplTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedMapImplTest.class);
     PojoCache cache_, cache1_;
  
     public CachedMapImplTest(String name)
     {
        super(name);
     }
  
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/replSync-service.xml";
        boolean toStart = true;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
  
        cache1_ = PojoCacheFactory.createCache(configFile, toStart);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
        cache1_.stop();
     }
  
     public void testSimpleRepl()
     {
        Map map = new HashMap();
        map.put("1", "1");
        map.put("2", "2");
  
        cache_.attach("map", map);
  
        // proxy now
        map = (Map)cache_.find("map");
  
        // test repl
        cache_.getCache().put(Fqn.fromString("test"), "1", map);
  
        Map m1 = (Map)cache1_.getCache().get(Fqn.fromString("test"), "1");
        System.out.println(" map : " +m1);
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedMapImplTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list