[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/notifications ...
Manik Surtani
msurtani at jboss.com
Wed Jan 3 10:33:09 EST 2007
User: msurtani
Date: 07/01/03 10:33:09
Modified: tests/functional/org/jboss/cache/notifications
CacheListenerOptimisticTest.java
CacheListenerTest.java
Added: tests/functional/org/jboss/cache/notifications
CacheListenerEvent.java
Log:
Improved notification mechanism, added a notification interceptor
Revision Changes Path
1.2 +5 -6 JBossCache/tests/functional/org/jboss/cache/notifications/CacheListenerOptimisticTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheListenerOptimisticTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/notifications/CacheListenerOptimisticTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CacheListenerOptimisticTest.java 15 Aug 2006 21:02:23 -0000 1.1
+++ CacheListenerOptimisticTest.java 3 Jan 2007 15:33:09 -0000 1.2
@@ -8,7 +8,6 @@
public class CacheListenerOptimisticTest extends CacheListenerTest
{
-
public CacheListenerOptimisticTest(String s)
{
super(s);
1.14 +69 -135 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.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- CacheListenerTest.java 2 Jan 2007 18:26:05 -0000 1.13
+++ CacheListenerTest.java 3 Jan 2007 15:33:09 -0000 1.14
@@ -73,17 +73,17 @@
public void testCreation() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
cache.put(fqn, "key", "value");
Map data = new HashMap();
data.put("key", "value");
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_CREATED, fqn, true, true, null));
- expected.add(new Event(ListenerMethod.NODE_CREATED, fqn, false, true, null));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, data));
+ 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));
assertEquals(expected, eventLog.events);
assertEquals("value", cache.get(fqn, "key"));
@@ -91,14 +91,14 @@
public void testOnlyModification() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
cache.put(fqn, "key", "value");
Map oldData = new HashMap();
oldData.put("key", "value");
- // clear event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.put(fqn, "key", "value2");
@@ -106,9 +106,9 @@
newData.put("key", "value2");
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
+ 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));
assertEquals(expected.size(), eventLog.events.size());
assertEquals(expected, eventLog.events);
@@ -117,24 +117,24 @@
public void testOnlyRemoval() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent 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 event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.removeNode(fqn);
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_REMOVED, fqn, true, true, oldData));
- expected.add(new Event(ListenerMethod.NODE_REMOVED, fqn, false, true, null));
+ 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));
assertEquals(expected, eventLog.events);
@@ -145,16 +145,16 @@
public void testRemoveData() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent 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 event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.remove(fqn, "key2");
@@ -162,40 +162,40 @@
newData.put("key", "value");
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
+ 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));
assertEquals(expected, eventLog.events);
}
public void testPutMap() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
Map oldData = new HashMap();
oldData.put("key", "value");
oldData.put("key2", "value2");
- // clear event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.put(fqn, oldData);
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_CREATED, fqn, true, true, null));
- expected.add(new Event(ListenerMethod.NODE_CREATED, fqn, false, true, null));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, oldData));
+ 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));
assertEquals(expected, eventLog.events);
}
public void testMove()
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
Fqn newParent = Fqn.fromString("/a");
cache.put(fqn, "key", "value");
cache.put(newParent, "key", "value");
@@ -204,16 +204,14 @@
Node n2 = cache.getRoot().getChild(newParent);
eventLog.events.clear(); // clear events
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
cache.move(n1.getFqn(), n2.getFqn());
//expected
Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, false, null));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, newFqn, true, false, null));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, false, null));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, newFqn, false, false, null));
+ 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));
assertEquals(expected, eventLog.events);
}
@@ -226,7 +224,7 @@
public void testTxCreationCommit() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
tm.begin();
cache.put(fqn, "key", "value");
assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
@@ -236,11 +234,11 @@
data.put("key", "value");
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_CREATED, fqn, true, true, null));
- expected.add(new Event(ListenerMethod.NODE_CREATED, fqn, false, true, null));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, Collections.emptyMap()));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, data));
+ 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));
assertEquals(expected, eventLog.events);
assertEquals("value", cache.get(fqn, "key"));
@@ -248,7 +246,7 @@
public void testTxCreationRollback() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
tm.begin();
cache.put(fqn, "key", "value");
assertEquals("Events log should be empty until commit time", 0, eventLog.events.size());
@@ -260,14 +258,14 @@
public void testTxOnlyModification() throws Exception
{
fail("implement me");
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
cache.put(fqn, "key", "value");
Map oldData = new HashMap();
oldData.put("key", "value");
- // clear event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.put(fqn, "key", "value2");
@@ -275,9 +273,9 @@
newData.put("key", "value2");
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
+ 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));
assertEquals(expected, eventLog.events);
}
@@ -286,24 +284,24 @@
public void testTxOnlyRemoval() throws Exception
{
fail("implement me");
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent 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 event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.removeNode(fqn);
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_REMOVED, fqn, true, true, oldData));
- expected.add(new Event(ListenerMethod.NODE_REMOVED, fqn, false, true, null));
+ 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));
assertEquals(expected, eventLog.events);
@@ -315,16 +313,16 @@
public void testTxRemoveData() throws Exception
{
fail("implement me");
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent 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 event log
+ // clear CacheListenerEvent log
eventLog.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
// modify existing node
cache.remove(fqn, "key2");
@@ -332,9 +330,9 @@
newData.put("key", "value");
//expected
- List<Event> expected = new ArrayList<Event>();
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, true, true, oldData));
- expected.add(new Event(ListenerMethod.NODE_MODIFIED, fqn, false, true, newData));
+ 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));
assertEquals(expected, eventLog.events);
}
@@ -350,37 +348,35 @@
public static class EventLog extends AbstractCacheListener
{
- public final List<Event> events = new ArrayList<Event>();
+ public final List<CacheListenerEvent> events = new ArrayList<CacheListenerEvent>();
public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
{
- Event e = new Event(ListenerMethod.NODE_CREATED, fqn, pre, isLocal, null);
+ 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)
{
- Event e = new Event(ListenerMethod.NODE_REMOVED, fqn, pre, isLocal, 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, Map data)
{
- Event e = new Event(ListenerMethod.NODE_MODIFIED, fqn, pre, isLocal, data);
+ CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MODIFIED, fqn, pre, isLocal, data);
events.add(e);
}
public void nodeVisited(Fqn fqn, boolean pre)
{
- Event e = new Event(ListenerMethod.NODE_VISITED, fqn, pre, false, null);
+ CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_VISITED, fqn, pre, false, null);
events.add(e);
}
- public void nodeMoved(Fqn from, Fqn to, boolean pre)
+ public void nodeMoved(Fqn from, Fqn to, boolean pre, boolean isLocal)
{
- Event e = new Event(ListenerMethod.NODE_MOVED, from, pre, false, null);
- events.add(e);
- e = new Event(ListenerMethod.NODE_MOVED, to, pre, false, null);
+ CacheListenerEvent e = new CacheListenerEvent(CacheListenerEvent.ListenerMethod.NODE_MOVED, from, to, pre, isLocal);
events.add(e);
}
@@ -392,66 +388,4 @@
'}';
}
}
-
-
- public static class Event
- {
- ListenerMethod methodName;
- Fqn fqn;
- boolean pre;
- boolean local;
- Map data;
-
- public Event(ListenerMethod methodName, Fqn fqn, boolean pre, boolean local, Map data)
- {
- this.methodName = methodName;
- this.fqn = fqn;
- this.pre = pre;
- this.local = local;
- this.data = data;
- }
-
- public String toString()
- {
- return "Event{" +
- "methodName=" + methodName +
- ", fqn=" + fqn +
- ", pre=" + pre +
- ", local=" + local +
- ", data=" + data +
- '}';
- }
-
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- final Event event = (Event) o;
-
- if (local != event.local) return false;
- if (pre != event.pre) return false;
- if (data != null ? !data.equals(event.data) : event.data != null) return false;
- if (fqn != null ? !fqn.equals(event.fqn) : event.fqn != null) return false;
- if (methodName != event.methodName) return false;
-
- return true;
- }
-
- public int hashCode()
- {
- int result;
- result = (methodName != null ? methodName.hashCode() : 0);
- result = 29 * result + (fqn != null ? fqn.hashCode() : 0);
- result = 29 * result + (pre ? 1 : 0);
- result = 29 * result + (local ? 1 : 0);
- result = 29 * result + (data != null ? data.hashCode() : 0);
- return result;
- }
- }
-
- public enum ListenerMethod
- {
- NODE_CREATED, NODE_REMOVED, NODE_VISITED, NODE_MODIFIED, NODE_MOVED
- }
}
1.1 date: 2007/01/03 15:33:09; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/notifications/CacheListenerEvent.java
Index: CacheListenerEvent.java
===================================================================
package org.jboss.cache.notifications;
import java.util.Arrays;
/**
* Internal class that encapsulates a cache listener event
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class CacheListenerEvent
{
public enum ListenerMethod
{
NODE_CREATED, NODE_MODIFIED, NODE_REMOVED, NODE_VISITED, NODE_EVICTED, NODE_LOADED, NODE_MOVED, NODE_ACTIVATED,
NODE_PASSIVATED, CACHE_STARTED, CACHE_STOPPED, VIEW_CHANGE
}
private ListenerMethod methodName;
private Object[] args;
public CacheListenerEvent(ListenerMethod methodName, Object... args)
{
this.methodName = methodName;
this.args = args;
}
public Object[] getArgs()
{
return args;
}
public String toString()
{
StringBuilder b = new StringBuilder("CacheListenerEvent methodName=");
b.append(methodName);
b.append(" {");
for (Object o : args)
{
b.append(o);
b.append(", ");
}
b.append("}");
return b.toString();
}
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CacheListenerEvent event = (CacheListenerEvent) o;
// Probably incorrect - comparing Object[] arrays with Arrays.equals
if (!Arrays.equals(args, event.args)) return false;
if (methodName != event.methodName) return false;
return true;
}
public int hashCode()
{
int result;
result = (methodName != null ? methodName.hashCode() : 0);
result = 31 * result + (args != null ? Arrays.hashCode(args) : 0);
return result;
}
}
More information about the jboss-cvs-commits
mailing list