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.DummyTransactionManagerLookup; 8 import org.jboss.cache.Fqn; 9 import org.jboss.cache.config.Configuration; 10 import org.jboss.cache.lock.IsolationLevel; 11 12 import javax.transaction.NotSupportedException ; 13 import javax.transaction.SystemException ; 14 import javax.transaction.Transaction ; 15 16 22 public class IsolationLevelNoneTest extends TestCase 23 { 24 CacheImpl cache = null; 25 final Fqn FQN = Fqn.fromString("/a/b/c"); 26 final String KEY = "key"; 27 final String VALUE = "value"; 28 Transaction tx; 29 30 31 protected void setUp() throws Exception 32 { 33 super.setUp(); 34 } 35 36 protected void tearDown() throws Exception 37 { 38 super.tearDown(); 39 if (cache != null) 40 { 41 cache.stop(); 42 cache.destroy(); 43 cache = null; 44 } 45 } 46 47 48 public void testWithoutTransactions() throws Exception 49 { 50 cache = new CacheImpl(); 51 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL); 52 cache.getConfiguration().setIsolationLevel(IsolationLevel.NONE); 53 cache.start(); 54 cache.put(FQN, KEY, VALUE); 55 cache.put(FQN + "/d", KEY, VALUE); 56 assertTrue(cache.exists(FQN, KEY)); 57 assertEquals(VALUE, cache.get(FQN, KEY)); 58 System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo()); 59 assertEquals(0, cache.getNumberOfLocksHeld()); 60 } 61 62 public void testWithTransactions() throws Exception 63 { 64 cache = new CacheImpl(); 65 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL); 66 cache.getConfiguration().setIsolationLevel(IsolationLevel.NONE); 67 cache.setTransactionManagerLookup(new DummyTransactionManagerLookup()); 68 cache.start(); 69 tx = startTransaction(); 70 cache.put(FQN, KEY, VALUE); 71 cache.put(FQN + "/d", KEY, VALUE); 72 assertTrue(cache.exists(FQN, KEY)); 73 assertEquals(VALUE, cache.get(FQN, KEY)); 74 System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo()); 75 assertEquals(0, cache.getNumberOfLocksHeld()); 76 tx.commit(); 77 } 78 79 80 public void testWithTransactionsRepeatableRead() throws Exception 81 { 82 cache = new CacheImpl(); 83 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL); 84 cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ); 85 cache.setTransactionManagerLookup(new DummyTransactionManagerLookup()); 86 cache.start(); 87 tx = startTransaction(); 88 cache.put(FQN, KEY, VALUE); 89 cache.put(FQN + "/d", KEY, VALUE); 90 assertTrue(cache.exists(FQN, KEY)); 91 assertEquals(VALUE, cache.get(FQN, KEY)); 92 System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo()); 93 assertEquals(5, cache.getNumberOfLocksHeld()); 94 tx.commit(); 95 } 96 97 private Transaction startTransaction() throws SystemException , NotSupportedException 98 { 99 DummyTransactionManager mgr = DummyTransactionManager.getInstance(); 100 mgr.begin(); 101 return mgr.getTransaction(); 102 } 103 104 public static Test suite() 105 { 106 return new TestSuite(IsolationLevelNoneTest.class); 107 } 108 109 110 } 111 | Popular Tags |