[infinispan-commits] Infinispan SVN: r299 - in trunk/core/src/test/java/org/infinispan: test and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu May 14 10:19:20 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-05-14 10:19:19 -0400 (Thu, 14 May 2009)
New Revision: 299

Added:
   trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java
Modified:
   trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java
   trunk/core/src/test/java/org/infinispan/test/ReplListener.java
Log:
improved repl listener, added tests for async api

Added: trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java	2009-05-14 14:19:19 UTC (rev 299)
@@ -0,0 +1,49 @@
+package org.infinispan.replication;
+
+import org.infinispan.commands.write.WriteCommand;
+import org.infinispan.test.ReplListener;
+import org.testng.annotations.Test;
+
+ at Test(groups = "functional", testName = "replication.AsyncAPIAsyncReplTest")
+public class AsyncAPIAsyncReplTest extends AsyncAPISyncReplTest {
+
+   ReplListener rl;
+
+   public AsyncAPIAsyncReplTest() {
+      cleanup = CleanupPhase.AFTER_METHOD;
+   }
+
+   @Override
+   protected void createCacheManagers() throws Throwable {
+      super.createCacheManagers();
+      rl = new ReplListener(c2, true);
+   }
+
+   @Override
+   protected boolean sync() {
+      return false;
+   }
+
+   @Override
+   protected void resetListeners() {
+      rl.resetEager();
+   }
+
+   @Override
+   protected void asyncWait(boolean tx, Class<? extends WriteCommand>... cmds) {
+      if (tx) {
+         if (cmds == null || cmds.length == 0)
+            rl.expectAnyWithTx();
+         else
+            rl.expectWithTx(cmds);
+      } else {
+         if (cmds == null || cmds.length == 0)
+            rl.expectAny();
+         else
+            rl.expect(cmds);
+      }
+
+
+      rl.waitForRpc();
+   }
+}
\ No newline at end of file


Property changes on: trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java	2009-05-14 13:36:58 UTC (rev 298)
+++ trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java	2009-05-14 14:19:19 UTC (rev 299)
@@ -1,6 +1,8 @@
 package org.infinispan.replication;
 
 import org.infinispan.Cache;
+import org.infinispan.commands.write.PutKeyValueCommand;
+import org.infinispan.commands.write.WriteCommand;
 import org.infinispan.config.Configuration;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.TestingUtil;
@@ -38,9 +40,12 @@
       return true;
    }
 
-   protected void asyncWait() {
+   protected void asyncWait(boolean tx, Class<? extends WriteCommand>... cms) {
    }
 
+   protected void resetListeners() {
+   }
+
    private void assertOnAllCaches(Key k, String v) {
       Object real;
       assert Util.safeEquals((real = c1.get(k)), v) : "Error on cache 1.  Expected " + v + " and got " + real;
@@ -148,8 +153,9 @@
       assertOnAllCaches(key, null);
 
       key.allowSerialization();
+      resetListeners();
       c1.put(key, v);
-      asyncWait();
+      asyncWait(false, PutKeyValueCommand.class);
 
       f = c1.replaceAsync(key, v5);
       assert f != null;
@@ -200,7 +206,7 @@
       assert c2.get(key) == null;
       assert f.get() == null;
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, v);
 
       tm.begin();
@@ -211,7 +217,7 @@
       assert !f.isCancelled();
       assert f.get().equals(v);
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, v2);
 
       // putAll
@@ -223,7 +229,7 @@
       assert !f2.isCancelled();
       assert f2.get() == null;
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, v3);
 
       // putIfAbsent
@@ -235,7 +241,6 @@
       assert !f.isCancelled();
       assert f.get().equals(v3);
       tm.commit();
-      asyncWait();
       assertOnAllCaches(key, v3);
 
       // remove
@@ -247,7 +252,7 @@
       assert !f.isCancelled();
       assert f.get().equals(v3);
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, null);
 
       // putIfAbsent again
@@ -259,7 +264,7 @@
       assert !f.isCancelled();
       assert f.get() == null;
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, v4);
 
       // removecond
@@ -270,7 +275,6 @@
       assert f3.get().equals(false);
       assert f3.isDone();
       tm.commit();
-      asyncWait();
       assertOnAllCaches(key, v4);
 
       tm.begin();
@@ -281,7 +285,7 @@
       assert !f3.isCancelled();
       assert f3.get().equals(true);
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, null);
 
       // replace
@@ -292,10 +296,10 @@
       assert f.get() == null;
       assert f.isDone();
       tm.commit();
-      asyncWait();
       assertOnAllCaches(key, null);
 
       c1.put(key, v);
+      asyncWait(false);
 
       tm.begin();
       f = c1.replaceAsync(key, v5);
@@ -305,7 +309,7 @@
       assert !f.isCancelled();
       assert f.get().equals(v);
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, v5);
 
       //replace2
@@ -316,7 +320,6 @@
       assert f3.get().equals(false);
       assert f3.isDone();
       tm.commit();
