weaver      2004/10/29 06:52:44

  Added:       components/cm/src/test/org/apache/jetspeed/cache/general
                        cache-test.xml InvocationCountingCache.java
                        TestCachingInterceptors.java
  Log:
  Start of a simple caching api.  Test cases
  
  Revision  Changes    Path
  1.1                  
jakarta-jetspeed-2/components/cm/src/test/org/apache/jetspeed/cache/general/cache-test.xml
  
  Index: cache-test.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd";>
  
  <!--
    - Application context definition for PortletEntity using Apache OJB.
        -->
  <beans>       
       
       <!-- define our caching service.  This one uses a simple hashmap and counts 
method access
        - for testing purposes 
         -->
       <bean id="systemCache" 
class="org.apache.jetspeed.cache.general.InvocationCountingCache" />
       
       <!-- This interceptor is responsible for retreiving/adding objects to the 
cache. -->
       <bean id="systemCachingInterceptor" 
class="org.apache.jetspeed.components.interceptors.CachingInterceptor" >
        <constructor-arg>
                <ref bean="systemCache"/>
        </constructor-arg>
       </bean>
      
      <!-- This interceptor is responsible for removing items from the cache -->
      <bean id="systemRemoveFromCacheInterceptor" 
class="org.apache.jetspeed.components.interceptors.RemoveFromCacheInterceptor" >
        <constructor-arg>
                <ref bean="systemCache"/>
        </constructor-arg>
      </bean>           
      
      <!-- We use a RegEx advisor to indicate when we should invoke the caching 
interceptor -->
      <bean id="mockCachingAdvisor" 
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
          <property name="advice">
               <ref bean="systemCachingInterceptor"/>
          </property>
          <property name="patterns">
           <list>
              <value>.*getValue</value>
          </list>
         </property>
      </bean>
      
      <!-- We use a RegEx advisor to indicate when we should invoke the remove from 
cache interceptor -->
      <bean id="mockRemoveFromCacheAdvisor" 
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
          <property name="advice">
               <ref bean="systemRemoveFromCacheInterceptor"/>
          </property>
          <property name="patterns">
           <list>
              <value>.*setValue</value>
          </list>
         </property>
      </bean>
      
      
      <!-- Simple object that will have its methods wrapped with cachinng aspects -->
      <bean id="baseMockTarget" 
class="org.apache.jetspeed.components.BaseMockComponent" >
        <constructor-arg index="0">
                <value>1</value>                
        </constructor-arg>
        <constructor-arg index="1">
                <value>value1</value>           
        </constructor-arg>
      </bean>
      
      <!-- Actual proxied component we will access from the bean factory.-->
        <bean id="mockComponent" 
           class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
                <value>org.apache.jetspeed.components.MockComponent</value>
        </property>
  
        <property name="target"><ref local="baseMockTarget"/></property>
        <property name="interceptorNames">
          <list>
              <value>mockCachingAdvisor</value>
              <value>mockRemoveFromCacheAdvisor</value>
          </list>
        </property>
      </bean>
  
  
  </beans>
  
  
  1.1                  
jakarta-jetspeed-2/components/cm/src/test/org/apache/jetspeed/cache/general/InvocationCountingCache.java
  
  Index: InvocationCountingCache.java
  ===================================================================
  /*
   * Created on Oct 20, 2004
   *
   * TODO To change the template for this generated file go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  package org.apache.jetspeed.cache.general;
  
  /**
   * <p>
   * InvocationCountingCache
   * </p>
   * <p>
   *
   * </p>
   * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
   * @version $Id: InvocationCountingCache.java,v 1.1 2004/10/29 13:52:44 weaver Exp $
   *
   */
  public class InvocationCountingCache extends SimpleHashMapCache
  {
      int getCount, putCount, removeCount, successGetCount, containsCount;
     
  
      public Object get( String key )
      {
          getCount++;
          
          Object value =  super.get(key);
          if(value != null)
          {
              successGetCount++;
          }
          
          return value;
      }
      
      public void put( String key, Object value )
      {
          putCount++;
          super.put(key, value);
      }
      
      public Object remove( String key )
      {
          removeCount++;
          return super.remove(key);
      }
      
      public boolean contains( String key )
      {
          containsCount++;
          return super.contains(key);
      }
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/cm/src/test/org/apache/jetspeed/cache/general/TestCachingInterceptors.java
  
  Index: TestCachingInterceptors.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cache.general;
  
  import org.apache.jetspeed.components.MockComponent;
  import org.apache.jetspeed.components.test.AbstractSpringTestCase;
  
  /**
   * <p>
   * TestCachingInterceptors
   * </p>
   * <p>
   *
   * </p>
   * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
   * @version $Id: TestCachingInterceptors.java,v 1.1 2004/10/29 13:52:44 weaver Exp $
   *
   */
  public class TestCachingInterceptors extends AbstractSpringTestCase
  {
         
      
      
      public void testInterceptors() throws Exception
      {
          MockComponent mc = (MockComponent) ctx.getBean("mockComponent");
          InvocationCountingCache cache = (InvocationCountingCache) 
ctx.getBean("systemCache");
          assertNotNull(mc);
          assertNotNull(cache);
          
          assertNotNull(mc.getValue("2"));
          assertEquals(1, cache.containsCount);
          assertEquals(0, cache.getCount);
          assertEquals(0, cache.successGetCount);
          assertEquals(1, cache.putCount);
          assertEquals(0, cache.removeCount);
          
          assertNotNull(mc.getValue("2"));
          assertEquals(2, cache.containsCount);
          assertEquals(1, cache.getCount);
          assertEquals(1, cache.successGetCount);
          assertEquals(1, cache.putCount);
          assertEquals(0, cache.removeCount);
          
          mc.setValue("2", "some other value");
          assertEquals(2, cache.containsCount);
          assertEquals(1, cache.getCount);
          assertEquals(1, cache.successGetCount);
          assertEquals(1, cache.putCount);
          assertEquals(1, cache.removeCount);
          
          assertEquals("some other value", mc.getValue("2"));
          assertEquals(3, cache.containsCount);
          assertEquals(1, cache.getCount);
          assertEquals(1, cache.successGetCount);
          assertEquals(2, cache.putCount);
          assertEquals(1, cache.removeCount);
      }
      
      
      protected String[] getConfigurations()
      {
          return new String[] {"org/apache/jetspeed/cache/general/cache-test.xml"};
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to