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

Manik Surtani msurtani at jboss.com
Wed Aug 9 10:50:01 EDT 2006


  User: msurtani
  Date: 06/08/09 10:50:01

  Added:       tests/functional/org/jboss/cache/notifications  
                        TreeCacheListenerOptimisticTest.java
                        TreeCacheListenerTest.java
  Log:
  Merged in fixes from 1.4.0.SP1
  
  Revision  Changes    Path
  1.2       +17 -0     JBossCache/tests/functional/org/jboss/cache/notifications/TreeCacheListenerOptimisticTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheListenerOptimisticTest.java
  ===================================================================
  RCS file: TreeCacheListenerOptimisticTest.java
  diff -N TreeCacheListenerOptimisticTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ TreeCacheListenerOptimisticTest.java	9 Aug 2006 14:50:01 -0000	1.2
  @@ -0,0 +1,17 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.cache.notifications;
  +
  +public class TreeCacheListenerOptimisticTest extends TreeCacheListenerTest
  +{
  +
  +    public TreeCacheListenerOptimisticTest(String s)
  +    {
  +        super(s);
  +        optLocking = true;
  +    }
  +}
  
  
  
  1.2       +160 -0    JBossCache/tests/functional/org/jboss/cache/notifications/TreeCacheListenerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheListenerTest.java
  ===================================================================
  RCS file: TreeCacheListenerTest.java
  diff -N TreeCacheListenerTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ TreeCacheListenerTest.java	9 Aug 2006 14:50:01 -0000	1.2
  @@ -0,0 +1,160 @@
  +/*****************************************
  + *                                       *
  + *  JBoss Portal: The OpenSource Portal  *
  + *                                       *
  + *   Distributable under LGPL license.   *
  + *   See terms of license at gnu.org.    *
  + *                                       *
  + *****************************************/
  +package org.jboss.cache.notifications;
  +
  +import junit.framework.TestCase;
  +import org.jboss.cache.AbstractCacheListener;
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.DummyTransactionManagerLookup;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.config.Configuration;
  +import org.jboss.cache.lock.IsolationLevel;
  +
  +import javax.transaction.TransactionManager;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Collections;
  +import java.util.HashMap;
  +import java.util.List;
  +import java.util.Map;
  +
  +/**
  + * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  + * @version $Id: TreeCacheListenerTest.java,v 1.2 2006/08/09 14:50:01 msurtani Exp $
  + */
  +public class TreeCacheListenerTest extends TestCase
  +{
  +
  +   protected boolean optLocking = false;
  +
  +   public TreeCacheListenerTest(String s)
  +   {
  +      super(s);
  +   }
  +
  +   private Cache cache;
  +   private TreeCache treeCache;
  +
  +   protected void setUp() throws Exception
  +   {
  +      super.setUp();
  +      treeCache = new TreeCache();
  +      treeCache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
  +      treeCache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
  +      if (optLocking) treeCache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
  +      treeCache.setTransactionManagerLookup(new DummyTransactionManagerLookup());
  +      treeCache.create();
  +      treeCache.start();
  +      cache = treeCache.getCacheSPI();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      super.tearDown();
  +      cache.stop();
  +      cache.destroy();
  +   }
  +
  +   public void testRemovePropertyWithCommit() throws Exception
  +   {
  +      cache.put(Fqn.ROOT, "name", "value");
  +
  +      EventLog el = new EventLog();
  +      cache.addCacheListener(el);
  +
  +      TransactionManager tm = treeCache.getTransactionManager();
  +      tm.begin();
  +      cache.remove(Fqn.ROOT, "name");
  +      tm.commit();
  +
  +      assertEquals(Arrays.asList(new Object[]{"modify about to modify local /","modified /", "modify Modified local /"}), el.events);
  +      el.events.clear();
  +   }
  +
  +   public void testNodeCreatedAndModifiedEvent() throws Exception
  +   {
  +       EventLog el = new EventLog();
  +       cache.addCacheListener(el);
  +       cache.put(Fqn.fromString("/hello/world"), "x", "y");
  +       System.out.println(el.events);
  +
  +       List expectedChanges = new ArrayList();
  +       expectedChanges.add("created /hello");
  +       expectedChanges.add("created /hello/world");
  +
  +       if (optLocking)
  +       {
  +           // all creations are fired as mods since these reflect as modified nodes in the workspace.  Opt locking only.
  +           expectedChanges.add("modify about to modify local /");
  +           expectedChanges.add("modified /");
  +           expectedChanges.add("modify Modified local /");
  +           expectedChanges.add("modify about to modify local /hello");
  +           expectedChanges.add("modified /hello");
  +           expectedChanges.add("modify Modified local /hello");
  +       }
  +
  +       expectedChanges.add("modify about to modify local /hello/world");
  +       expectedChanges.add("modified /hello/world");
  +       expectedChanges.add("modify Modified local /hello/world");
  +
  +       //assertEquals(expectedChanges.size(), el.events.size());
  +       assertEquals(expectedChanges, el.events);
  +       el.events.clear();
  +   }
  +
  +   public void testRemoveNodeWithRollback() throws Exception
  +   {
  +      cache.put("/child", new HashMap());
  +
  +      EventLog el = new EventLog();
  +      cache.addCacheListener(el);
  +
  +      TransactionManager tm = treeCache.getTransactionManager();
  +      tm.begin();
  +      cache.remove(Fqn.fromString("/child"));
  +      tm.rollback();
  +      if (optLocking)
  +      {
  +        // in opt locking, a rollback will result in nothing having changed in the cache and hence
  +        // no notifications will fire.
  +        assertEquals(Collections.EMPTY_LIST, el.events);
  +      }
  +      else
  +      {
  +        // with pess locking, a rollback consists of modifications + equal and opposite modifications.
  +        assertEquals(Arrays.asList(new Object[]{"remove about to remove local /child","removed /child","remove Removed local /child","created /child"}), el.events);
  +      }
  +      el.events.clear();
  +   }
  +
  +   public static class EventLog extends AbstractCacheListener
  +   {
  +      public final List events = new ArrayList();
  +
  +      public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
  +      {
  +         if (pre) events.add("created " + fqn);
  +      }
  +      public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
  +      {
  +         events.add("remove "+
  +                 (pre? "about to remove " : "Removed ") +
  +                 (isLocal? "local " : "remote ") + fqn);
  +      }
  +      public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
  +      {
  +         events.add("modify "+
  +                 (pre? "about to modify " : "Modified ") +
  +                 (isLocal? "local " : "remote ") + fqn);
  +      }
  +   }
  +
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list