Source Code Cross Referenced for TxnTestCase.java in  » JMX » je » com » sleepycat » je » test » 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 » JMX » je » com.sleepycat.je.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2002,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: TxnTestCase.java,v 1.17.2.3 2008/01/07 15:14:33 cwl Exp $
007:         */
008:
009:        package com.sleepycat.je.test;
010:
011:        import java.io.File;
012:        import java.util.Enumeration;
013:
014:        import junit.framework.TestCase;
015:        import junit.framework.TestSuite;
016:
017:        import com.sleepycat.je.DatabaseException;
018:        import com.sleepycat.je.Environment;
019:        import com.sleepycat.je.EnvironmentConfig;
020:        import com.sleepycat.je.Transaction;
021:        import com.sleepycat.je.TransactionConfig;
022:        import com.sleepycat.je.util.TestUtils;
023:
024:        /**
025:         * Permuates test cases over three transaction types: null (non-transactional),
026:         * auto-commit, and user (explicit).
027:         *
028:         * <p>Overrides runTest, setUp and tearDown to open/close the environment and to
029:         * set up protected members for use by test cases.</p>
030:         *
031:         * <p>If a subclass needs to override setUp or tearDown, the overridden method
032:         * should call super.setUp or super.tearDown.</p>
033:         *
034:         * <p>When writing a test case based on this class, write it as if a user txn
035:         * were always used: call txnBegin, txnCommit and txnAbort for all write
036:         * operations.  Use the isTransactional protected field for setup of a database
037:         * config.</p>
038:         */
039:        public abstract class TxnTestCase extends TestCase {
040:
041:            public static final String TXN_NULL = "txn-null";
042:            public static final String TXN_AUTO = "txn-auto";
043:            public static final String TXN_USER = "txn-user";
044:
045:            protected File envHome;
046:            protected Environment env;
047:            protected EnvironmentConfig envConfig;
048:            protected String txnType;
049:            protected boolean isTransactional;
050:
051:            /**
052:             * Returns a txn test suite.  If txnTypes is null, all three types are run.
053:             */
054:            public static TestSuite txnTestSuite(Class testCaseClass,
055:                    EnvironmentConfig envConfig, String[] txnTypes) {
056:                if (txnTypes == null) {
057:                    txnTypes = new String[] { TxnTestCase.TXN_NULL,
058:                            TxnTestCase.TXN_USER, TxnTestCase.TXN_AUTO };
059:                }
060:                if (envConfig == null) {
061:                    envConfig = TestUtils.initEnvConfig();
062:                    envConfig.setAllowCreate(true);
063:                    envConfig.setTxnNoSync(Boolean
064:                            .getBoolean(TestUtils.NO_SYNC));
065:                }
066:                TestSuite suite = new TestSuite();
067:                for (int i = 0; i < txnTypes.length; i += 1) {
068:                    TestSuite baseSuite = new TestSuite(testCaseClass);
069:                    Enumeration e = baseSuite.tests();
070:                    while (e.hasMoreElements()) {
071:                        TxnTestCase test = (TxnTestCase) e.nextElement();
072:                        test.txnInit(envConfig, txnTypes[i]);
073:                        suite.addTest(test);
074:                    }
075:                }
076:                return suite;
077:            }
078:
079:            private void txnInit(EnvironmentConfig envConfig, String txnType) {
080:
081:                this .envConfig = envConfig;
082:                this .txnType = txnType;
083:                isTransactional = (txnType != TXN_NULL);
084:            }
085:
086:            public void setUp() throws Exception {
087:
088:                envHome = new File(System.getProperty(TestUtils.DEST_DIR));
089:                TestUtils.removeLogFiles("Setup", envHome, false);
090:            }
091:
092:            public void runTest() throws Throwable {
093:
094:                openEnv();
095:                super .runTest();
096:                closeEnv();
097:            }
098:
099:            public void tearDown() throws Exception {
100:
101:                /* Set test name for reporting; cannot be done in the ctor or setUp. */
102:                setName(txnType + ':' + getName());
103:
104:                if (env != null) {
105:                    try {
106:                        env.close();
107:                    } catch (Throwable e) {
108:                        System.out.println("tearDown: " + e);
109:                    }
110:                    env = null;
111:                }
112:
113:                try {
114:                    TestUtils.removeLogFiles("TearDown", envHome, false);
115:                } catch (Throwable e) {
116:                    System.out.println("tearDown: " + e);
117:                }
118:            }
119:
120:            /**
121:             * Closes the environment and sets the env field to null.
122:             * Used for closing and reopening the environment.
123:             */
124:            public void closeEnv() throws DatabaseException {
125:
126:                if (env != null) {
127:                    env.close();
128:                    env = null;
129:                }
130:            }
131:
132:            /**
133:             * Opens the environment based on the txnType for this test case.
134:             * Used for closing and reopening the environment.
135:             */
136:            public void openEnv() throws DatabaseException {
137:
138:                if (txnType == TXN_NULL) {
139:                    envConfig.setTransactional(false);
140:                    env = new Environment(envHome, envConfig);
141:                } else if (txnType == TXN_AUTO) {
142:                    envConfig.setTransactional(true);
143:                    env = new Environment(envHome, envConfig);
144:                } else if (txnType == TXN_USER) {
145:                    envConfig.setTransactional(true);
146:                    env = new Environment(envHome, envConfig);
147:                } else {
148:                    assert false;
149:                }
150:            }
151:
152:            /**
153:             * Begin a txn if in TXN_USER mode; otherwise return null;
154:             */
155:            protected Transaction txnBegin() throws DatabaseException {
156:
157:                return txnBegin(null, null);
158:            }
159:
160:            /**
161:             * Begin a txn if in TXN_USER mode; otherwise return null;
162:             */
163:            protected Transaction txnBegin(Transaction parentTxn,
164:                    TransactionConfig config) throws DatabaseException {
165:
166:                if (txnType == TXN_USER) {
167:                    return env.beginTransaction(parentTxn, config);
168:                } else {
169:                    return null;
170:                }
171:            }
172:
173:            /**
174:             * Begin a txn if in TXN_USER or TXN_AUTO mode; otherwise return null;
175:             */
176:            protected Transaction txnBeginCursor() throws DatabaseException {
177:
178:                return txnBeginCursor(null, null);
179:            }
180:
181:            /**
182:             * Begin a txn if in TXN_USER or TXN_AUTO mode; otherwise return null;
183:             */
184:            protected Transaction txnBeginCursor(Transaction parentTxn,
185:                    TransactionConfig config) throws DatabaseException {
186:
187:                if (txnType == TXN_USER || txnType == TXN_AUTO) {
188:                    return env.beginTransaction(parentTxn, config);
189:                } else {
190:                    return null;
191:                }
192:            }
193:
194:            /**
195:             * Commit a txn if non-null.
196:             */
197:            protected void txnCommit(Transaction txn) throws DatabaseException {
198:
199:                if (txn != null) {
200:                    txn.commit();
201:                }
202:            }
203:
204:            /**
205:             * Commit a txn if non-null.
206:             */
207:            protected void txnAbort(Transaction txn) throws DatabaseException {
208:
209:                if (txn != null) {
210:                    txn.abort();
211:                }
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.