Source Code Cross Referenced for G_MultiRelation.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » clients » entity » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jtests.clients.entity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         * --------------------------------------------------------------------------
021:         * $Id: G_MultiRelation.java 7533 2005-10-19 15:55:05Z durieuxp $
022:         * --------------------------------------------------------------------------
023:         */
024:
025:        package org.objectweb.jonas.jtests.clients.entity;
026:
027:        import java.util.Collection;
028:        import java.util.Date;
029:        import java.util.Iterator;
030:
031:        import javax.ejb.FinderException;
032:        import javax.naming.NamingException;
033:        import javax.rmi.PortableRemoteObject;
034:
035:        import junit.framework.Test;
036:        import junit.framework.TestSuite;
037:
038:        import org.objectweb.jonas.jtests.beans.relation.cascade.AddressDO;
039:        import org.objectweb.jonas.jtests.beans.relation.cascade.AddressHR;
040:        import org.objectweb.jonas.jtests.beans.relation.cascade.AddressR;
041:        import org.objectweb.jonas.jtests.beans.relation.cascade.CreditCardHR;
042:        import org.objectweb.jonas.jtests.beans.relation.cascade.CustomerHR;
043:        import org.objectweb.jonas.jtests.beans.relation.cascade.CustomerR;
044:        import org.objectweb.jonas.jtests.beans.relation.cascade.Name;
045:        import org.objectweb.jonas.jtests.beans.relation.cascade.PhoneHR;
046:        import org.objectweb.jonas.jtests.beans.relation.cascade.CarHR;
047:        import org.objectweb.jonas.jtests.util.JTestCase;
048:
049:        /**
050:         * This is a test suite on multiple threads accessing relationship beans
051:         * @author Philippe Durieux
052:         */
053:        public class G_MultiRelation extends JTestCase {
054:
055:            private static CustomerHR customerhome = null;
056:            private static CreditCardHR creditcardhome = null;
057:            private static AddressHR addresshome = null;
058:            private static PhoneHR phonehome = null;
059:            private static CarHR carhome = null;
060:
061:            public G_MultiRelation(String name) {
062:                super (name);
063:            }
064:
065:            protected boolean isInit = false;
066:            protected boolean threadfail = false;
067:
068:            protected void setUp() {
069:                super .setUp();
070:                if (!isInit) {
071:                    useBeans("cascade", false);
072:                    try {
073:                        customerhome = (CustomerHR) PortableRemoteObject
074:                                .narrow(ictx
075:                                        .lookup("cascadeCustomerHomeRemote"),
076:                                        CustomerHR.class);
077:                        creditcardhome = (CreditCardHR) PortableRemoteObject
078:                                .narrow(ictx
079:                                        .lookup("cascadeCreditCardHomeRemote"),
080:                                        CreditCardHR.class);
081:                        addresshome = (AddressHR) PortableRemoteObject.narrow(
082:                                ictx.lookup("cascadeAddressHomeRemote"),
083:                                AddressHR.class);
084:                        phonehome = (PhoneHR) PortableRemoteObject.narrow(ictx
085:                                .lookup("cascadePhoneHomeRemote"),
086:                                PhoneHR.class);
087:                        carhome = (CarHR) PortableRemoteObject.narrow(ictx
088:                                .lookup("cascadeCarHomeRemote"), CarHR.class);
089:                    } catch (NamingException e) {
090:                        fail("Cannot get bean home: " + e.getMessage());
091:                    }
092:                    isInit = true;
093:                }
094:            }
095:
096:            private CustomerR createFullCustomer(int pk, String lname, String cc)
097:                    throws Exception {
098:                // create new customer
099:                CustomerR customer = customerhome.create(new Integer(pk));
100:                Name name = new Name(lname, "Jean");
101:                customer.setName(name);
102:                // set its credit card
103:                customer.setCreditCard(new Date(), cc, lname);
104:                // set its address
105:                String zip = "38170";
106:                customer.setAddress("rue des fleurs", "Seyssinet", "France",
107:                        zip);
108:                // add phones
109:                customer.addPhoneNumber("1111", (byte) 1);
110:                customer.addPhoneNumber("2222", (byte) 2);
111:                customer.addPhoneNumber("3333", (byte) 3);
112:                return customer;
113:            }
114:
115:            private void removeFullCustomer(int pk) throws Exception {
116:                CustomerR customer = customerhome.findByPrimaryKey(new Integer(
117:                        pk));
118:                customer.remove();
119:            }
120:
121:            private void runThreads(int threads, int pkmin, int pkmax)
122:                    throws Exception {
123:                // Create and start all threads
124:                Ithread[] t_thr = new Ithread[threads];
125:                for (int i = 0; i < threads; i++) {
126:                    t_thr[i] = new Ithread(pkmin, pkmax);
127:                    t_thr[i].start();
128:                }
129:
130:                // Wait end of all threads
131:                for (int p = 0; p < threads; p++) {
132:                    t_thr[p].join();
133:                }
134:
135:                // Check if all threads run ok
136:                if (threadfail) {
137:                    throw new Error("thread error");
138:                }
139:            }
140:
141:            public void testBasicCreateRemove() throws Exception {
142:                int pk = 7;
143:                createFullCustomer(pk, "Galtier", "65423");
144:                removeFullCustomer(pk);
145:            }
146:
147:            public void testCreateRemoveTwice() throws Exception {
148:                int pk = 8;
149:                createFullCustomer(pk, "Galtier", "65423");
150:                removeFullCustomer(pk);
151:                createFullCustomer(pk, "Galtier", "65423");
152:                removeFullCustomer(pk);
153:            }
154:
155:            public void testManyThreads() throws Exception {
156:                stopTxAt(200);
157:                int pkmin = 100;
158:                int pkmax = 300;
159:                for (int pk = pkmin; pk < pkmax; pk++) {
160:                    CustomerR customer = createFullCustomer(pk, "Nom" + pk,
161:                            "65423" + pk);
162:                    // add cars
163:                    String carnb = "car-pk" + pk;
164:                    customer.addCar("1111" + pk, (byte) 1);
165:                    customer.addCar(carnb, (byte) 2);
166:                    customer.addCar("1131" + pk, (byte) 3);
167:                    // crash
168:                    customer.accident(carnb, carnb + "-inv");
169:                }
170:                runThreads(80, pkmin, pkmax);
171:                for (int pk = pkmin; pk < pkmax; pk++) {
172:                    removeFullCustomer(pk);
173:                }
174:            }
175:
176:            protected boolean initStateOK() throws Exception {
177:                return true;
178:            }
179:
180:            public static Test suite() {
181:                return new TestSuite(G_MultiRelation.class);
182:            }
183:
184:            public static void main(String args[]) {
185:                String testtorun = null;
186:                // Get args
187:                for (int argn = 0; argn < args.length; argn++) {
188:                    String sarg = args[argn];
189:                    if (sarg.equals("-n")) {
190:                        testtorun = args[++argn];
191:                    }
192:                }
193:                if (testtorun == null) {
194:                    junit.textui.TestRunner.run(suite());
195:                } else {
196:                    junit.textui.TestRunner.run(new G_MultiRelation(testtorun));
197:                }
198:            }
199:
200:            class Ithread extends Thread {
201:                int pkmin;
202:                int pkmax;
203:
204:                public Ithread(int pkmin, int pkmax) {
205:                    this .pkmin = pkmin;
206:                    this .pkmax = pkmax;
207:                }
208:
209:                public void run() {
210:                    try {
211:                        for (int pk = pkmin; pk < pkmax; pk++) {
212:                            CustomerR customer = customerhome
213:                                    .findByPrimaryKey(new Integer(pk));
214:                            yield();
215:                            AddressDO addr = customer.getAddress();
216:                        }
217:                    } catch (Exception e) {
218:                        threadfail = true;
219:                    }
220:                }
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.