1 package org.apache.ojb.broker.locking; 2 3 import org.apache.ojb.broker.metadata.ClassDescriptor; 4 import org.apache.ojb.broker.metadata.MetadataManager; 5 import org.apache.ojb.junit.OJBTestCase; 6 7 13 public class LockTestCommitedReads extends OJBTestCase 14 { 15 final int testIsoLevel = LockManager.IL_READ_COMMITTED; 16 17 public static void main(String [] args) 18 { 19 String [] arr = {LockTestCommitedReads.class.getName()}; 20 junit.textui.TestRunner.main(arr); 21 } 22 23 public LockTestCommitedReads(String name) 24 { 25 super(name); 26 } 27 28 Object tx1; 29 Object tx2; 30 org.apache.ojb.broker.Article obj; 31 org.apache.ojb.broker.locking.LockManager lockManager; 32 int oldIsolationLevel; 33 ClassDescriptor cld; 34 35 public void setUp() throws Exception 36 { 37 super.setUp(); 38 39 cld = MetadataManager.getInstance().getRepository().getDescriptorFor(org.apache.ojb.broker.Article.class); 41 oldIsolationLevel = cld.getIsolationLevel(); 42 cld.setIsolationLevel(testIsoLevel); 43 44 lockManager = LockManagerHelper.getLockManagerSpecifiedByConfiguration(); 45 46 tx2 = new Object (); 48 tx1 = new Object (); 49 50 obj = org.apache.ojb.broker.Article.createInstance(); 51 } 52 53 public void tearDown() throws Exception 54 { 55 cld.setIsolationLevel(oldIsolationLevel); 57 try 58 { 59 lockManager.releaseLock(tx1, obj); 60 lockManager.releaseLock(tx2, obj); 61 } 62 finally 63 { 64 super.tearDown(); 65 } 66 } 67 68 69 72 public void testWriteReleaseCheckRead() 73 { 74 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 75 assertTrue(lockManager.hasRead(tx2, obj)); 76 assertTrue(lockManager.releaseLock(tx2, obj)); 77 assertFalse(lockManager.hasRead(tx2, obj)); 78 } 79 80 83 public void testReadWriteReleaseCheckRead() 84 { 85 assertTrue(lockManager.readLock(tx2, obj, testIsoLevel)); 86 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 87 assertTrue(lockManager.hasRead(tx2, obj)); 88 assertTrue(lockManager.releaseLock(tx2, obj)); 89 assertFalse(lockManager.hasRead(tx2, obj)); 90 } 91 92 95 public void testSingleReadLock() 96 { 97 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 98 } 99 100 103 public void testUpgradeReadLock() 104 { 105 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 106 assertTrue(lockManager.upgradeLock(tx1, obj, testIsoLevel)); 107 } 108 109 112 public void testReadThenWrite() 113 { 114 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 115 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 116 } 117 118 121 public void testSingleWriteLock() 122 { 123 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 124 } 125 126 129 public void testWriteThenRead() 130 { 131 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 132 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 133 } 134 135 138 public void testMultipleReadLock() 139 { 140 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 141 assertTrue(lockManager.readLock(tx2, obj, testIsoLevel)); 142 } 143 144 147 public void testUpgradeWithExistingReader() 148 { 149 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 150 assertTrue(lockManager.upgradeLock(tx2, obj, testIsoLevel)); 151 } 152 153 156 public void testWriteWithExistingReader() 157 { 158 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 159 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 160 } 161 162 165 public void testUpgradeWithMultipleReaders() 166 { 167 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 168 assertTrue(lockManager.readLock(tx2, obj, testIsoLevel)); 169 assertTrue(lockManager.upgradeLock(tx2, obj, testIsoLevel)); 170 } 171 172 175 public void testWriteWithMultipleReaders() 176 { 177 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 178 assertTrue(lockManager.readLock(tx2, obj, testIsoLevel)); 179 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 180 } 181 182 185 public void testUpgradeWithMultipleReadersOn1() 186 { 187 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 188 assertTrue(lockManager.readLock(tx2, obj, testIsoLevel)); 189 assertTrue(lockManager.upgradeLock(tx1, obj, testIsoLevel)); 190 } 191 192 195 public void testWriteWithMultipleReadersOn1() 196 { 197 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 198 assertTrue(lockManager.readLock(tx2, obj, testIsoLevel)); 199 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 200 } 201 202 205 public void testReadWithExistingWriter() 206 { 207 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 208 assertFalse(lockManager.readLock(tx2, obj, testIsoLevel)); 209 } 210 211 214 public void testMultipleWriteLock() 215 { 216 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 217 assertTrue(!lockManager.writeLock(tx2, obj, testIsoLevel)); 218 } 219 220 223 public void testReleaseReadLock() 224 { 225 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 226 assertTrue(lockManager.releaseLock(tx1, obj)); 227 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 228 } 229 230 233 public void testReleaseUpgradeLock() 234 { 235 assertTrue(lockManager.upgradeLock(tx1, obj, testIsoLevel)); 236 assertTrue(lockManager.releaseLock(tx1, obj)); 237 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 238 } 239 240 243 public void testReleaseWriteLock() 244 { 245 assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel)); 246 assertTrue(lockManager.releaseLock(tx1, obj)); 247 assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel)); 248 } 249 250 253 public void testReadThenRead() 254 { 255 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 256 assertTrue(lockManager.readLock(tx1, obj, testIsoLevel)); 257 } 258 } 259 | Popular Tags |