KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > stress > TestRelation1_1


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.speedo.stress;
20
21 import javax.jdo.JDOFatalException;
22 import javax.jdo.PersistenceManager;
23
24 import org.objectweb.speedo.pobjects.relations.A;
25 import org.objectweb.speedo.pobjects.relations.B;
26
27 /**
28  * Stress the relation one-one implementation by Speedo.
29  *
30  * @author M. Guillemin
31  */

32 public class TestRelation1_1 extends StressHelper {
33
34     public TestRelation1_1(String JavaDoc s) {
35         super(s);
36     }
37
38     protected String JavaDoc[] getClassNamesToInit() {
39         return new String JavaDoc[]{
40             org.objectweb.speedo.pobjects.relations.A.class.getName(),
41             org.objectweb.speedo.pobjects.relations.B.class.getName()
42         };
43     }
44
45     protected String JavaDoc getLoggerName() {
46         return STRESS_LOG_NAME + ".TestRelation1_1";
47     }
48
49
50     protected void perform(StressHelper.Task task,
51                            int threadId,
52                            int txId,
53                            Object JavaDoc ctx,
54                            StressHelper.PerformResult res) {
55         PersistenceManager pm = getPM(task, threadId, txId);
56         try {
57             res.beginTest();
58             int oid = txId * 2;
59             beginTx(pm, task, threadId, txId);
60             // Execute first transaction (makePersistent)
61
A a1 = new A("a" + oid);
62             A a2 = new A("a" + oid + 1);
63             B b1 = new B("b" + oid);
64             B b2 = new B("b" + oid + 1);
65             pm.makePersistent(a1);
66             pm.makePersistent(a2);
67             pm.makePersistent(b1);
68             pm.makePersistent(b2);
69             commitTx(pm, task, threadId, txId);
70
71             a1.setB(b1);
72             assertTrue(b1.getA() == a1);
73             a2.setB(b2);
74             assertTrue(b2.getA() == a2);
75             a1.setB(b2);
76             assertTrue(b1.getA() == null);
77             assertTrue(b2.getA() == a1);
78             assertTrue(a2.getB() == null);
79             b1.setA(a2);
80             assertTrue(a2.getB() == b1);
81             b1.setA(a1);
82             assertTrue(a1.getB() == b1);
83             assertTrue(b2.getA() == null);
84             assertTrue(a2.getB() == null);
85
86             // Delete persistent (speedoproxy)
87
beginTx(pm, task, threadId, txId);
88             pm.deletePersistent(a1);
89             pm.deletePersistent(a2);
90             pm.deletePersistent(b1);
91             pm.deletePersistent(b2);
92             commitTx(pm, task, threadId, txId);
93
94             res.endTest();
95         } catch (JDOFatalException e) {
96             rollbackOnException(pm, e, res, task, threadId, txId);
97         } catch (Throwable JavaDoc e) {
98             stopOnError(pm, e, res, task, threadId, txId);
99         } finally {
100             closePM(pm, threadId, txId, task, res);
101         }
102     }
103
104     /**
105      * Tests the read of a lot of persistent objects, with interactive setting
106      * of test parameteres (see file userconf/project.properties).
107      */

108     public void testRelation1_1() {
109         if (interactive) {
110             perform(Integer.getInteger(THREAD, 1).intValue(),
111                     Integer.getInteger(TX, 1).intValue(),
112                     Integer.getInteger(TIMEOUT, 1).intValue(), null);
113         }
114     }
115
116     /**
117      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
118      */

119     public void testRelation1_1Th1Tx100() {
120         if (!interactive) {
121             perform(1, 100, 1000000, null);
122         }
123     }
124
125     /**
126      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
127      */

128     public void testRelation1_1Th1Tx1000() {
129         if (!interactive) {
130             perform(1, 1000, 1000000, null);
131         }
132     }
133
134     /**
135      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
136      */

137     public void testRelation1_1Th1Tx10000() {
138         if (!interactive) {
139             perform(1, 10000, 1000000, null);
140         }
141     }
142
143     /**
144      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
145      */

146     public void testRelation1_1Th2Tx100() {
147         if (!interactive) {
148             perform(2, 100, 1000000, null);
149         }
150     }
151
152     /**
153      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
154      */

155     public void testRelation1_1Th2Tx1000() {
156         if (!interactive) {
157             perform(2, 1000, 1000000, null);
158         }
159     }
160
161     /**
162      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
163      */

164     public void testRelation1_1Th2Tx10000() {
165         if (!interactive) {
166             perform(2, 10000, 1000000, null);
167         }
168     }
169
170     /**
171      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
172      */

173     public void testRelation1_1Th10Tx100() {
174         if (!interactive) {
175             perform(10, 100, 1000000, null);
176         }
177     }
178
179     /**
180      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
181      */

182     public void testRelation1_1Th10Tx1000() {
183         if (!interactive) {
184             perform(10, 1000, 1000000, null);
185         }
186     }
187
188     /**
189      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
190      */

191     public void testRelation1_1Th10Tx10000() {
192         if (!interactive) {
193             perform(10, 10000, 1000000, null);
194         }
195     }
196 }
197
Popular Tags