1 package org.jboss.cache.transaction; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.jboss.cache.CacheImpl; 7 import org.jboss.cache.Fqn; 8 9 import javax.transaction.Transaction ; 10 import javax.transaction.TransactionManager ; 11 12 18 public class SuspendTxTest extends TestCase 19 { 20 CacheImpl cache; 21 TransactionManager mgr; 22 23 protected void setUp() throws Exception 24 { 25 super.setUp(); 26 cache = new CacheImpl(); 27 cache.getConfiguration().setCacheMode("local"); 28 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 29 cache.start(); 30 mgr = cache.getTransactionManager(); 31 } 32 33 protected void tearDown() throws Exception 34 { 35 super.tearDown(); 36 cache.stop(); 37 if (mgr.getTransaction() != null) 38 { 39 mgr.rollback(); 40 } 41 mgr = null; 42 } 43 44 48 public void testSuspendedLocks() throws Exception 49 { 50 cache.put("/one", null); 52 cache.put("/a", null); 53 mgr.begin(); 54 55 cache.put("/one/two", "key1", "val1"); 56 int numLocksBefore = cache.getNumberOfLocksHeld(); 57 58 Transaction tx = mgr.suspend(); 59 60 cache.put("/a/b", "key1", "val1"); 61 mgr.resume(tx); 62 63 assertEquals(numLocksBefore, cache.getNumberOfLocksHeld()); 64 } 65 66 70 public void testSuspendedUsingOptionsLocks() throws Exception 71 { 72 mgr.begin(); 73 74 cache.put("/one/two", "key1", "val1"); 75 int numLocksBefore = cache.getNumberOfLocksHeld(); 76 77 cache.getInvocationContext().getOptionOverrides().setFailSilently(true); cache.put(Fqn.fromString("/a/b"), "key1", "val1"); 79 80 assertEquals(numLocksBefore, cache.getNumberOfLocksHeld()); 81 } 82 83 84 public static Test suite() 85 { 86 return new TestSuite(SuspendTxTest.class); 87 } 88 89 public static void main(String [] args) 90 { 91 junit.textui.TestRunner.run(suite()); 92 } 93 94 } 95 | Popular Tags |