KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > otm > LockTestRepeatableReads


1 package org.apache.ojb.otm;
2
3 /**
4  * This is the TestSuite based on the ODMG locking documentation
5  */

6 import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
7 import org.apache.ojb.otm.lock.isolation.RepeatableReadIsolation;
8
9 public class LockTestRepeatableReads extends LockTestBase
10 {
11     private static Class JavaDoc CLASS = LockTestRepeatableReads.class;
12
13     public LockTestRepeatableReads(String JavaDoc name)
14     {
15         super(name);
16     }
17
18     protected TransactionIsolation newIsolation()
19     {
20         return new RepeatableReadIsolation();
21     }
22
23     /**
24      * Test 1
25      */

26     public void testSingleReadLock()
27     {
28         assertTrue(readLock(_tx1));
29     }
30
31     /**
32      * Test3
33      */

34     public void testReadThenWrite()
35     {
36         assertTrue(readLock(_tx1));
37         assertTrue(writeLock(_tx1));
38     }
39
40     /**
41      * Test 4
42      */

43     public void testSingleWriteLock()
44     {
45         assertTrue(writeLock(_tx1));
46     }
47
48     /**
49      * Test 5
50      */

51     public void testWriteThenRead()
52     {
53         assertTrue(writeLock(_tx1));
54         assertTrue(readLock(_tx1));
55     }
56
57     /**
58      * Test 6
59      */

60     public void testMultipleReadLock()
61     {
62         assertTrue(readLock(_tx1));
63         assertTrue(readLock(_tx2));
64     }
65
66     /**
67      * Test 8
68      */

69     public void testWriteWithExistingReader()
70     {
71         assertTrue(readLock(_tx1));
72         assertTrue(!writeLock(_tx2));
73     }
74
75     /**
76      * Test 10
77      */

78     public void testWriteWithMultipleReaders()
79     {
80         assertTrue(readLock(_tx1));
81         assertTrue(readLock(_tx2));
82         assertTrue(!writeLock(_tx2));
83     }
84
85     /**
86      * Test 12
87      */

88     public void testWriteWithMultipleReadersOn1()
89     {
90         assertTrue(readLock(_tx1));
91         assertTrue(readLock(_tx2));
92         assertTrue(!writeLock(_tx1));
93     }
94
95     /**
96      * Test 13
97      */

98     public void testReadWithExistingWriter()
99     {
100         assertTrue(writeLock(_tx1));
101         assertTrue(!readLock(_tx2));
102     }
103
104     /**
105      * Test 14
106      */

107     public void testMultipleWriteLock()
108     {
109         assertTrue(writeLock(_tx1));
110         assertTrue(!writeLock(_tx2));
111     }
112
113     /**
114      * Test 15
115      */

116     public void testReleaseReadLock()
117     {
118         assertTrue(readLock(_tx1));
119         assertTrue(releaseLock(_tx1));
120         assertTrue(writeLock(_tx2));
121     }
122
123     /**
124      * Test 17
125      */

126     public void testReleaseWriteLock()
127     {
128         assertTrue(writeLock(_tx1));
129         assertTrue(releaseLock(_tx1));
130         assertTrue(writeLock(_tx2));
131     }
132
133     /**
134      * Test 18
135      */

136     public void testReadThenRead()
137     {
138         assertTrue(readLock(_tx1));
139         assertTrue(readLock(_tx1));
140     }
141
142     public static void main(String JavaDoc[] args)
143     {
144         String JavaDoc[] arr = {CLASS.getName()};
145         junit.textui.TestRunner.main(arr);
146     }
147 }
148
Popular Tags