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

Manik Surtani manik at jboss.org
Thu Jun 28 12:53:36 EDT 2007


  User: msurtani
  Date: 07/06/28 12:53:36

  Modified:    tests/functional/org/jboss/cache/notifications      
                        RemoteCacheListenerTest.java CacheListenerTest.java
  Added:       tests/functional/org/jboss/cache/notifications      
                        AnnotationsTest.java NotificationThreadTest.java
                        EventLog.java
  Removed:     tests/functional/org/jboss/cache/notifications      
                        CacheListenerEvent.java
  Log:
  Notification changes
  
  Revision  Changes    Path
  1.17      +221 -204  JBossCache/tests/functional/org/jboss/cache/notifications/RemoteCacheListenerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RemoteCacheListenerTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/notifications/RemoteCacheListenerTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -b -r1.16 -r1.17
  --- RemoteCacheListenerTest.java	14 Jun 2007 17:56:07 -0000	1.16
  +++ RemoteCacheListenerTest.java	28 Jun 2007 16:53:36 -0000	1.17
  @@ -23,19 +23,23 @@
   package org.jboss.cache.notifications;
   
   import junit.framework.TestCase;
  -import org.jboss.cache.AbstractCacheListener;
   import org.jboss.cache.Cache;
   import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.lock.IsolationLevel;
  -import org.jboss.cache.misc.TestingUtil;
  +import org.jboss.cache.notifications.event.Event;
  +import static org.jboss.cache.notifications.event.Event.Type.*;
  +import org.jboss.cache.notifications.event.EventImpl;
  +import static org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType.*;
   
  +import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.HashMap;
  +import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
   
  @@ -53,7 +57,6 @@
      private TransactionManager tm1, tm2;
      private EventLog eventLog1 = new EventLog(), eventLog2 = new EventLog();
      private Fqn fqn = Fqn.fromString("/test");
  -   private static final long eventSleepTime = 250; // 250ms should be more than enough
   
      protected void setUp() throws Exception
      {
  @@ -134,21 +137,28 @@
         data.put("key", "value");
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, true, null));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, true, null));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, data));
  +      List<Event> expected = new ArrayList<Event>();
  +
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog1.scrubImplicitTransactions();
  +         eventLog2.scrubImplicitTransactions();
  +      }
  +
  +      assertEquals("Local events not as expected", expected, eventLog1.events);
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, false, null));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, false, null));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, Collections.emptyMap()));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, data));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +
  +      assertEquals("Remote events not as expected", expected, eventLog2.events);
         assertEquals("value", cache1.get(fqn, "key"));
      }
   
  @@ -165,7 +175,6 @@
         assertEquals("value", cache2.get(fqn, "key"));
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -176,18 +185,26 @@
         Map newData = new HashMap();
         newData.put("key", "value2");
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
  +
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, PUT_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, PUT_DATA, newData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog1.scrubImplicitTransactions();
  +         eventLog2.scrubImplicitTransactions();
  +      }
  +
  +      assertEquals("Local events not as expected", expected, eventLog1.events);
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, oldData));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, newData));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +
  +      assertEquals("Remote events not as expected", expected, eventLog2.events);
      }
   
   
  @@ -202,7 +219,6 @@
         assertEquals("value", cache2.get(fqn, "key"));
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -211,18 +227,25 @@
         // modify existing node
         cache1.removeNode(fqn);
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, true, true, oldData));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, false, true, null));
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, oldData, fqn, null, true, null, false, null, NODE_REMOVED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_REMOVED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog1.scrubImplicitTransactions();
  +         eventLog2.scrubImplicitTransactions();
  +      }
  +
  +      assertEquals("Local events not as expected", expected, eventLog1.events);
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, true, false, oldData));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, false, false, null));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +
  +      assertEquals("Remote events not as expected", expected, eventLog2.events);
   
         // test that the node has in fact been removed.
         assertNull("Should be null", cache1.getRoot().getChild(fqn));
  @@ -240,7 +263,6 @@
         oldData.put("key2", "value2");
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -251,18 +273,25 @@
         Map removed = new HashMap();
         removed.put("key2", "value2");
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, removed));
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, REMOVE_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, REMOVE_DATA, removed, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog1.scrubImplicitTransactions();
  +         eventLog2.scrubImplicitTransactions();
  +      }
  +
  +      assertEquals("Local events not as expected", expected, eventLog1.events);
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, oldData));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, removed));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +
  +      assertEquals("Remote events not as expected", expected, eventLog2.events);
      }
   
      public void testPutMap() throws Exception
  @@ -276,7 +305,6 @@
         assertNull(cache2.getRoot().getChild(fqn));
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -284,22 +312,27 @@
   
         cache1.put(fqn, oldData);
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, true, null));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, true, null));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, oldData));
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache1, PUT_MAP, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, PUT_MAP, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog1.scrubImplicitTransactions();
  +         eventLog2.scrubImplicitTransactions();
  +      }
  +
  +      assertEquals("Local events not as expected", expected, eventLog1.events);
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, false, null));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, false, null));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, Collections.emptyMap()));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, oldData));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +
  +      assertEquals("Remote events not as expected", expected, eventLog2.events);
      }
   
      public void testMove()
  @@ -312,7 +345,6 @@
         Node n1 = cache1.getRoot().getChild(fqn);
         Node n2 = cache1.getRoot().getChild(newParent);
   
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();// clear events
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -321,18 +353,26 @@
         cache1.move(n1.getFqn(), n2.getFqn());
         Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, true, true));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, false, true));
  +
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog1.scrubImplicitTransactions();
  +         eventLog2.scrubImplicitTransactions();
  +      }
  +
  +      assertEquals("Local events not as expected", expected, eventLog1.events);
   
         //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, true, false));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, false, false));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +
  +      assertEquals("Remote events not as expected", expected, eventLog2.events);
      }
   
      // -- now the transactional ones
  @@ -341,45 +381,58 @@
      {
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
         tm1.begin();
  +      Transaction tx = tm1.getTransaction();
         cache1.put(fqn, "key", "value");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog1.events.size());
  -      assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
  -      tm1.commit();
         Map data = new HashMap();
         data.put("key", "value");
   
  -      //expectedRemote
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, true, null));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, true, null));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, data));
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +
  +      assertEquals(expected, eventLog1.events);
  +      assertTrue(eventLog2.events.isEmpty());
  +
  +      tm1.commit();
  +
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog1.events);
  +
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +      scrubTransactions(expected);
  +      eventLog2.scrubImplicitTransactions();
  +      assertEquals(expected, eventLog2.events);
   
  -      //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, false, null));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, false, null));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, Collections.emptyMap()));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, data));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
         assertEquals("value", cache1.get(fqn, "key"));
  +      assertEquals("value", cache2.get(fqn, "key"));
      }
   
      public void testTxCreationRollback() throws Exception
      {
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
         tm1.begin();
  +      Transaction tx = tm1.getTransaction();
         cache1.put(fqn, "key", "value");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog1.events.size());
  -      assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
  +      Map data = new HashMap();
  +      data.put("key", "value");
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +
  +      assertEquals(expected, eventLog1.events);
  +      assertTrue(eventLog2.events.isEmpty());
         tm1.rollback();
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty since tx rolled back", 0, eventLog1.events.size());
  -      assertEquals("Events log should be empty since tx rolled back", 0, eventLog2.events.size());
  +
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog1.events);
  +      assertTrue(eventLog2.events.isEmpty());
   
         assertNull(cache1.get(fqn, "key"));
         assertNull(cache2.get(fqn, "key"));
  @@ -399,7 +452,6 @@
         assertEquals("value", cache2.get(fqn, "key"));
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -407,26 +459,27 @@
   
         // modify existing node
         tm1.begin();
  +      Transaction tx = tm1.getTransaction();
  +      Map newData = new HashMap();
  +      newData.put("key", "value2");
         cache1.put(fqn, "key", "value2");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog1.events.size());
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, PUT_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, PUT_DATA, newData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      assertEquals(expected, eventLog1.events);
  +
         assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
         tm1.commit();
  -      Map newData = new HashMap();
  -      newData.put("key", "value2");
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog1.events);
   
  -      //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, oldData));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, newData));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +      scrubTransactions(expected);
  +      eventLog2.scrubImplicitTransactions();
  +      assertEquals(expected, eventLog2.events);
      }
   
   
  @@ -441,7 +494,6 @@
         assertEquals("value", cache2.get(fqn, "key"));
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -449,24 +501,24 @@
   
         // modify existing node
         tm1.begin();
  +      Transaction tx = tm1.getTransaction();
         cache1.removeNode(fqn);
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog1.events.size());
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, oldData, fqn, tx, true, null, false, null, NODE_REMOVED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_REMOVED));
  +      assertEquals(expected, eventLog1.events);
         assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
         tm1.commit();
   
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, true, true, oldData));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, false, true, null));
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog1.events);
   
  -      //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, true, false, oldData));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, false, false, null));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +      scrubTransactions(expected);
  +      eventLog2.scrubImplicitTransactions();
  +      assertEquals(expected, eventLog2.events);
   
         // test that the node has in fact been removed.
         assertNull("Should be null", cache1.getRoot().getChild(fqn));
  @@ -484,7 +536,6 @@
         oldData.put("key2", "value2");
   
         // clear event log
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
  @@ -492,27 +543,26 @@
   
         // modify existing node
         tm1.begin();
  +      Transaction tx = tm1.getTransaction();
  +      Map removed = new HashMap();
  +      removed.put("key2", "value2");
         cache1.remove(fqn, "key2");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog1.events.size());
  +      List<Event> expected = new LinkedList<Event>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, REMOVE_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache1, REMOVE_DATA, removed, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      assertEquals(expected, eventLog1.events);
         assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
         tm1.commit();
   
  -      Map removed = new HashMap();
  -      removed.put("key2", "value2");
  -
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, removed));
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog1.events);
   
  -      //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, false, oldData));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, false, removed));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +      scrubTransactions(expected);
  +      eventLog2.scrubImplicitTransactions();
  +      assertEquals(expected, eventLog2.events);
   
      }
   
  @@ -526,78 +576,45 @@
         Node n1 = cache1.getRoot().getChild(fqn);
         Node n2 = cache1.getRoot().getChild(newParent);
   
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog1.events.clear();
         eventLog2.events.clear();// clear events
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
         assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
   
         tm1.begin();
  +      Transaction tx = tm1.getTransaction();
  +      Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
         cache1.move(n1.getFqn(), n2.getFqn());
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog1.events.size());
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
  +      expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
  +      assertEquals(expected, eventLog1.events);
         assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
         tm1.commit();
   
  -      Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
  -
  -      //expectedLocal
  -      List<CacheListenerEvent> expectedLocal = new ArrayList<CacheListenerEvent>();
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, true, true));
  -      expectedLocal.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, false, true));
  -
  -      //expectedRemote
  -      List<CacheListenerEvent> expectedRemote = new ArrayList<CacheListenerEvent>();
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, true, false));
  -      expectedRemote.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, false, false));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expectedLocal, eventLog1.events);
  -      assertEquals(expectedRemote, eventLog2.events);
  -   }
  -
  -   // ============= supporting classes and enums =======================
  -
  -
  -   public static class EventLog extends AbstractCacheListener
  -   {
  -      public final List<CacheListenerEvent> events = new ArrayList<CacheListenerEvent>();
  +      expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog1.events);
   
  -      public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, pre, isLocal, null);
  -         events.add(e);
  +      setCache(cache2, expected);
  +      markOriginRemote(expected);
  +      scrubTransactions(expected);
  +      eventLog2.scrubImplicitTransactions();
  +      assertEquals(expected, eventLog2.events);
         }
   
  -      public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
  +   private void setCache(Cache c, List<Event> l)
         {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, pre, isLocal, data);
  -         events.add(e);
  +      for (Event e : l) ((EventImpl) e).setCache(c);
         }
   
  -      public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
  +   private void markOriginRemote(List<Event> l)
         {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, pre, isLocal, data);
  -         events.add(e);
  +      for (Event e : l) ((EventImpl) e).setOriginLocal(false);
         }
   
  -      public void nodeVisited(Fqn fqn, boolean pre)
  +   private void scrubTransactions(List<Event> l)
         {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_VISITED, fqn, pre, false, null);
  -         events.add(e);
  -      }
  -
  -      public void nodeMoved(Fqn from, Fqn to, boolean pre, boolean isLocal)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, from, to, pre, isLocal);
  -         events.add(e);
  -      }
  -
  -
  -      public String toString()
  -      {
  -         return "EventLog{" +
  -                "events=" + events +
  -                '}';
  -      }
  +      for (Event e : l) ((EventImpl) e).setTransaction(null);
      }
   }
  
  
  
  1.20      +167 -164  JBossCache/tests/functional/org/jboss/cache/notifications/CacheListenerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheListenerTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/notifications/CacheListenerTest.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- CacheListenerTest.java	14 Jun 2007 17:56:07 -0000	1.19
  +++ CacheListenerTest.java	28 Jun 2007 16:53:36 -0000	1.20
  @@ -9,14 +9,16 @@
   package org.jboss.cache.notifications;
   
   import junit.framework.TestCase;
  -import org.jboss.cache.AbstractCacheListener;
   import org.jboss.cache.Cache;
   import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.lock.IsolationLevel;
  -import org.jboss.cache.misc.TestingUtil;
  +import org.jboss.cache.notifications.event.Event;
  +import static org.jboss.cache.notifications.event.Event.Type.*;
  +import org.jboss.cache.notifications.event.EventImpl;
  +import static org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType.*;
   
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
  @@ -28,7 +30,7 @@
   
   /**
    * Note that this is significantly different from the old <b>TreeCacheListenerTest</b> of the JBoss Cache 1.x series, and
  - * exercises the new {@link org.jboss.cache.CacheListener} interface.
  + * exercises the new CacheListener annotation.
    *
    * @since 2.0.0
    */
  @@ -36,7 +38,6 @@
   {
   
      protected boolean optLocking = false;
  -   private static final long eventSleepTime = 250; // 250ms should be more than enough
   
      public CacheListenerTest(String s)
      {
  @@ -75,35 +76,38 @@
   
      public void testCreation() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         Map data = new HashMap();
         data.put("key", "value");
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, true, null));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, true, null));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, data));
  -
  -      TestingUtil.sleepThread(eventSleepTime);
  -
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog.scrubImplicitTransactions();
  +      }
         assertEquals(expected, eventLog.events);
         assertEquals("value", cache.get(fqn, "key"));
      }
   
      public void testOnlyModification() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         Map oldData = new HashMap();
         oldData.put("key", "value");
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         cache.put(fqn, "key", "value2");
  @@ -111,10 +115,17 @@
         newData.put("key", "value2");
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, PUT_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, PUT_DATA, newData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog.scrubImplicitTransactions();
  +      }
  +
         assertEquals(expected.size(), eventLog.events.size());
         assertEquals(expected, eventLog.events);
      }
  @@ -122,26 +133,32 @@
   
      public void testOnlyRemoval() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         Map oldData = new HashMap();
         oldData.put("key", "value");
   
         assertEquals("value", cache.get(fqn, "key"));
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         cache.removeNode(fqn);
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, true, true, oldData));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, false, true, null));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, oldData, fqn, null, true, null, false, null, NODE_REMOVED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_REMOVED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog.scrubImplicitTransactions();
  +      }
  +
         assertEquals(expected, eventLog.events);
   
         // test that the node has in fact been removed.
  @@ -151,17 +168,16 @@
   
      public void testRemoveData() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         cache.put(fqn, "key2", "value2");
         Map oldData = new HashMap();
         oldData.put("key", "value");
         oldData.put("key2", "value2");
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         cache.remove(fqn, "key2");
  @@ -169,58 +185,79 @@
         removedData.put("key2", "value2");
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, removedData));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      List<Event> expected = new ArrayList<Event>();
  +
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, REMOVE_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, REMOVE_DATA, removedData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog.scrubImplicitTransactions();
  +      }
  +
         assertEquals(expected, eventLog.events);
      }
   
      public void testPutMap() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         Map oldData = new HashMap();
         oldData.put("key", "value");
         oldData.put("key2", "value2");
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         cache.put(fqn, oldData);
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, true, null));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, true, null));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, oldData));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      List<Event> expected = new ArrayList<Event>();
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache, PUT_MAP, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, PUT_MAP, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog.scrubImplicitTransactions();
  +      }
  +
         assertEquals(expected, eventLog.events);
      }
   
      public void testMove()
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         Fqn newParent = Fqn.fromString("/a");
         cache.put(fqn, "key", "value");
         cache.put(newParent, "key", "value");
   
         Node n1 = cache.getRoot().getChild(fqn);
         Node n2 = cache.getRoot().getChild(newParent);
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog.events.clear();// clear events
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         cache.move(n1.getFqn(), n2.getFqn());
         //expected
         Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, true, true));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, false, true));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      List<Event> expected = new ArrayList<Event>();
  +
  +      if (optLocking)
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
  +      if (optLocking)
  +      {
  +         expected.add(new EventImpl(false, cache, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
  +         eventLog.scrubImplicitTransactions();
  +      }
  +
         assertEquals(expected, eventLog.events);
      }
   
  @@ -228,98 +265,110 @@
   
      public void testTxCreationCommit() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         tm.begin();
  +      Transaction tx = tm.getTransaction();
         cache.put(fqn, "key", "value");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
  -      tm.commit();
  -
  +      //expected
         Map data = new HashMap();
         data.put("key", "value");
  +      List<Event> expected = new ArrayList<Event>();
   
  -      //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, true, true, null));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, false, true, null));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, data));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      assertEquals(expected, eventLog.events);
  +      tm.commit();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
         assertEquals(expected, eventLog.events);
         assertEquals("value", cache.get(fqn, "key"));
      }
   
      public void testTxCreationRollback() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         tm.begin();
  +      Transaction tx = tm.getTransaction();
         cache.put(fqn, "key", "value");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
  +      //expected
  +      Map data = new HashMap();
  +      data.put("key", "value");
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
  +      expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +
  +
  +      assertEquals(expected, eventLog.events);
         tm.rollback();
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty since tx rolled back", 0, eventLog.events.size());
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog.events);
      }
   
   
      public void testTxOnlyModification() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         Map oldData = new HashMap();
         oldData.put("key", "value");
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         tm.begin();
  +      Transaction tx = tm.getTransaction();
         cache.put(fqn, "key", "value2");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
  -      tm.commit();
         Map newData = new HashMap();
         newData.put("key", "value2");
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
  -      TestingUtil.sleepThread(eventSleepTime);
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, PUT_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, PUT_DATA, newData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +
  +      assertEquals(expected, eventLog.events);
  +      tm.commit();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
         assertEquals(expected, eventLog.events);
      }
   
   
      public void testTxOnlyRemoval() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         Map oldData = new HashMap();
         oldData.put("key", "value");
   
         assertEquals("value", cache.get(fqn, "key"));
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         tm.begin();
  +      Transaction tx = tm.getTransaction();
         cache.removeNode(fqn);
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
  -      tm.commit();
  -
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, true, true, oldData));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, false, true, null));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expected, eventLog.events);
  +      List<Event> expected = new ArrayList<Event>();
  +
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, oldData, fqn, tx, true, null, false, null, NODE_REMOVED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_REMOVED));
   
  +      assertEquals(expected, eventLog.events);
  +      tm.commit();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog.events);
         // test that the node has in fact been removed.
         assertNull("Should be null", cache.getRoot().getChild(fqn));
      }
  @@ -327,108 +376,62 @@
   
      public void testTxRemoveData() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         cache.put(fqn, "key", "value");
         cache.put(fqn, "key2", "value2");
         Map oldData = new HashMap();
         oldData.put("key", "value");
         oldData.put("key2", "value2");
   
  -      // clear CacheListenerEvent log
  -      TestingUtil.sleepThread(eventSleepTime);
  +      // clear Event log
         eventLog.events.clear();
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         // modify existing node
         tm.begin();
  +      Transaction tx = tm.getTransaction();
         cache.remove(fqn, "key2");
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
  -      tm.commit();
  -
         Map removedData = new HashMap();
         removedData.put("key2", "value2");
   
         //expected
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, REMOVE_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +      expected.add(new EventImpl(false, cache, REMOVE_DATA, removedData, fqn, tx, true, null, false, null, NODE_MODIFIED));
  +
  +      tm.commit();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog.events);
   
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, false, true, removedData));
  -      TestingUtil.sleepThread(eventSleepTime);
         assertEquals(expected, eventLog.events);
      }
   
      public void testTxMove() throws Exception
      {
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
         Fqn newParent = Fqn.fromString("/a");
         cache.put(fqn, "key", "value");
         cache.put(newParent, "key", "value");
   
         Node n1 = cache.getRoot().getChild(fqn);
         Node n2 = cache.getRoot().getChild(newParent);
  -      TestingUtil.sleepThread(eventSleepTime);
         eventLog.events.clear();// clear events
  -      assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
  +      assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
   
         tm.begin();
  +      Transaction tx = tm.getTransaction();
         cache.move(n1.getFqn(), n2.getFqn());
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
  -      tm.commit();
  -
         //expected
         Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
  -      List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, true, true));
  -      expected.add(new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, fqn, newFqn, false, true));
  -      TestingUtil.sleepThread(eventSleepTime);
  -      assertEquals(expected, eventLog.events);
  -   }
  -
  -   // ============= supporting classes and enums =======================
  +      List<Event> expected = new ArrayList<Event>();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
  +      expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
  +      expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
   
  -
  -   public static class EventLog extends AbstractCacheListener
  -   {
  -      public final List<CacheListenerEvent> events = new ArrayList<CacheListenerEvent>();
  -
  -      public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_CREATED, fqn, pre, isLocal, null);
  -         events.add(e);
  -      }
  -
  -      public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_REMOVED, fqn, pre, isLocal, data);
  -         events.add(e);
  -      }
  -
  -      public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, pre, isLocal, data);
  -         events.add(e);
  -      }
  -
  -      public void nodeVisited(Fqn fqn, boolean pre)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_VISITED, fqn, pre, false, null);
  -         events.add(e);
  -      }
  -
  -      public void nodeMoved(Fqn from, Fqn to, boolean pre, boolean isLocal)
  -      {
  -         CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, from, to, pre, isLocal);
  -         events.add(e);
  -      }
  -
  -
  -      public String toString()
  -      {
  -         return "EventLog{" +
  -                "events=" + events +
  -                '}';
  -      }
  +      assertEquals(expected, eventLog.events);
  +      tm.commit();
  +      expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
  +      assertEquals(expected, eventLog.events);
      }
   }
  
  
  
  1.1      date: 2007/06/28 16:53:36;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/notifications/AnnotationsTest.java
  
  Index: AnnotationsTest.java
  ===================================================================
  package org.jboss.cache.notifications;
  
  import junit.framework.TestCase;
  import org.jboss.cache.Cache;
  import org.jboss.cache.DefaultCacheFactory;
  import org.jboss.cache.notifications.annotation.CacheListener;
  import org.jboss.cache.notifications.annotation.CacheStarted;
  import org.jboss.cache.notifications.annotation.CacheStopped;
  import org.jboss.cache.notifications.annotation.NodeMoved;
  import org.jboss.cache.notifications.event.Event;
  import org.jboss.cache.notifications.event.NodeMovedEvent;
  
  /**
   * Tests both correct and incorrect annotations for listeners
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   * @since 2.0.0
   */
  public class AnnotationsTest extends TestCase
  {
     private Notifier n;
  
     protected void setUp()
     {
        Cache c = DefaultCacheFactory.getInstance().createCache(false);
        n = new Notifier(c);
     }
  
     public void testControl()
     {
        @CacheListener
        class Listener
        {
           @CacheStarted
           @CacheStopped
           public void callback(Event e)
           {
              System.out.println("Hello");
           }
        }
  
        Listener l = new Listener();
        n.addCacheListener(l);
        assertEquals(1, n.getCacheListeners().size());
     }
  
     public void testCacheListenerNoMethods()
     {
        @CacheListener
        class Listener
        {
           public String toString()
           {
              return "Hello";
           }
        }
  
        Listener l = new Listener();
        n.addCacheListener(l);
        assertEquals("Hello", l.toString());
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty()); // since the valid listener has no methods to listen
     }
  
     public void testNonAnnotatedListener()
     {
        class Listener
        {
           public String toString()
           {
              return "Hello";
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept an un-annotated cache listener");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
     }
  
     public void testNonVoidReturnTypeListener()
     {
        @CacheListener
        class Listener
        {
           @CacheStarted
           public String callback(Event e)
           {
              return "Hello";
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept a listener method with a return type");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
     }
  
  
     public void testIncorrectMethodSignature1()
     {
        @CacheListener
        class Listener
        {
           @CacheStarted
           public void callback()
           {
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept a cache listener with a bad method signature");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
     }
  
     public void testIncorrectMethodSignature2()
     {
        @CacheListener
        class Listener
        {
           @CacheStarted
           public void callback(Event e, String s)
           {
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept a cache listener with a bad method signature");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
     }
  
     public void testIncorrectMethodSignature3()
     {
        @CacheListener
        class Listener
        {
           @CacheStarted
           public void callback(Event e, String... s)
           {
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept a cache listener with a bad method signature");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
     }
  
     public void testUnassignableMethodSignature()
     {
        @CacheListener
        class Listener
        {
           @CacheStarted
           public void callback(NodeMovedEvent nme)
           {
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept a cache listener with a bad method signature");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
        assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
     }
  
     public void testPartlyUnassignableMethodSignature()
     {
        @CacheListener
        class Listener
        {
           @NodeMoved
           @CacheStarted
           public void callback(NodeMovedEvent nme) // sig valid for NodeMoved but not CacheStarted
           {
           }
        }
  
        Listener l = new Listener();
        try
        {
           n.addCacheListener(l);
           fail("Should not accept a cache listener with a bad method signature");
        }
        catch (IncorrectCacheListenerException icle)
        {
           // expected
        }
     }
  
  }
  
  
  
  1.1      date: 2007/06/28 16:53:36;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/notifications/NotificationThreadTest.java
  
  Index: NotificationThreadTest.java
  ===================================================================
  package org.jboss.cache.notifications;
  
  import junit.framework.Assert;
  import org.jboss.cache.Cache;
  import org.jboss.cache.DefaultCacheFactory;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.config.Configuration;
  import org.jboss.cache.loader.AbstractCacheLoaderTestBase;
  import org.jboss.cache.loader.DummyInMemoryCacheLoader;
  import org.jboss.cache.misc.TestingUtil;
  import org.jboss.cache.notifications.annotation.*;
  import org.jboss.cache.notifications.event.Event;
  import org.jboss.cache.transaction.DummyTransactionManagerLookup;
  
  import javax.transaction.TransactionManager;
  import java.util.LinkedList;
  import java.util.List;
  
  /**
   * Tests the threading model used when calling notifications
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   * @since 2.0.0
   */
  public class NotificationThreadTest extends AbstractCacheLoaderTestBase
  {
     private Cache cache1, cache2;
  
     private TestCacheListener listener;
  
     protected void setUp() throws Exception
     {
        // need 2 caches to test viewChange notifications
  
        cache1 = DefaultCacheFactory.getInstance().createCache(false);
        cache2 = DefaultCacheFactory.getInstance().createCache(false);
        cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
        cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
        cache1.getConfiguration().setSyncCommitPhase(true);
        cache2.getConfiguration().setSyncCommitPhase(true);
        cache1.getConfiguration().setSyncRollbackPhase(true);
        cache2.getConfiguration().setSyncRollbackPhase(true);
        cache1.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
        cache2.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
        cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyInMemoryCacheLoader.class.getName(), null, false, false, false));
  
        listener = new TestCacheListener();
        cache1.addCacheListener(listener);
     }
  
     protected void tearDown()
     {
        cache1.stop();
        cache2.stop();
     }
  
     public void testPessimisticWithCacheLoader() throws Throwable
     {
        doTest(false);
     }
  
     public void testOptimisticWithCacheLoader() throws Throwable
     {
        cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        doTest(false);
     }
  
     public void testPessimisticWithPassivation() throws Throwable
     {
        cache1.getConfiguration().getCacheLoaderConfig().setPassivation(true);
        doTest(false);
     }
  
     public void testOptimisticWithPassivation() throws Throwable
     {
        cache1.getConfiguration().getCacheLoaderConfig().setPassivation(true);
        cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        doTest(false);
     }
  
     public void testPessimisticWithCacheLoaderTx() throws Throwable
     {
        doTest(true);
     }
  
     public void testOptimisticWithCacheLoaderTx() throws Throwable
     {
        cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        doTest(true);
     }
  
     public void testPessimisticWithPassivationTx() throws Throwable
     {
        cache1.getConfiguration().getCacheLoaderConfig().setPassivation(true);
        doTest(true);
     }
  
     public void testOptimisticWithPassivationTx() throws Throwable
     {
        cache1.getConfiguration().getCacheLoaderConfig().setPassivation(true);
        cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
        doTest(true);
     }
  
  
     private void doTest(boolean tx) throws Throwable
     {
        // stop and start events
        cache1.stop();
  
        cache1.start();
        cache2.start();
  
        TransactionManager tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
  
        listener.sameThreadExpected = true;
        listener.mainThread = Thread.currentThread();
        Fqn<String> fqn = Fqn.fromString("/a/b/c");
  
        // basic node manipulation events
        if (tx) tm.begin();
        cache1.put(fqn, "k", "v");
        if (tx) tm.commit();
        if (tx) tm.begin();
        cache1.get(fqn, "k");
        if (tx) tm.commit();
        if (tx) tm.begin();
        cache1.put(fqn, "k", "v2");
        if (tx) tm.commit();
        if (tx) tm.begin();
        cache1.removeNode(fqn);
        if (tx) tm.commit();
        if (tx) tm.begin();
        cache1.put(fqn, "k", "v3");
        if (tx) tm.commit();
        if (tx) tm.begin();
        // eviction
        cache1.evict(fqn, true);
        if (tx) tm.commit();
        if (tx) tm.begin();
        // and cache loading or activation
        cache1.get(fqn, "k");
        if (tx) tm.commit();
        if (tx) tm.begin();
        // move event
        cache1.move(fqn, Fqn.ROOT);
        if (tx) tm.commit();
  
        // now a view-change - will be in a different thread
        listener.sameThreadExpected = false;
        cache2.stop();
  
        // short sleep in case some events are in different threads
        TestingUtil.sleepThread(500);
  
        // now test for exceptions
        for (Throwable e : listener.exceptions) throw e;
     }
  }
  
  @CacheListener
  class TestCacheListener
  {
     boolean sameThreadExpected;
     Thread mainThread;
     List<Throwable> exceptions = new LinkedList<Throwable>();
  
     @NodeCreated
     @NodeModified
     @NodeRemoved
     @NodeVisited
     @NodeEvicted
     @NodeLoaded
     @NodeMoved
     @NodeActivated
     @NodePassivated
     @CacheStarted
     @CacheStopped
     @ViewChanged
     @TransactionCompleted
     @TransactionRegistered
     public void testCallbackThread(Event e)
     {
        try
        {
           if (sameThreadExpected)
              Assert.assertSame(mainThread, Thread.currentThread());
           else
              Assert.assertNotSame(mainThread, Thread.currentThread());
        }
        catch (Throwable t)
        {
           exceptions.add(t);
        }
     }
  }
  
  
  
  1.1      date: 2007/06/28 16:53:36;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/notifications/EventLog.java
  
  Index: EventLog.java
  ===================================================================
  package org.jboss.cache.notifications;
  
  import org.jboss.cache.notifications.annotation.CacheListener;
  import org.jboss.cache.notifications.annotation.NodeCreated;
  import org.jboss.cache.notifications.annotation.NodeModified;
  import org.jboss.cache.notifications.annotation.NodeMoved;
  import org.jboss.cache.notifications.annotation.NodeRemoved;
  import org.jboss.cache.notifications.annotation.NodeVisited;
  import org.jboss.cache.notifications.annotation.TransactionCompleted;
  import org.jboss.cache.notifications.annotation.TransactionRegistered;
  import org.jboss.cache.notifications.event.Event;
  import org.jboss.cache.notifications.event.EventImpl;
  
  import java.util.ArrayList;
  import java.util.List;
  
  @CacheListener
  public class EventLog
  {
     public final List<Event> events = new ArrayList<Event>();
  
     @NodeCreated
     @NodeRemoved
     @NodeModified
     @NodeVisited
     @NodeMoved
     @TransactionCompleted
     @TransactionRegistered
     public void callback(Event e)
     {
        events.add(e);
     }
  
     public String toString()
     {
        return "EventLog{" +
                "events=" + events +
                '}';
     }
  
     /**
      * Done when we don't have a Transaction reference to compare with, e.g., when using implicit transactions in
      * opt locking.
      */
     public void scrubImplicitTransactions()
     {
        for (Event e : events) ((EventImpl) e).setTransaction(null);
     }
  }
  
  



More information about the jboss-cvs-commits mailing list