KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.speedo.pobjects.relations.C;
22 import org.objectweb.speedo.pobjects.relations.D;
23 import org.objectweb.util.monolog.api.BasicLevel;
24
25 import javax.jdo.JDOFatalException;
26 import javax.jdo.PersistenceManager;
27
28 /**
29  * Stress the relation one-one implementation by Speedo.
30  *
31  * @author M. Guillemin
32  */

33 public class TestRelation1_1Concurrency extends CDRelationHelper {
34
35     public TestRelation1_1Concurrency(String JavaDoc s) {
36         super(s);
37     }
38
39     protected String JavaDoc[] getClassNamesToInit() {
40         return new String JavaDoc[]{
41             org.objectweb.speedo.pobjects.relations.C.class.getName(),
42             org.objectweb.speedo.pobjects.relations.D.class.getName()
43         };
44     }
45
46     protected String JavaDoc getLoggerName() {
47         return STRESS_LOG_NAME + ".TestRelation1_1Concurrency";
48     }
49
50     protected int getNbSucc() {
51         return 2; // because d1, d2
52
}
53     
54     protected void perform(StressHelper.Task task,
55                            int threadId,
56                            int txId,
57                            Object JavaDoc ctx,
58                            StressHelper.PerformResult res) {
59         CDCtx cdctx = (CDCtx) ctx;
60         PersistenceManager pm = getPM(task, threadId, txId);
61         try {
62             res.beginTest();
63             beginTx(pm, task, threadId, txId);
64             
65             int oid = getOid(cdctx, true, getNbSucc());
66
67             C c1 = (C) pm.getObjectById(cdctx.oidsC[oid], false);
68             C c2 = (C) pm.getObjectById(cdctx.oidsC[oid+1], false);
69             D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false);
70             D d2 = (D) pm.getObjectById(cdctx.oidsD[oid+1], false);
71
72             c1.setD(d1);
73             assertTrue(d1.getC() == c1);
74             c2.setD(d2);
75             assertTrue(d2.getC() == c2);
76             c1.setD(d2);
77             assertTrue(d1.getC() == null);
78             assertTrue(d2.getC() == c1);
79             assertTrue(c2.getD() == null);
80             d1.setC(c2);
81             assertTrue(c2.getD() == d1);
82             d1.setC(c1);
83             assertTrue(c1.getD() == d1);
84             assertTrue(d2.getC() == null);
85             assertTrue(c2.getD() == null);
86
87             commitTx(pm, task, threadId, txId);
88
89             res.endTest();
90         } catch (JDOFatalException e) {
91             rollbackOnException(pm, e, res, task, threadId, txId);
92         } catch (Throwable JavaDoc e) {
93             stopOnError(pm, e, res, task, threadId, txId);
94         } finally {
95             closePM(pm, threadId, txId, task, res);
96         }
97     }
98
99     /**
100      * Tests the read of a lot of persistent objects, with interactive setting
101      * of test parameteres (see file userconf/project.properties).
102      */

103     public void testIntercative() {
104         if (interactive) {
105             logger.log(BasicLevel.INFO, "testInteractive");
106             perform(Integer.getInteger(THREAD, 1).intValue(),
107                     Integer.getInteger(TX, 1).intValue(),
108                     Integer.getInteger(TIMEOUT, 1).intValue(),
109                     new CDCtx(Integer.getInteger(DBSIZE, 1000).intValue()));
110         } else {
111             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
112         }
113     }
114
115     /**
116      * Methode d'aiguillage
117      */

118     private void perform(
119             int nbThread,
120             int dbSize,
121             int nbTx,
122             int threadTimeout) {
123         perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize));
124     }
125
126     /**
127      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
128      */

129     public void testRelation1_1ConcurrencyTh1Tx100() {
130         if (!interactive) {
131             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh1Tx100");
132             perform(1, 10000, 100, 1000000);
133         } else {
134             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh1Tx100");
135         }
136     }
137
138     /**
139      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
140      */

141     public void testRelation1_1ConcurrencyTh1Tx1000() {
142         if (!interactive) {
143             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh1Tx1000");
144             perform(1, 10000, 1000, 1000000);
145         } else {
146             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh1Tx1000");
147         }
148     }
149
150     /**
151      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
152      */

153     public void testRelation1_1ConcurrencyTh1Tx10000() {
154         if (!interactive) {
155             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh1Tx10000");
156             perform(1, 10000, 10000, 1000000);
157         } else {
158             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh1Tx10000");
159         }
160     }
161
162     /**
163      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
164      */

165     public void testRelation1_1ConcurrencyTh2Tx100() {
166         if (!interactive) {
167             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh2Tx100");
168             perform(2, 10000, 100, 1000000);
169         } else {
170             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh2Tx100");
171         }
172     }
173
174     /**
175      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
176      */

177     public void testRelation1_1ConcurrencyTh2Tx1000() {
178         if (!interactive) {
179             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh2Tx1000");
180             perform(2, 10000, 1000, 1000000);
181         } else {
182             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh2Tx1000");
183         }
184     }
185
186     /**
187      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
188      */

189     public void testRelation1_1ConcurrencyTh2Tx10000() {
190         if (!interactive) {
191             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh2Tx10000");
192             perform(2, 10000, 10000, 1000000);
193         } else {
194             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh2Tx10000");
195         }
196     }
197
198     /**
199      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
200      */

201     public void testRelation1_1ConcurrencyTh10Tx100() {
202         if (!interactive) {
203             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh10Tx100");
204             perform(10, 10000, 100, 1000000);
205         } else {
206             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh10Tx100");
207         }
208     }
209
210     /**
211      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
212      */

213     public void testRelation1_1ConcurrencyTh10Tx1000() {
214         if (!interactive) {
215             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh10Tx1000");
216             perform(10, 10000, 1000, 1000000);
217         } else {
218             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh10Tx1000");
219         }
220     }
221
222     /**
223      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
224      */

225     public void testRelation1_1ConcurrencyTh10Tx10000() {
226         if (!interactive) {
227             logger.log(BasicLevel.INFO, "testRelation1_1ConcurrencyTh10Tx10000");
228             perform(10, 10000, 10000, 1000000);
229         } else {
230             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_1ConcurrencyTh10Tx10000");
231         }
232     }
233 }
234
Popular Tags