portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pau...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletcache TestTurbineCache.java
Date Tue, 22 Jan 2002 17:11:21 GMT
paulsp      02/01/22 09:11:21

  Modified:    build    build.xml
  Added:       src/java/org/apache/jetspeed/services/portletcache
                        TestTurbineCache.java
  Log:
  Add unit test for Turbine's ClobalCacheService
  
  Revision  Changes    Path
  1.123     +5 -4      jakarta-jetspeed/build/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/build/build.xml,v
  retrieving revision 1.122
  retrieving revision 1.123
  diff -u -r1.122 -r1.123
  --- build.xml	20 Jan 2002 15:02:36 -0000	1.122
  +++ build.xml	22 Jan 2002 17:11:21 -0000	1.123
  @@ -131,7 +131,7 @@
           <echo message="java.class.path = ${java.class.path}"/>        
           <echo message=""/>
           <echo message="java.home = ${java.home}"/>
  -  <echo message="ant.home = ${ant.home}"/>
  +        <echo message="ant.home = ${ant.home}"/>
           <echo message="user.home = ${user.home}"/>
           <echo message=""/>
           <echo message="basedir = ${basedir}"/>
  @@ -638,7 +638,8 @@
               <formatter type="plain" usefile="false"/>            
   
               <!-- Cactus unit tests -->            
  -            <test name="org.apache.jetspeed.modules.actions.TestJLoginUser"/>   
        
  +            <test name="org.apache.jetspeed.modules.actions.TestJLoginUser"/>
  +            <test name="org.apache.jetspeed.services.portletcache.TestTurbineCache"/>
   
           </junit>
       </target>
  @@ -664,8 +665,8 @@
               <formatter type="plain" usefile="false"/>            
   
               <!-- Cactus unit tests -->            
  -            <test name="org.apache.jetspeed.modules.actions.TestJLoginUser"/>   
        
  -
  +            <test name="org.apache.jetspeed.modules.actions.TestJLoginUser"/>
  +            <test name="org.apache.jetspeed.services.portletcache.TestTurbineCache"/>
           </junit>
       </target>
   
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletcache/TestTurbineCache.java
  
  Index: TestTurbineCache.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  package org.apache.jetspeed.services.portletcache;
  
  // Cactus and Junit imports
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import org.apache.cactus.ServletTestCase;
  
  // Turbine imports
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.services.cache.GlobalCacheService;
  import org.apache.turbine.services.cache.CachedObject;
  import org.apache.turbine.services.cache.ObjectExpiredException;
  import org.apache.turbine.services.cache.Refreshable;
  import org.apache.turbine.services.cache.RefreshableCachedObject;
  
  /**
   * TestTurbineCache
   *
   * @author <a href="paulsp@apache.org">Paul Spencer</a>
   * @version $Id: TestTurbineCache.java,v 1.1 2002/01/22 17:11:21 paulsp Exp $
   */
  public class TestTurbineCache extends ServletTestCase {
      
      private static final String cacheKey = new String("CacheKey");
      private static final String cacheKey_2 = new String("CacheKey_2");
      private static final long TURBINE_CACHE_REFRESH = 5000; // in millis
      private static final long TEST_EXPIRETIME = TURBINE_CACHE_REFRESH + 1000;
      private static final long TEST_TIMETOLIVE = TEST_EXPIRETIME * 5;
      private static final boolean turbineCachePatchApplied = false;
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestTurbineCache( String name ) {
          super( name );
      }
      
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[]) {
          junit.awtui.TestRunner.main( new String[] { TestTurbineCache.class.getName() } );
      }
   
      public void setup() {
          logger.warn("Caching test may take a few minutes");
          System.out.println("Caching test may take a few minutes");
      }
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite() {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite( TestTurbineCache.class );
      }
      
      /**
       * Simple test that verify an object can be created and deleted.
       * @throws Exception
       */
      public void testSimpleAddGetCacheObject() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          CachedObject cacheObject1 = null;
          
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Create object
          cacheObject1 = new CachedObject(testString);
          assertNotNull( "Failed to create a cachable object 1", cacheObject1);
          
          // Add object to cache
          globalCache.addObject(cacheKey, cacheObject1);
          
          // Get object from cache
          retrievedObject = globalCache.getObject(cacheKey);
          assertNotNull( "Did not retrieved a cached object 1", retrievedObject);
          assertTrue( "Did not retrieved a correct, expected cached object 1", retrievedObject
== cacheObject1);
          
          // Remove object from cache
          globalCache.removeObject(cacheKey);
          
          // Verify object removed from cache
          retrievedObject = null;
          cacheObject1 = null;
          try {
              retrievedObject = globalCache.getObject(cacheKey);
              assertNull( "Retrieved the deleted cached object 1 and did not get expected
ObjectExpiredException", retrievedObject);
              assertNotNull( "Did not get expected ObjectExpiredException retrieving a deleted
object", retrievedObject);
          } catch (ObjectExpiredException e) {
              assertNull( "Retrieved the deleted cached object 1, but caught expected ObjectExpiredException
exception", retrievedObject);
          } catch (Exception e) {
              throw e;
          }
          
          // Remove object from cache that does NOT exist in the cache
          globalCache.removeObject(cacheKey);
      }
      
      /**
       * Simple test that adds, retrieves, and deletes 2 object.
       *
       * @throws Exception
       */
      public void test2ObjectAddGetCachedObject() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          CachedObject cacheObject1 = null;
          CachedObject cacheObject2 = null;
          
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Create and add Object #1
          cacheObject1 = new CachedObject(testString);
          assertNotNull( "Failed to create a cachable object 1", cacheObject1);
          globalCache.addObject(cacheKey, cacheObject1);
          retrievedObject = globalCache.getObject(cacheKey);
          assertNotNull( "Did not retrieved a cached object 1", retrievedObject);
          assertEquals( "Did not retrieved correct cached object", cacheObject1, retrievedObject);
          
          // Create and add Object #2
          cacheObject2 = new CachedObject(testString);
          assertNotNull( "Failed to create a cachable object 2", cacheObject2);
          globalCache.addObject(cacheKey_2, cacheObject2);
          retrievedObject = globalCache.getObject(cacheKey_2);
          assertNotNull( "Did not retrieved a cached object 2", retrievedObject);
          assertEquals( "Did not retrieved correct cached object 2", cacheObject2, retrievedObject);
          
          // Get object #1
          retrievedObject = globalCache.getObject(cacheKey);
          assertNotNull( "Did not retrieved a cached object 1. Attempt #2", retrievedObject);
          assertEquals( "Did not retrieved correct cached object 1. Attempt #2", cacheObject1,
retrievedObject);
          
          // Get object #1
          retrievedObject = globalCache.getObject(cacheKey);
          assertNotNull( "Did not retrieved a cached object 1. Attempt #3", retrievedObject);
          assertEquals( "Did not retrieved correct cached object 1. Attempt #3", cacheObject1,
retrievedObject);
          
          // Get object #2
          retrievedObject = globalCache.getObject(cacheKey_2);
          assertNotNull( "Did not retrieved a cached object 2. Attempt #2", retrievedObject);
          assertEquals( "Did not retrieved correct cached object 2 Attempt #2", cacheObject2,
retrievedObject);
          
          // Remove objects
          globalCache.removeObject(cacheKey);
          globalCache.removeObject(cacheKey_2);
      }
      
      /**
       * Verify that an object will throw the ObjectExpiredException
       * when it now longer exists in cache.
       *
       * @throws Exception
       */    
      public void testObjectExpiration() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          CachedObject cacheObject = null;
          
          logger.warn("This test will take a few mintes");
          System.out.println("This test will take a few mintes");
          
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Create and add Object that expires in 1000 millis (1 second)
          cacheObject = new CachedObject(testString, 1000);
          assertNotNull( "Failed to create a cachable object", cacheObject);
          long addTime = System.currentTimeMillis();
          globalCache.addObject(cacheKey, cacheObject);
          
          // Try to get un-expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNotNull( "Did not retrieved a cached object", retrievedObject);
              assertEquals( "Did not retrieved correct cached object", cacheObject, retrievedObject);
          } catch (ObjectExpiredException e) {
              assertTrue( "Object expired early ( " + (System.currentTimeMillis() - addTime)
+ " millis)", false);
          } catch (Exception e) {
              throw e;
          }
          
          // Sleep 1500 Millis (1.5 seconds)
          Thread.sleep(1500);
          
          // Try to get expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNull( "Retrieved the expired cached object  and did not get expected ObjectExpiredException",
