KickJava   Java API By Example, From Geeks To Geeks.

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


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 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  *
19  * @author Bela Ban
20  * @version $Id: IsolationLevelNoneTest.java,v 1.6 2006/12/30 17:49:53 msurtani Exp $
21  */

22 public class IsolationLevelNoneTest extends TestCase
23 {
24    CacheImpl cache = null;
25    final Fqn FQN = Fqn.fromString("/a/b/c");
26    final String JavaDoc KEY = "key";
27    final String JavaDoc VALUE = "value";
28    Transaction JavaDoc tx;
29
30
31    protected void setUp() throws Exception JavaDoc
32    {
33       super.setUp();
34    }
35
36    protected void tearDown() throws Exception JavaDoc
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 JavaDoc
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 JavaDoc
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 JavaDoc
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 JavaDoc startTransaction() throws SystemException JavaDoc, NotSupportedException JavaDoc
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