[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...

Galder Zamarreno galder.zamarreno at jboss.com
Tue Jul 17 18:16:49 EDT 2007


  User: gzamarreno
  Date: 07/07/17 18:16:49

  Modified:    tests/functional/org/jboss/cache/loader  
                        SingletonStoreCacheLoaderTest.java
                        CacheLoaderManagerTest.java
  Log:
  [JBCACHE-1134] singleton store cache loader class configuration added and changed the way SSCL is configured in the XML. Also migrated push state logic to use java.util.concurrent package. Still missing, changing user guide for the updated configuration and an XML example in etc/
  
  Revision  Changes    Path
  1.7       +105 -53   JBossCache/tests/functional/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SingletonStoreCacheLoaderTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- SingletonStoreCacheLoaderTest.java	11 Jan 2007 13:49:06 -0000	1.6
  +++ SingletonStoreCacheLoaderTest.java	17 Jul 2007 22:16:48 -0000	1.7
  @@ -12,12 +12,23 @@
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.loader.SingletonStoreCacheLoader.PushStateException;
   import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.xml.XmlHelper;
   import org.w3c.dom.Element;
   
  +import java.util.concurrent.Future;
  +import java.util.concurrent.FutureTask;
  +import java.util.concurrent.ExecutorService;
  +import java.util.concurrent.Executors;
  +import java.util.concurrent.CountDownLatch;
  +import java.util.concurrent.Callable;
  +import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.ExecutionException;
  +import java.util.concurrent.TimeoutException;
  +
   /**
    * Unit test class for SingletonStoreCacheLoader
    *
  @@ -25,9 +36,10 @@
    */
   public class SingletonStoreCacheLoaderTest extends AbstractCacheLoaderTestBase
   {
  -   private CacheSPI cache1, cache2, cache3;
      private static final Log log = LogFactory.getLog(SingletonStoreCacheLoaderTest.class);
   
  +   private CacheSPI cache1, cache2, cache3;
  +
      protected void setUp() throws Exception
      {
         log.info("*** test:" + getName() + " ***");
  @@ -140,7 +152,7 @@
         Thread.sleep(1000);
   
         SingletonStoreCacheLoader scl2 = (SingletonStoreCacheLoader) cache2.getCacheLoaderManager().getCacheLoader();
  -      joinPushThread(scl2.getPushStateThread());
  +      waitForPushStateCompletion(scl2.getPushStateFuture());
   
         assertTrue(cl2.get(fqn("/a")).containsKey("a-key"));
         assertTrue(cl2.get(fqn("/a")).containsKey("aa-key"));
  @@ -172,7 +184,7 @@
         Thread.sleep(1000);
   
         SingletonStoreCacheLoader scl3 = (SingletonStoreCacheLoader) cache3.getCacheLoaderManager().getCacheLoader();
  -      joinPushThread(scl3.getPushStateThread());
  +      waitForPushStateCompletion(scl3.getPushStateFuture());
   
         assertTrue(cl3.get(fqn("/a")).containsKey("a-key"));
         assertTrue(cl3.get(fqn("/a")).containsKey("aa-key"));
  @@ -192,21 +204,46 @@
         stopCache3();
      }
   
  -   public void testAvoidConcurrentStatePush() throws InterruptedException
  +   public void testAvoidConcurrentStatePush() throws Exception
      {
  -      MockSingletonStoreCacheLoader mscl = new MockSingletonStoreCacheLoader(null, true, 3000);
  +      final ExecutorService executor = Executors.newFixedThreadPool(2);
  +      final CountDownLatch pushStateCanFinish = new CountDownLatch(1);
  +      final CountDownLatch secondActiveStatusChangerCanStart = new CountDownLatch(1);
  +      final MockSingletonStoreCacheLoader mscl = new MockSingletonStoreCacheLoader(pushStateCanFinish, secondActiveStatusChangerCanStart, new SingletonStoreDefaultConfig());
   
  -      Thread t1 = new Thread(createActiveStatusChanger(mscl));
  -      Thread t2 = new Thread(createActiveStatusChanger(mscl));
  +      Future f1 = executor.submit(createActiveStatusChanger(mscl));
  +      secondActiveStatusChangerCanStart.await();
   
  -      t1.start();
  -      Thread.sleep(1000);
  -      t2.start();
  +      Future f2 = executor.submit(createActiveStatusChanger(mscl));
   
  -      t1.join();
  -      t2.join();
  +      f1.get();
  +      f2.get();
  +
  +      assertEquals(1, mscl.getNumberCreatedTasks());
  +   }
  +
  +   public void testPushStateTimedOut() throws Exception
  +   {
  +      final CountDownLatch pushStateCanFinish = new CountDownLatch(1);
  +      SingletonStoreDefaultConfig ssdc = new SingletonStoreDefaultConfig();
  +      ssdc.setPushStateWhenCoordinatorTimeout(1000);
  +      final MockSingletonStoreCacheLoader mscl = new MockSingletonStoreCacheLoader(pushStateCanFinish, null, ssdc);
  +
  +      Future f = Executors.newSingleThreadExecutor().submit(createActiveStatusChanger(mscl));
  +      pushStateCanFinish.await(2000, TimeUnit.MILLISECONDS);
  +      pushStateCanFinish.countDown();
  +
  +      try
  +      {
  +         f.get();
  +         fail("Should have timed out");         
  +      }
  +      catch (ExecutionException e)
  +      {
  +         Throwable t = e.getCause().getCause().getCause();
  +         assertTrue(t + " should have been TimeoutException", t instanceof TimeoutException);
  +      }
   
  -      assertEquals(1, mscl.getNumberCreatedThreads());
      }
   
      private void createCaches() throws Exception
  @@ -223,33 +260,36 @@
         cache3.start();
      }
   
  -   private void joinPushThread(Thread pushThread) throws InterruptedException
  +   private void waitForPushStateCompletion(Future pushThreadFuture) throws Exception
      {
  -      if (pushThread != null)
  +      if (pushThreadFuture != null)
         {
  -         pushThread.join();
  +         pushThreadFuture.get();
         }
      }
   
  -   private Runnable createActiveStatusChanger(SingletonStoreCacheLoader mscl)
  +   private Callable<?> createActiveStatusChanger(SingletonStoreCacheLoader mscl)
      {
         return new ActiveStatusModifier(mscl);
      }
   
  -   protected CacheLoaderConfig getSingletonStoreCacheLoaderConfig(String cacheloaderClass, boolean singleton,
  -                                                                  boolean pushStateWhenCoordinator) throws Exception
  +   protected CacheLoaderConfig getSingletonStoreCacheLoaderConfig(String cacheloaderClass, boolean singletonEnabled,
  +                                                                  boolean pushStateWhenCoordinator,
  +                                                                  int pushStateWhenCoordinatorTimeout) throws Exception
      {
         String xml = "<config>\n" +
                 "<passivation>false</passivation>\n" +
                 "<preload></preload>\n" +
                 "<cacheloader>\n" +
  -              "<class>" + cacheloaderClass + "</class>\n" +
  -              "<properties></properties>\n" +
  -              // "<async>false</async>\n" +
  -              // "<shared>false</shared>\n" +
  -              // "<fetchPersistentState>false</fetchPersistentState>\n" +
  -              // "<purgeOnStartup>false</purgeOnStartup>\n" +
  -              "<singletonStore pushStateWhenCoordinator=\"" + pushStateWhenCoordinator + "\">" + singleton + "</singletonStore>\n" +
  +              "  <class>" + cacheloaderClass + "</class>\n" +
  +              "  <properties></properties>\n" +
  +              "  <singletonStore>" +
  +              "     <enabled>true</enabled>" +
  +              "     <properties>" +
  +              "        pushStateWhenCoordinator = true\n" +
  +              "        pushStateWhenCoordinatorTimeout = 5000\n" +
  +              "     </properties>" +
  +              "  </singletonStore>" +
                 "</cacheloader>\n" +
                 "</config>";
         Element element = XmlHelper.stringToElement(xml);
  @@ -259,13 +299,13 @@
      private void initSingletonNonPushCache(CacheSPI cache) throws Exception
      {
         cache.getConfiguration().setCacheLoaderConfig(getSingletonStoreCacheLoaderConfig(
  -              DummyInMemoryCacheLoader.class.getName(), true, false));
  +              DummyInMemoryCacheLoader.class.getName(), true, false, 1000));
      }
   
      private void initSingletonWithPushCache(CacheSPI cache) throws Exception
      {
         cache.getConfiguration().setCacheLoaderConfig(getSingletonStoreCacheLoaderConfig(
  -              DummyInMemoryCacheLoader.class.getName(), true, true));
  +              DummyInMemoryCacheLoader.class.getName(), true, true, 1000));
      }
   
      private CacheLoader getDelegatingCacheLoader(CacheSPI cache)
  @@ -318,46 +358,62 @@
   
      class MockSingletonStoreCacheLoader extends SingletonStoreCacheLoader
      {
  -      private int numberCreatedThreads = 0;
  -      private long busyPeriod;
  +      private int numberCreatedTasks = 0;
  +      private CountDownLatch pushStateCanFinish;
  +      private CountDownLatch secondActiveStatusChangerCanStart;
   
  -      public MockSingletonStoreCacheLoader(CacheLoader loader, boolean pushConfiguration, long busyPeriodTime)
  +      public MockSingletonStoreCacheLoader(CountDownLatch pushStateCanFinish, CountDownLatch secondActiveStatusChangerCanStart, SingletonStoreDefaultConfig config)
         {
  -         super(loader, pushConfiguration);
  -         busyPeriod = busyPeriodTime;
  +         super(config);
  +         this.pushStateCanFinish = pushStateCanFinish;
  +         this.secondActiveStatusChangerCanStart = secondActiveStatusChangerCanStart;
         }
   
  -      public int getNumberCreatedThreads()
  +      public int getNumberCreatedTasks()
         {
  -         return numberCreatedThreads;
  +         return numberCreatedTasks;
         }
   
  -      public void setNumberCreatedThreads(int numberCreatedThreads)
  +      public void setNumberCreatedTasks(int numberCreatedTasks)
         {
  -         this.numberCreatedThreads = numberCreatedThreads;
  +         this.numberCreatedTasks = numberCreatedTasks;
         }
   
  -      protected Thread createPushStateThread()
  +      @Override
  +      protected Callable<?> createPushStateTask()
         {
  -         return new Thread(new Runnable()
  +         return new Callable()
            {
  -            public void run()
  +            public Object call() throws Exception
               {
  -               numberCreatedThreads++;
  +               numberCreatedTasks++;
                  try
                  {
  -                  Thread.sleep(busyPeriod);
  +                  if (secondActiveStatusChangerCanStart != null)
  +                  {
  +                     secondActiveStatusChangerCanStart.countDown();                     
  +                  }
  +                  pushStateCanFinish.await();
                  }
                  catch (InterruptedException e)
                  {
                     fail("ActiveStatusModifier interrupted");
                  }
  +               return null;
  +            }
  +         };
               }
  -         });
  +
  +
  +      @Override
  +      protected void awaitForPushToFinish(Future future, int timeout, TimeUnit unit)
  +      {
  +         pushStateCanFinish.countDown();         
  +         super.awaitForPushToFinish(future, timeout, unit);
         }
      }
   
  -   class ActiveStatusModifier implements Runnable
  +   class ActiveStatusModifier implements Callable
      {
         private SingletonStoreCacheLoader scl;
   
  @@ -366,17 +422,13 @@
            scl = singleton;
         }
   
  -      public void run()
  +      public Object call() throws Exception
         {
  +         log.debug("active status modifier started");
            scl.activeStatusChanged(true);
  -         try
  -         {
  -            scl.getPushStateThread().join();
  -         }
  -         catch (InterruptedException e)
  -         {
  -            throw new RuntimeException(e);
  -         }
  +         scl.getPushStateFuture().get();
  +
  +         return null;
         }
      }
   }
  
  
  
  1.15      +154 -27   JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderManagerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheLoaderManagerTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderManagerTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- CacheLoaderManagerTest.java	28 Jun 2007 16:53:38 -0000	1.14
  +++ CacheLoaderManagerTest.java	17 Jul 2007 22:16:48 -0000	1.15
  @@ -9,7 +9,7 @@
   import junit.framework.Assert;
   import junit.framework.Test;
   import junit.framework.TestSuite;
  -import org.jboss.cache.Cache;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.xml.XmlHelper;
  @@ -22,6 +22,7 @@
    * Tests the construction of a cache laoder based on an XML element passed in.
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  + * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
    */
   public class CacheLoaderManagerTest extends AbstractCacheLoaderTestBase
   {
  @@ -465,8 +466,9 @@
         mgr.setConfig(clc, null);
   
         CacheLoaderConfig.IndividualCacheLoaderConfig iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertFalse("Singleton has not been configured", iclc.isSingletonStore());
  -      assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
  +      assertNull("Singleton has not been configured", iclc.getSingletonStoreConfig());
  +
  +      /************************************************************************************************************/
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -479,7 +481,9 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore>true</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>false</enabled>" +              
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  @@ -487,8 +491,10 @@
         mgr.setConfig(clc, null);
   
         iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertTrue("Singleton has been configured", iclc.isSingletonStore());
  -      assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertFalse("Singleton is not enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +
  +      /************************************************************************************************************/
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -501,16 +507,26 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore>false</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +              
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  -      mgr = new CacheLoaderManager();
  +      mgr = new MockCacheLoaderManager();
         mgr.setConfig(clc, null);
   
         iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertFalse("Singleton has not been configured", iclc.isSingletonStore());
  -      assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +      assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
  +      assertNotNull("Singleton properties should be not null", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
  +      assertTrue("Singleton properties should be empty", iclc.getSingletonStoreConfig().getSingletonStoreproperties().keySet().isEmpty());
  +      SingletonStoreDefaultConfig ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
  +      assertTrue("Singleton pushStateWhenCoordinator should be true (default)", ssdc.isPushStateWhenCoordinator());
  +      assertEquals("Singleton pushStateWhenCoordinatorTimeout should be default value", 20000, ssdc.getPushStateWhenCoordinatorTimeout());
  +
  +      /************************************************************************************************************/
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -523,16 +539,25 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore pushStateWhenCoordinator=\"false\">true</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +
  +              "       <class>org.jboss.cache.loader.CacheLoaderManagerTest$MockSingletonStoreCacheLoader</class>" +              
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  -      mgr = new MockCacheLoaderManager();
  +      mgr = new CacheLoaderManager();
         mgr.setConfig(clc, null);
   
         iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertTrue("Singleton has been configured", iclc.isSingletonStore());
  -      assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +      assertEquals("Singleton class should be a user defined one", MockSingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
  +      assertNotNull("Singleton properties should be not null", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
  +      assertTrue("Singleton properties should be empty", iclc.getSingletonStoreConfig().getSingletonStoreproperties().keySet().isEmpty());
  +      assertTrue(mgr.getCacheLoader() instanceof MockSingletonStoreCacheLoader);
  +
  +      /************************************************************************************************************/
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -545,7 +570,10 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore pushStateWhenCoordinator=\"false\">false</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>false</enabled>" +
  +              "       <class>org.jboss.cache.loader.FileCacheLoader</class>" +
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  @@ -553,8 +581,10 @@
         mgr.setConfig(clc, null);
   
         iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertFalse("Singleton has not been configured", iclc.isSingletonStore());
  -      assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertFalse("Singleton is not enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +
  +      /************************************************************************************************************/
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -567,16 +597,58 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore pushStateWhenCoordinator=\"true\">false</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +
  +              "       <properties></properties>" +
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  -      mgr = new CacheLoaderManager();
  +      mgr = new MockCacheLoaderManager();
  +      mgr.setConfig(clc, null);
  +
  +      iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +      assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
  +      assertNotNull("Singleton properties should be defined, but empty", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
  +      ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
  +      assertTrue("Singleton pushStateWhenCoordinator should be true", ssdc.isPushStateWhenCoordinator());
  +
  +      /************************************************************************************************************/
  +
  +      conf = "<config>" +
  +              "<passivation>false</passivation>" +
  +              "<preload>/, /blah, /blah2</preload>" +
  +              "<cacheloader>" +
  +              "    <class>org.jboss.cache.loader.FileCacheLoader</class>" +
  +              "    <async>false</async>" +
  +              "    <fetchPersistentState>false</fetchPersistentState>" +
  +              "    <ignoreModifications>true</ignoreModifications>" +
  +              "    <properties>" +
  +              "        location=" + getTempDir() +
  +              "    </properties>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +
  +              "       <properties>" +
  +              "          pushStateWhenCoordinator = false" +              
  +              "       </properties>" +
  +              "    </singletonStore>" +
  +              "</cacheloader>" +
  +              "</config>";
  +      clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  +      mgr = new MockCacheLoaderManager();
         mgr.setConfig(clc, null);
   
         iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertFalse("Singleton has not been configured", iclc.isSingletonStore());
  -      assertFalse("Singleton.pushStateWhenCoordinator should be false has not been configured", iclc.isPushStateWhenCoordinator());
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +      assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
  +      assertNotNull("Singleton properties should be defined", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
  +      ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
  +      assertFalse("Singleton pushStateWhenCoordinator should be false", ssdc.isPushStateWhenCoordinator());
  +
  +      /************************************************************************************************************/
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -589,7 +661,13 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore pushStateWhenCoordinator=\"true\">true</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +
  +              "       <properties>" +
  +              "          pushStateWhenCoordinator = true\n" +
  +              "          pushStateWhenCoordinatorTimeout = 5000\n" +                            
  +              "       </properties>" +
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  @@ -597,8 +675,15 @@
         mgr.setConfig(clc, null);
   
         iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
  -      assertTrue("Singleton has been configured", iclc.isSingletonStore());
  -      assertTrue("Singleton.pushStateWhenCoordinator has been configured", iclc.isPushStateWhenCoordinator());
  +      assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
  +      assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
  +      assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
  +      assertNotNull("Singleton properties should not be defined", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
  +      ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
  +      assertTrue("Singleton pushStateWhenCoordinator should be true", ssdc.isPushStateWhenCoordinator());
  +      assertEquals("Singleton pushStateWhenCoordinatorTimeout should be default value", 5000, ssdc.getPushStateWhenCoordinatorTimeout());      
  +
  +      /************************************************************************************************************/      
   
         conf = "<config>" +
                 "<passivation>false</passivation>" +
  @@ -612,7 +697,9 @@
                 "    <properties>" +
                 "        location=" + getTempDir() +
                 "    </properties>" +
  -              "    <singletonStore pushStateWhenCoordinator=\"true\">true</singletonStore>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +
  +              "    </singletonStore>" +
                 "</cacheloader>" +
                 "</config>";
         clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  @@ -625,13 +712,53 @@
         catch (Exception e)
         {
         }
  +
  +      /************************************************************************************************************/      
  +
  +      conf = "<config>" +
  +              "<passivation>false</passivation>" +
  +              "<preload>/, /blah, /blah2</preload>" +
  +              "<cacheloader>" +
  +              "    <class>org.jboss.cache.loader.FileCacheLoader</class>" +
  +              "    <async>false</async>" +
  +              "    <fetchPersistentState>false</fetchPersistentState>" +
  +              "    <ignoreModifications>true</ignoreModifications>" +
  +              "    <properties>" +
  +              "        location=" + getTempDir() +
  +              "    </properties>" +
  +              "    <singletonStore>" +
  +              "       <enabled>true</enabled>" +
  +              "       <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>" +
  +              "    </singletonStore>" +
  +              "</cacheloader>" +
  +              "</config>";
  +      clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
  +      mgr = new CacheLoaderManager();
  +
  +      try
  +      {
  +         mgr.setConfig(clc, null);
  +         fail("A singleton store class implementation must extend AbstractDelegatingCacheLoader");
  +      }
  +      catch (Exception e)
  +      {
  +      }
      }
   
      private class MockCacheLoaderManager extends CacheLoaderManager
      {
  -      protected void addCacheListener(Cache cache, Object listener)
  +      @Override
  +      protected void setCacheInLoader(CacheSPI c, CacheLoader loader)
  +      {
  +         /* do nothing */
  +      }
  +   }
  +
  +   public static class MockSingletonStoreCacheLoader extends AbstractDelegatingCacheLoader
  +   {
  +      public MockSingletonStoreCacheLoader()
         {
  -         /* do nothing... */
  +         super(null);
         }
      }
   
  
  
  



More information about the jboss-cvs-commits mailing list