KickJava   Java API By Example, From Geeks To Geeks.

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


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-many implementation by Speedo.
30  *
31  * @author M. Guillemin
32  */

33 public class TestRelation1_NConcurrency extends CDRelationHelper {
34
35     public TestRelation1_NConcurrency(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_NConcurrency";
48     }
49
50     protected int getNbSucc() {
51         return 4; // because d1, d2, d3, d4
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, (task.txToExecute.length==0), 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             D d3 = (D) pm.getObjectById(cdctx.oidsD[oid+2], false);
72             D d4 = (D) pm.getObjectById(cdctx.oidsD[oid+3], false);
73             
74             c1.getNds().add(d1);
75             assertTrue(d1.getNc() == c1);
76             c1.getNds().add(d2);
77             assertTrue(d2.getNc() == c1);
78
79             c2.getNds().add(d3);
80             assertTrue(d3.getNc() == c2);
81             c2.getNds().add(d4);
82             assertTrue(d4.getNc() == c2);
83
84             c1.getNds().add(d3);
85             assertTrue(d3.getNc() == c1);
86             assertTrue(!c2.getNds().contains(d3));
87
88             c1.getNds().remove(d1);
89             assertTrue(d1.getNc() == null);
90
91             d3.setNc(c2);
92             assertTrue(!c1.getNds().contains(d3));
93             assertTrue(c2.getNds().contains(d3));
94
95             c1.setNds(c2.getNds());
96             
97             commitTx(pm, task, threadId, txId);
98             
99             assertTrue(!c1.getNds().contains(d1));
100             assertTrue(!c1.getNds().contains(d2));
101             assertTrue(c1.getNds().contains(d3));
102             assertTrue(c1.getNds().contains(d4));
103             assertTrue(c1.getNds().size() == 2);
104
105             assertTrue(!c2.getNds().contains(d1));
106             assertTrue(!c2.getNds().contains(d2));
107             assertTrue(!c2.getNds().contains(d3));
108             assertTrue(!c2.getNds().contains(d4));
109
110             assertTrue(d1.getNc() == null);
111             assertTrue(d2.getNc() == null);
112             assertTrue(d3.getNc() == c1);
113             assertTrue(d4.getNc() == c1);
114             
115             res.endTest();
116         } catch (JDOFatalException e) {
117             rollbackOnException(pm, e, res, task, threadId, txId);
118         } catch (Throwable JavaDoc e) {
119             stopOnError(pm, e, res, task, threadId, txId);
120         } finally {
121             closePM(pm, threadId, txId, task, res);
122         }
123     }
124
125
126     /**
127      * Tests the read of a lot of persistent objects, with interactive setting
128      * of test parameteres (see file userconf/project.properties).
129      */

130     public void testInteractive() {
131         if (interactive) {
132             logger.log(BasicLevel.INFO, "testInteractive");
133             perform(Integer.getInteger(THREAD, 1).intValue(),
134                     Integer.getInteger(TX, 1).intValue(),
135                     Integer.getInteger(TIMEOUT, 1).intValue(),
136                     new CDCtx(Integer.getInteger(DBSIZE, 1000).intValue()));
137         } else {
138             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
139         }
140     }
141
142     /**
143      * Methode d'aiguillage
144      */

145     private void perform(
146             int nbThread,
147             int dbSize,
148             int nbTx,
149             int threadTimeout) {
150         perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize));
151     }
152
153     /**
154      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
155      */

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

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

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

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

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

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

228     public void testRelation1_NConcurrencyTh10Tx100() {
229         if (!interactive) {
230             logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh10Tx100");
231             perform(10, 10000, 100, 1000000);
232         } else {
233             logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx100");
234         }
235     }
236
237     /**
238      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
239      */

240     public void testRelation1_NConcurrencyTh10Tx1000() {
241         if (!interactive) {
242             logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh10Tx1000");
243             perform(10, 10000, 1000, 1000000);
244         } else {
245             logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx1000");
246         }
247     }
248
249     /**
250      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
251      */

252     public void testRelation1_NConcurrencyTh10Tx10000() {
253         if (!interactive) {
254             logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh10Tx10000");
255             perform(10, 10000, 10000, 1000000);
256         } else {
257             logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx10000");
258         }
259     }
260 }
261
Popular Tags