Author: jason.greene(a)jboss.com
Date: 2008-11-20 00:17:16 -0500 (Thu, 20 Nov 2008)
New Revision: 7181
Added:
core/branches/flat/src/test/java/org/jboss/starobrno/loader/
core/branches/flat/src/test/java/org/jboss/starobrno/loader/CacheLoaderTest.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CacheLoaderInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/loader/AbstractCacheLoader.java
Log:
Implement getMarshaller()
Add a cache loader test
Fix type-o
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-11-20
04:56:54 UTC (rev 7180)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-11-20
05:17:16 UTC (rev 7181)
@@ -21,12 +21,18 @@
*/
package org.jboss.starobrno;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Version;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.buddyreplication.GravitateResult;
-import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.marshall.Marshaller;
import org.jboss.starobrno.atomic.AtomicHashMap;
import org.jboss.starobrno.atomic.AtomicMap;
import org.jboss.starobrno.atomic.AtomicMapCache;
@@ -50,20 +56,15 @@
import org.jboss.starobrno.interceptors.InterceptorChain;
import org.jboss.starobrno.interceptors.base.CommandInterceptor;
import org.jboss.starobrno.invocation.InvocationContextContainer;
+import org.jboss.starobrno.loader.CacheLoaderManager;
import org.jboss.starobrno.lock.LockManager;
+import org.jboss.starobrno.marshall.ExtendedMarshaller;
import org.jboss.starobrno.notifications.Notifier;
import org.jboss.starobrno.statetransfer.StateTransferManager;
import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jboss.starobrno.transaction.TransactionTable;
import org.jgroups.Address;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* @author Mircea.Markus(a)jboss.com
*/
@@ -79,6 +80,7 @@
protected ComponentRegistry componentRegistry;
protected TransactionManager transactionManager;
protected RPCManager rpcManager;
+ protected ExtendedMarshaller marshaller;
private String name;
private EvictionManager evictionManager;
private DataContainer dataContainer;
@@ -96,6 +98,7 @@
TransactionManager transactionManager,
BatchContainer batchContainer,
RPCManager rpcManager, DataContainer dataContainer,
+ ExtendedMarshaller marshaller,
LockManager lockManager)
{
this.invocationContextContainer = invocationContextContainer;
@@ -109,6 +112,7 @@
this.rpcManager = rpcManager;
this.evictionManager = evictionManager;
this.dataContainer = dataContainer;
+ this.marshaller = marshaller;
this.lockManager = lockManager;
}
@@ -274,9 +278,9 @@
throw new IllegalStateException();//todo Implement me properly
}
- public Marshaller getMarshaller()
+ public ExtendedMarshaller getMarshaller()
{
- throw new IllegalStateException();//todo Implement me properly
+ return marshaller;
}
public void addInterceptor(CommandInterceptor i, int position)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java 2008-11-20 04:56:54
UTC (rev 7180)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java 2008-11-20 05:17:16
UTC (rev 7181)
@@ -21,27 +21,30 @@
*/
package org.jboss.starobrno;
+import java.util.List;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
import net.jcip.annotations.ThreadSafe;
+
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.buddyreplication.GravitateResult;
-import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.marshall.Marshaller;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.ComponentRegistry;
import org.jboss.starobrno.interceptors.base.CommandInterceptor;
import org.jboss.starobrno.loader.CacheLoader;
+import org.jboss.starobrno.loader.CacheLoaderManager;
import org.jboss.starobrno.lock.LockManager;
+import org.jboss.starobrno.marshall.ExtendedMarshaller;
import org.jboss.starobrno.notifications.Notifier;
import org.jboss.starobrno.statetransfer.StateTransferManager;
import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jboss.starobrno.transaction.TransactionTable;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.List;
-
/**
* A more detailed interface to {@link Cache}, which is used when writing plugins for or
extending JBoss Cache. A reference
* to this interface should only be obtained when it is passed in to your code, for
example when you write an
@@ -98,7 +101,7 @@
*
* @return an instance of {@link Marshaller}
*/
- Marshaller getMarshaller();
+ ExtendedMarshaller getMarshaller();
/**
* Retrieves the current CacheCacheLoaderManager instance associated with the current
Cache instance.
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CacheLoaderInterceptor.java 2008-11-20
04:56:54 UTC (rev 7180)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CacheLoaderInterceptor.java 2008-11-20
05:17:16 UTC (rev 7181)
@@ -147,7 +147,7 @@
}
// Reuse the lock and create a new entry for loading
- MVCCEntry n = creator.wrapEntryForWriting(ctx, key, false, true);
+ MVCCEntry n = creator.wrapEntryForWriting(ctx, key, true, false);
n = loadEntry(ctx, key, n);
}
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/loader/AbstractCacheLoader.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/loader/AbstractCacheLoader.java 2008-11-20
04:56:54 UTC (rev 7180)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/loader/AbstractCacheLoader.java 2008-11-20
05:17:16 UTC (rev 7181)
@@ -31,12 +31,12 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.marshall.Marshaller;
import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.marshall.EntryData;
import org.jboss.starobrno.marshall.EntryDataExceptionMarker;
import org.jboss.starobrno.marshall.EntryDataMarker;
+import org.jboss.starobrno.marshall.ExtendedMarshaller;
/**
* A convenience abstract implementation of a {@link CacheLoader}. Specific methods to
note are methods like
@@ -138,7 +138,7 @@
}
}
- protected Marshaller getMarshaller()
+ protected ExtendedMarshaller getMarshaller()
{
return cache.getMarshaller();
}
Added: core/branches/flat/src/test/java/org/jboss/starobrno/loader/CacheLoaderTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/loader/CacheLoaderTest.java
(rev 0)
+++
core/branches/flat/src/test/java/org/jboss/starobrno/loader/CacheLoaderTest.java 2008-11-20
05:17:16 UTC (rev 7181)
@@ -0,0 +1,86 @@
+package org.jboss.starobrno.loader;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.jboss.cache.CacheFactory;
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.UnitTestCacheFactory;
+import org.jboss.starobrno.config.CacheLoaderConfig;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.starobrno.util.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests CacheLoader
+ *
+ * @author Jason T. Greene
+ */
+
+@Test(groups = {"functional", "pessimistic"})
+public class CacheLoaderTest
+{
+ private ThreadLocal<CacheSPI<String, String>> cacheTL = new
ThreadLocal<CacheSPI<String, String>>();
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+
+ try
+ {
+ File dir = new File("file-loader-dir");
+ for (File file : dir.listFiles())
+ file.delete();
+ }
+ catch (Throwable t)
+ {
+ }
+
+
+ // start a single cache instance
+ CacheFactory<String, String> cf = new UnitTestCacheFactory<String,
String>();
+ CacheSPI<String, String> cache = (CacheSPI<String, String>)
cf.createCache("configs/local-tx.xml", false);
+ cache.getConfiguration().setEvictionConfig(null);
+ CacheLoaderConfig loaderConfig = new CacheLoaderConfig();
+ IndividualCacheLoaderConfig fileConfig = new IndividualCacheLoaderConfig();
+ fileConfig.setClassName("org.jboss.starobrno.loader.FileCacheLoader");
+ Properties p = new Properties();
+ p.setProperty("location", "file-loader-dir");
+ fileConfig.setProperties(p);
+ loaderConfig.addIndividualCacheLoaderConfig(fileConfig);
+ cache.getConfiguration().setCacheLoaderConfig(loaderConfig);
+ configure(cache.getConfiguration());
+ cache.start();
+ cacheTL.set(cache);
+
+ }
+
+ protected void configure(Configuration c)
+ {
+ }
+
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
+ {
+ CacheSPI<String, String> cache = cacheTL.get();
+ TestingUtil.killCaches(cache);
+ cacheTL.set(null);
+ }
+
+ public void testLoader()
+ {
+ CacheSPI<String, String> cache = cacheTL.get();
+ cache.put("foo", "foo-data");
+ cache.put("foo2", "foo2-data");
+ cache.evict("foo");
+ cache.evict("foo2");
+ assertEquals("foo-data", cache.get("foo"));
+ assertEquals("foo2-data", cache.get("foo2"));
+ }
+}
Property changes on:
core/branches/flat/src/test/java/org/jboss/starobrno/loader/CacheLoaderTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF