KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24
25 import javax.jdo.JDOFatalException;
26 import javax.jdo.PersistenceManager;
27
28 import junit.framework.Assert;
29 import org.objectweb.speedo.Alea;
30 import org.objectweb.speedo.pobjects.collection.AllCollection;
31 import org.objectweb.util.monolog.api.BasicLevel;
32
33 /**
34  * Stress the collection access function of Speedo.
35  *
36  * @author M.Guillemin
37  */

38 public class TestCollectionConcurrency extends AllCollectionHelper {
39
40     public TestCollectionConcurrency(String JavaDoc s) {
41         super(s);
42         logger.log(BasicLevel.INFO, "TestCollectionConcurrency");
43     }
44
45     protected String JavaDoc[] getClassNamesToInit() {
46         return new String JavaDoc[]{AllCollection.class.getName()};
47     }
48
49     protected String JavaDoc getLoggerName() {
50         return STRESS_LOG_NAME + ".TestCollectionConcurrency";
51     }
52
53     protected void perform(Task task, int threadId, int txId, Object JavaDoc ctx, PerformResult res) {
54         long _oids = (txId * 6);
55         ACCtx acctx = (ACCtx) ctx;
56         PersistenceManager pm = getPM(task, threadId,txId);
57         try {
58             res.beginTest();
59                         
60             long[] reverse = new long[]{_oids + 5, _oids + 4, _oids + 3, _oids + 2, _oids + 1, _oids};
61             // Reverse a persistent Collections at random
62
int oid = Alea.rand(0, acctx.dbSize - 1);
63             beginTx(pm, task, threadId, txId);
64             AllCollection ac = (AllCollection) pm.getObjectById(acctx.oids[oid], false);
65             
66             // Reverse the data
67
logger.log(BasicLevel.DEBUG, "reverse data of "+ac.getId());
68             ac.setLongs(reverse);
69             ac.setRefs(new Object JavaDoc[]{ac});
70             
71             
72             // Verify result
73
List JavaDoc expectedLong = new ArrayList JavaDoc(reverse.length);
74             for (int i = 0; i < reverse.length; i++) {
75                 expectedLong.add(new Long JavaDoc(reverse[i]));
76             }
77
78             List JavaDoc expectedRef = new ArrayList JavaDoc(1);
79             expectedRef.add(ac);
80
81             //Collection
82
Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
83             assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long());
84             Assert.assertNotNull("The collection of reference is null", ac.getCol_ref());
85             assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref());
86
87             //HashSet
88
Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long());
89             assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long());
90             Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref());
91             assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref());
92
93             //List
94
Assert.assertNotNull("The list of Long is null", ac.getList_Long());
95             assertSameList("The list of Long", expectedLong, ac.getList_Long());
96             Assert.assertNotNull("The list of reference is null", ac.getList_ref());
97             assertSameList("The list of reference", expectedRef, ac.getList_ref());
98
99             //Set
100
Assert.assertNotNull("The set of Long is null", ac.getSet_Long());
101             assertSameCollection("The set of Long", expectedLong, ac.getSet_Long());
102             Assert.assertNotNull("The set of reference is null", ac.getSet_ref());
103             assertSameCollection("The set of ref", expectedRef, ac.getSet_ref());
104             
105             commitTx(pm, task, threadId, txId);
106
107             res.endTest();
108         } catch (JDOFatalException e) {
109             rollbackOnException(pm, e, res, task, threadId, txId);
110         } catch (Throwable JavaDoc e) {
111             stopOnError(pm, e, res, task, threadId, txId);
112         } finally {
113             closePM(pm, threadId, txId, task, res);
114         }
115     }
116
117     /**
118      * Methode d'aiguillage
119      */

120     private void perform(
121             int nbThread,
122             int dbSize,
123             int nbTx,
124             int threadTimeout) {
125         perform(nbThread, nbTx, threadTimeout, new ACCtx(dbSize));
126     }
127
128     /**
129      * Tests the modification of a lot of persistent Collection objects, with interactive
130      * setting of test parameteres (see file userconf/project.properties).
131      */

132     public void testInteractive (){
133         if (interactive) {
134             logger.log(BasicLevel.INFO, "testInteractive");
135             perform(Integer.getInteger(THREAD, 1).intValue(),
136                     Integer.getInteger(TX, 9).intValue(),
137                     Integer.getInteger(TIMEOUT, 200000).intValue(),
138                     new ACCtx(Integer.getInteger(DBSIZE, 1000).intValue())
139             );
140         } else {
141             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
142         }
143     }
144
145     /**
146      * Tests 100 transactions which stress collections using 1 thread.
147      */