retrievedObject);
              assertNotNull( "Did not get expected ObjectExpiredException retrieving an expired
object", retrievedObject);
          } catch (ObjectExpiredException e) {
              assertNull( "Retrieved the expired cached object, but caught expected ObjectExpiredException
exception", retrievedObject);
          } catch (Exception e) {
              throw e;
          }
          
          // Remove objects
          globalCache.removeObject(cacheKey);
      }
  
      /**
       * Verify the all object will be flushed from the cache.
       *
       * This test can take server minutes.
       *
       * @throws Exception
       */    
  
      public void testCacheFlush() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          CachedObject cacheObject = null;
          
  
          /* FIXME: Remove this test when the caching
           * patch to Turbine has been applied
           */
          if (turbineCachePatchApplied == false) {
              System.out.println( "*** ");
              System.out.println( "* This test will NOT be run because the cache patch to
Turbine has");
              System.out.println( "* not been applied.");
              System.out.println( "*** ");
              logger.warn( "This test will NOT be run because the  "
              + "cache patch to Turbine has not been applied.");
          }
  
  /*
   * FIXME:  Uncomment the following after the cache path is applied
   *
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Create and add Object that expires in 1 turbine Refresh + 1 millis 
          cacheObject = new CachedObject(testString, (TURBINE_CACHE_REFRESH*5) + 1);
          assertNotNull( "Failed to create a cachable object", cacheObject);
          long addTime = System.currentTimeMillis();
          globalCache.addObject(cacheKey, cacheObject);
  
          // 1 Refresh
          Thread.sleep(TURBINE_CACHE_REFRESH + 1);
          assertTrue("No object in cache before flush", (0 < globalCache.getNumberOfObjects()));
          
          // Flush Cache
          globalCache.flushCache();
  
          // Wait 15 seconds, 3 Refresh
          Thread.sleep((TURBINE_CACHE_REFRESH * 2) + 1);
          assertEquals("After refresh", 0, globalCache.getNumberOfObjects());
          // Remove objects
          globalCache.removeObject(cacheKey);
  */        
      }
  
      /**
       * Verify the Cache count is correct.
       *
       * This test can take serveral minutes.
       *
       * @throws Exception
       */    
      
      public void testObjectCount() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          CachedObject cacheObject = null;
  
          /* FIXME: Remove this test when the caching
           * patch to Turbine has been applied
           */
          if (turbineCachePatchApplied == false) {
              System.out.println( "*** ");
              System.out.println( "* This test will NOT be run because the cache patch to
Turbine has");
              System.out.println( "* not been applied.");
              System.out.println( "*** ");
              logger.warn( "This test will NOT be run because the  "
              + "cache patch to Turbine has not been applied.");
          }
          
  /*
   * FIXME:  Uncomment the following after the cache path is applied
   *
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Wait 2 Refresh to allow for remove object to be deleted
          Thread.sleep(TURBINE_CACHE_REFRESH * 2);
          assertEquals("Initial Object Count", 0, globalCache.getNumberOfObjects());
  
          // Create and add Object that expires in 1 turbine Refresh + 1 millis 
          cacheObject = new CachedObject(testString, TURBINE_CACHE_REFRESH  + 1);
          assertNotNull( "Failed to create a cachable object", cacheObject);
          long addTime = System.currentTimeMillis();
          globalCache.addObject(cacheKey, cacheObject);
          
          assertEquals("After adding 1 Object", 1, globalCache.getNumberOfObjects());
          
          // Wait 1 Refresh
          Thread.sleep(TURBINE_CACHE_REFRESH + 1);
          assertEquals("After refresh", 1, globalCache.getNumberOfObjects());
  
          // Wait 2 additional Refresh
          Thread.sleep((TURBINE_CACHE_REFRESH * 2) + 1);
          assertEquals("After refresh", 0, globalCache.getNumberOfObjects());
  
          // Remove objects
          globalCache.removeObject(cacheKey);
  */        
      }
  
      /**
       * Verfy a refreshable object will refreshed in the following cases:
       * o The object is retrieved via getObject an it is stale.
       * o The object is determied to be stale during a cache
       *   refresh
       *
       * This test can take serveral minutes.
       *
       * @throws Exception
       */    
      public void testRefreshableObject() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          RefreshableCachedObject cacheObject = null;
          long addTime = 0;
          
          boolean turbineCachePatchApplied = false; // FIXME:  Remove when patch applied
          
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Create and add Object that expires in TEST_EXPIRETIME millis.
          cacheObject = new RefreshableCachedObject(new RefreshableObject(), TEST_EXPIRETIME);
          assertNotNull( "Failed to create a cachable object", cacheObject);
          globalCache.addObject(cacheKey, cacheObject);
          addTime = System.currentTimeMillis();
          
          // Try to get un-expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNotNull( "Did not retrieved a cached object", retrievedObject);
              assertEquals( "Did not retrieved correct cached object", cacheObject, retrievedObject);
          } catch (ObjectExpiredException e) {
              assertTrue( "Object expired early ( " + (System.currentTimeMillis() - addTime)
+ " millis)", false);
          } catch (Exception e) {
              throw e;
          }
          
          // Wait 1 Turbine cache refresh + 1 second.
          Thread.sleep(TEST_EXPIRETIME + 1000);
          
          // Try to get expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNotNull( "Did not retrieved a cached object, after sleep", retrievedObject);
              assertNotNull( "Cached object has no contents, after sleep.", ((RefreshableCachedObject)retrievedObject).getContents());
              assertTrue( "Object did not refresh.", ( ((RefreshableObject)((RefreshableCachedObject)retrievedObject).getContents()).getRefreshCount()
> 0));
              if (turbineCachePatchApplied == false) {
                  System.out.println( "*** ");
                  System.out.println( "* It appears the cache patch to Turbine MAY be applied,
but");
                  System.out.println( "* this test has not been updated!");
                  System.out.println( "*** ");
                  logger.warn( "It appears the cache patch to Turbine has "
                  + "been applied, but this test has not been updated!");
              }
          } catch (ObjectExpiredException e) {
              /* FIXME: Remove the if test and false section when the caching
               * patch to Turbine has been applied
               */
              if (turbineCachePatchApplied == true) {
                  assertTrue( "Received unexpected ObjectExpiredException exception "
                  + "when retrieving refreshable object after ( "
                  + (System.currentTimeMillis() - addTime) + " millis)", false);
              } else {
                  System.out.println( "*** ");
                  System.out.println( "* Their is a Turbine patch to resolve the following
error");
                  System.out.println( "*** ");
                  System.out.println( "Received unexpected ObjectExpiredException exception
"
                  + "when retrieving refreshable object after ( "
                  + (System.currentTimeMillis() - addTime) + " millis)");
                  logger.warn("Refreshable object did NOT refresh.  Their is a Turbine patch
to fix this problem.");
              }
          } catch (Exception e) {
              throw e;
          }
          
          // See if object will expires (testing every second for 100 seconds.  It sould not!
          /* FIXME: Remove the "&& (turbineCachePatchApplied == true)" test when the
           *        caching patch to turbine is applied
           */       
          for (int i=0; ((i<100) && (turbineCachePatchApplied == true)); i++) {

              Thread.sleep(1000); // Sleep 0.5 seconds
              
              // Try to get expired object
              try {
                  retrievedObject = null;
                  retrievedObject = globalCache.getObject(cacheKey);
                  assertNotNull( "Did not retrieved a cached object, after sleep", retrievedObject);
                  assertNotNull( "Cached object has no contents, after sleep.", ((RefreshableCachedObject)retrievedObject).getContents());
                  assertTrue( "Object did not refresh.", ( ((RefreshableObject)((RefreshableCachedObject)retrievedObject).getContents()).getRefreshCount()
> 0));
              } catch (ObjectExpiredException e) {
                  assertTrue( "Received unexpected ObjectExpiredException exception "
                  + "when retrieving refreshable object after ( "
                  + (System.currentTimeMillis() - addTime) + " millis)", false);
              } catch (Exception e) {
                  throw e;
              }
          }
          
          // Remove objects
          globalCache.removeObject(cacheKey);
      }
      
      /**
       * Verify a cached object will be delete after it has been
       * untouched beyond it's TimeToLive.
       *
       * This test can take serveral minutes.
       *
       * @throws Exception
       */    
      public void testRefreshableTimeToLive() throws Exception {
          String testString = new String( "This is a test");
          Object retrievedObject = null;
          RefreshableCachedObject cacheObject = null;
          long addTime = 0;
          
          GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
          .getInstance()
          .getService( GlobalCacheService.SERVICE_NAME );
          
          // Create and add Object that expires in TEST_EXPIRETIME millis.
          cacheObject = new RefreshableCachedObject(new RefreshableObject(), TEST_EXPIRETIME);
          assertNotNull( "Failed to create a cachable object", cacheObject);
          cacheObject.setTTL(TEST_TIMETOLIVE);
  
          // Verify TimeToLive was set
          assertEquals( "Returned TimeToLive", TEST_TIMETOLIVE, cacheObject.getTTL());
  
          // Add object to Cache
          globalCache.addObject(cacheKey, cacheObject);
          addTime = System.currentTimeMillis();
          
          // Try to get un-expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNotNull( "Did not retrieved a cached object", retrievedObject);
              assertEquals( "Did not retrieved correct cached object", cacheObject, retrievedObject);
          } catch (ObjectExpiredException e) {
              if (turbineCachePatchApplied == true) {
                 assertTrue( "Object expired early ( " + (System.currentTimeMillis() - addTime)
+ " millis)", false);
              } else {
                  System.out.println( "*** ");
                  System.out.println( "* Their is a Turbine patch to resolve the following
error");
                  System.out.println( "*** ");
                  System.out.println( "Object expired early ( " + (System.currentTimeMillis()
- addTime) + " millis)");
                  logger.warn( "Object expired early ( " + (System.currentTimeMillis() - addTime)
+ " millis)" );
              }
          } catch (Exception e) {
              throw e;
          }
          
          // Wait long enough to allow object to expire, but do not exceed TTL
          Thread.sleep(TEST_TIMETOLIVE - 2000);
          
          // Try to get expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNotNull( "Did not retrieved a cached object, after sleep", retrievedObject);
              assertNotNull( "Cached object has no contents, after sleep.", ((RefreshableCachedObject)retrievedObject).getContents());
              assertTrue( "Object did not refresh.", ( ((RefreshableObject)((RefreshableCachedObject)retrievedObject).getContents()).getRefreshCount()
> 0));
          } catch (ObjectExpiredException e) {
              if (turbineCachePatchApplied == true) {
                  assertTrue( "Received unexpected ObjectExpiredException exception "
                  + "when retrieving refreshable object after ( "
                  + (System.currentTimeMillis() - addTime) + " millis)", false);
              } else {
                  System.out.println( "*** ");
                  System.out.println( "* Their is a Turbine patch to resolve the following
error");
                  System.out.println( "*** ");
                  System.out.println(  "Received unexpected ObjectExpiredException exception
"
                  + "when retrieving refreshable object after ( "
                  + (System.currentTimeMillis() - addTime) + " millis)");
                  logger.warn( "Received unexpected ObjectExpiredException exception "
                  + "when retrieving refreshable object after ( "
                  + (System.currentTimeMillis() - addTime) + " millis)");
              }
          } catch (Exception e) {
              throw e;
          }
          
          // Wait long enough to allow object to expire and exceed TTL
          Thread.sleep(TEST_TIMETOLIVE +5000);
          
          // Try to get expired object
          try {
              retrievedObject = null;
              retrievedObject = globalCache.getObject(cacheKey);
              assertNull( "Retrieved a cached object, after exceeding TimeToLive", retrievedObject);
          } catch (ObjectExpiredException e) {
              if (turbineCachePatchApplied == true) {
                  assertNull( "Retrieved the expired cached object, but caught expected ObjectExpiredException
exception", retrievedObject);
              } else {
                  System.out.println( "*** ");
                  System.out.println( "* Their is a Turbine patch to resolve the following
error");
                  System.out.println( "*** ");
                  System.out.println( "Retrieved the expired cached object, but caught expected
ObjectExpiredException exception");
                  logger.warn( "Retrieved the expired cached object, but caught expected ObjectExpiredException
exception");
              }
          } catch (Exception e) {
              throw e;
          }
      }
  
      /**
       * Simple object that can be refreshed
       */
      class RefreshableObject implements Refreshable {
          
          private int refreshCount = 0;
          
          /**
           * Increment the refresh counter
           */
          public void refresh() {
              this.refreshCount++;
          }
          
          /**
           * Reutrn the number of time this object has been refreshed
           *
           * @return Number of times refresh() has been called
           */
          public int getRefreshCount() {
              return this.refreshCount;
          }
          
      }
      
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message