[jbosscache-commits] JBoss Cache SVN: r4515 - in core/trunk/src: main/java/org/jboss/cache/marshall and 3 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Sep 27 01:34:14 EDT 2007


Author: mircea.markus
Date: 2007-09-27 01:34:14 -0400 (Thu, 27 Sep 2007)
New Revision: 4515

Modified:
   core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
   core/trunk/src/main/java/org/jboss/cache/Node.java
   core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
   core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java
   core/trunk/src/main/resources/META-INF/local-lru-eviction-service.xml
   core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
   core/trunk/src/test/resources/log4j.xml
Log:
JBCACHE-1154

Modified: core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNode.java	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNode.java	2007-09-27 05:34:14 UTC (rev 4515)
@@ -20,7 +20,7 @@
    /**
     * Under this key the {@link #resident} attribute will be keept within the data map.
     */
-   protected static final String INTERNAL_IS_RESIDENT = "_jbosscache.internal.resident";
+   public static final String JBOSSCACHE_INTERNAL_RESIDENT = "_jbosscache.internal.resident";
 
    public boolean isDeleted()
    {
@@ -51,10 +51,10 @@
    {
       if (!resident)
       {
-         remove((K)INTERNAL_IS_RESIDENT);
+         remove((K)JBOSSCACHE_INTERNAL_RESIDENT);
       } else
       {
-         put((K)INTERNAL_IS_RESIDENT, (V)"True");
+         put((K)JBOSSCACHE_INTERNAL_RESIDENT, (V)Boolean.TRUE);
       }
    }
 
@@ -62,7 +62,7 @@
    public boolean isResident()
    {
       //hack - see setResident internals for details
-      return "True".equals(get((K)INTERNAL_IS_RESIDENT));
+      return Boolean.TRUE.equals(get((K)JBOSSCACHE_INTERNAL_RESIDENT));
    }
 
 

Modified: core/trunk/src/main/java/org/jboss/cache/Node.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Node.java	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/main/java/org/jboss/cache/Node.java	2007-09-27 05:34:14 UTC (rev 4515)
@@ -282,7 +282,8 @@
     * "keep LRU 10 nodes" - the resident nodes won't be counted within those 10 nodes,
     * and also won't be evicted when the threshold is reached.
     * N.B. calling this method won't have any effect on node's eviction, e.g. we won't consider this node as being
-    * 'used' in a LRU scenario
+    * 'used' in a LRU scenario. If the cache is used in a replicated environment then the resident property is also
+    * replicated across the cluster(just like attribute map)
     */
    boolean isResident();
 

Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java	2007-09-27 05:34:14 UTC (rev 4515)
@@ -34,11 +34,6 @@
    private static final int INDENT = 4;
 
    /**
-    * Metadata-entry needed for refering the node's metadata.
-    */
-   public static final String JBOSSCACHE_INTERNAL_RESIDENT = "_jbosscache.internal.resident";
-
-   /**
     * Debug log.
     */
    private static Log log = LogFactory.getLog(UnversionedNode.class);
@@ -717,7 +712,7 @@
 
    public boolean isResidentDirect()
    {
-      return getDataDirect().containsKey(AbstractNode.INTERNAL_IS_RESIDENT);
+      return getDataDirect().containsKey(JBOSSCACHE_INTERNAL_RESIDENT);
    }
 
    public Set<NodeSPI<K, V>> getChildrenDirect(boolean includeMarkedForRemoval)

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java	2007-09-27 05:34:14 UTC (rev 4515)
@@ -92,16 +92,4 @@
       return ret.toString();
 
    }
-
-
-   public Object invoke(Object object) throws Throwable
-   {
-      return super.invoke(object);    //To change body of overridden methods use File | Settings | File Templates.
-   }
-
-
-   public Object invoke(Object object, Object[] objects) throws Throwable
-   {
-      return super.invoke(object, objects);    //To change body of overridden methods use File | Settings | File Templates.
-   }
 }

