[jboss-cvs] JBossAS SVN: r100641 - in projects/cluster/ha-server-cache-jbc/trunk/src: test/java/org/jboss/ha/cachemanager and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 5 18:27:27 EST 2010


Author: bstansberry at jboss.com
Date: 2010-02-05 18:27:27 -0500 (Fri, 05 Feb 2010)
New Revision: 100641

Modified:
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManager.java
   projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java
Log:
[JBCLUSTER-250] Get eager-start caches working

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManager.java	2010-02-05 23:24:23 UTC (rev 100640)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManager.java	2010-02-05 23:27:27 UTC (rev 100641)
@@ -77,6 +77,8 @@
    public static final String DEFAULT_CORE_CACHE_JMX_ATTRIBUTES = "service=Cache,config=";
    public static final String DEFAULT_POJO_CACHE_JMX_ATTRIBUTES = "service=Cache,cacheType=PojoCache,config=";
    
+   private static final ThreadLocal<Boolean> starting = new ThreadLocal<Boolean>();
+   
    private MBeanServer mbeanServer;
    private String jmxDomain;
    private String coreCacheJmxAttributes = DEFAULT_CORE_CACHE_JMX_ATTRIBUTES;
@@ -343,27 +345,36 @@
          if (channelFactory == null)
             throw new IllegalStateException("Must provide a ChannelFactory before calling start()");
 
-         if (!configRegistryInjected)
+         try
          {
-            ((XmlParsingConfigurationRegistry) configRegistry).start();
+            starting.set(Boolean.TRUE);
+            
+            if (!configRegistryInjected)
+            {
+               ((XmlParsingConfigurationRegistry) configRegistry).start();
+            }
+            
+            startEagerStartCaches();
+            
+            CacheManagerLocator locator = CacheManagerLocator.getCacheManagerLocator();
+            if (locator.getDirectlyRegisteredManager() == null)
+               locator.registerCacheManager(this);
+            
+            PojoCacheManagerLocator pclocator = PojoCacheManagerLocator.getCacheManagerLocator();
+            if (pclocator.getDirectlyRegisteredManager() == null)
+               pclocator.registerCacheManager(this);
+            
+            // Bind ourself in the public JNDI space if configured to do so
+            if (jndiName != null)
+            {
+               Context ctx = new InitialContext();
+               this.bind(jndiName, this, CacheManager.class, ctx);
+               log.debug("Bound in JNDI under " + jndiName);
+            }
          }
-         
-         startEagerStartCaches();
-         
-         CacheManagerLocator locator = CacheManagerLocator.getCacheManagerLocator();
-         if (locator.getDirectlyRegisteredManager() == null)
-            locator.registerCacheManager(this);
-         
-         PojoCacheManagerLocator pclocator = PojoCacheManagerLocator.getCacheManagerLocator();
-         if (pclocator.getDirectlyRegisteredManager() == null)
-            pclocator.registerCacheManager(this);
-         
-         // Bind ourself in the public JNDI space if configured to do so
-         if (jndiName != null)
+         finally
          {
-            Context ctx = new InitialContext();
-            this.bind(jndiName, this, CacheManager.class, ctx);
-            log.debug("Bound in JNDI under " + jndiName);
+            starting.remove();
          }
          
          started = true;
@@ -625,7 +636,7 @@
    
    private void checkStarted()
    {
-      if (!started)
+      if (!started && Boolean.TRUE.equals(starting.get()) == false)
       {
          throw new IllegalStateException(getClass().getSimpleName() + " is not started.");
       }      

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java	2010-02-05 23:24:23 UTC (rev 100640)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java	2010-02-05 23:27:27 UTC (rev 100641)
@@ -7,18 +7,21 @@
 package org.jboss.ha.cachemanager;
 
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
 import org.jboss.cache.Cache;
 import org.jboss.cache.CacheStatus;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.config.ConfigurationRegistry;
+import org.jboss.cache.pojo.PojoCache;
 import org.jgroups.JChannelFactory;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
 /**
  * Tests CacheManager.
  *
@@ -29,7 +32,8 @@
    /**
     * A file that includes every configuration element I could think of
     */
-   public static final String DEFAULT_CONFIGURATION_FILE = "jbc3-registry-configs.xml";
+   public static final String DEFAULT_CONFIGURATION_FILE = "jboss-cache-configs.xml";
+   public static final String DEFAULT_CONFIG = "local-query";
 
    private Set<Cache<Object, Object>> caches = new HashSet<Cache<Object, Object>>();
 
@@ -66,7 +70,7 @@
       ConfigurationRegistry configRegistry = registry.getConfigurationRegistry();
 
       Set<String> configNames = registry.getConfigurationNames();
-      assertEquals(7, configNames.size());
+      assertEquals(17, configNames.size());
       Set<String> cacheNames = registry.getCacheNames();
       assertEquals(0, cacheNames.size());
 
@@ -158,6 +162,130 @@
       assertEquals("No configs", 0, registry.getConfigurationNames().size());
    }
    
