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

Brian Stansberry brian.stansberry at jboss.com
Tue May 22 21:37:03 EDT 2007


  User: bstansberry
  Date: 07/05/22 21:37:03

  Modified:    tests/functional/org/jboss/cache/jmx 
                        CacheJmxWrapperTest.java
  Log:
  [JBCACHE-1058] Test duplicate invocations; lifecycle state
  
  Revision  Changes    Path
  1.5       +94 -0     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.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- CacheJmxWrapperTest.java	22 May 2007 23:00:45 -0000	1.4
  +++ CacheJmxWrapperTest.java	23 May 2007 01:37:03 -0000	1.5
  @@ -6,8 +6,11 @@
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   
  +import org.jboss.cache.AbstractCacheListener;
   import org.jboss.cache.Cache;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.LifecycleState;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.Configuration.CacheMode;
   import org.jboss.cache.misc.TestingUtil;
  @@ -264,6 +267,79 @@
         }
      }
   
  +   public void testDuplicateInvocation() throws Exception
  +   {
  +      CacheJmxWrapperMBean cache = registerWrapper();
  +      cache.create();
  +      cache.start();
  +      cache.create();
  +      cache.start();
  +
  +      cache.getCache().put(Fqn.fromString("/a/b/c"), null);
  +      assertTrue(cache.getNumberOfNodes() > 0);
  +      assertEquals(0, cache.getNumberOfAttributes());
  +
  +      System.out.println("cache locks before restart:\n" + cache.getLockInfo());
  +      cache.destroy();
  +      cache.start();
  +      System.out.println("cache locks after restart:\n" + cache.getLockInfo());
  +
  +      assertTrue(cache.getNumberOfNodes() > 0);
  +      assertEquals(0, cache.getNumberOfAttributes());
  +      
  +      cache.stop();
  +      cache.destroy();
  +      cache.stop();
  +      cache.destroy();
  +   }
  +   
  +   public void testFailedStart() throws Exception
  +   {
  +      CacheJmxWrapper wrapper = new CacheJmxWrapper(createCache(createConfiguration()));
  +      registerWrapper(wrapper);
  +      assertEquals("Correct state", LifecycleState.INSTANTIATED, wrapper.getLifecycleState());
  +      DisruptLifecycleListener listener = new DisruptLifecycleListener();
  +      wrapper.getCache().addCacheListener(listener);
  +      wrapper.create();
  +      assertEquals("Correct state", LifecycleState.CREATED, wrapper.getLifecycleState());
  +      try
  +      {
  +         wrapper.start();
  +         fail("Listener did not prevent start");         
  +      }
  +      catch (IllegalStateException good) {}
  +      
  +      assertEquals("Correct state", LifecycleState.FAILED, wrapper.getLifecycleState());
  +      
  +      wrapper.getCache().removeCacheListener(listener);
  +      
  +      wrapper.start();
  +      
  +      assertEquals("Correct state", LifecycleState.STARTED, wrapper.getLifecycleState());
  +      
  +      wrapper.getCache().put(Fqn.fromString("/a/b/c"), null);
  +      assertTrue(wrapper.getNumberOfNodes() > 0);
  +      assertEquals(0, wrapper.getNumberOfAttributes());
  +      
  +      wrapper.getCache().addCacheListener(listener);      
  +
  +      try
  +      {
  +         wrapper.stop();
  +         fail("Listener did not prevent stop");         
  +      }
  +      catch (IllegalStateException good) {}
  +      
  +      assertEquals("Correct state", LifecycleState.FAILED, wrapper.getLifecycleState());
  +      
  +      wrapper.getCache().removeCacheListener(listener);
  +      
  +      wrapper.stop();
  +      assertEquals("Correct state", LifecycleState.STOPPED, wrapper.getLifecycleState());
  +      wrapper.destroy();
  +      assertEquals("Correct state", LifecycleState.DESTROYED, wrapper.getLifecycleState());
  +   }
  +
      private String getCacheDetailsTest(boolean html) throws Exception
      {
         CacheJmxWrapperMBean wrapper = registerWrapper();
  @@ -334,4 +410,22 @@
         assertTrue("No spaces", html.indexOf(' ') == -1);
         
      }
  +
  +
  +   class DisruptLifecycleListener extends AbstractCacheListener
  +   {
  +
  +      @Override
  +      public void cacheStarted(CacheSPI cache)
  +      {
  +         throw new IllegalStateException("I don't want to start");
  +      }
  +
  +      @Override
  +      public void cacheStopped(CacheSPI cache)
  +      {
  +         throw new IllegalStateException("I don't want to stop");
  +      }
  +      
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list