<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I've made a few changes to the ReplListener helper class that lives in the test harness. &nbsp;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.<div><br></div><div>Enjoy!</div><div>Manik<br><div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>From: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:infinispan-commits@lists.jboss.org">infinispan-commits@lists.jboss.org</a></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Date: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">22 April 2009 10:51:08 BST</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:infinispan-commits@lists.jboss.org">infinispan-commits@lists.jboss.org</a></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Subject: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><b>[infinispan-commits] Infinispan SVN: r158 - trunk/core/src/test/java/org/infinispan/test.</b></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Reply-To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:infinispan-commits@lists.jboss.org">infinispan-commits@lists.jboss.org</a></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div> </div><div>Author: <a href="mailto:manik.surtani@jboss.com">manik.surtani@jboss.com</a><br>Date: 2009-04-22 05:51:08 -0400 (Wed, 22 Apr 2009)<br>New Revision: 158<br><br>Modified:<br> &nbsp;&nbsp;trunk/core/src/test/java/org/infinispan/test/ReplListener.java<br>Log:<br>Ability to eagerly record commands<br><br>Modified: trunk/core/src/test/java/org/infinispan/test/ReplListener.java<br>===================================================================<br>--- trunk/core/src/test/java/org/infinispan/test/ReplListener.java<span class="Apple-tab-span" style="white-space:pre">        </span>2009-04-21 13:37:17 UTC (rev 157)<br>+++ trunk/core/src/test/java/org/infinispan/test/ReplListener.java<span class="Apple-tab-span" style="white-space:pre">        </span>2009-04-22 09:51:08 UTC (rev 158)<br>@@ -19,12 +19,37 @@<br> &nbsp;* attachReplicationListener(cache); r.expect(RemoveCommand.class); // ... r.waitForRPC(); &lt;/code><br> &nbsp;*/<br> public class ReplListener {<br>- &nbsp;&nbsp;Cache c;<br>- &nbsp;&nbsp;Set&lt;Class&lt;? extends VisitableCommand>> expectedCommands;<br>+ &nbsp;&nbsp;Cache&lt;?, ?> c;<br>+ &nbsp;&nbsp;volatile Set&lt;Class&lt;? extends VisitableCommand>> expectedCommands;<br>+ &nbsp;&nbsp;Set&lt;Class&lt;? extends VisitableCommand>> eagerCommands;<br>+ &nbsp;&nbsp;boolean recordCommandsEagerly;<br> &nbsp;&nbsp;&nbsp;CountDownLatch latch = new CountDownLatch(1);<br><br>- &nbsp;&nbsp;public ReplListener(Cache c) {<br>+ &nbsp;&nbsp;/**<br>+ &nbsp;&nbsp;&nbsp;* This listener atatches itself to a cache and when {@link #expect(Class[])} is invoked, will start checking for<br>+ &nbsp;&nbsp;&nbsp;* invocations of the command on the cache, waiting for all expected commands to be received in {@link<br>+ &nbsp;&nbsp;&nbsp;* #waitForRpc()}.<br>+ &nbsp;&nbsp;&nbsp;*<br>+ &nbsp;&nbsp;&nbsp;* @param c cache on which to attach listener<br>+ &nbsp;&nbsp;&nbsp;*/<br>+ &nbsp;&nbsp;public ReplListener(Cache&lt;?, ?> c) {<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this(c, false);<br>+ &nbsp;&nbsp;}<br>+<br>+ &nbsp;&nbsp;/**<br>+ &nbsp;&nbsp;&nbsp;* As {@link #ReplListener(org.infinispan.Cache)} except that you can optionally configure whether command recording<br>+ &nbsp;&nbsp;&nbsp;* is eager (false by default).<br>+ &nbsp;&nbsp;&nbsp;* &lt;p/><br>+ &nbsp;&nbsp;&nbsp;* If &lt;tt>recordCommandsEagerly&lt;/tt> is true, then commands are recorded from the moment the listener is attached to<br>+ &nbsp;&nbsp;&nbsp;* the cache, even before {@link #expect(Class[])} is invoked. &nbsp;As such, when {@link #expect(Class[])} is called, the<br>+ &nbsp;&nbsp;&nbsp;* list of commands to wait for will take into account commands already seen thanks to eager recording.<br>+ &nbsp;&nbsp;&nbsp;*<br>+ &nbsp;&nbsp;&nbsp;* @param c &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cache on which to attach listener<br>+ &nbsp;&nbsp;&nbsp;* @param recordCommandsEagerly whether to record commands eagerly<br>+ &nbsp;&nbsp;&nbsp;*/<br>+ &nbsp;&nbsp;public ReplListener(Cache&lt;?, ?> c, boolean recordCommandsEagerly) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.c = c;<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.recordCommandsEagerly = recordCommandsEagerly;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.c.getAdvancedCache().addInterceptor(new ReplListenerInterceptor(), 1);<br> &nbsp;&nbsp;&nbsp;}<br><br>@@ -70,6 +95,8 @@<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.expectedCommands = new HashSet&lt;Class&lt;? extends VisitableCommand>>();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.expectedCommands.addAll(Arrays.asList(expectedCommands));<br>+<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (recordCommandsEagerly) this.expectedCommands.removeAll(eagerCommands);<br> &nbsp;&nbsp;&nbsp;}<br><br> &nbsp;&nbsp;&nbsp;/**<br>@@ -99,6 +126,10 @@<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;}<br><br>+ &nbsp;&nbsp;public Cache&lt;?, ?> getCache() {<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return c;<br>+ &nbsp;&nbsp;}<br>+<br> &nbsp;&nbsp;&nbsp;protected class ReplListenerInterceptor extends CommandInterceptor {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable {<br>@@ -124,7 +155,11 @@<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expectedCommands.remove(cmd.getClass());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (expectedCommands.isEmpty()) latch.countDown();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Received unexpected command: " + cmd);<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (recordCommandsEagerly) {<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eagerCommands.add(cmd.getClass());<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Received unexpected command: " + cmd);<br>+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;}<br><br>_______________________________________________<br>infinispan-commits mailing list<br><a href="mailto:infinispan-commits@lists.jboss.org">infinispan-commits@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/infinispan-commits<br></div></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Manik Surtani</div><div><a href="mailto:manik@jboss.org">manik@jboss.org</a></div><div>Lead, Infinispan</div><div>Lead, JBoss Cache</div><div><a href="http://www.infinispan.org">http://www.infinispan.org</a></div><div><a href="http://www.jbosscache.org">http://www.jbosscache.org</a></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br></div></body></html>