Author: galder.zamarreno(a)jboss.com
Date: 2008-07-07 14:12:35 -0400 (Mon, 07 Jul 2008)
New Revision: 6187
Added:
core/branches/1.4.X/tests/functional/org/jboss/cache/loader/MarshalledCacheLoaderTest.java
Modified:
core/branches/1.4.X/src/org/jboss/cache/TreeCache.java
core/branches/1.4.X/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/branches/1.4.X/src/org/jboss/cache/loader/FileCacheLoader.java
Log:
[JBCACHE-1357] Root region node is now created as UNINITIALIZED.
Modified: core/branches/1.4.X/src/org/jboss/cache/TreeCache.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/TreeCache.java 2008-07-07 14:39:36 UTC (rev
6186)
+++ core/branches/1.4.X/src/org/jboss/cache/TreeCache.java 2008-07-07 18:12:35 UTC (rev
6187)
@@ -100,6 +100,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang(a)jboss.org)
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
* @version $Id$
* <p/>
* @see <a
href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache
doc</a>
@@ -2301,6 +2302,9 @@
child = factory.createDataNode(type, name,
subtree.getFqnChild(i + 1),
parent, null, this);
+ // Add uninitialized flag so that data stored at the root of the
+ // region can be loaded/preloaded from the cache loader.
+ child.put(UNINITIALIZED, null);
parent.addChild(name, child);
}
finally
Modified:
core/branches/1.4.X/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/branches/1.4.X/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-07-07
14:39:36 UTC (rev 6186)
+++
core/branches/1.4.X/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-07-07
18:12:35 UTC (rev 6187)
@@ -30,6 +30,7 @@
* Loads nodes that don't exist at the time of the call into memory from the
CacheLoader
*
* @author Bela Ban
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
* @version $Id$
*/
public class CacheLoaderInterceptor extends Interceptor implements
CacheLoaderInterceptorMBean
@@ -169,9 +170,10 @@
{
DataNode n = cache.peek(fqn);
+ boolean mustLoad = mustLoad(n, key);
if (log.isTraceEnabled())
- log.trace("load element " + fqn + " mustLoad=" +
mustLoad(n, key));
- if (mustLoad(n, key))
+ log.trace("load element " + fqn + " mustLoad=" +
mustLoad);
+ if (mustLoad)
{
if (initNode)
{
@@ -254,6 +256,11 @@
private boolean mustLoad(DataNode n, Object key)
{
+ if (log.isTraceEnabled())
+ {
+ log.trace("mustLoad called with key=" + key + " and
datanode=" + n);
+ }
+
return n == null ||
(n.containsKey(TreeCache.UNINITIALIZED) && (key == null ||
!n.containsKey(key)));
}
Modified: core/branches/1.4.X/src/org/jboss/cache/loader/FileCacheLoader.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/loader/FileCacheLoader.java 2008-07-07
14:39:36 UTC (rev 6186)
+++ core/branches/1.4.X/src/org/jboss/cache/loader/FileCacheLoader.java 2008-07-07
18:12:35 UTC (rev 6187)
@@ -560,6 +560,10 @@
FileInputStream in = new FileInputStream(child);
MarshalledValueInputStream input = new MarshalledValueInputStream(in);
Map m = (Map) input.readObject();
+ if (log.isTraceEnabled())
+ {
+ log.trace("Read fqn="+ fqn + " from file input stream and
returned " + m);
+ }
in.close();
return m;
}
@@ -573,6 +577,10 @@
throw new IOException("Unable to create file: " + child);
FileOutputStream out = new FileOutputStream(child);
ObjectOutputStream output = new ObjectOutputStream(out);
+ if (log.isTraceEnabled())
+ {
+ log.trace("Writing to file output stream: fqn="+ fqn + "
modifications=" + attrs);
+ }
output.writeObject(attrs);
out.close();
}
Added:
core/branches/1.4.X/tests/functional/org/jboss/cache/loader/MarshalledCacheLoaderTest.java
===================================================================
---
core/branches/1.4.X/tests/functional/org/jboss/cache/loader/MarshalledCacheLoaderTest.java
(rev 0)
+++
core/branches/1.4.X/tests/functional/org/jboss/cache/loader/MarshalledCacheLoaderTest.java 2008-07-07
18:12:35 UTC (rev 6187)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.cache.loader;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Node;
+import org.jboss.cache.TreeCache;
+
+/**
+ * Unit test for checking interaction between cache loader and marshalled
+ * regions.
+ *
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
+ */
+public class MarshalledCacheLoaderTest extends AbstractCacheLoaderTestBase
+{
+ private static final Log log = LogFactory.getLog(MarshalledCacheLoaderTest.class);
+
+ private TreeCache cache;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ cache=new TreeCache();
+ cache.setCacheMode("LOCAL");
+
cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
+ cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("true",
"org.jboss.cache.loader.FileCacheLoader", "", false, true, false));
+ cache.setUseRegionBasedMarshalling(true);
+ cache.setInactiveOnStartup(true);
+ cache.startService();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ cache.remove("/");
+ cache.stopService();
+ cache.destroyService();
+ }
+
+ public void testLoadNodesAtRootOfRegion() throws Exception
+ {
+ String rootRegionName = "/myregion";
+ String fqn = rootRegionName + "/here";
+
+ cache.registerClassLoader(rootRegionName,
Thread.currentThread().getContextClassLoader());
+ cache.activateRegion(rootRegionName);
+ cache.put(rootRegionName, "a key", "a value");
+ cache.put(fqn, "another key", "another value");
+
+ cache.inactivateRegion(rootRegionName);
+ cache.unregisterClassLoader(rootRegionName);
+
+ cache.stopService();
+ cache.destroyService();
+
+ cache.startService();
+
+ cache.registerClassLoader(rootRegionName,
Thread.currentThread().getContextClassLoader());
+ cache.activateRegion(rootRegionName);
+
+ Node rootRegionNode = cache.get(rootRegionName);
+ Node fqnNode = cache.get(fqn);
+ assertNotNull(rootRegionNode);
+ assertNotNull(fqnNode);
+
+ assertEquals(fqnNode.get("another key"), "another value");
+ assertEquals(rootRegionNode.get("a key"), "a value");
+ }
+
+}