KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Assert;
25
26 import org.objectweb.speedo.Alea;
27 import org.objectweb.speedo.pobjects.userid.LinkedIntUserId;
28 import org.objectweb.util.monolog.api.BasicLevel;
29
30 /**
31  * Stresses the reference iteration of Speedo.
32  *
33  * @author M. Guillemin
34  */

35 public class TestNavigation extends LinkedIntUserIdHelper {
36
37     public TestNavigation(String JavaDoc s) {
38         super(s);
39     }
40
41     protected String JavaDoc getLoggerName() {
42         return STRESS_LOG_NAME + ".TestNavigation";
43     }
44
45     protected void perform(Task task,
46                            int threadId,
47                            int txId,
48                            Object JavaDoc ctx,
49                            PerformResult res) {
50         LIUICtx nctx = (LIUICtx) ctx;
51         PersistenceManager pm = getPM(task, threadId, txId);
52         try {
53             res.beginTest();
54             beginTx(pm, task, threadId, txId);
55             // Execute one transaction: Iterate nbRead from first
56
int first = Alea.rand(0, nctx.dbSize - 1);
57             int nbRead = Alea.rand(1, 1000);
58             int name = -1;
59             if (debug) {
60                 logger.log(BasicLevel.DEBUG, "first= " + first);
61                 logger.log(BasicLevel.DEBUG, "nbRead= " + nbRead);
62             }
63             LinkedIntUserId current = (LinkedIntUserId) pm.getObjectById(nctx.oids[first], false);
64             for (int no = 0; no < nbRead; no++) {
65                 Assert.assertNotNull("first=" + first + " nbRead=" + nbRead, current);
66                 name = current.getName();
67                 if (debug) {
68                     logger.log(BasicLevel.DEBUG, "Obj " + name);
69                 }
70                 current = current.getNext();
71             }
72             commitTx(pm, task, threadId, txId);
73             res.endTest();
74         } catch (JDOFatalException e) {
75             rollbackOnException(pm, e, res, task, threadId, txId);
76         } catch (Throwable JavaDoc e) {
77             stopOnError(pm, e, res, task, threadId, txId);
78         } finally {
79             closePM(pm, threadId, txId, task, res);
80         }
81     }
82
83     private void performNavigation(int nbThread, int dbsize, int nbTx, int to) {
84         perform(nbThread, nbTx, to, new LIUICtx(dbsize));
85     }
86
87
88     /**
89      * Tests the reference iteration of a lot of persistent objects, with
90      * interactive setting of test parameteres (see file
91      * userconf/project.properties).
92      */

93     public void testNavigation() {
94         if (interactive) {
95             perform(Integer.getInteger(THREAD, 10).intValue(),
96                     Integer.getInteger(TX, 100).intValue(),
97                     Integer.getInteger(TIMEOUT, 200000).intValue(),
98                     new LIUICtx(
99                         Integer.getInteger(DBSIZE, 100000).intValue()));
100         }
101     }
102
103     /**
104      * Tests 100 transactions where each of them iterates nbread from first using 1 thread.
105      */

106     public void testNavigationTh1Tx100De1() {
107         if (!interactive) {
108             performNavigation(1, 100, 100, 1000000);
109         }
110     }
111
112     /**
113      * Tests 1.000 transactions where each of them iterates nbread from first using 1 thread.
114      */

115
116     public void testNavigationTh1Tx1000De1() {
117         if (!interactive) {
118             performNavigation(1, 1000, 1000, 1000000);
119         }
120     }
121
122     /**
123      * Tests 10.000 transactions where each of them iterates nbread from first using 1 thread.
124      * thread.
125      */

126
127     public void testNavigationTh1Tx10000De1() {
128         if (!interactive) {
129             performNavigation(1, 10000, 10000, 1000000);
130         }
131     }
132
133     /**
134      * Tests 100.000 transactions where each of them iterates nbread from first using 1 thread.
135      */

136
137     public void testNavigationTh1Tx100000De1() {
138         if (!interactive) {
139             performNavigation(1, 100000, 100000, 1000000);
140         }
141     }
142
143     /**
144      * Tests 100 transactions where each of them iterates nbread from first using 10 thread.
145      */

146     public void testNavigationTh10Tx100De1() {
147         if (!interactive) {
148             performNavigation(10, 100, 100, 1000000);
149         }
150     }
151
152     /**
153      * Tests 1.000 transactions where each of them iterates nbread from first using 10 thread.
154      */

155
156     public void testNavigationTh10Tx1000De1() {
157         if (!interactive) {
158             performNavigation(10, 1000, 1000, 1000000);
159         }
160     }
161
162     /**
163      * Tests 10.000 transactions where each of them iterates nbread from first using 10 threads.
164      * thread.
165      */

166
167     public void testNavigationTh10Tx10000De1() {
168         if (!interactive) {
169             performNavigation(10, 10000, 10000, 1000000);
170         }
171     }
172
173     /**
174      * Tests 100.000 transactions where each of them iterates nbread from first using 10 threads.
175      */

176
177     public void testNavigationTh10Tx100000De1() {
178         if (!interactive) {
179             performNavigation(10, 100000, 100000, 1000000);
180         }
181     }
182 }
183
Popular Tags