148     public void testCollectionConcurrencyTh1Tx100() {
149         if (!interactive) {
150             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx100");
151             perform(1, 10000, 100, 1000000);
152         } else {
153             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx100");
154         }
155     }
156
157     /**
158      * Tests 1.000 transactions which stress collections using 1 thread.
159      */

160     public void testCollectionConcurrencyTh1Tx1000() {
161
162         if (!interactive) {
163             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx1000");
164             perform(1, 10000, 1000, 1000000);
165         } else {
166             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx1000");
167         }
168     }
169
170     /**
171      * Tests 10.000 transactions which stress collections using 1 thread.
172      */

173     public void testCollectionConcurrencyTh1Tx10000() {
174
175         if (!interactive) {
176             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx10000");
177             perform(1, 10000, 10000, 1000000);
178         } else {
179             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx10000");
180         }
181     }
182
183     /**
184      * Tests 100.000 transactions which stress collections using 1 thread.
185      */

186     public void _testCollectionConcurrencyTh1Tx100000() {
187
188         if (!interactive) {
189             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx100000");
190             perform(1, 10000, 100000, 1000000);
191         } else {
192             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx100000");
193         }
194     }
195
196     /**
197      * Tests 100 transactions which stress collections using 2 thread.
198      */

199     public void testCollectionConcurrencyTh2Tx100() {
200
201         if (!interactive) {
202             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx100");
203             perform(2, 10000, 100, 1000000);
204         } else {
205             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx100");
206         }
207         
208     }
209
210     /**
211      * Tests 1000 transactions which stress collections using 2 thread.
212      */

213     public void testCollectionConcurrencyTh2Tx1000() {
214
215         if (!interactive) {
216             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx1000");
217             perform(2, 10000, 1000, 1000000);
218         } else {
219             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx1000");
220         }
221     }
222
223     /**
224      * Tests 10.000 transactions which stress collections using 2 thread.
225      */

226     public void testCollectionConcurrencyTh2Tx10000() {
227
228         if (!interactive) {
229             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx10000");
230             perform(2, 10000, 10000, 1000000);
231         } else {
232             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx10000");
233         }
234     }
235
236     /**
237      * Tests 100.000 transactions which stress collections using 2 thread.
238      */

239     public void _testCollectionConcurrencyTh2Tx100000() {
240
241         if (!interactive) {
242             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx100000");
243             perform(2, 10000, 100000, 1000000);
244         } else {
245             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx100000");
246         }
247     }
248
249
250     /**
251      * Tests 1000 transactions which stress collections using 10 thread.
252      */

253     public void testCollectionConcurrencyTh10Tx1000() {
254
255         if (!interactive) {
256             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx1000");
257             perform(10, 10000, 1000, 1000000);
258         } else {
259             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx1000");
260         }
261     }
262
263     /**
264      * Tests 10.000 transactions which stress collections using 10 thread.
265      */

266     public void testCollectionConcurrencyTh10Tx10000() {
267
268         if (!interactive) {
269             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx10000");
270             perform(10, 10000, 10000, 1000000);
271         } else {
272             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx10000");
273         }
274     }
275
276     /**
277      * Tests 100.000 transactions which stress collections using 10 thread.
278      */

279     public void _testCollectionConcurrencyTh10Tx100000() {
280
281         if (!interactive) {
282             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx100000");
283             perform(10, 10000, 100000, 1000000);
284         } else {
285             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx100000");
286         }
287     }
288
289     /**
290      * Tests 100 transactions which stress collections using 100 thread.
291      */

292     public void testCollectionConcurrencyTh100Tx100() {
293
294         if (!interactive) {
295             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh100Tx100");
296             perform(100, 10000, 100, 1000000);
297         } else {
298             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh100Tx100");
299         }
300     }
301
302     /**
303      * Tests 1000 transactions which stress collections using 1000 thread.
304      */

305     public void testCollectionConcurrencyTh1000Tx1000() {
306         
307         if (!interactive) {
308             logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1000Tx1000");
309             perform(1000, 10000, 1000, 1000000);
310         } else {
311             logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1000Tx1000");
312         }
313     }
314
315 }
316
Popular Tags