From jbosscache-commits at lists.jboss.org Mon Mar 31 13:53:53 2008 Content-Type: multipart/mixed; boundary="===============3599045718625298771==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r5479 - core/trunk/src/test/java/org/jboss/cache/marshall. Date: Mon, 31 Mar 2008 13:53:52 -0400 Message-ID: --===============3599045718625298771== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2008-03-31 13:53:52 -0400 (Mon, 31 Mar 2008) New Revision: 5479 Added: core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForStateT= ransferTest.java Log: JBCACHE-1170 - added test Added: core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForSt= ateTransferTest.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/InvalidRegionForState= TransferTest.java (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForState= TransferTest.java 2008-03-31 17:53:52 UTC (rev 5479) @@ -0,0 +1,90 @@ +package org.jboss.cache.marshall; + +import org.jboss.cache.Cache; +import org.jboss.cache.DefaultCacheFactory; +import org.jboss.cache.Fqn; +import org.jboss.cache.Region; +import org.jboss.cache.config.Configuration; +import org.jboss.cache.factories.UnitTestCacheConfigurationFactory; +import org.jboss.cache.misc.TestingUtil; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * This test ensures the CacheMarshaller doesn't use stale regions when at= tempting to unmarshall state transfers. Seen intermittently + * when async replication is used, since JGroups doesn't attempt to marsha= ll a return value, thereby leaving a stale region in thread local + * in the cache marshaller, which then gets reused when the thread is reus= ed to provide state. + *

+ * Need to ensure that the same thread is used to process incoming request= s as well as state transfers, hence limiting the JGroups + * thread pool size to 1. + *

+ * + * @author Manik Surtani (manik(a)jbo= ss.org) + * @since 2.1.0 + */ +(a)Test(groups =3D "functional") +public class InvalidRegionForStateTransferTest +{ + Cache c1, c2; + + @BeforeMethod + public void setUp() throws CloneNotSupportedException + { + c1 =3D new DefaultCacheFactory().createCache(UnitTes= tCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL= _ASYNC), false); + + String jgroupsCfg =3D c1.getConfiguration().getClusterConfig(); + + // make sure we use STATE_TRANSFER and not STREAMING_STATE_TRANSFER,= so the same thread pool is used for incoming calls and ST + jgroupsCfg =3D jgroupsCfg.replace("STREAMING_STATE_TRANSFER", "STATE= _TRANSFER"); + // also make sure we use a thread pool size of 1 + jgroupsCfg =3D jgroupsCfg.replaceFirst("thread_pool.max_threads=3D[0= -9]*;", "thread_pool.max_threads=3D1;"); + + System.out.println(">>>> " + jgroupsCfg); + c1.getConfiguration().setClusterConfig(jgroupsCfg); + + c1.getConfiguration().setUseRegionBasedMarshalling(true); + c1.start(); + + c2 =3D new DefaultCacheFactory().createCache(c1.getC= onfiguration().clone()); + + TestingUtil.blockUntilViewsReceived(60000, c1, c2); + } + + @AfterMethod + public void tearDown() + { + TestingUtil.killCaches(c1, c2); + } + + public void testUseOfInvalidRegion() + { + Fqn fqn =3D Fqn.fromString("/a/b/c/d"); + c1.getRegion(fqn.getParent(), true).registerContextClassLoader(getCl= ass().getClassLoader()); + c2.getRegion(fqn.getParent(), true).registerContextClassLoader(getCl= ass().getClassLoader()); + + // write something; will cause a stale region to be stored in C2's c= ache marshaller + c1.put(fqn, "k", "v"); + assert c1.get(fqn, "k").equals("v"); + + TestingUtil.sleepThread(250); // async repl + + // assert that this made it to c2 + assert c2.get(fqn, "k").equals("v"); + + // c2's cache marshaller's thread local would be polluted now. + + // restart c1 so that it forces a state transfer from c2 + c1.destroy(); + c1.create(); + Region r =3D c1.getRegion(fqn.getParent(), true); + r.registerContextClassLoader(getClass().getClassLoader()); + r.deactivate(); + c1.start(); + + TestingUtil.blockUntilViewsReceived(60000, c1, c2); + + // assert that the state has been transferred to C1 + assert c1.get(fqn, "k").equals("v"); + } +} --===============3599045718625298771==--