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

Manik Surtani msurtani at jboss.com
Thu Jan 11 08:49:07 EST 2007


  User: msurtani
  Date: 07/01/11 08:49:07

  Modified:    tests/functional/org/jboss/cache/factories   
                        InterceptorChainFactoryTest.java
                        CustomInterceptorChainTest.java
  Added:       tests/functional/org/jboss/cache/factories   
                        UnitTestCacheFactory.java
  Log:
  Changed CacheImpl ctor to be protected, and changed cache factories accordingly
  
  Revision  Changes    Path
  1.8       +10 -9     JBossCache/tests/functional/org/jboss/cache/factories/InterceptorChainFactoryTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InterceptorChainFactoryTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/factories/InterceptorChainFactoryTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- InterceptorChainFactoryTest.java	3 Jan 2007 15:33:10 -0000	1.7
  +++ InterceptorChainFactoryTest.java	11 Jan 2007 13:49:06 -0000	1.8
  @@ -4,6 +4,7 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   import org.jboss.cache.CacheImpl;
  +import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.config.BuddyReplicationConfig;
   import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.config.EvictionConfig;
  @@ -21,7 +22,7 @@
      protected void setUp() throws Exception
      {
         super.setUp();
  -      cache = new CacheImpl();
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setCacheMode("LOCAL");
      }
   
  @@ -191,7 +192,7 @@
   
      public void testOptimisticChain() throws Exception
      {
  -      CacheImpl cache = new CacheImpl();
  +      CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setExposeManagementStatistics(false);
         cache.getConfiguration().setNodeLockingOptimistic(true);
   
  @@ -217,7 +218,7 @@
   
      public void testOptimisticReplicatedChain() throws Exception
      {
  -      CacheImpl cache = new CacheImpl();
  +      CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setExposeManagementStatistics(false);
         cache.getConfiguration().setNodeLockingOptimistic(true);
         cache.getConfiguration().setCacheMode("REPL_SYNC");
  @@ -245,7 +246,7 @@
   
      public void testOptimisticCacheLoaderChain() throws Exception
      {
  -      CacheImpl cache = new CacheImpl();
  +      CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setExposeManagementStatistics(false);
         cache.getConfiguration().setNodeLockingOptimistic(true);
         cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(false, false));
  @@ -274,7 +275,7 @@
   
      public void testOptimisticPassivationCacheLoaderChain() throws Exception
      {
  -      CacheImpl cache = new CacheImpl();
  +      CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setExposeManagementStatistics(false);
         cache.getConfiguration().setNodeLockingOptimistic(true);
         cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(true, false));
  @@ -304,7 +305,7 @@
   
      public void testInvalidationInterceptorChain() throws Exception
      {
  -      CacheImpl cache = new CacheImpl();
  +      CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setExposeManagementStatistics(false);
         cache.getConfiguration().setCacheMode("REPL_ASYNC");
   
  @@ -327,7 +328,7 @@
         // ok, my replication chain looks good.
   
         // now for my invalidation chain.
  -      cache = new CacheImpl();
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setExposeManagementStatistics(false);
         cache.getConfiguration().setCacheMode("INVALIDATION_ASYNC");
         chain = new InterceptorChainFactory().buildInterceptorChain(cache);
  @@ -417,7 +418,7 @@
   
         cache.getConfiguration().setCacheMode("REPL_SYNC");
         cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
  -      cache.create(); // initialise various subsystems such as BRManager
  +      cache.create();// initialise various subsystems such as BRManager
         Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
   
         List<Interceptor> list = InterceptorChainFactory.asList(chain);
  @@ -456,7 +457,7 @@
         cache.getConfiguration().setBuddyReplicationConfig(brc);
   
         cache.getConfiguration().setCacheMode("REPL_SYNC");
  -      cache.create(); // initialise various subsystems such as BRManager
  +      cache.create();// initialise various subsystems such as BRManager
         Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
   
         List<Interceptor> list = InterceptorChainFactory.asList(chain);
  
  
  
  1.5       +1 -0      JBossCache/tests/functional/org/jboss/cache/factories/CustomInterceptorChainTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CustomInterceptorChainTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/factories/CustomInterceptorChainTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- CustomInterceptorChainTest.java	3 Jan 2007 18:21:23 -0000	1.4
  +++ CustomInterceptorChainTest.java	11 Jan 2007 13:49:06 -0000	1.5
  @@ -1,6 +1,7 @@
   package org.jboss.cache.factories;
   
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.DefaultCacheFactory;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.interceptors.Interceptor;
   
  
  
  
  1.1      date: 2007/01/11 13:49:06;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/factories/UnitTestCacheFactory.java
  
  Index: UnitTestCacheFactory.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.factories;
  
  import org.jboss.cache.Cache;
  import org.jboss.cache.DefaultCacheFactory;
  import org.jboss.cache.config.CacheLoaderConfig;
  import org.jboss.cache.config.Configuration;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.config.ConfigurationException;
  import org.jboss.cache.xml.XmlHelper;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  
  import java.io.InputStream;
  
  /**
   * Cache factory used by unit tests.
   */
  public class UnitTestCacheFactory
  {
     public static String JGROUPS_CHANNEL = "udp";//use udp by default
     public static String JGROUPS_STACK_TYPE = "jgroups.stack";
     public static String DEFAULT_CONFIGURATION_FILE = "META-INF/unit-test-cache-service.xml";
  
     static
     {
        JGROUPS_CHANNEL = System.getProperty(JGROUPS_STACK_TYPE, JGROUPS_CHANNEL);
     }
  
  
     public static Cache createCache() throws ConfigurationException
     {
        return createCache(new Configuration());
     }
  
     public static Cache createCache(CacheMode mode, boolean start) throws ConfigurationException
     {
        return createCache(createConfiguration(mode), start);
     }
  
     public static Configuration createConfiguration(CacheMode mode) throws ConfigurationException
     {
        return createConfiguration(mode, false, false);
     }
  
     public static Configuration createConfiguration(CacheMode mode, boolean useEviction) throws ConfigurationException
     {
        return createConfiguration(mode, useEviction, false);
     }
  
     public static Configuration createConfiguration(CacheMode mode, boolean useEviction, boolean usePassivation) throws ConfigurationException
     {
        UnitTestXmlConfigurationParser parser = new UnitTestXmlConfigurationParser();
        Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE, mode);
  
        if (!useEviction)
        {
           c.setEvictionConfig(null);
        }
  
        if (!usePassivation)
        {
           c.setCacheLoaderConfig(null);
        }
  
        return c;
     }
  
     public static Cache createCache(Configuration configuration) throws ConfigurationException
     {
        return createCache(configuration, true);
     }
  
     public static Cache createCache(Configuration configuration, boolean start) throws ConfigurationException
     {
        try
        {
           return DefaultCacheFactory.getInstance().createCache(configuration, start);
        }
        catch (Exception e)
        {
           if (e instanceof ConfigurationException) throw (ConfigurationException) e;
           if (e instanceof RuntimeException) throw (RuntimeException) e;
           throw new RuntimeException(e);
        }
     }
  
     public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared) throws Exception
     {
        return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async, fetchPersistentState, shared, false);
     }
  
     public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
     {
        return getSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, async, fetchPersistentState, shared, purgeOnStartup);
     }
  
     protected static CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
     {
        String xml = "<config>\n" +
                "<passivation>" + passivation + "</passivation>\n" +
                "<preload>" + preload + "</preload>\n" +
                "<cacheloader>\n" +
                "<class>" + cacheloaderClass + "</class>\n" +
                "<properties>" + properties + "</properties>\n" +
                "<async>" + async + "</async>\n" +
                "<shared>" + shared + "</shared>\n" +
                "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
                "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
                "</cacheloader>\n" +
                "</config>";
        Element element = XmlHelper.stringToElement(xml);
        return XmlConfigurationParser.parseCacheLoaderConfig(element);
     }
  
     private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser
     {
  
        public Configuration parseFile(String filename, CacheMode mode)
        {
           return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE), mode);
        }
  
        public Configuration parseStream(InputStream stream, CacheMode mode)
        {
           // loop through all elements in XML.
           if (stream == null) throw new ConfigurationException("Input stream for configuration xml is null!");
  
           Element root = XmlHelper.getDocumentRoot(stream);
           Element mbeanElement = getMBeanElement(root);
  
           ParsedAttributes attributes = extractAttributes(mbeanElement);
  
           // Special handling for the old separate property for
           // eviction policy -- just cache it and use with the eviction XML
           String defaultEvictionClass = (String) attributes.stringAttribs.remove("EvictionPolicyClass");
  
           // Deal with rename of the old property that controlled MBean registration
           String keepStats = (String) attributes.stringAttribs.remove("UseMbean");
           if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
           {
              attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
           }
  
           Configuration c = new Configuration();
           setValues(c, attributes.stringAttribs, false);
           // Special handling for XML elements -- we hard code the parsing
           setXmlValues(c, attributes.xmlAttribs, defaultEvictionClass);
  
           Element list = (Element) root.getElementsByTagName("protocol_stacks").item(0);
           NodeList stacks = list.getElementsByTagName("stack");
  
           for (int i = 0; i < stacks.getLength(); i++)
           {
              Element stack = (Element) stacks.item(i);
              String stackName = stack.getAttribute("name");
              if (stackName.startsWith(JGROUPS_CHANNEL))
              {
                 Element jgroupsStack = (Element) stack.getElementsByTagName("config").item(0);
                 if (mode == CacheMode.REPL_ASYNC && !stackName.contains("-"))
                 {
                    c.setClusterConfig(jgroupsStack);
                    c.setCacheMode(CacheMode.REPL_ASYNC);
                    break;
                 }
                 else if (mode == CacheMode.REPL_SYNC && stackName.contains("-"))
                 {
                    c.setClusterConfig(jgroupsStack);
                    c.setCacheMode(CacheMode.REPL_SYNC);
                    break;
                 }
              }
           }
           return c;
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list