KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > transaction > IsolationLevelNoneTest


1 package org.jboss.cache.tests.transaction;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.jboss.cache.DummyTransactionManagerLookup;
7 import org.jboss.cache.Fqn;
8 import org.jboss.cache.TreeCache;
9 import org.jboss.cache.lock.IsolationLevel;
10 import org.jboss.cache.transaction.DummyTransactionManager;
11
12 import javax.transaction.NotSupportedException JavaDoc;
13 import javax.transaction.SystemException JavaDoc;
14 import javax.transaction.Transaction JavaDoc;
15
16 /**
17  * Tests whether modifications within callbacks (TreeCacheListener) are handled correctly
18  * @author Bela Ban
19  * @version $Id: IsolationLevelNoneTest.java,v 1.1.1.1 2005/03/31 10:15:10 belaban Exp $
20  */

21 public class IsolationLevelNoneTest extends TestCase {
22    TreeCache cache=null;
23    final Fqn FQN=Fqn.fromString("/a/b/c");
24    final String JavaDoc KEY="key";
25    final String JavaDoc VALUE="value";
26    Transaction JavaDoc tx;
27
28
29
30    protected void setUp() throws Exception JavaDoc {
31       super.setUp();
32    }
33
34    protected void tearDown() throws Exception JavaDoc {
35       super.tearDown();
36       if(cache != null) {
37          cache.stopService();
38          cache.destroyService();
39          cache=null;
40       }
41    }
42
43
44
45    public void testWithoutTransactions() throws Exception JavaDoc {
46       cache=new TreeCache();
47       cache.setCacheMode(TreeCache.LOCAL);
48       cache.setIsolationLevel(IsolationLevel.NONE);
49       cache.startService();
50       cache.put(FQN, KEY, VALUE);
51       cache.put(FQN + "/d", KEY, VALUE);
52       assertTrue(cache.exists(FQN, KEY));
53       assertEquals(VALUE, cache.get(FQN, KEY));
54       System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
55       assertEquals(0, cache.getNumberOfLocksHeld());
56    }
57
58    public void testWithTransactions() throws Exception JavaDoc {
59       cache=new TreeCache();
60       cache.setCacheMode(TreeCache.LOCAL);
61       cache.setIsolationLevel(IsolationLevel.NONE);
62       cache.setTransactionManagerLookup(new DummyTransactionManagerLookup());
63       cache.startService();
64       tx=startTransaction();
65       cache.put(FQN, KEY, VALUE);
66       cache.put(FQN + "/d", KEY, VALUE);
67       assertTrue(cache.exists(FQN, KEY));
68       assertEquals(VALUE, cache.get(FQN, KEY));
69       System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
70       assertEquals(0, cache.getNumberOfLocksHeld());
71       tx.commit();
72    }
73
74
75    public void testWithTransactionsRepeatableRead() throws Exception JavaDoc {
76       cache=new TreeCache();
77       cache.setCacheMode(TreeCache.LOCAL);
78       cache.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
79       cache.setTransactionManagerLookup(new DummyTransactionManagerLookup());
80       cache.startService();
81       tx=startTransaction();
82       cache.put(FQN, KEY, VALUE);
83       cache.put(FQN + "/d", KEY, VALUE);
84       assertTrue(cache.exists(FQN, KEY));
85       assertEquals(VALUE, cache.get(FQN, KEY));
86       System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
87       assertEquals(4, cache.getNumberOfLocksHeld());
88       tx.commit();
89    }
90
91    private Transaction JavaDoc startTransaction() throws SystemException JavaDoc, NotSupportedException JavaDoc {
92       DummyTransactionManager mgr=DummyTransactionManager.getInstance();
93       mgr.begin();
94       return mgr.getTransaction();
95    }
96
97    public static Test suite() {
98       return new TestSuite(IsolationLevelNoneTest.class);
99    }
100
101
102
103 }
104
Popular Tags