-      asyncWait();
       assertOnAllCaches(key, v5);
 
       tm.begin();
@@ -327,7 +330,7 @@
       assert !f3.isCancelled();
       assert f3.get().equals(true);
       tm.commit();
-      asyncWait();
+      asyncWait(true);
       assertOnAllCaches(key, v6);
    }
 

Modified: trunk/core/src/test/java/org/infinispan/test/ReplListener.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/ReplListener.java	2009-05-14 13:36:58 UTC (rev 298)
+++ trunk/core/src/test/java/org/infinispan/test/ReplListener.java	2009-05-14 14:19:19 UTC (rev 299)
@@ -8,7 +8,10 @@
 import org.infinispan.context.InvocationContext;
 import org.infinispan.context.impl.TxInvocationContext;
 import org.infinispan.interceptors.base.CommandInterceptor;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
@@ -31,6 +34,7 @@
    CountDownLatch latch = new CountDownLatch(1);
    volatile boolean sawAtLeastOneInvocation = false;
    boolean expectAny = false;
+   private Log log = LogFactory.getLog(ReplListener.class);
 
    /**
     * This listener atatches itself to a cache and when {@link #expect(Class[])} is invoked, will start checking for
@@ -89,21 +93,29 @@
     * @param commands commands to expect (not counting transaction boundary commands like PrepareCommand and
     *                 CommitCommand)
     */
+   @SuppressWarnings("unchecked")
    public void expectWithTx(Class<? extends VisitableCommand>... commands) {
-      expect(PrepareCommand.class);
-      expect(commands);
+      List<Class<? extends VisitableCommand>> cmdsToExpect = new ArrayList<Class<? extends VisitableCommand>>();
+      cmdsToExpect.add(PrepareCommand.class);
+      if (commands != null) cmdsToExpect.addAll(Arrays.asList(commands));
       //this is because for async replication we have an 1pc transaction
-      if (c.getConfiguration().getCacheMode().isSynchronous()) expect(CommitCommand.class);
+      if (c.getConfiguration().getCacheMode().isSynchronous()) cmdsToExpect.add(CommitCommand.class);
+
+      expect(cmdsToExpect.toArray(new Class[cmdsToExpect.size()]));
    }
 
    /**
     * Expects any commands, within transactional scope (i.e., as a payload to a PrepareCommand).  If the cache mode is
     * synchronous, a CommitCommand is expected as well.
     */
+   @SuppressWarnings("unchecked")
    public void expectAnyWithTx() {
-      expect(PrepareCommand.class);
+      List<Class<? extends VisitableCommand>> cmdsToExpect = new ArrayList<Class<? extends VisitableCommand>>(2);
+      cmdsToExpect.add(PrepareCommand.class);
       //this is because for async replication we have an 1pc transaction
-      if (c.getConfiguration().getCacheMode().isSynchronous()) expect(CommitCommand.class);
+      if (c.getConfiguration().getCacheMode().isSynchronous()) cmdsToExpect.add(CommitCommand.class);
+
+      expect(cmdsToExpect.toArray(new Class[cmdsToExpect.size()]));
    }
 
    /**
@@ -118,7 +130,8 @@
             this.expectedCommands = new LinkedList<Class<? extends VisitableCommand>>();
          }
          this.expectedCommands.addAll(Arrays.asList(expectedCommands));
-
+         log.trace("Setting expected commands to {0}", this.expectedCommands);
+         log.trace("Record eagerly is {0}, and eager commands are {1}", recordCommandsEagerly, eagerCommands);
          if (recordCommandsEagerly) {
             this.expectedCommands.removeAll(eagerCommands);
             if (!eagerCommands.isEmpty()) sawAtLeastOneInvocation = true;
@@ -143,6 +156,7 @@
    public void waitForRpc(long time, TimeUnit unit) {
       assert expectedCommands != null : "there are no replication expectations; please use ReplListener.expect() before calling this method";
       try {
+         log.trace("Expect Any is {0}, saw at least one? {1} Expected {2}", expectAny, sawAtLeastOneInvocation, expectedCommands);
          boolean successful = (expectAny && sawAtLeastOneInvocation) || (!expectAny && expectedCommands.isEmpty());
          if (!successful && !latch.await(time, unit)) {
             assert false : "Waiting for more than " + time + " " + unit + " and following commands did not replicate: " + expectedCommands + " on cache [" + c.getCacheManager().getAddress() + "]";
@@ -156,6 +170,7 @@
          expectAny = false;
          sawAtLeastOneInvocation = false;
          latch = new CountDownLatch(1);
+         eagerCommands.clear();
       }
    }
 
@@ -163,6 +178,10 @@
       return c;
    }
 
+   public void resetEager() {
+      eagerCommands.clear();
+   }
+
    protected class ReplListenerInterceptor extends CommandInterceptor {
       @Override
       protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable {




More information about the infinispan-commits mailing list