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

Ben Wang bwang at jboss.com
Mon Jul 17 21:36:23 EDT 2006


  User: bwang   
  Date: 06/07/17 21:36:23

  Modified:    tests-50/functional/org/jboss/cache/pojo    
                        ObjectGraphTest.java ReplicatedObjectGraphTest.java
  Added:       tests-50/functional/org/jboss/cache/pojo    
                        CircularGraphTest.java
                        ReplicatedCircularGraphTest.java
  Log:
  new cases.
  
  Revision  Changes    Path
  1.4       +65 -109   JBossCache/tests-50/functional/org/jboss/cache/pojo/ObjectGraphTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ObjectGraphTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/ObjectGraphTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ObjectGraphTest.java	17 Jul 2006 09:30:02 -0000	1.3
  +++ ObjectGraphTest.java	18 Jul 2006 01:36:23 -0000	1.4
  @@ -86,149 +86,105 @@
         assertEquals(add1.getCity(), add2.getCity());
      }
   
  -   public void testRefCount() throws Exception
  +   public void testReAttach() throws Exception
      {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testRefCount() ...");
  -      Person joe = createPerson("Joe Black", 31);
  -      Person ben = createPerson("Ben Hogan", 51);
  -      cache_.attach("/person/joe", joe);
  -      cache_.attach("/person/ben", ben);
  +      log.info("testMultipleReference() ...");
  +      cache_.attach("/person/joe", createPerson("Joe Black", 31));
  +      Person joe = (Person) cache_.find("/person/joe");
  +      cache_.attach("/person/ben", createPerson("Ben Hogan", 51));
  +      Person ben = (Person) cache_.find("/person/ben");
   
         Address addr = new Address();
         addr.setStreet("123 Albert Ave.");
         addr.setCity("Sunnyvale");
         addr.setZip(94087);
   
  +      // They share the sub-object: address
  +      log.info("testMultipleReference(): set Joe address");
         joe.setAddress(addr);
  +      log.info("testMultipleReference(): set Ben address");
         ben.setAddress(addr);
  -      // They share the sub-object: address
  +
  +      log.info("testMultipleReference(): verify");
         Address add1 = (Address) ((Person) cache_.find("/person/joe")).getAddress();
         Address add2 = (Address) ((Person) cache_.find("/person/ben")).getAddress();
  -      assertEquals("Joe's address should still be valid ", "Sunnyvale", add1.getCity());
  -      assertEquals("Ben's address should still be valid ", "Sunnyvale", add2.getCity());
         assertEquals(add1.getCity(), add2.getCity());
         addr.setCity("Santa Clara");
         assertEquals(add1.getCity(), add2.getCity());
   
         cache_.detach("/person/joe");
  -      ben = (Person) cache_.find("/person/ben");
  -      addr = ben.getAddress();
  -      addr.setCity("Santa Clara");
  -      assertEquals("Ben's address should be changed ", "Santa Clara", addr.getCity());
   
  -      cache_.detach("/person/ben");
  -   }
  -
  -   /**
  -    * Pure parent child relationsip
  -    *
  -    * @throws Exception
  -    */
  -   public void testCircularReference1() throws Exception
  -   {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testCircularReference1() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      parent.setLink(child);
  -      child.setLink(parent);
  -      cache_.attach("/link/parent", parent);
  -      assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
  -      Link link = (Link) cache_.detach("/link/parent");
  -      assertEquals("child", link.getLink().getName());
  -      assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/parent")));
  -   }
  -
  -   /**
  -    * cache managed first before put in the relationsip.
  -    *
  -    * @throws Exception
  -    */
  -   public void testCircularReference2() throws Exception
  -   {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testCircularReference2() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      cache_.attach("/link/parent", parent);
  -      parent.setLink(child);
  -      child.setLink(parent);
  -      assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
  -      Link link = (Link) cache_.detach("/link/parent");
  -      assertEquals("child", link.getLink().getName());
  -      assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/parent")));
  +      cache_.attach("/person/joe", joe);
      }
   
      /**
  -    * Put first before settting the relationship
  -    *
  +    * Reattach in reverse order
       * @throws Exception
       */
  -   public void testCircularReference3() throws Exception
  +   public void testReAttach1() throws Exception
      {
  -      log.info("testCircularReference3() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      cache_.attach("/link/parent", parent);
  -      cache_.attach("/link/child", child);
  -      parent.setLink(child);
  -      child.setLink(parent);
  -      assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
  -      assertEquals("child", ((Link) cache_.find("/link/child")).getName());
  -      assertEquals("parent", ((Link) cache_.find("/link/child")).getLink().getName());
  -      Link link = (Link) cache_.detach("/link/parent");
  -      assertEquals("child", link.getLink().getName());
  -      assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/parent")));
  -   }
  +      log.info("testMultipleReference() ...");
  +      cache_.attach("/person/joe", createPerson("Joe Black", 31));
  +      Person joe = (Person) cache_.find("/person/joe");
  +      cache_.attach("/person/ben", createPerson("Ben Hogan", 51));
  +      Person ben = (Person) cache_.find("/person/ben");
   
  -   /**
  -    * Setting the circular relationship and also as a shared object.
  -    *
  -    * @throws Exception
  -    */
  -   public void testCircularReference4() throws Exception
  -   {
  -      log.info("testCircularReference3() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      parent.setLink(child);
  -      child.setLink(parent);
  +      Address addr = new Address();
  +      addr.setStreet("123 Albert Ave.");
  +      addr.setCity("Sunnyvale");
  +      addr.setZip(94087);
   
  -      List<Link> list = new ArrayList<Link>();
  -      list.add(parent);
  +      // They share the sub-object: address
  +      log.info("testMultipleReference(): set Joe address");
  +      joe.setAddress(addr);
  +      log.info("testMultipleReference(): set Ben address");
  +      ben.setAddress(addr);
   
  -      cache_.attach("/list", list);
  -      cache_.attach("/alias", list);
  +      log.info("testMultipleReference(): verify");
  +      Address add1 = (Address) ((Person) cache_.find("/person/joe")).getAddress();
  +      Address add2 = (Address) ((Person) cache_.find("/person/ben")).getAddress();
  +      assertEquals(add1.getCity(), add2.getCity());
  +      addr.setCity("Santa Clara");
  +      assertEquals(add1.getCity(), add2.getCity());
   
  -      List<Link> list1 = (List<Link>) cache_.find("/list");
  -      List<Link> list2 = (List<Link>) cache_.find("/alias");
  +      cache_.detach("/person/ben");
  +      cache_.detach("/person/joe");
   
  -      assertEquals("parent", ((Link) list1.get(0)).getName());
  -      assertEquals("child", ((Link) list2.get(0)).getLink().getName());
  +      cache_.attach("/person/ben", ben);
  +      cache_.attach("/person/joe", joe);
      }
   
  -   public void testCircularAndSharedReferences() throws Exception
  +   public void testRefCount() throws Exception
      {
  -      log.info("testCircularAndSharedReferences() ...");
  -      NodeManager pm_ = new NodeManager();
  +      log.info("testRefCount() ...");
  +      Person joe = createPerson("Joe Black", 31);
  +      Person ben = createPerson("Ben Hogan", 51);
  +      cache_.attach("/person/joe", joe);
  +      cache_.attach("/person/ben", ben);
  +
  +      Address addr = new Address();
  +      addr.setStreet("123 Albert Ave.");
  +      addr.setCity("Sunnyvale");
  +      addr.setZip(94087);
   
  -      pm_.setRootNode("root");
  -      pm_.addNode("root", "kanto");
  -      pm_.addNode("root.kanto", "tokyo");
  -      pm_.addNode("root.kanto", "kanagawa");
  +      joe.setAddress(addr);
  +      ben.setAddress(addr);
  +      // They share the sub-object: address
  +      Address add1 = (Address) ((Person) cache_.find("/person/joe")).getAddress();
  +      Address add2 = (Address) ((Person) cache_.find("/person/ben")).getAddress();
  +      assertEquals("Joe's address should still be valid ", "Sunnyvale", add1.getCity());
  +      assertEquals("Ben's address should still be valid ", "Sunnyvale", add2.getCity());
  +      assertEquals(add1.getCity(), add2.getCity());
  +      addr.setCity("Santa Clara");
  +      assertEquals(add1.getCity(), add2.getCity());
   
  -      assertEquals("kanagawa", pm_.findNode("root.kanto.kanagawa").getNodeRDN());
  -      cache_.attach("/propagation", pm_);
  -      pm_.addNode("root.kanto.tokyo", "hadanshita");
  -      assertEquals("hadanshita", pm_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
  +      cache_.detach("/person/joe");
  +      ben = (Person) cache_.find("/person/ben");
  +      addr = ben.getAddress();
  +      addr.setCity("Santa Clara");
  +      assertEquals("Ben's address should be changed ", "Santa Clara", addr.getCity());
   
  -      List list = pm_.findNode("root").getChildren();
  -      assertEquals("Root should have children of ", 1, list.size());
  -      pm_.printNodes();
  +      cache_.detach("/person/ben");
      }
   
      public void testRemoveObject1() throws Exception
  
  
  
  1.4       +0 -134    JBossCache/tests-50/functional/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedObjectGraphTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ReplicatedObjectGraphTest.java	17 Jul 2006 09:57:35 -0000	1.3
  +++ ReplicatedObjectGraphTest.java	18 Jul 2006 01:36:23 -0000	1.4
  @@ -151,140 +151,6 @@
         cache2.detach("/person/ben");
      }
   
  -   public void testCircularReference1() throws Exception
  -   {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testCircularReference1() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      parent.setLink(child);
  -      child.setLink(parent);
  -      cache1.attach("/link/parent", parent);
  -      TestingUtil.sleepThread(100);
  -      assertEquals("parent", ((Link) cache1.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache1.find("/link/parent")).getLink().getName());
  -      assertEquals("parent", ((Link) cache2.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache2.find("/link/parent")).getLink().getName());
  -      ((Link) cache2.find("/link/parent")).setLink(null);
  -      assertNull("Child should be null", ((Link) cache2.find("/link/parent")).getLink());
  -      Link link = (Link) cache1.detach("/link/parent");
  -      assertNotNull("Link should not be null ", link);
  -      System.out.println("Link: " + link);
  -   }
  -
  -   public void testCircularReference2() throws Exception
  -   {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testCircularReference2() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      cache1.attach("/link/parent", parent);
  -      parent.setLink(child);
  -      child.setLink(parent);
  -      assertEquals("parent", ((Link) cache1.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache1.find("/link/parent")).getLink().getName());
  -      assertEquals("parent", ((Link) cache2.find("/link/parent")).getName());
  -      assertEquals("child", ((Link) cache2.find("/link/parent")).getLink().getName());
  -      ((Link) cache2.find("/link/parent")).setLink(null);
  -      assertNull("Child should be null", ((Link) cache2.find("/link/parent")).getLink());
  -      Link link = (Link) cache1.detach("/link/parent");
  -      assertNotNull("Link should not be null ", link);
  -   }
  -
  -   public void testCircularReference3() throws Exception
  -   {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testCircularReference3() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      cache1.attach("/link/parent", parent);
  -      cache1.attach("/link/child", child);
  -      TestingUtil.sleepThread(100);
  -      parent.setLink(child);
  -      child.setLink(parent);
  -
  -      Link p1 = (Link) cache1.find("/link/parent");
  -      Link c1 = (Link) cache1.find("/link/child");
  -      assertEquals("parent", p1.getName());
  -      assertEquals("child", p1.getLink().getName());
  -      assertEquals("child", c1.getName());
  -      assertEquals("parent", c1.getLink().getName());
  -
  -      Link p2 = (Link) cache1.find("/link/parent");
  -      Link c2 = (Link) cache1.find("/link/child");
  -
  -      assertEquals("parent", p2.getName());
  -      assertEquals("child", p2.getLink().getName());
  -      assertEquals("child", c2.getName());
  -      assertEquals("parent", c2.getLink().getName());
  -
  -      p2.setLink(null);
  -      assertNull("Child should be null", p2.getLink());
  -      Link link = (Link) cache1.detach("/link/parent");
  -      assertNotNull("Link should not be null ", link);
  -   }
  -
  -   /**
  -    * Setting the circular relationship and also as a shared object.
  -    *
  -    * @throws Exception
  -    */
  -   public void testCircularReference4() throws Exception
  -   {
  -//        try {Thread.sleep(10000); } catch (Exception e) {};
  -      log.info("testCircularReference3() ...");
  -      Link parent = new Link("parent");
  -      Link child = new Link("child");
  -      parent.setLink(child);
  -      child.setLink(parent);
  -
  -      List<Link> list = new ArrayList<Link>();
  -      list.add(parent);
  -
  -      cache1.attach("/list", list);
  -      cache1.attach("/alias", list);
  -
  -      TestingUtil.sleepThread(100);
  -      List list1 = (List) cache2.find("/list");
  -      List list2 = (List) cache2.find("/alias");
  -
  -      assertEquals("parent", ((Link) list1.get(0)).getName());
  -      assertEquals("child", ((Link) list2.get(0)).getLink().getName());
  -   }
  -
  -   public void testCircularAndSharedReferences() throws Exception
  -   {
  -      log.info("testCircularAndSharedReferences() ...");
  -      NodeManager pm_ = new NodeManager();
  -
  -      pm_.setRootNode("root");
  -      pm_.addNode("root", "kanto");
  -      pm_.addNode("root.kanto", "tokyo");
  -      pm_.addNode("root.kanto", "kanagawa");
  -
  -      cache1.attach("/propagation", pm_);
  -      assertEquals("kanagawa", pm_.findNode("root.kanto.kanagawa").getNodeRDN());
  -      pm_.addNode("root.kanto.tokyo", "hadanshita");
  -      assertEquals("hadanshita", pm_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
  -
  -      NodeManager pm2_ = (NodeManager) cache2.find("/propagation");
  -      assertEquals("kanagawa", pm2_.findNode("root.kanto.kanagawa").getNodeRDN());
  -      assertEquals("hadanshita", pm2_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
  -
  -/*
  -      System.out.println("\n\n");
  -      System.out.println("---------------------------------------------");
  -      System.out.println("Initial pm state");
  -      System.out.println("---------------------------------------------");
  -      pm_.printNodes();
  -
  -      System.out.println("\n\n");
  -      System.out.println("---------------------------------------------");
  -      System.out.println("Initial cache content");
  -      System.out.println(cache_.printDetails());
  -      System.out.println("---------------------------------------------");
  -*/
  -   }
   
      public void testdetach1() throws Exception
      {
  
  
  
  1.1      date: 2006/07/18 01:36:23;  author: bwang;  state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/CircularGraphTest.java
  
  Index: CircularGraphTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo;
  
  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.test.Person;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Link;
  import org.jboss.cache.pojo.test.NodeManager;
  import org.jboss.cache.DataNode;
  
  import java.util.List;
  import java.util.ArrayList;
  
  /**
   * Test object graph handling in PojoCache, e.g., circular reference, multiple reference, link, etc.
   *
   * @author Ben Wang
   */
  
  public class CircularGraphTest extends TestCase
  {
     Log log = LogFactory.getLog(CircularGraphTest.class);
     PojoCache cache_;
  
     public CircularGraphTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        cache_ = PojoCacheFactory.createInstance(configFile);
        cache_.start();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
  //   public void testDummy() {}
  
     protected Person createPerson(String name, int age)
     {
        Person p = new Person();
        p.setName(name);
        p.setAge(age);
        return p;
     }
  
     /**
      * Pure parent child relationsip
      *
      * @throws Exception
      */
     public void testCircularReference1() throws Exception
     {
        log.info("testCircularReference1() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
        cache_.attach("/link/parent", parent);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
     }
  
     /**
      * Pure parent child relationsip. Attach both parent and child.
      *
      * @throws Exception
      */
     public void testCircularReference2() throws Exception
     {
        log.info("testCircularReference2() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
        cache_.attach("/link/parent", parent);
        cache_.attach("/link/child", child);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
     }
  
     /**
      * Pure parent child relationsip with detach
      *
      * @throws Exception
      */
     public void testCircularReference3() throws Exception
     {
        log.info("testCircularReference3() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
        cache_.attach("/link/parent", parent);
        cache_.attach("/link/child", child);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
        Link link = (Link) cache_.detach("/link/parent");
        cache_.detach("/link/child");
        assertEquals("child", link.getLink().getName());
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/link/parent")));
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/link/child")));
     }
  
     /**
      * Pure parent child relationsip with detach reversed
      *
      * @throws Exception
      */
     public void testCircularReference3a() throws Exception
     {
        log.info("testCircularReference3() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
        cache_.attach("/link/parent", parent);
        cache_.attach("/link/child", child);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
        cache_.detach("/link/child");
        Link link = (Link) cache_.detach("/link/parent");
        assertEquals("child", link.getLink().getName());
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/link/parent")));
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/link/child")));
     }
  
     /**
      * cache managed first before put in the relationsip.
      *
      * @throws Exception
      */
     public void testCircularReference4() throws Exception
     {
        log.info("testCircularReference4() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        cache_.attach("/link/parent", parent);
        cache_.attach("/link/child", child);
        parent.setLink(child);
        child.setLink(parent);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
        Link link = (Link) cache_.detach("/link/parent");
        assertEquals("child", link.getLink().getName());
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/parent")));
     }
  
     /**
      * Put first before settting the relationship
      *
      * @throws Exception
      */
     public void testCircularReference5() throws Exception
     {
        log.info("testCircularReference5() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        cache_.attach("/link/parent", parent);
        cache_.attach("/link/child", child);
        parent.setLink(child);
        child.setLink(parent);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
        assertEquals("child", ((Link) cache_.find("/link/child")).getName());
        assertEquals("parent", ((Link) cache_.find("/link/child")).getLink().getName());
        Link link = (Link) cache_.detach("/link/parent");
        assertEquals("child", link.getLink().getName());
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/parent")));
     }
  
     /**
      * Put first before settting the relationship
      *
      * @throws Exception
      */
     public void testCircularReference6() throws Exception
     {
        log.info("testCircularReference6() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        cache_.attach("/link/parent", parent);
        cache_.attach("/link/child", child);
        parent.setLink(child);
        child.setLink(parent);
        assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
        assertEquals("child", ((Link) cache_.find("/link/child")).getName());
        assertEquals("parent", ((Link) cache_.find("/link/child")).getLink().getName());
        Link link = (Link) cache_.detach("/link/parent");
        assertEquals("child", link.getLink().getName());
        assertNull("Cache should be null ", ((DataNode) cache_.getCache().get("/parent")));
  
        // re-attach
        cache_.attach("/link/parent", parent);
     }
  
     /**
      * Setting the circular relationship and also as a shared object.
      *
      * @throws Exception
      */
     public void testCircularReference7() throws Exception
     {
        log.info("testCircularReference7() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
  
        List<Link> list = new ArrayList<Link>();
        list.add(parent);
  
        cache_.attach("/list", list);
        cache_.attach("/alias", list);
  
        List<Link> list1 = (List<Link>) cache_.find("/list");
        List<Link> list2 = (List<Link>) cache_.find("/alias");
  
        assertEquals("parent", ((Link) list1.get(0)).getName());
        assertEquals("child", ((Link) list2.get(0)).getLink().getName());
     }
  
     public void testCircularAndSharedReferences() throws Exception
     {
        log.info("testCircularAndSharedReferences() ...");
        NodeManager pm_ = new NodeManager();
  
        pm_.setRootNode("root");
        pm_.addNode("root", "kanto");
        pm_.addNode("root.kanto", "tokyo");
        pm_.addNode("root.kanto", "kanagawa");
  
        assertEquals("kanagawa", pm_.findNode("root.kanto.kanagawa").getNodeRDN());
        cache_.attach("/propagation", pm_);
        pm_.addNode("root.kanto.tokyo", "hadanshita");
        assertEquals("hadanshita", pm_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
  
        List list = pm_.findNode("root").getChildren();
        assertEquals("Root should have children of ", 1, list.size());
        pm_.printNodes();
     }
  
     public void XtestObjectIdentity() throws Exception
     {
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CircularGraphTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(CircularGraphTest.suite());
     }
  
  }
  
  
  
  1.1      date: 2006/07/18 01:36:23;  author: bwang;  state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
  
  Index: ReplicatedCircularGraphTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo;
  
  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.test.Person;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Link;
  import org.jboss.cache.pojo.test.NodeManager;
  
  import java.util.List;
  import java.util.ArrayList;
  
  /**
   * Test object graph handling in aop, e.g., circular reference, multiple reference, link, etc.
   *
   * @author Ben Wang
   */
  
  public class ReplicatedCircularGraphTest extends TestCase
  {
     Log log = LogFactory.getLog(ReplicatedCircularGraphTest.class);
     PojoCache cache1;
     PojoCache cache2;
  
     public ReplicatedCircularGraphTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        cache1 = createCache("CacheGroup");
        cache2 = createCache("CacheGroup");
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache1.getCache().remove("/");
        cache1.stop();
        cache2.stop();
     }
  
     private PojoCache createCache(String name) throws Exception
     {
        PojoCache tree = PojoCacheFactory.createInstance("META-INF/replSync-service.xml");
        tree.start();
        return tree;
     }
  
  //   public void testDummy() {}
  
     protected Person createPerson(String name, int age)
     {
        Person p = new Person();
        p.setName(name);
        p.setAge(age);
        return p;
     }
  
     public void testCircularReference1() throws Exception
     {
  //        try {Thread.sleep(10000); } catch (Exception e) {};
        log.info("testCircularReference1() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
        cache1.attach("/link/parent", parent);
        TestingUtil.sleepThread(100);
        assertEquals("parent", ((Link) cache1.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache1.find("/link/parent")).getLink().getName());
        assertEquals("parent", ((Link) cache2.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache2.find("/link/parent")).getLink().getName());
        ((Link) cache2.find("/link/parent")).setLink(null);
        assertNull("Child should be null", ((Link) cache2.find("/link/parent")).getLink());
        Link link = (Link) cache1.detach("/link/parent");
        assertNotNull("Link should not be null ", link);
        System.out.println("Link: " + link);
     }
  
     public void testCircularReference2() throws Exception
     {
  //        try {Thread.sleep(10000); } catch (Exception e) {};
        log.info("testCircularReference2() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        cache1.attach("/link/parent", parent);
        parent.setLink(child);
        child.setLink(parent);
        assertEquals("parent", ((Link) cache1.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache1.find("/link/parent")).getLink().getName());
        assertEquals("parent", ((Link) cache2.find("/link/parent")).getName());
        assertEquals("child", ((Link) cache2.find("/link/parent")).getLink().getName());
        ((Link) cache2.find("/link/parent")).setLink(null);
        assertNull("Child should be null", ((Link) cache2.find("/link/parent")).getLink());
        Link link = (Link) cache1.detach("/link/parent");
        assertNotNull("Link should not be null ", link);
     }
  
     public void testCircularReference3() throws Exception
     {
  //        try {Thread.sleep(10000); } catch (Exception e) {};
        log.info("testCircularReference3() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        cache1.attach("/link/parent", parent);
        cache1.attach("/link/child", child);
        TestingUtil.sleepThread(100);
        parent.setLink(child);
        child.setLink(parent);
  
        Link p1 = (Link) cache1.find("/link/parent");
        Link c1 = (Link) cache1.find("/link/child");
        assertEquals("parent", p1.getName());
        assertEquals("child", p1.getLink().getName());
        assertEquals("child", c1.getName());
        assertEquals("parent", c1.getLink().getName());
  
        Link p2 = (Link) cache1.find("/link/parent");
        Link c2 = (Link) cache1.find("/link/child");
  
        assertEquals("parent", p2.getName());
        assertEquals("child", p2.getLink().getName());
        assertEquals("child", c2.getName());
        assertEquals("parent", c2.getLink().getName());
  
        p2.setLink(null);
        assertNull("Child should be null", p2.getLink());
        Link link = (Link) cache1.detach("/link/parent");
        assertNotNull("Link should not be null ", link);
     }
  
     /**
      * Setting the circular relationship and also as a shared object.
      *
      * @throws Exception
      */
     public void testCircularReference4() throws Exception
     {
  //        try {Thread.sleep(10000); } catch (Exception e) {};
        log.info("testCircularReference3() ...");
        Link parent = new Link("parent");
        Link child = new Link("child");
        parent.setLink(child);
        child.setLink(parent);
  
        List<Link> list = new ArrayList<Link>();
        list.add(parent);
  
        cache1.attach("/list", list);
        cache1.attach("/alias", list);
  
        TestingUtil.sleepThread(100);
        List list1 = (List) cache2.find("/list");
        List list2 = (List) cache2.find("/alias");
  
        assertEquals("parent", ((Link) list1.get(0)).getName());
        assertEquals("child", ((Link) list2.get(0)).getLink().getName());
     }
  
     public void testCircularAndSharedReferences() throws Exception
     {
        log.info("testCircularAndSharedReferences() ...");
        NodeManager pm_ = new NodeManager();
  
        pm_.setRootNode("root");
        pm_.addNode("root", "kanto");
        pm_.addNode("root.kanto", "tokyo");
        pm_.addNode("root.kanto", "kanagawa");
  
        cache1.attach("/propagation", pm_);
        assertEquals("kanagawa", pm_.findNode("root.kanto.kanagawa").getNodeRDN());
        pm_.addNode("root.kanto.tokyo", "hadanshita");
        assertEquals("hadanshita", pm_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
  
        NodeManager pm2_ = (NodeManager) cache2.find("/propagation");
        assertEquals("kanagawa", pm2_.findNode("root.kanto.kanagawa").getNodeRDN());
        assertEquals("hadanshita", pm2_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
  
  /*
        System.out.println("\n\n");
        System.out.println("---------------------------------------------");
        System.out.println("Initial pm state");
        System.out.println("---------------------------------------------");
        pm_.printNodes();
  
        System.out.println("\n\n");
        System.out.println("---------------------------------------------");
        System.out.println("Initial cache content");
        System.out.println(cache_.printDetails());
        System.out.println("---------------------------------------------");
  */
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedCircularGraphTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ReplicatedCircularGraphTest.suite());
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list