Source Code Cross Referenced for MTTransactionManagerUnitTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » tm » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.tm.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.tm.test;
023:
024:        import javax.management.ObjectName;
025:        import javax.transaction.RollbackException;
026:
027:        import junit.framework.Test;
028:
029:        import org.jboss.test.JBossTestCase;
030:        import org.jboss.test.JBossTestSetup;
031:        import org.jboss.test.tm.resource.MTOperation;
032:
033:        /**
034:         * Multithreaded tests for the transaction manager
035:         * 
036:         * Based on TransactionManagerUnitTestCase
037:         * 
038:         * @author <a href="dimitris@jboss.org">Dimitris Andreadis</a>
039:         * @version $Revision: 57211 $
040:         */
041:        public class MTTransactionManagerUnitTestCase extends JBossTestCase {
042:            static String[] SIG = new String[] { String.class.getName(),
043:                    new MTOperation[0][0].getClass().getName() };
044:
045:            ObjectName mtMBean;
046:
047:            public MTTransactionManagerUnitTestCase(String name) {
048:                super (name);
049:
050:                try {
051:                    mtMBean = new ObjectName(
052:                            "jboss.test:test=MTTransactionManagerUnitTestCase");
053:                } catch (Exception e) {
054:                    throw new RuntimeException(e.toString());
055:                }
056:            }
057:
058:            public void runTest(MTOperation[][] ops) throws Exception {
059:                getServer().invoke(mtMBean, "testMTOperations",
060:                        new Object[] { getName(), ops }, SIG);
061:            }
062:
063:            public static Test suite() throws Exception {
064:                return new JBossTestSetup(getDeploySetup(
065:                        MTTransactionManagerUnitTestCase.class, "mttest.sar"));
066:            }
067:
068:            /**
069:             * Start a tx on one thread and commit it on another
070:             * withouth the 2nd thread actually associating itself
071:             * with the transaction.
072:             * 
073:             * This is an error if the TransactionIntegrity plugin is active
074:             */
075:            public void testCommitTxStartedOnADifferentThread()
076:                    throws Exception {
077:                if (isTransactionIntegrityActive()) {
078:                    runTest(new MTOperation[][] {
079:                            {
080:                                    // thread 0
081:                                    new MTOperation(MTOperation.TM_BEGIN, 10),
082:                                    new MTOperation(MTOperation.TM_GET_STATUS),
083:                                    new MTOperation(MTOperation.XX_SLEEP_200), // other thread must commit
084:                                    new MTOperation(MTOperation.TM_GET_STATUS) },
085:                            {
086:                                    // thread 1
087:                                    new MTOperation(MTOperation.XX_WAIT_FOR, 10),
088:                                    new MTOperation(MTOperation.TX_COMMIT, 10,
089:                                            new RollbackException()),
090:                                    new MTOperation(MTOperation.TM_GET_STATUS), } });
091:                } else {
092:                    runTest(new MTOperation[][] {
093:                            {
094:                                    // thread 0
095:                                    new MTOperation(MTOperation.TM_BEGIN, 10),
096:                                    new MTOperation(MTOperation.TM_GET_STATUS),
097:                                    new MTOperation(MTOperation.XX_SLEEP_200), // other thread must commit
098:                                    new MTOperation(MTOperation.TM_GET_STATUS) },
099:                            {
100:                                    // thread 1
101:                                    new MTOperation(MTOperation.XX_WAIT_FOR, 10),
102:                                    new MTOperation(MTOperation.TX_COMMIT, 10),
103:                                    new MTOperation(MTOperation.TM_GET_STATUS), } });
104:                }
105:            }
106:
107:            /**
108:             * Start a tx on one thread, then resume this tx and commit it from
109:             * another thread. Normally this is allowed, but if the
110:             * TransactionIntegrity policy is active, then the 2 threads associated
111:             * with the tx will be detected at commit time and an exception
112:             * will be thrown.
113:             */
114:            public void testResumeAndCommitTxStartedOnADifferentThread()
115:                    throws Exception {
116:                if (isTransactionIntegrityActive()) {
117:                    runTest(new MTOperation[][] {
118:                            {
119:                                    // thread 0
120:                                    new MTOperation(MTOperation.TM_BEGIN, 10),
121:                                    new MTOperation(MTOperation.TM_GET_STATUS), },
122:                            {
123:                                    // thread 1
124:                                    new MTOperation(MTOperation.TM_GET_STATUS),
125:                                    new MTOperation(MTOperation.XX_WAIT_FOR, 10),
126:                                    new MTOperation(MTOperation.TM_RESUME, 10),
127:                                    new MTOperation(MTOperation.TM_GET_STATUS),
128:                                    new MTOperation(MTOperation.TX_COMMIT, 10,
129:                                            new RollbackException()),
130:                                    new MTOperation(MTOperation.TM_GET_STATUS), } });
131:                } else {
132:                    runTest(new MTOperation[][] {
133:                            {
134:                                    // thread 0
135:                                    new MTOperation(MTOperation.TM_BEGIN, 10),
136:                                    new MTOperation(MTOperation.TM_GET_STATUS), },
137:                            {
138:                                    // thread 1
139:                                    new MTOperation(MTOperation.TM_GET_STATUS),
140:                                    new MTOperation(MTOperation.XX_WAIT_FOR, 10),
141:                                    new MTOperation(MTOperation.TM_RESUME, 10),
142:                                    new MTOperation(MTOperation.TM_GET_STATUS),
143:                                    new MTOperation(MTOperation.TX_COMMIT, 10),
144:                                    new MTOperation(MTOperation.TM_GET_STATUS), } });
145:                }
146:            }
147:
148:            /**
149:             * Start a tx on one thread and commit it on another thread
150:             * without the 2nd thread actually associating itself with
151:             * the transaction. The try to commit the tx on the 1st
152:             * thread as well, thus producing an exception.
153:             * 
154:             * This only works when the TransactionIntegrity policy is innactive
155:             */
156:            public void testCommitSameTxInTwoThreads() throws Exception {
157:                if (!isTransactionIntegrityActive()) {
158:                    runTest(new MTOperation[][] {
159:                            {
160:                                    // thread 0
161:                                    new MTOperation(MTOperation.TM_BEGIN, 10),
162:                                    new MTOperation(MTOperation.TM_GET_STATUS),
163:                                    new MTOperation(MTOperation.XX_SLEEP_200),
164:                                    new MTOperation(MTOperation.TM_GET_STATUS),
165:                                    new MTOperation(MTOperation.TM_COMMIT, -1,
166:                                            new IllegalStateException())
167:
168:                            },
169:                            {
170:                                    // thread 1
171:                                    new MTOperation(MTOperation.XX_WAIT_FOR, 10),
172:                                    new MTOperation(MTOperation.TX_COMMIT, 10),
173:                                    new MTOperation(MTOperation.TM_GET_STATUS), } });
174:                }
175:            }
176:
177:            /**
178:             * Find out if the plugin is installed.
179:             * 
180:             * This is specific to this particular plugin!
181:             */
182:            private boolean isTransactionIntegrityActive() {
183:                boolean isActive = false;
184:                try {
185:                    ObjectName target = new ObjectName(
186:                            "jboss:service=TransactionManager,plugin=TransactionIntegrity");
187:                    isActive = getServer().isRegistered(target);
188:                } catch (Exception ignore) {
189:                    // empty
190:                }
191:                return isActive;
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.