From jbosscache-commits at lists.jboss.org Thu Sep 20 13:10:13 2007 Content-Type: multipart/mixed; boundary="===============5426661670455154842==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r4492 - core/trunk/src/test/java/org/jboss/cache/replicated. Date: Thu, 20 Sep 2007 13:10:12 -0400 Message-ID: --===============5426661670455154842== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2007-09-20 13:10:12 -0400 (Thu, 20 Sep 2007) New Revision: 4492 Added: core/trunk/src/test/java/org/jboss/cache/replicated/ExceptionTest.java Log: Added test for JBCACHE-1152 Added: core/trunk/src/test/java/org/jboss/cache/replicated/ExceptionTest.ja= va =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/replicated/ExceptionTest.java = (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/replicated/ExceptionTest.java = 2007-09-20 17:10:12 UTC (rev 4492) @@ -0,0 +1,86 @@ +package org.jboss.cache.replicated; + +import org.jboss.cache.Cache; +import org.jboss.cache.DefaultCacheFactory; +import org.jboss.cache.Fqn; +import org.jboss.cache.ReplicationException; +import org.jboss.cache.config.Configuration; +import org.jboss.cache.lock.TimeoutException; +import org.jboss.cache.misc.TestingUtil; +import org.jboss.cache.transaction.DummyTransactionManagerLookup; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; + +/** + * Tests the type of exceptions thrown for Lock Acquisition Timeouts versu= s Sync Repl Timeouts + * + * @author Manik Surtani + * @since 2.1.0 + */ +public class ExceptionTest +{ + private Cache cache1; + private Cache cache2; + private Fqn fqn =3D Fqn.fromString("/a"); + + @BeforeMethod + public void setUp() + { + cache1 =3D DefaultCacheFactory.getInstance().createCache(false); + cache2 =3D DefaultCacheFactory.getInstance().createCache(false); + + cache1.getConfiguration().setSyncCommitPhase(true); + cache1.getConfiguration().setSyncRollbackPhase(true); + cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_= SYNC); + cache1.getConfiguration().setTransactionManagerLookupClass(DummyTran= sactionManagerLookup.class.getName()); + + cache2.getConfiguration().setSyncCommitPhase(true); + cache2.getConfiguration().setSyncRollbackPhase(true); + cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_= SYNC); + cache2.getConfiguration().setTransactionManagerLookupClass(DummyTran= sactionManagerLookup.class.getName()); + } + + @AfterMethod + public void tearDown() + { + if (cache1 !=3D null) cache1.stop(); + if (cache2 !=3D null) cache2.stop(); + } + + @Test (groups =3D {"functional"}, expectedExceptions =3D {ReplicationEx= ception.class}) + public void testSyncReplTimeout() + { + cache1.getConfiguration().setSyncReplTimeout(1); // 1ms. this is *b= ound* to fail. + cache2.getConfiguration().setSyncReplTimeout(1); + + cache1.start(); + cache2.start(); + + TestingUtil.blockUntilViewsReceived(10000, cache1, cache2); + + cache1.put(fqn, "k", "v"); + } + + @Test (groups =3D {"functional"}, expectedExceptions =3D {TimeoutExcept= ion.class}) + public void testLockAcquisitionTimeout() throws Exception + { + cache2.getConfiguration().setLockAcquisitionTimeout(1); + + cache1.start(); + cache2.start(); + + TestingUtil.blockUntilViewsReceived(10000, cache1, cache2); + + // get a lock on cache 2 and hold on to it. + TransactionManager tm =3D cache2.getConfiguration().getRuntimeConfig= ().getTransactionManager(); + tm.begin(); + cache2.put(fqn, "block", "block"); + Transaction t =3D tm.suspend(); + + cache1.put(fqn, "k", "v"); + } +} --===============5426661670455154842==--