Source Code Cross Referenced for LockTestCommitedReads.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » locking » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » db ojb » org.apache.ojb.broker.locking 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker.locking;
002:
003:        import org.apache.ojb.broker.metadata.ClassDescriptor;
004:        import org.apache.ojb.broker.metadata.MetadataManager;
005:        import org.apache.ojb.junit.OJBTestCase;
006:
007:        /**
008:         * This is the TestSuite that checks the ODMG locking strategies.
009:         * It performs 17 testMethods as defined in the Locking documentation.
010:         *
011:         * @author Thomas Mahler
012:         */
013:        public class LockTestCommitedReads extends OJBTestCase {
014:            final int testIsoLevel = LockManager.IL_READ_COMMITTED;
015:
016:            public static void main(String[] args) {
017:                String[] arr = { LockTestCommitedReads.class.getName() };
018:                junit.textui.TestRunner.main(arr);
019:            }
020:
021:            public LockTestCommitedReads(String name) {
022:                super (name);
023:            }
024:
025:            Object tx1;
026:            Object tx2;
027:            org.apache.ojb.broker.Article obj;
028:            org.apache.ojb.broker.locking.LockManager lockManager;
029:            int oldIsolationLevel;
030:            ClassDescriptor cld;
031:
032:            public void setUp() throws Exception {
033:                super .setUp();
034:
035:                // change isolation-level used for test
036:                cld = MetadataManager.getInstance().getRepository()
037:                        .getDescriptorFor(org.apache.ojb.broker.Article.class);
038:                oldIsolationLevel = cld.getIsolationLevel();
039:                cld.setIsolationLevel(testIsoLevel);
040:
041:                lockManager = LockManagerHelper
042:                        .getLockManagerSpecifiedByConfiguration();
043:
044:                // initialize the dummies
045:                tx2 = new Object();
046:                tx1 = new Object();
047:
048:                obj = org.apache.ojb.broker.Article.createInstance();
049:            }
050:
051:            public void tearDown() throws Exception {
052:                // restore isolation level
053:                cld.setIsolationLevel(oldIsolationLevel);
054:                try {
055:                    lockManager.releaseLock(tx1, obj);
056:                    lockManager.releaseLock(tx2, obj);
057:                } finally {
058:                    super .tearDown();
059:                }
060:            }
061:
062:            /**
063:             * Test 19
064:             */
065:            public void testWriteReleaseCheckRead() {
066:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
067:                assertTrue(lockManager.hasRead(tx2, obj));
068:                assertTrue(lockManager.releaseLock(tx2, obj));
069:                assertFalse(lockManager.hasRead(tx2, obj));
070:            }
071:
072:            /**
073:             * Test 20
074:             */
075:            public void testReadWriteReleaseCheckRead() {
076:                assertTrue(lockManager.readLock(tx2, obj, testIsoLevel));
077:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
078:                assertTrue(lockManager.hasRead(tx2, obj));
079:                assertTrue(lockManager.releaseLock(tx2, obj));
080:                assertFalse(lockManager.hasRead(tx2, obj));
081:            }
082:
083:            /**
084:             * Test 1
085:             */
086:            public void testSingleReadLock() {
087:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
088:            }
089:
090:            /**
091:             * Test 2
092:             */
093:            public void testUpgradeReadLock() {
094:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
095:                assertTrue(lockManager.upgradeLock(tx1, obj, testIsoLevel));
096:            }
097:
098:            /**
099:             * Test3
100:             */
101:            public void testReadThenWrite() {
102:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
103:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
104:            }
105:
106:            /**
107:             * Test 4
108:             */
109:            public void testSingleWriteLock() {
110:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
111:            }
112:
113:            /**
114:             * Test 5
115:             */
116:            public void testWriteThenRead() {
117:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
118:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
119:            }
120:
121:            /**
122:             * Test 6
123:             */
124:            public void testMultipleReadLock() {
125:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
126:                assertTrue(lockManager.readLock(tx2, obj, testIsoLevel));
127:            }
128:
129:            /**
130:             * Test 7
131:             */
132:            public void testUpgradeWithExistingReader() {
133:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
134:                assertTrue(lockManager.upgradeLock(tx2, obj, testIsoLevel));
135:            }
136:
137:            /**
138:             * Test 8
139:             */
140:            public void testWriteWithExistingReader() {
141:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
142:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
143:            }
144:
145:            /**
146:             * Test 9
147:             */
148:            public void testUpgradeWithMultipleReaders() {
149:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
150:                assertTrue(lockManager.readLock(tx2, obj, testIsoLevel));
151:                assertTrue(lockManager.upgradeLock(tx2, obj, testIsoLevel));
152:            }
153:
154:            /**
155:             * Test 10
156:             */
157:            public void testWriteWithMultipleReaders() {
158:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
159:                assertTrue(lockManager.readLock(tx2, obj, testIsoLevel));
160:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
161:            }
162:
163:            /**
164:             * Test 11
165:             */
166:            public void testUpgradeWithMultipleReadersOn1() {
167:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
168:                assertTrue(lockManager.readLock(tx2, obj, testIsoLevel));
169:                assertTrue(lockManager.upgradeLock(tx1, obj, testIsoLevel));
170:            }
171:
172:            /**
173:             * Test 12
174:             */
175:            public void testWriteWithMultipleReadersOn1() {
176:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
177:                assertTrue(lockManager.readLock(tx2, obj, testIsoLevel));
178:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
179:            }
180:
181:            /**
182:             * Test 13
183:             */
184:            public void testReadWithExistingWriter() {
185:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
186:                assertFalse(lockManager.readLock(tx2, obj, testIsoLevel));
187:            }
188:
189:            /**
190:             * Test 14
191:             */
192:            public void testMultipleWriteLock() {
193:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
194:                assertTrue(!lockManager.writeLock(tx2, obj, testIsoLevel));
195:            }
196:
197:            /**
198:             * Test 15
199:             */
200:            public void testReleaseReadLock() {
201:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
202:                assertTrue(lockManager.releaseLock(tx1, obj));
203:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
204:            }
205:
206:            /**
207:             * Test 16
208:             */
209:            public void testReleaseUpgradeLock() {
210:                assertTrue(lockManager.upgradeLock(tx1, obj, testIsoLevel));
211:                assertTrue(lockManager.releaseLock(tx1, obj));
212:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
213:            }
214:
215:            /**
216:             * Test 17
217:             */
218:            public void testReleaseWriteLock() {
219:                assertTrue(lockManager.writeLock(tx1, obj, testIsoLevel));
220:                assertTrue(lockManager.releaseLock(tx1, obj));
221:                assertTrue(lockManager.writeLock(tx2, obj, testIsoLevel));
222:            }
223:
224:            /**
225:             * Test 18
226:             */
227:            public void testReadThenRead() {
228:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
229:                assertTrue(lockManager.readLock(tx1, obj, testIsoLevel));
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.