Modified: core/trunk/src/main/resources/META-INF/local-lru-eviction-service.xml
===================================================================
--- core/trunk/src/main/resources/META-INF/local-lru-eviction-service.xml	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/main/resources/META-INF/local-lru-eviction-service.xml	2007-09-27 05:34:14 UTC (rev 4515)
@@ -106,11 +106,6 @@
                <attribute name="timeToLiveSeconds">8</attribute>
                <attribute name="maxAgeSeconds">10</attribute>
             </region>
-            <region name="/residentNodesTest">
-               <attribute name="maxNodes">3</attribute>
-               <attribute name="timeToLiveSeconds">800000</attribute>
-               <attribute name="maxAgeSeconds">100000</attribute>
-            </region>
          </config>
       </attribute>
    </mbean>

Modified: core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java	2007-09-27 05:34:14 UTC (rev 4515)
@@ -6,15 +6,19 @@
 import static org.testng.Assert.*;
 import static org.testng.Assert.assertNotNull;
 import org.jboss.cache.*;
+import org.jboss.cache.eviction.LRUConfiguration;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import org.jboss.cache.misc.TestingUtil;
 import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
 import org.jboss.cache.config.CacheLoaderConfig;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.loader.DummyInMemoryCacheLoader;
 import org.jboss.cache.loader.DummyCacheLoader;
 import org.jboss.cache.lock.IsolationLevel;
 
+import javax.transaction.TransactionManager;
 import java.util.List;
 import java.util.ArrayList;
 
@@ -31,27 +35,45 @@
    private CacheImpl<Object, Object> cache;
 
    private final String TEST_NODES_ROOT = "residentNodesTest";
+   private Configuration cacheConfig;
+   private Cache[] caches = {};
 
    @BeforeMethod(alwaysRun = true)
    public void setUp()
    {
-      cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-lru-eviction-service.xml", false);
+      cacheConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+      cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(cacheConfig, false);
       cache.getConfiguration().getEvictionConfig().setWakeupIntervalSeconds(1);
-      cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
-      CacheLoaderConfig.IndividualCacheLoaderConfig indCLConfig = new CacheLoaderConfig.IndividualCacheLoaderConfig();
-      indCLConfig.setClassName(DummyInMemoryCacheLoader.class.getName());
-      List<CacheLoaderConfig.IndividualCacheLoaderConfig> indCLConfigs = new ArrayList<CacheLoaderConfig.IndividualCacheLoaderConfig>();
-      indCLConfigs.add(indCLConfig);
-      CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
-      cacheLoaderConfig.setIndividualCacheLoaderConfigs(indCLConfigs);
-      cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
+      createNewRegion();
       cache.start();
    }
 
