I've made a few changes to the ReplListener helper class that lives in
the test harness. The ReplListener can now be constructed to eagerly
listen for commands, and reconciliate these with expectations set in
expect() so that commands seen between construction of the listener
and calling expect() are also recorded and noted.
Enjoy!
Manik
Begin forwarded message:
From: infinispan-commits(a)lists.jboss.org
Date: 22 April 2009 10:51:08 BST
To: infinispan-commits(a)lists.jboss.org
Subject: [infinispan-commits] Infinispan SVN: r158 - trunk/core/src/
test/java/org/infinispan/test.
Reply-To: infinispan-commits(a)lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-04-22 05:51:08 -0400 (Wed, 22 Apr 2009)
New Revision: 158
Modified:
trunk/core/src/test/java/org/infinispan/test/ReplListener.java
Log:
Ability to eagerly record commands
Modified: trunk/core/src/test/java/org/infinispan/test/
ReplListener.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/ReplListener.java
2009-04-21 13:37:17 UTC (rev 157)
+++ trunk/core/src/test/java/org/infinispan/test/ReplListener.java
2009-04-22 09:51:08 UTC (rev 158)
@@ -19,12 +19,37 @@
* attachReplicationListener(cache);
r.expect(RemoveCommand.class); // ... r.waitForRPC(); </code>
*/
public class ReplListener {
- Cache c;
- Set<Class<? extends VisitableCommand>> expectedCommands;
+ Cache<?, ?> c;
+ volatile Set<Class<? extends VisitableCommand>> expectedCommands;
+ Set<Class<? extends VisitableCommand>> eagerCommands;
+ boolean recordCommandsEagerly;
CountDownLatch latch = new CountDownLatch(1);
- public ReplListener(Cache c) {
+ /**
+ * This listener atatches itself to a cache and when {@link
#expect(Class[])} is invoked, will start checking for
+ * invocations of the command on the cache, waiting for all
expected commands to be received in {@link
+ * #waitForRpc()}.
+ *
+ * @param c cache on which to attach listener
+ */
+ public ReplListener(Cache<?, ?> c) {
+ this(c, false);
+ }
+
+ /**
+ * As {@link #ReplListener(org.infinispan.Cache)} except that
you can optionally configure whether command recording
+ * is eager (false by default).
+ * <p/>
+ * If <tt>recordCommandsEagerly</tt> is true, then commands are
recorded from the moment the listener is attached to
+ * the cache, even before {@link #expect(Class[])} is invoked.
As such, when {@link #expect(Class[])} is called, the
+ * list of commands to wait for will take into account commands
already seen thanks to eager recording.
+ *
+ * @param c cache on which to attach listener
+ * @param recordCommandsEagerly whether to record commands eagerly
+ */
+ public ReplListener(Cache<?, ?> c, boolean
recordCommandsEagerly) {
this.c = c;
+ this.recordCommandsEagerly = recordCommandsEagerly;
this.c.getAdvancedCache().addInterceptor(new
ReplListenerInterceptor(), 1);
}
@@ -70,6 +95,8 @@
this.expectedCommands = new HashSet<Class<? extends
VisitableCommand>>();
}
this.expectedCommands.addAll(Arrays.asList(expectedCommands));
+
+ if (recordCommandsEagerly)
this.expectedCommands.removeAll(eagerCommands);
}
/**
@@ -99,6 +126,10 @@
}
}
+ public Cache<?, ?> getCache() {
+ return c;
+ }
+
protected class ReplListenerInterceptor extends
CommandInterceptor {
@Override
protected Object handleDefault(InvocationContext ctx,
VisitableCommand cmd) throws Throwable {
@@ -124,7 +155,11 @@
expectedCommands.remove(cmd.getClass());
if (expectedCommands.isEmpty()) latch.countDown();
} else {
- System.out.println("Received unexpected command: " +
cmd);
+ if (recordCommandsEagerly) {
+ eagerCommands.add(cmd.getClass());
+ } else {
+ System.out.println("Received unexpected command: " +
cmd);
+ }
}
}
}
_______________________________________________
infinispan-commits mailing list
infinispan-commits(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-commits