[jbosscache-commits] JBoss Cache SVN: r7392 - in core/trunk/src/test/java/org/jboss/cache: integration/websession and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Jan 7 12:55:54 EST 2009


Author: mircea.markus
Date: 2009-01-07 12:55:54 -0500 (Wed, 07 Jan 2009)
New Revision: 7392

Modified:
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
   core/trunk/src/test/java/org/jboss/cache/integration/websession/BuddyReplicationFailoverTest.java
   core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManager.java
   core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManagerSupport.java
   core/trunk/src/test/java/org/jboss/cache/integration/websession/util/WebSessionTestBase.java
   core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java
Log:
test enhancements

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java	2009-01-07 17:51:32 UTC (rev 7391)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java	2009-01-07 17:55:54 UTC (rev 7392)
@@ -288,7 +288,7 @@
       return 1000;
    }
 
-   protected void assertIsBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy)
+   protected static void assertIsBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy)
    {
       Address dataOwnerLocalAddress = dataOwner.getLocalAddress();
       Address buddyLocalAddress = buddy.getLocalAddress();
@@ -310,14 +310,14 @@
       assertTrue(buddyLocalAddress + " should be a buddy to " + group.getGroupName(), group.getBuddies().contains(buddyLocalAddress));
    }
 
-   public void waitForBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy) throws Exception
+   public static void waitForBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy) throws Exception
    {
       waitForBuddy(dataOwner, buddy, onlyBuddy, 60000);
    }
 
 
 
-   public void waitForSingleBuddy(List caches) throws Exception
+   public static void waitForSingleBuddy(List caches) throws Exception
    {
       Cache[] array = (Cache[]) caches.toArray(new Cache[0]);
       waitForSingleBuddy(array);
@@ -327,7 +327,7 @@
     * Will wait for 60 secs + 10sec * caches.length for the given caches to become buddys.
     * The caches should be ordered as per underlying view.
     */
-   public void waitForSingleBuddy(Cache... caches) throws Exception
+   public static void waitForSingleBuddy(Cache... caches) throws Exception
    {
       long timeout = 60000 + caches.length;
       for (int i = 0; i < caches.length - 1; i++)
@@ -337,7 +337,7 @@
       waitForBuddy(caches[caches.length - 1], caches[0], true, timeout);
    }
 
-   public void waitForBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy, long timeout) throws Exception
+   public static void waitForBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy, long timeout) throws Exception
    {
       long start = System.currentTimeMillis();
       while ((System.currentTimeMillis() - start) < timeout)
@@ -350,7 +350,7 @@
    }
 
 