+   /**
+    * Setting up a new region for our purposes.
+    */
+   private void createNewRegion()
+   {
+      EvictionConfig evConfig = cache.getConfiguration().getEvictionConfig();
+      EvictionRegionConfig evRegConfig = new EvictionRegionConfig();
+      evRegConfig.setRegionFqn(Fqn.fromString("/"+TEST_NODES_ROOT));
+      evRegConfig.setEventQueueSize(3);
+      LRUConfiguration lruConfig = new LRUConfiguration();
+      lruConfig.setMaxAgeSeconds(100000);
+      lruConfig.setTimeToLiveSeconds(100000);
+      lruConfig.setMaxNodes(3);
+      evRegConfig.setEvictionPolicyConfig(lruConfig);
+      evConfig.getEvictionRegionConfigs().add(evRegConfig);
+      //end setting up region stuff
+   }
+
    @AfterMethod(alwaysRun = true)
    public void tearDown() throws Exception
    {
       cache.stop();
+      for (Cache c : caches)
+      {
+         if (c!= null) c.stop();
+      }
    }
 
    /**
@@ -168,7 +190,7 @@
    {
       Cache first = DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC));
       Cache second = DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC));
-      Cache[] caches = {first, second};
+      caches = new Cache[]{first, second};
       TestingUtil.blockUntilViewsReceived(caches, 5000);
 
       System.out.println("Caches started!");
@@ -182,17 +204,13 @@
 
       second.getRoot().getChild(fqn).setResident(false);
       assertFalse(first.getRoot().getChild(fqn).isResident());
-
-      for (Cache c : caches)
-      {
-         c.stop();
-      }
    }
 
    /**
     * If a node is marked as resident, and a get is made on that given node then an VISITED event would normally be
     * added to the eviction queue. In a LRU scenario, this will cause another node to be evicted given that the size of
     * the eviction queue is bounded. This test makes sure that this scenario will not hapen.
+    * //todo - check why it does not work fine in suite, but works individually
     */
    public void testNoEvictionEventsForResidentNodes() throws InterruptedException
    {
@@ -215,7 +233,7 @@
       cache.get(getSubFqn("/a"));
       cache.get(getSubFqn("/b"));
 
-      Thread.sleep(3000);//so that eviction is activated
+      TestingUtil.sleepThread(3000);//so that eviction is activated
 
       //a and b should exist as those were marked resident. Also they shouldn't be caunted as nodes in the eviction
       // queue
@@ -243,7 +261,8 @@
    public void testNoStringCache()
    {
       CacheFactory<Integer, Float> cacheFactory = DefaultCacheFactory.getInstance();
-      Cache<Integer, Float> cache = cacheFactory.createCache("META-INF/local-lru-eviction-service.xml", true);
+      Configuration cc = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+      Cache<Integer, Float> cache = cacheFactory.createCache(cc, true);
       cache.put(getSubFqn("/a"), 1, 5.3f);
       cache.put(getSubFqn("/b"), 1, 2.3f);
       cache.put(getSubFqn("/c"), 1, 7.3f);
@@ -258,14 +277,18 @@
 
    /**
     * When using optimistic locking , check to see that at commit time the cache is successfully updated.
+    * //todo - this test fails only if setup is called prio it. Should be something with nesting tx context- take a look
     */
    public void testResidencyAndOptimisticLocking() throws Exception
    {
-      javax.transaction.TransactionManager txManager = new DummyTransactionManagerLookup().getTransactionManager();
-      CacheImpl cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/optimistic-eviction.xml");
 
+      Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+      config.setNodeLockingOptimistic(true);
+      CacheImpl cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(config, true);
+//      CacheImpl cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/optimistic-eviction.xml");
+
       cache.put(Fqn.fromString("/a/b"), "key", "value");
-
+      TransactionManager txManager = cache.getTransactionManager();
       txManager.begin();
       cache.getRoot().getChild(Fqn.fromString("/a/b")).setResident(true);
       txManager.rollback();

Modified: core/trunk/src/test/resources/log4j.xml
===================================================================
--- core/trunk/src/test/resources/log4j.xml	2007-09-27 02:48:37 UTC (rev 4514)
+++ core/trunk/src/test/resources/log4j.xml	2007-09-27 05:34:14 UTC (rev 4515)
@@ -69,15 +69,15 @@
    -->
 
    <category name="org.jboss.cache">
-      <priority value="INFO"/>
+      <priority value="DEBUG"/>
    </category>
 
    <category name="org.jboss.tm">
-      <priority value="ERROR"/>
+      <priority value="DEBUG"/>
    </category>
 
    <category name="org.jgroups">
-      <priority value="ERROR"/>
+      <priority value="DEBUG"/>
    </category>
 
    <!-- ======================= -->
@@ -85,9 +85,8 @@
    <!-- ======================= -->
 
    <root>
-      <priority value="ERROR"/>
-       <appender-ref ref="CONSOLE"/> 
-      <!--<appender-ref ref="FILE"/>-->
+      <priority value="DEBUG"/>
+       <appender-ref ref="CONSOLE"/>
    </root>
 
 </log4j:configuration>




More information about the jbosscache-commits mailing list