KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.jdo.JDOFatalException;
25 import javax.jdo.PersistenceManager;
26
27 import junit.framework.Assert;
28
29 import org.objectweb.speedo.pobjects.collection.AllCollection;
30 import org.objectweb.util.monolog.api.BasicLevel;
31
32 /**
33  * Stress the collection access function of Speedo.
34  *
35  * @author S.Rodiere
36  */

37 public class TestCollection extends StressHelper {
38     static private int nbBeginTest = 0;
39     
40     public TestCollection(String JavaDoc s) {
41         super(s);
42     }
43
44     protected String JavaDoc[] getClassNamesToInit() {
45         return new String JavaDoc[]{AllCollection.class.getName()};
46     }
47
48     protected String JavaDoc getLoggerName() {
49         return STRESS_LOG_NAME + ".TestCollection";
50     }
51
52     protected void perform(Task task, int threadId, int txId, Object JavaDoc ctx, PerformResult res) {
53         synchronized (this){
54             nbBeginTest++;
55         }
56         long oids = (nbBeginTest * 6);
57         PersistenceManager pm = getPM(task, threadId, txId);
58         try {
59             res.beginTest();
60             // Execute first transaction on persistent Collections
61
beginTx(pm, task, threadId, txId);
62             long[] ls = new long[]{oids, oids + 1, oids + 2, oids + 3, oids + 4, oids + 5};
63             long[] reverse = new long[]{oids + 5, oids + 4, oids + 3, oids + 2, oids + 1, oids};
64             AllCollection ac = new AllCollection("stressCollection" + nbBeginTest);
65             ac.setLongs(ls);
66             ac.setRefs(new Object JavaDoc[]{ac});
67             pm.makePersistent(ac);
68             commitTx(pm, task, threadId, txId);
69
70             // Reverse the data
71
ac.setLongs(reverse);
72             ac.setRefs(new Object JavaDoc[]{ac});
73
74             // Verify result
75
List JavaDoc expectedLong = new ArrayList JavaDoc(reverse.length);
76             for (int i = 0; i < reverse.length; i++) {
77                 expectedLong.add(new Long JavaDoc(reverse[i]));
78             }
79
80             List JavaDoc expectedRef = new ArrayList JavaDoc(1);
81             expectedRef.add(ac);
82
83             //Collection
84
Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
85             assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long());
86             Assert.assertNotNull("The collection of reference is null", ac.getCol_ref());
87             assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref());
88
89             //HashSet
90
Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long());
91             assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long());
92             Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref());
93             assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref());
94
95             //List
96
Assert.assertNotNull("The list of Long is null", ac.getList_Long());
97             assertSameList("The list of Long", expectedLong, ac.getList_Long());
98             Assert.assertNotNull("The list of reference is null", ac.getList_ref());
99             assertSameList("The list of reference", expectedRef, ac.getList_ref());
100
101             //Set
102
Assert.assertNotNull("The set of Long is null", ac.getSet_Long());
103             assertSameCollection("The set of Long", expectedLong, ac.getSet_Long());
104             Assert.assertNotNull("The set of reference is null", ac.getSet_ref());
105             assertSameCollection("The set of ref", expectedRef, ac.getSet_ref());
106
107             // Execute second transaction on persistent Collections
108
beginTx(pm, task, threadId, txId);
109             logger.log(BasicLevel.DEBUG, ac.getId() + " is being deleted");
110             pm.deletePersistent(ac);
111             commitTx(pm, task, threadId, txId);
112             res.endTest();
113             
114         } catch (JDOFatalException e) {
115             rollbackOnException(pm, e, res, task, threadId, txId);
116         } catch (Throwable JavaDoc e) {
117             stopOnError(pm, e, res, task, threadId, txId);
118         } finally {
119             closePM(pm, threadId, txId, task, res);
120         }
121     }
122
123     /**
124      * Tests the read of a lot of persistent objects, with interactive setting
125      * of test parameteres (see file userconf/project.properties).
126      */

127     public void testCollection() {
128         if (interactive) {
129             perform(Integer.getInteger(THREAD, 1).intValue(),
130                     Integer.getInteger(TX, 9).intValue(),
131                     Integer.getInteger(TIMEOUT, 200000).intValue(), null);
132         }
133     }
134
135     /**
136      * Tests 100 transactions which stress collections using 1 thread.
137      */