+   public void testEagerStartCaches() throws Exception
+   {
+      JChannelFactory cf = new JChannelFactory();
+      cf.setMultiplexerConfig("stacks.xml");
+      cf.setExposeChannels(false);
+      cf.start();
+      CacheManager registry = new CacheManager(DEFAULT_CONFIGURATION_FILE, cf);
+      
+      Set<String> cores = new HashSet<String>();
+      cores.add("ha-partition");
+      cores.add("local-query");
+      registry.setEagerStartCaches(cores);
+//      Set<String> pojos = new HashSet<String>();
+//      pojos.add("test5");
+//      pojos.add("test6");
+//      registry.setEagerStartPojoCaches(pojos);
+      
+      registry.start();
+      
+      assertEquals(cores, registry.getCacheNames());
+//      assertEquals(pojos, registry.getPojoCacheNames());
+      
+      Set<Cache> caches = new HashSet<Cache>();
+      
+      for (String name : cores)
+      {
+         Cache cache = registry.getCache(name, false);
+         assertNotNull(cache);
+         assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+         caches.add(cache);
+      }
+      
+//      for (String name : pojos)
+//      {
+//         PojoCache pojocache = registry.getPojoCache(name, false);
+//         assertNotNull(pojocache);
+//         Cache cache = pojocache.getCache();
+//         assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+//         caches.add(cache);
+//      }
+//      
+      for (String name : cores)
+      {
+         registry.releaseCache(name);
+      }
+      
+//      for (String name : pojos)
+//      {
+//         registry.releaseCache(name);
+//      }
+      
+      for (Cache cache : caches)
+      {
+         assertEquals(CacheStatus.STARTED, cache.getCacheStatus());         
+      }
+      
+      registry.stop();
+      
+      for (Cache cache : caches)
+      {
+         assertEquals(CacheStatus.DESTROYED, cache.getCacheStatus());         
+      }
+      
+   }
+   
+   public void testAliasing() throws Exception
+   {
+      JChannelFactory cf = new JChannelFactory();
+      cf.setMultiplexerConfig("stacks.xml");
+      cf.setExposeChannels(false);
+      cf.start();
+      CacheManager registry = new CacheManager(DEFAULT_CONFIGURATION_FILE, cf);
+      registry.start();
+
+      Set<String> configNames = registry.getConfigurationNames();
+      assertEquals(17, configNames.size());
+      
+      assertEquals(0, registry.getCacheNames().size());
+      
+      assertEquals(0, registry.getPojoCacheNames().size());
+      
+      Map<String, String> aliases = new HashMap<String, String>();
+      aliases.put("alias", DEFAULT_CONFIG);
+      registry.setConfigAliases(aliases);
+      
+      Map<String, String> registered = registry.getConfigAliases();
+      assertEquals(1, registered.size());
+      assertEquals(DEFAULT_CONFIG, registered.get("alias"));
+      
+      configNames = registry.getConfigurationNames();
+      assertEquals(18, configNames.size());
+      assertTrue(configNames.contains("alias"));
+      
+      Cache cache = registry.getCache("alias", true);
+      assertNotNull(cache);
+      Cache other = registry.getCache(DEFAULT_CONFIG, false);
+      assertEquals(cache, other);
+      
+      assertEquals(1, registry.getCacheNames().size());
+      
+      registry.releaseCache(DEFAULT_CONFIG);
+      
+      assertEquals(1, registry.getCacheNames().size());
+      
+      registry.releaseCache("alias");
+      
+      assertEquals(0, registry.getCacheNames().size());
+      
+      PojoCache pcache = registry.getPojoCache("alias", true);
+      assertNotNull(pcache);
+      PojoCache otherPC = registry.getPojoCache(DEFAULT_CONFIG, false);
+      assertEquals(pcache, otherPC);
+      
+      assertEquals(1, registry.getPojoCacheNames().size());
+      
+      registry.releaseCache(DEFAULT_CONFIG);
+      
+      assertEquals(1, registry.getPojoCacheNames().size());
+      
+      registry.releaseCache("alias");
+      
+      assertEquals(0, registry.getPojoCacheNames().size());      
+   }
+   
    @SuppressWarnings("unchecked")
    private boolean areCachesEquivalent(Cache<Object, Object> a, Cache<Object, Object> b)
    {




More information about the jboss-cvs-commits mailing list