From jbosscache-commits at lists.jboss.org Thu Feb 7 08:36:10 2008 Content-Type: multipart/mixed; boundary="===============0596220923642587039==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r5321 - core/trunk/src/test/java/org/jboss/cache/marshall. Date: Thu, 07 Feb 2008 08:36:10 -0500 Message-ID: --===============0596220923642587039== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: bstansberry(a)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/CacheLoaderMarshalling= Test.java Log: [JBAS-1287] Test marshalling of cache loader ops Added: core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshal= lingTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallin= gTest.java (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallin= gTest.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.IndividualCacheLoaderConfi= g; +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 involvin= g types = + * not visible to the cache's default classloader. + * + * @author Brian Stansberr= y + * @since 2.1.0 + */ +(a)Test(groups =3D {"functional", "jgroups"}) +public class CacheLoaderMarshallingTest extends RegionBasedMarshallingTest= Base +{ + private static final String tmpDir =3D System.getProperty("java.io.tmpd= ir") + File.separatorChar + "CacheLoaderMarshallingTest"; + = + private static final String className =3D "org.jboss.cache.marshall.MyU= UID"; + = + private Cache cache; + private Fqn fqn =3D Fqn.fromString("/a"); + + @BeforeMethod(alwaysRun =3D true) + protected void setUp() throws Exception + { + originalClassLoader =3D Thread.currentThread().getContextClassLoader= (); = + } + + @AfterMethod(alwaysRun =3D true) + protected void tearDown() + { + resetContextClassLoader(); + TestingUtil.killCaches(cache); + = + File f =3D new File(tmpDir); + if (f.exists()) + if (!f.delete()) + f.deleteOnExit(); + } + + @Override + protected ClassLoader getClassLoader() + { + String[] includesClasses =3D {className}; + String[] excludesClasses =3D {}; + ClassLoader cl =3D Thread.currentThread().getContextClassLoader(); + return new SelectedClassnameClassLoader(includesClasses, excludesCla= sses, cl); + } + = + public void testCacheLoaderMarshalling() throws Exception + { + cacheLoaderMarshallingTest(false); + } + = + public void testCacheLoaderRegionBasedMarshalling() throws Exception + { + cacheLoaderMarshallingTest(true); + } + = + private void cacheLoaderMarshallingTest(boolean useRegionBased) throws = Exception + { + cache =3D createCache(useRegionBased); + cache.start(); + = + FooClassLoader loader =3D new FooClassLoader(originalClassLoader); + = + if (useRegionBased) + { + Region r =3D cache.getRegion(Fqn.ROOT, true); + r.registerContextClassLoader(loader); + r.activate(); + } + = + Class clazz =3D loader.loadFoo(); + Object obj =3D 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 =3D (CacheSPI) new DefaultCacheFactory()= .createCache(false); + Configuration config =3D cache.getConfiguration(); + config.setUseRegionBasedMarshalling(useRegionBased); + config.setInactiveOnStartup(useRegionBased); + = + EvictionConfig ec =3D new EvictionConfig(); + ec.setDefaultEvictionPolicyClass(LRUPolicy.class.getName()); + ec.setWakeupIntervalSeconds(1000); // a long time; really disabled + EvictionRegionConfig erc =3D new EvictionRegionConfig(); + erc.setRegionFqn(Fqn.ROOT); + erc.setRegionName("_default_"); + LRUConfiguration epc =3D new LRUConfiguration(); + epc.setMaxNodes(1000); + epc.setTimeToLiveSeconds(1000); + erc.setEvictionPolicyConfig(epc); + List ercs =3D new ArrayList(); + ercs.add(erc); + ec.setEvictionRegionConfigs(ercs); + config.setEvictionConfig(ec); + = + CacheLoaderConfig clc =3D new CacheLoaderConfig(); + clc.setPassivation(true); + clc.setShared(false); + FileCacheLoaderConfig fclc =3D new FileCacheLoaderConfig(); + fclc.setLocation(tmpDir); + List clcs =3D new ArrayList(); + clcs.add(fclc); + clc.setIndividualCacheLoaderConfigs(clcs); + config.setCacheLoaderConfig(clc); + = + return cache; + } + +} --===============0596220923642587039==--