[jbosscache-commits] JBoss Cache SVN: r4679 - core/trunk/src/test/java/org/jboss/cache/statetransfer.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Oct 24 08:45:45 EDT 2007


Author: mircea.markus
Date: 2007-10-24 08:45:45 -0400 (Wed, 24 Oct 2007)
New Revision: 4679

Modified:
   core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
   core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
Log:
fixed tests

Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java	2007-10-23 20:53:27 UTC (rev 4678)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java	2007-10-24 12:45:45 UTC (rev 4679)
@@ -99,7 +99,7 @@
          CacheSPI[] caches = new CacheSPI[count];
          for (int i = 0; i < count; i++)
          {
-            activators[i] = new CacheActivator(semaphore, names[i], sync);
+            activators[i] = new CacheActivator(semaphore, names[i], sync, caches);
             caches[i] = activators[i].getCacheSPI();
             activators[i].start();
          }
@@ -149,7 +149,6 @@
                        "VALUE", activators[i].getCacheValue(fqn));
                //               System.out.println(names[i] + ":" + fqn + " = " + activators[i].getCacheValue(fqn));
             }
-
          }
       }
       catch (Exception ex)
@@ -647,18 +646,23 @@
    private class CacheActivator extends CacheUser
    {
 
+      private CacheSPI[] caches;
+
       CacheActivator(Semaphore semaphore,
                      String name,
-                     boolean sync)
+                     boolean sync, CacheSPI[] caches)
               throws Exception
       {
          super(semaphore, name, sync, false);
+         this.caches = caches;
       }
 
       void useCache() throws Exception
       {
+         System.out.println("---- Cache" + name + " = " + cache.getLocalAddress() + " being used");
          TestingUtil.sleepRandom(5000);
          createAndActivateRegion(cache, A_B);
+         waitUntillAllChachesActivatedRegion();
          System.out.println(name + " activated region" + " " + System.currentTimeMillis());
          Fqn<String> childFqn = new Fqn<String>(A_B, name);
 
@@ -667,6 +671,34 @@
 
       }
 
+      /**
+       * If we do not wait for all being activated, following scenario might happen:
+       * A activates the /a/b
+       * A puts something in /a/b and replicates
+       * B fails to accept the replication as it has the /a/b region inactive.
+       *
+       * So we cannot expect all the put operation to replicate accross all the members from the cluser, WITHOUTH
+       * having the region active on ALL members.
+       *
+       */
+      private void waitUntillAllChachesActivatedRegion()
+      {
+         boolean allActive = true;
+         do
+         {
+            allActive = true;
+            for (Cache cache : caches)
+            {
+               if (cache.getRegion(A_B, false) == null || !cache.getRegion(A_B, false).isActive())
+               {
+                  allActive = false;
+               }
+            }
+            TestingUtil.sleepThread(1000);
+         } while (!allActive);
+         System.out.println("---- /a/b is active on all cache instances");
+      }
+
       public Object getCacheValue(Fqn fqn) throws CacheException
       {
          return cache.get(fqn, "KEY");

Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java	2007-10-23 20:53:27 UTC (rev 4678)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java	2007-10-24 12:45:45 UTC (rev 4679)
@@ -480,7 +480,7 @@
 
       public void start()
       {
-         thread = new Thread(this);
+         thread = new Thread(this, name);
          thread.start();
       }
 




More information about the jbosscache-commits mailing list