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.java
===================================================================
--- 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 versus Sync Repl
Timeouts
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.1.0
+ */
+public class ExceptionTest
+{
+ private Cache cache1;
+ private Cache cache2;
+ private Fqn fqn = Fqn.fromString("/a");
+
+ @BeforeMethod
+ public void setUp()
+ {
+ cache1 = DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = DefaultCacheFactory.getInstance().createCache(false);
+
+ cache1.getConfiguration().setSyncCommitPhase(true);
+ cache1.getConfiguration().setSyncRollbackPhase(true);
+ cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+
cache1.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+ cache2.getConfiguration().setSyncCommitPhase(true);
+ cache2.getConfiguration().setSyncRollbackPhase(true);
+ cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+
cache2.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (cache1 != null) cache1.stop();
+ if (cache2 != null) cache2.stop();
+ }
+
+ @Test (groups = {"functional"}, expectedExceptions =
{ReplicationException.class})
+ public void testSyncReplTimeout()
+ {
+ cache1.getConfiguration().setSyncReplTimeout(1); // 1ms. this is *bound* to fail.
+ cache2.getConfiguration().setSyncReplTimeout(1);
+
+ cache1.start();
+ cache2.start();
+
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+
+ cache1.put(fqn, "k", "v");
+ }
+
+ @Test (groups = {"functional"}, expectedExceptions =
{TimeoutException.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 =
cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
+ tm.begin();
+ cache2.put(fqn, "block", "block");
+ Transaction t = tm.suspend();
+
+ cache1.put(fqn, "k", "v");
+ }
+}
Show replies by date