-   private boolean isBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy)
+   private static boolean isBuddy(Cache dataOwner, Cache buddy, boolean onlyBuddy)
    {
       Address dataOwnerLocalAddress = dataOwner.getLocalAddress();
       Address buddyLocalAddress = buddy.getLocalAddress();

Modified: core/trunk/src/test/java/org/jboss/cache/integration/websession/BuddyReplicationFailoverTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/integration/websession/BuddyReplicationFailoverTest.java	2009-01-07 17:51:32 UTC (rev 7391)
+++ core/trunk/src/test/java/org/jboss/cache/integration/websession/BuddyReplicationFailoverTest.java	2009-01-07 17:55:54 UTC (rev 7392)
@@ -22,31 +22,40 @@
 
 package org.jboss.cache.integration.websession;
 
-import java.util.Collections;
-
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheManager;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyReplicationTestsBase;
 import org.jboss.cache.commands.write.PutDataMapCommand;
 import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.integration.websession.util.BuddyReplicationAssertions;
-import org.jboss.cache.integration.websession.util.GetAttributesServlet;
-import org.jboss.cache.integration.websession.util.InvalidationServlet;
-import org.jboss.cache.integration.websession.util.MultipleActionServlet;
-import org.jboss.cache.integration.websession.util.Request;
-import org.jboss.cache.integration.websession.util.SessionManager;
-import org.jboss.cache.integration.websession.util.SetAttributesServlet;
-import org.jboss.cache.integration.websession.util.WebSessionTestBase;
+import org.jboss.cache.integration.websession.util.*;
+import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.FileCacheLoaderConfig;
+import org.jboss.cache.util.TestingUtil;
 import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
+
 /**
  * @author Brian Stansberry
  *
  */
- at Test(groups = "integration", sequential = true, testName = "integration.websession.BuddyReplicationFailoverTest")
+ at Test(groups = "integration", testName = "integration.websession.BuddyReplicationFailoverTest")
 public class BuddyReplicationFailoverTest extends WebSessionTestBase
 {
    public static final String KEY = "key";
+   public static final String FILE_CL_ROOT_DIR = "./testFiles/BuddyReplicationFailoverTest";
+   private static int FOLDER_INDEX = 0;
 
+
    @Override
    protected String getCacheConfigName()
    {
@@ -64,7 +73,44 @@
    {
       return true;
    }
-   
+
+   @BeforeClass(alwaysRun = true)
+   public void beforeClass() throws Exception
+   {
+      super.beforeClass();
+      /* Make sure that the buddy group is formed before starting the tests */
+      List<Cache> createdCaches = new ArrayList<Cache>();
+      for (CacheManager cacheMngr : getCacheManagers())
+      {
+         Cache cache = cacheMngr.getCache(getCacheConfigName(), false);
+         createdCaches.add(cache);
+      }
+      BuddyReplicationTestsBase.waitForSingleBuddy(createdCaches);
+   }
+
+   protected void amendCacheBeforeStartup(Cache<Object, Object> cache)
+   {
+      FileCacheLoaderConfig config = (FileCacheLoaderConfig) cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig();
+      config.setLocation(FILE_CL_ROOT_DIR + "/session" + FOLDER_INDEX ++);
+   }
+
+   @BeforeMethod
+   public void clearCacheLoader() throws Exception
+   {
+      for (CacheManager mgr: getCacheManagers())
+      {
+         CacheSPI cache = (CacheSPI) mgr.getCache(getCacheConfigName(), false);
+         CacheLoader cl = cache.getCacheLoaderManager().getCacheLoader();
+         cl.remove(Fqn.ROOT);
+      }
+   }
+
+   @AfterTest
+   public void removeFileClassLoaderDirs()
+   {
+      TestingUtil.recursiveFileRemove(FILE_CL_ROOT_DIR);
+   }
+
    public void testFailoverAndImmediateInvalidate()
    {
       int attr = 0;
@@ -344,7 +390,7 @@
       BuddyReplicationAssertions.assertUnrelated(contextHostName, sessionId, mgr2.getCache());
       BuddyReplicationAssertions.assertUnrelated(contextHostName, sessionId, mgr3.getCache());
    }
-   
+
    public void testFailoverAndFailBack()
    {
       int attr = 0;
@@ -386,11 +432,11 @@
       MultipleActionServlet mas = new MultipleActionServlet(gas, sas);
       ReplicationListener replListener0 = getReplicationListener(mgr0.getCache());
       replListener0.expectWithTx(PutDataMapCommand.class); 
-      
+
       req = new Request(mgr3, sessionId, mas);
-      req.execute();      
+      req.execute();
       replListener0.waitForReplicationToOccur();
-      
+
       assert sessionId.equals(mas.getSessionId()) : "wrong session id; expected " + sessionId + " got " + mas.getSessionId();
       Integer integer = (Integer) gas.getReadAttributes().get(KEY);
       assert integer != null : "null attribute value";
@@ -491,7 +537,7 @@
       req = new Request(mgr3, sessionId, sas);
       req.execute();      
       replListener0.waitForReplicationToOccur();      
-      
+
       // Invalidate the session
       sas = new SetAttributesServlet(Collections.singletonMap(KEY, getAttributeValue(attr++)));
       InvalidationServlet invs = new InvalidationServlet();

Modified: core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManager.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManager.java	2009-01-07 17:51:32 UTC (rev 7391)
+++ core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManager.java	2009-01-07 17:55:54 UTC (rev 7392)
@@ -34,11 +34,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheManager;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
+import org.jboss.cache.*;
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.config.BuddyReplicationConfig;
 import org.jboss.cache.integration.websession.util.WebAppMetadata.Granularity;
@@ -96,7 +92,7 @@
    
    public void start()
    {
-      this.started = true;;
+      this.started = true;
       
       try
       {
@@ -126,12 +122,10 @@
       this.buddyReplication = brc != null && brc.isEnabled();      
    }
    
-   public void stop()
+   public void stop() throws Exception
    {     
       if (started)
       {
-         
-      
          if (cache != null)
          {
             cache.removeCacheListener(this);

Modified: core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManagerSupport.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManagerSupport.java	2009-01-07 17:51:32 UTC (rev 7391)
+++ core/trunk/src/test/java/org/jboss/cache/integration/websession/util/SessionManagerSupport.java	2009-01-07 17:55:54 UTC (rev 7392)
@@ -59,7 +59,7 @@
      return new ArrayList<SessionManager>(existing);
   }
   
-  public static void tearDown()
+  public static void tearDown() throws Exception
   {
      List<SessionManager> existing = threadSessionManagers.get();
      for (SessionManager sm : existing)

Modified: core/trunk/src/test/java/org/jboss/cache/integration/websession/util/WebSessionTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/integration/websession/util/WebSessionTestBase.java	2009-01-07 17:51:32 UTC (rev 7391)
+++ core/trunk/src/test/java/org/jboss/cache/integration/websession/util/WebSessionTestBase.java	2009-01-07 17:55:54 UTC (rev 7392)
@@ -62,6 +62,7 @@
          for (CacheManager cm : cacheManagers)
          {
             Cache<Object, Object> cache = cm.getCache(getCacheConfigName(), true);
+            amendCacheBeforeStartup(cache);
             if (cache.getCacheStatus() != CacheStatus.STARTED)
             {
                cache.start();
@@ -70,10 +71,16 @@
          }
       }
    }
-   
+
+   protected void amendCacheBeforeStartup(Cache<Object, Object> cache)
+   {
+      //do nothing
+   }
+
    @AfterClass(alwaysRun = true)
    public void afterClass()
    {
+
       CacheManagerSupport.tearDown();
    }
    

Modified: core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java	2009-01-07 17:51:32 UTC (rev 7391)
+++ core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java	2009-01-07 17:55:54 UTC (rev 7392)
@@ -36,26 +36,25 @@
  * Utilities for unit testing JBossCache.
  *
  * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
- * @version $Revision$
  */
 public class TestingUtil
 {
    private static Random random = new Random();
 
    public static final String TEST_FILES = "testFiles";
-   
+
    /**
     *  Holds unique mcast_port for each thread used for JGroups channel construction.
     */
-   private static final ThreadLocal<Integer> threadID = new ThreadLocal<Integer>() {     
-      
+   private static final ThreadLocal<Integer> threadID = new ThreadLocal<Integer>() {
+
       private final AtomicInteger uniquePort = new AtomicInteger(0);
-      
+
       @Override protected Integer initialValue() {
          return uniquePort.getAndIncrement();
-      }      
+      }
    };
-   
+
    private static UnitTestCacheFactory utf = new UnitTestCacheFactory();
 
 
@@ -412,6 +411,7 @@
    {
       if (file.exists())
       {
+         System.out.println("Deleting file " + file);
          recursivedelete(file);
       }
    }
@@ -426,6 +426,7 @@
             recursivedelete(file);
          }
       }
+      //System.out.println("File " + f.toURI() + " deleted = " + f.delete());
       f.delete();
    }
 
@@ -474,7 +475,7 @@
                   }
                }
 
-               try 
+               try
                {
                   spi.stop();
                } catch (Throwable t) {
@@ -501,7 +502,7 @@
                   if (channel.isConnected()) {
                      System.err.println(Thread.currentThread().getName() + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Channel still connected.");
                      Thread.dumpStack();
-                     System.exit(-1);                     
+                     System.exit(-1);
                   }
                }
             }
@@ -510,7 +511,7 @@
          {
             t.printStackTrace();
             System.exit(-1);
-         }         
+         }
       }
    }
 
@@ -548,11 +549,11 @@
          try {
             txManager.rollback();
          } catch (Exception e) {
-               // don't care            
+               // don't care
          }
       }
    }
-   
+
    /**
     * For testing only - introspects a cache and extracts the ComponentRegistry
     *
@@ -681,12 +682,23 @@
 
    public static void dumpCacheContents(List caches)
    {
+      System.out.println("**** START: Cache Contents ****");
       int count = 1;
       for (Object o : caches)
       {
          CacheSPI c = (CacheSPI) o;
+         if (c == null)
+         {
+            System.out.println("  ** Cache " + count + " is null!");
+         }
+         else
+         {
+            System.out.println("  ** Cache " + count + " is " + c.getLocalAddress());
+            System.out.println("    " + CachePrinter.printCacheDetails(c));
+         }
          count++;
       }
+      System.out.println("**** END: Cache Contents ****");
    }
 
    public static void dumpCacheContents(Cache... caches)




More information about the jbosscache-commits mailing list