138     public void testCollectionTh1Tx100() {
139         if (!interactive) {
140             logger.log(BasicLevel.INFO, "testCollectionTh1Tx100");
141             perform(1, 100, 1000000, null);
142         }
143     }
144
145     /**
146      * Tests 1.000 transactions which stress collections using 1 thread.
147      */

148     public void testCollectionTh1Tx1000() {
149
150         if (!interactive) {
151             logger.log(BasicLevel.INFO, "testCollectionTh1Tx1000");
152             perform(1, 1000, 1000000, null);
153         }
154     }
155
156     /**
157      * Tests 10.000 transactions which stress collections using 1 thread.
158      */

159     public void testCollectionTh1Tx10000() {
160
161         if (!interactive) {
162             logger.log(BasicLevel.INFO, "testCollectionTh1Tx10000");
163             perform(1, 10000, 1000000, null);
164         }
165     }
166
167     /**
168      * Tests 100.000 transactions which stress collections using 1 thread.
169      */

170     public void _testCollectionTh1Tx100000() {
171
172         if (!interactive) {
173             logger.log(BasicLevel.INFO, "testCollectionTh1Tx100000");
174             perform(1, 100000, 1000000, null);
175         }
176     }
177
178     /**
179      * Tests 100 transactions which stress collections using 2 thread.
180      */

181     public void testCollectionTh2Tx100() {
182
183         if (!interactive) {
184             logger.log(BasicLevel.INFO, "testCollectionTh2Tx100");
185             perform(2, 100, 1000000, null);
186         }
187     }
188
189     /**
190      * Tests 1000 transactions which stress collections using 2 thread.
191      */

192     public void testCollectionTh2Tx1000() {
193
194         if (!interactive) {
195             logger.log(BasicLevel.INFO, "testCollectionTh2Tx1000");
196             perform(2, 1000, 1000000, null);
197         }
198     }
199
200     /**
201      * Tests 10.000 transactions which stress collections using 2 thread.
202      */

203     public void testCollectionTh2Tx10000() {
204
205         if (!interactive) {
206             logger.log(BasicLevel.INFO, "testCollectionTh2Tx10000");
207             perform(2, 10000, 1000000, null);
208         }
209     }
210
211     /**
212      * Tests 100.000 transactions which stress collections using 2 thread.
213      */

214     public void _testCollectionTh2Tx100000() {
215
216         if (!interactive) {
217             logger.log(BasicLevel.INFO, "testCollectionTh2Tx100000");
218             perform(2, 100000, 1000000, null);
219         }
220     }
221
222
223     /**
224      * Tests 1000 transactions which stress collections using 10 thread.
225      */

226     public void testCollectionTh10Tx1000() {
227
228         if (!interactive) {
229             logger.log(BasicLevel.INFO, "testCollectionTh10Tx1000");
230             perform(10, 1000, 1000000, null);
231         }
232     }
233
234     /**
235      * Tests 10.000 transactions which stress collections using 10 thread.
236      */

237     public void testCollectionTh10Tx10000() {
238
239         if (!interactive) {
240             logger.log(BasicLevel.INFO, "testCollectionTh10Tx10000");
241             perform(10, 10000, 1000000, null);
242         }
243     }
244
245     /**
246      * Tests 100.000 transactions which stress collections using 10 thread.
247      */

248     public void _testCollectionTh10Tx100000() {
249
250         if (!interactive) {
251             logger.log(BasicLevel.INFO, "testCollectionTh10Tx100000");
252             perform(10, 100000, 1000000, null);
253         }
254     }
255
256     /**
257      * Tests 100 transactions which stress collections using 100 thread.
258      */

259     public void testCollectionTh100Tx100() {
260
261         if (!interactive) {
262             logger.log(BasicLevel.INFO, "testCollectionTh100Tx100");
263             perform(100, 100, 1000000, null);
264         }
265     }
266
267     /**
268      * Tests 1000 transactions which stress collections using 1000 thread.
269      */

270     public void testCollectionTh1000Tx1000() {
271         
272         if (!interactive) {
273             logger.log(BasicLevel.INFO, "testCollectionTh1000Tx1000");
274             perform(1000, 1000, 1000000, null);
275         }
276     }
277
278 }
279
Popular Tags