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

Manik Surtani manik at jboss.org
Tue Jul 3 07:57:48 EDT 2007


  User: msurtani
  Date: 07/07/03 07:57:48

  Modified:    tests/functional/org/jboss/cache/jmx 
                        CacheJmxWrapperTest.java
  Log:
  listener based fixes
  
  Revision  Changes    Path
  1.10      +35 -43    JBossCache/tests/functional/org/jboss/cache/jmx/CacheJmxWrapperTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheJmxWrapperTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/jmx/CacheJmxWrapperTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- CacheJmxWrapperTest.java	15 Jun 2007 12:37:56 -0000	1.9
  +++ CacheJmxWrapperTest.java	3 Jul 2007 11:57:48 -0000	1.10
  @@ -2,16 +2,15 @@
   
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
  -import org.jboss.cache.CacheImpl;
   import org.jboss.cache.CacheStatus;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.Configuration.CacheMode;
  -import org.jboss.cache.loader.CacheLoader;
  -import org.jboss.cache.loader.FileCacheLoader;
  -import org.jboss.cache.loader.FileCacheLoaderConfig;
   import org.jboss.cache.misc.TestingUtil;
  +import org.jboss.cache.notifications.annotation.CacheListener;
  +import org.jboss.cache.notifications.annotation.CacheStarted;
  +import org.jboss.cache.notifications.annotation.CacheStopped;
  +import org.jboss.cache.notifications.event.Event;
   import org.jboss.cache.transaction.DummyTransactionManagerLookup;
   import org.jgroups.Address;
   import org.jgroups.stack.IpAddress;
  @@ -19,7 +18,6 @@
   import javax.management.ObjectName;
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
  -import java.util.ArrayList;
   import java.util.List;
   
   /**
  @@ -299,45 +297,14 @@
   
      public void testFailedStart() throws Exception
      {
  -      // since listener notifications are now delivered asynchronously via a thread pool, exceptions in cacheStarted()
  -      // will not cause the startup to fail.  Instead I've changed the test to use a mock cache loader which
  -      // will barf.
  -
         CacheJmxWrapper wrapper = new CacheJmxWrapper(createCache(createConfiguration()));
         registerWrapper(wrapper);
         assertEquals("Correct state", CacheStatus.INSTANTIATED, wrapper.getCacheStatus());
  -//      DisruptLifecycleListener listener = new DisruptLifecycleListener();
  -//      wrapper.getCache().addCacheListener(listener);
  -
  -
  -      List<CacheLoaderConfig.IndividualCacheLoaderConfig> list = new ArrayList<CacheLoaderConfig.IndividualCacheLoaderConfig>(1);
  -      list.add(new FileCacheLoaderConfig());
  -      CacheLoaderConfig clc = new CacheLoaderConfig();
  -      clc.setIndividualCacheLoaderConfigs(list);
  -      wrapper.getCache().getConfiguration().setCacheLoaderConfig(clc);
  -
         wrapper.create();
   
  -      CacheImpl ci = (CacheImpl) wrapper.getCache();
  -
  -      assertNotNull(ci.getCacheLoaderManager());
  -
  -      // now inject the cache loader with a mock cache loader
  -      CacheLoader normalCacheLoader = ci.getCacheLoaderManager().getCacheLoader();
  -      CacheLoader barfingCacheLoader = new FileCacheLoader()
  -      {
  -         public void start()
  -         {
  -            throw new CacheException("Prevent startup");
  -         }
  -
  -         public void stop()
  -         {
  -            throw new CacheException("Prevent stop");
  -         }
  -      };
  -
  -      ci.getCacheLoaderManager().setCacheLoader(barfingCacheLoader);
  +      DisruptLifecycleListener listener = new DisruptLifecycleListener();
  +      listener.setDisrupt(true);
  +      wrapper.getCache().addCacheListener(listener);
   
         assertEquals("Correct state", CacheStatus.CREATED, wrapper.getCacheStatus());
         try
  @@ -351,7 +318,7 @@
   
         assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
   
  -      ci.getCacheLoaderManager().setCacheLoader(normalCacheLoader);
  +      listener.setDisrupt(false);
   
         wrapper.start();
   
  @@ -361,7 +328,9 @@
         assertTrue(wrapper.getNumberOfNodes() > 0);
         assertEquals(0, wrapper.getNumberOfAttributes());
   
  -      ci.getCacheLoaderManager().setCacheLoader(barfingCacheLoader);
  +      listener.setDisrupt(true);
  +      // need to re-add the listener since the failed start would have nullified the notifier.
  +      cache.addCacheListener(listener);
   
         try
         {
  @@ -374,7 +343,7 @@
   
         assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
   
  -      ci.getCacheLoaderManager().setCacheLoader(normalCacheLoader);
  +      listener.setDisrupt(false);
   
         wrapper.stop();
         assertEquals("Correct state", CacheStatus.STOPPED, wrapper.getCacheStatus());
  @@ -452,4 +421,27 @@
         assertTrue("No spaces", html.indexOf(' ') == -1);
   
      }
  +
  +   @CacheListener
  +   public class DisruptLifecycleListener
  +   {
  +      private boolean disrupt;
  +
  +      @CacheStarted
  +      public void cacheStarted(Event e)
  +      {
  +         if (disrupt) throw new IllegalStateException("I don't want to start");
  +      }
  +
  +      @CacheStopped
  +      public void cacheStopped(Event e)
  +      {
  +         if (disrupt) throw new IllegalStateException("I don't want to stop");
  +      }
  +
  +      public void setDisrupt(boolean disrupt)
  +      {
  +         this.disrupt = disrupt;
  +      }
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list