[jbosscache-commits] JBoss Cache SVN: r7719 - in core/branches/flat/src/test/java/org/horizon: invalidation and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Feb 18 04:26:51 EST 2009


Author: mircea.markus
Date: 2009-02-18 04:26:50 -0500 (Wed, 18 Feb 2009)
New Revision: 7719

Modified:
   core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java
   core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
   core/branches/flat/src/test/java/org/horizon/test/ReplListener.java
Log:
more strict replication controll

Modified: core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java	2009-02-17 19:55:45 UTC (rev 7718)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java	2009-02-18 09:26:50 UTC (rev 7719)
@@ -315,7 +315,7 @@
 
       Thread[] movers = new Thread[N];
       final CountDownLatch latch = new CountDownLatch(1);
-      final Random r = new Random();
+      final Random rnd = new Random();
 
       for (int i = 0; i < N; i++) {
          movers[i] = new Thread("Mover-" + i) {
@@ -328,16 +328,15 @@
 
                for (int counter = 0; counter < loops; counter++) {
 
-                  System.out.println(getName() + ": Attempt " + counter);
                   try {
-                     treeCache.move(NODE_X.getFqn(), NODES[r.nextInt(NODES.length)].getFqn());
+                     treeCache.move(NODE_X.getFqn(), NODES[rnd.nextInt(NODES.length)].getFqn());
                   }
                   catch (NodeNotExistsException e) {
                      // this may happen ...
                   }
                   TestingUtil.sleepRandom(250);
                   try {
-                     treeCache.move(NODE_Y.getFqn(), NODES[r.nextInt(NODES.length)].getFqn());
+                     treeCache.move(NODE_Y.getFqn(), NODES[rnd.nextInt(NODES.length)].getFqn());
                   }
                   catch (NodeNotExistsException e) {
                      // this may happen ...

Modified: core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java	2009-02-17 19:55:45 UTC (rev 7718)
+++ core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java	2009-02-18 09:26:50 UTC (rev 7719)
@@ -117,7 +117,10 @@
    }
 
    public void testTxSyncUnableToInvalidate() throws Exception {
+      replListener(cache2).expect(InvalidateCommand.class);
       cache1.put("key", "value");
+      replListener(cache2).waitForRPC();
+
       assertEquals("value", cache1.get("key"));
       assertNull(cache2.get("key"));
 
@@ -125,6 +128,8 @@
       TransactionManager mgr1 = TestingUtil.getTransactionManager(cache1);
       TransactionManager mgr2 = TestingUtil.getTransactionManager(cache2);
 
+      replListener(cache1).expect(InvalidateCommand.class);
+      replListener(cache2).expect(InvalidateCommand.class);
       mgr1.begin();
       cache1.put("key", "value2");
       Transaction tx1 = mgr1.suspend();
@@ -135,25 +140,29 @@
       // this oughtta fail
       try {
          mgr1.commit();
-         if (isSync)
-            assertTrue("Ought to have failed!", false);
-         else
+         if (isSync) {
+            fail("Ought to have failed!");
+         } else {
             assert true : "Ought to have succeeded";
+//            replListener(cache2).waitForRPC();
+         }
       }
       catch (RollbackException roll) {
          if (isSync)
             assertTrue("Ought to have failed!", true);
          else
-            assert false : "Ought to have succeeded!";
+            fail("Ought to have succeeded!");
       }
 
       mgr2.resume(tx2);
       try {
          mgr2.commit();
+         replListener(cache1).waitForRPC();
+         if (!isSync) replListener(cache2).waitForRPC();
          assertTrue("Ought to have succeeded!", true);
       }
       catch (RollbackException roll) {
-         assertTrue("Ought to have succeeded!", false);
+         fail("Ought to have succeeded!");
       }
    }
 
@@ -185,7 +194,7 @@
    }
 
    public void testPutIfAbsent() {
-      cache2.put("key", "value", Options.CACHE_MODE_LOCAL);
+      assert null == cache2.put("key", "value", Options.CACHE_MODE_LOCAL);
       assert cache2.get("key").equals("value");
       assert cache1.get("key") == null;
 
@@ -196,7 +205,7 @@
       assert cache1.get("key").equals("value");
       assert cache2.get("key") == null;
 
-      cache2.put("key", "value2", Options.CACHE_MODE_LOCAL);
+      assert null == cache2.put("key", "value2", Options.CACHE_MODE_LOCAL);
 
       assert cache1.get("key").equals("value");
       assert cache2.get("key").equals("value2");
@@ -213,7 +222,7 @@
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
-      cache1.remove("key", "value");
+      assert !cache1.remove("key", "value");
 
       assert cache1.get("key").equals("value1") : "Should not remove";
       assert cache2.get("key").equals("value2") : "Should not evict";
@@ -245,12 +254,12 @@
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      cache1.replace("key", "value1"); // should do nothing since there is nothing to replace on cache1
+      assert null == cache1.replace("key", "value1"); // should do nothing since there is nothing to replace on cache1
 
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      cache1.put("key", "valueN", Options.CACHE_MODE_LOCAL);
+      assert null == cache1.put("key", "valueN", Options.CACHE_MODE_LOCAL);
 
       replListener(cache2).expect(InvalidateCommand.class);
       cache1.replace("key", "value1");
@@ -265,20 +274,20 @@
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
+      assert !cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
 
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      cache1.put("key", "valueN", Options.CACHE_MODE_LOCAL);
+      assert null == cache1.put("key", "valueN", Options.CACHE_MODE_LOCAL);
 
-      cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
+      assert !cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
 
       assert cache1.get("key").equals("valueN");
       assert cache2.get("key").equals("value2");
 
       replListener(cache2).expect(InvalidateCommand.class);
-      cache1.replace("key", "valueN", "value1");
+      assert cache1.replace("key", "valueN", "value1");
       replListener(cache2).waitForRPC();
 
       assert cache1.get("key").equals("value1");

Modified: core/branches/flat/src/test/java/org/horizon/test/ReplListener.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/test/ReplListener.java	2009-02-17 19:55:45 UTC (rev 7718)
+++ core/branches/flat/src/test/java/org/horizon/test/ReplListener.java	2009-02-18 09:26:50 UTC (rev 7719)
@@ -25,7 +25,7 @@
 
    public ReplListener(Cache c) {
       this.c = c;
-      this.c.getAdvancedCache().addInterceptor(new ReplListenerInterceptor(), 0);
+      this.c.getAdvancedCache().addInterceptor(new ReplListenerInterceptor(), 1);
    }
 
    /**
@@ -77,7 +77,7 @@
     * been detected.  If the commands have not been detected by this time, an exception is thrown.
     */
    public void waitForRPC() {
-      waitForRPC(120, TimeUnit.SECONDS);
+      waitForRPC(30, TimeUnit.SECONDS);
    }
 
    /**
@@ -104,7 +104,7 @@
       protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable {
          // first pass up chain
          Object o = invokeNextInterceptor(ctx, cmd);
-         markAsVisited(cmd);
+         if (!ctx.isOriginLocal()) markAsVisited(cmd);
          return o;
       }
 
@@ -112,8 +112,10 @@
       public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand cmd) throws Throwable {
          // first pass up chain
          Object o = invokeNextInterceptor(ctx, cmd);
-         markAsVisited(cmd);
-         for (DataCommand mod : cmd.getModifications()) markAsVisited(mod);
+         if (!ctx.isOriginLocal()) {
+            markAsVisited(cmd);
+            for (DataCommand mod : cmd.getModifications()) markAsVisited(mod);
+         }
          return o;
       }
 
@@ -121,6 +123,8 @@
          if (expectedCommands != null) {
             expectedCommands.remove(cmd.getClass());
             if (expectedCommands.isEmpty()) latch.countDown();
+         } else {
+            System.out.println("Received unexpected command: " + cmd);
          }
       }
    }




More information about the jbosscache-commits mailing list