[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/notifications ...
Manik Surtani
manik at jboss.org
Thu Jun 14 11:19:24 EDT 2007
User: msurtani
Date: 07/06/14 11:19:24
Modified: tests/functional/org/jboss/cache/notifications
CacheListenerTest.java RemoteCacheListenerTest.java
Log:
JBCACHE-1107 and JBCACHE-1109
Revision Changes Path
1.18 +17 -14 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.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- CacheListenerTest.java 7 Feb 2007 22:06:51 -0000 1.17
+++ CacheListenerTest.java 14 Jun 2007 15:19:24 -0000 1.18
@@ -16,6 +16,7 @@
import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.misc.TestingUtil;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -35,6 +36,7 @@
{
protected boolean optLocking = false;
+ private static final long eventSleepTime = 250; // 250ms should be more than enough
public CacheListenerTest(String s)
{
@@ -85,6 +87,8 @@
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);
+
assertEquals(expected, eventLog.events);
assertEquals("value", cache.get(fqn, "key"));
}
@@ -97,6 +101,7 @@
oldData.put("key", "value");
// clear CacheListenerEvent log
+ TestingUtil.sleepThread(eventSleepTime);
eventLog.events.clear();
assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
@@ -109,7 +114,7 @@
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);
assertEquals(expected.size(), eventLog.events.size());
assertEquals(expected, eventLog.events);
}
@@ -125,6 +130,7 @@
assertEquals("value", cache.get(fqn, "key"));
// clear CacheListenerEvent log
+ TestingUtil.sleepThread(eventSleepTime);
eventLog.events.clear();
assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
@@ -135,7 +141,7 @@
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);
// test that the node has in fact been removed.
@@ -153,6 +159,7 @@
oldData.put("key2", "value2");
// clear CacheListenerEvent log
+ TestingUtil.sleepThread(eventSleepTime);
eventLog.events.clear();
assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
@@ -165,7 +172,7 @@
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);
assertEquals(expected, eventLog.events);
}
@@ -177,6 +184,7 @@
oldData.put("key2", "value2");
// clear CacheListenerEvent log
+ TestingUtil.sleepThread(eventSleepTime);
eventLog.events.clear();
assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
@@ -189,7 +197,7 @@
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);
assertEquals(expected, eventLog.events);
}
@@ -202,7 +210,7 @@
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);
@@ -212,16 +220,12 @@
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);
}
// -- now the transactional ones
- /*
-
- // TODO: Reinstate these once we have a proper plan for dealing with transactions and notifications.
-
public void testTxCreationCommit() throws Exception
{
assertEquals("CacheListenerEvent log should be empty", Collections.emptyList(), eventLog.events);
@@ -306,7 +310,7 @@
assertEquals(expected, eventLog.events);
// test that the node has in fact been removed.
- assertNull("Should be null", cache.getChild(fqn));
+ assertNull("Should be null", cache.getRoot().getChild(fqn));
}
@@ -341,7 +345,6 @@
{
fail("implement me");
}
- */
// ============= supporting classes and enums =======================
1.15 +17 -101 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.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- RemoteCacheListenerTest.java 7 Feb 2007 22:06:51 -0000 1.14
+++ RemoteCacheListenerTest.java 14 Jun 2007 15:19:24 -0000 1.15
@@ -30,6 +30,7 @@
import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.misc.TestingUtil;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
@@ -41,7 +42,6 @@
/**
* Remote conterpart of CacheListenerTest. Main difference is event is originating as local.
*
- * @author Ben Wang
* @since 2.0.0
*/
public class RemoteCacheListenerTest extends TestCase
@@ -52,6 +52,7 @@
private Cache cache1, cache2;
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
{
@@ -141,7 +142,7 @@
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"));
@@ -160,6 +161,7 @@
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);
@@ -179,7 +181,7 @@
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);
}
@@ -196,6 +198,7 @@
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);
@@ -213,7 +216,7 @@
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);
@@ -232,6 +235,7 @@
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,7 +255,7 @@
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);
}
@@ -267,6 +271,7 @@
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);
@@ -287,7 +292,7 @@
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);
}
@@ -302,6 +307,7 @@
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);
@@ -319,136 +325,46 @@
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);
}
// -- now the transactional ones
- /*
- // TODO: Reinstate these once we have a proper plan for dealing with transactions and notifications.
-
public void testTxCreationCommit() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
- tm.begin();
- cache1.put(fqn, "key", "value");
-// assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
- tm.commit();
-
- Map data = new HashMap();
- data.put("key", "value");
-
- //expected
- List<CacheListenerEvent> expected = new ArrayList<CacheListenerEvent>();
- expected.add(new CacheListenerEvent(RemoteCacheListenerTest.ListenerMethod.NODE_CREATED, fqn, true, false, null));
- expected.add(new CacheListenerEvent(RemoteCacheListenerTest.ListenerMethod.NODE_CREATED, fqn, false, false, null));
- expected.add(new CacheListenerEvent(RemoteCacheListenerTest.ListenerMethod.NODE_MODIFIED, fqn, true, false, Collections.emptyMap()));
- expected.add(new CacheListenerEvent(RemoteCacheListenerTest.ListenerMethod.NODE_MODIFIED, fqn, false, false, data));
-
- assertEquals(expected, eventLog2.events);
- assertEquals("value", cache1.get(fqn, "key"));
+ fail("implement me");
}
public void testTxCreationRollback() throws Exception
{
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
- tm.begin();
- cache1.put(fqn, "key", "value");
- assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
- tm.rollback();
- assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
+ fail("implement me");
}
public void testTxOnlyModification() throws Exception
{
fail("implement me");
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
- cache1.put(fqn, "key", "value");
- Map oldData = new HashMap();
- oldData.put("key", "value");
-
- // clear event log
- eventLog2.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
-
- // modify existing node
- cache1.put(fqn, "key", "value2");
- Map newData = new HashMap();
- 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));
-
- assertEquals(expected, eventLog2.events);
}
public void testTxOnlyRemoval() throws Exception
{
fail("implement me");
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
- cache1.put(fqn, "key", "value");
- Map oldData = new HashMap();
- oldData.put("key", "value");
-
- assertEquals("value", cache1.get(fqn, "key"));
-
- // clear event log
- eventLog2.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
-
- // modify existing node
- cache1.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));
-
- assertEquals(expected, eventLog2.events);
-
- // test that the node has in fact been removed.
- assertNull("Should be null", cache1.getChild(fqn));
}
public void testTxRemoveData() throws Exception
{
fail("implement me");
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
- cache1.put(fqn, "key", "value");
- cache1.put(fqn, "key2", "value2");
- Map oldData = new HashMap();
- oldData.put("key", "value");
- oldData.put("key2", "value2");
- // clear event log
- eventLog2.events.clear();
- assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
-
- // modify existing node
- cache1.remove(fqn, "key2");
- Map newData = new HashMap();
- 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));
-
- assertEquals(expected, eventLog2.events);
}
public void testTxMove()
{
fail("implement me");
}
- */
// ============= supporting classes and enums =======================
More information about the jboss-cvs-commits
mailing list