[jbosscache-commits] JBoss Cache SVN: r5321 - core/trunk/src/test/java/org/jboss/cache/marshall.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Thu Feb 7 08:36:10 EST 2008
Author: bstansberry at jboss.com
Date: 2008-02-07 08:36:10 -0500 (Thu, 07 Feb 2008)
New Revision: 5321
Added:
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
Log:
[JBAS-1287] Test marshalling of cache loader ops
Added: core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-02-07 13:36:10 UTC (rev 5321)
@@ -0,0 +1,143 @@
+package org.jboss.cache.marshall;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+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.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.loader.FileCacheLoaderConfig;
+import org.jboss.cache.misc.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests marshalling/unmarshalling during cache loader operations involving types
+ * not visible to the cache's default classloader.
+ *
+ * @author <a href="mailto:brian.stansberry at jboss.org">Brian Stansberry</a>
+ * @since 2.1.0
+ */
+ at Test(groups = {"functional", "jgroups"})
+public class CacheLoaderMarshallingTest extends RegionBasedMarshallingTestBase
+{
+ private static final String tmpDir = System.getProperty("java.io.tmpdir") + File.separatorChar + "CacheLoaderMarshallingTest";
+
+ private static final String className = "org.jboss.cache.marshall.MyUUID";
+
+ private Cache<Object, Object> cache;
+ private Fqn fqn = Fqn.fromString("/a");
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ originalClassLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown()
+ {
+ resetContextClassLoader();
+ TestingUtil.killCaches(cache);
+
+ File f = new File(tmpDir);
+ if (f.exists())
+ if (!f.delete())
+ f.deleteOnExit();
+ }
+
+ @Override
+ protected ClassLoader getClassLoader()
+ {
+ String[] includesClasses = {className};
+ String[] excludesClasses = {};
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
+ }
+
+ public void testCacheLoaderMarshalling() throws Exception
+ {
+ cacheLoaderMarshallingTest(false);
+ }
+
+ public void testCacheLoaderRegionBasedMarshalling() throws Exception
+ {
+ cacheLoaderMarshallingTest(true);
+ }
+
+ private void cacheLoaderMarshallingTest(boolean useRegionBased) throws Exception
+ {
+ cache = createCache(useRegionBased);
+ cache.start();
+
+ FooClassLoader loader = new FooClassLoader(originalClassLoader);
+
+ if (useRegionBased)
+ {
+ Region r = cache.getRegion(Fqn.ROOT, true);
+ r.registerContextClassLoader(loader);
+ r.activate();
+ }
+
+ Class clazz = loader.loadFoo();
+ Object obj = clazz.newInstance();
+
+ Thread.currentThread().setContextClassLoader(loader);
+ cache.put(fqn, "key", obj);
+
+ this.resetContextClassLoader();
+ cache.evict(fqn);
+
+ Thread.currentThread().setContextClassLoader(loader);
+ assertEquals(obj, cache.get(fqn, "key"));
+ }
+
+ private Cache createCache(boolean useRegionBased)
+ {
+ Cache cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+ Configuration config = cache.getConfiguration();
+ config.setUseRegionBasedMarshalling(useRegionBased);
+ config.setInactiveOnStartup(useRegionBased);
+
+ EvictionConfig ec = new EvictionConfig();
+ ec.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
+ ec.setWakeupIntervalSeconds(1000); // a long time; really disabled
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionFqn(Fqn.ROOT);
+ erc.setRegionName("_default_");
+ LRUConfiguration epc = new LRUConfiguration();
+ epc.setMaxNodes(1000);
+ epc.setTimeToLiveSeconds(1000);
+ erc.setEvictionPolicyConfig(epc);
+ List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>();
+ ercs.add(erc);
+ ec.setEvictionRegionConfigs(ercs);
+ config.setEvictionConfig(ec);
+
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ clc.setPassivation(true);
+ clc.setShared(false);
+ FileCacheLoaderConfig fclc = new FileCacheLoaderConfig();
+ fclc.setLocation(tmpDir);
+ List<IndividualCacheLoaderConfig> clcs = new ArrayList<IndividualCacheLoaderConfig>();
+ clcs.add(fclc);
+ clc.setIndividualCacheLoaderConfigs(clcs);
+ config.setCacheLoaderConfig(clc);
+
+ return cache;
+ }
+
+}
More information about the jbosscache-commits
mailing list