001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.stress;
018:
019: import javax.jdo.JDOFatalException;
020: import javax.jdo.PersistenceManager;
021:
022: import junit.framework.Assert;
023:
024: import org.objectweb.speedo.Alea;
025: import org.objectweb.speedo.pobjects.userid.LinkedIntUserId;
026: import org.objectweb.util.monolog.api.BasicLevel;
027:
028: /**
029: * Stresses the reference iteration of Speedo.
030: *
031: * @author M. Guillemin
032: */
033: public class TestNavigation extends LinkedIntUserIdHelper {
034:
035: public TestNavigation(String s) {
036: super (s);
037: }
038:
039: protected String getLoggerName() {
040: return STRESS_LOG_NAME + ".TestNavigation";
041: }
042:
043: protected void perform(Task task, int threadId, int txId,
044: Object ctx, PerformResult res) {
045: LIUICtx nctx = (LIUICtx) ctx;
046: PersistenceManager pm = getPM(task, threadId, txId);
047: try {
048: res.beginTest();
049: beginTx(pm, task, threadId, txId);
050: // Execute one transaction: Iterate nbRead from first
051: int first = Alea.rand(0, nctx.dbSize - 1);
052: int nbRead = Alea.rand(1, 1000);
053: int name = -1;
054: if (debug) {
055: logger.log(BasicLevel.DEBUG, "first= " + first);
056: logger.log(BasicLevel.DEBUG, "nbRead= " + nbRead);
057: }
058: LinkedIntUserId current = (LinkedIntUserId) pm
059: .getObjectById(nctx.oids[first], false);
060: for (int no = 0; no < nbRead; no++) {
061: Assert.assertNotNull("first=" + first + " nbRead="
062: + nbRead, current);
063: name = current.getName();
064: if (debug) {
065: logger.log(BasicLevel.DEBUG, "Obj " + name);
066: }
067: current = current.getNext();
068: }
069: commitTx(pm, task, threadId, txId);
070: res.endTest();
071: } catch (JDOFatalException e) {
072: rollbackOnException(pm, e, res, task, threadId, txId);
073: } catch (Throwable e) {
074: stopOnError(pm, e, res, task, threadId, txId);
075: } finally {
076: closePM(pm, threadId, txId, task, res);
077: }
078: }
079:
080: private void performNavigation(int nbThread, int dbsize, int nbTx,
081: int to) {
082: perform(nbThread, nbTx, to, new LIUICtx(dbsize));
083: }
084:
085: /**
086: * Tests the reference iteration of a lot of persistent objects, with
087: * interactive setting of test parameteres (see file
088: * userconf/project.properties).
089: */
090: public void testNavigation() {
091: if (interactive) {
092: perform(Integer.getInteger(THREAD, 10).intValue(), Integer
093: .getInteger(TX, 100).intValue(), Integer
094: .getInteger(TIMEOUT, 200000).intValue(),
095: new LIUICtx(Integer.getInteger(DBSIZE, 100000)
096: .intValue()));
097: }
098: }
099:
100: /**
101: * Tests 100 transactions where each of them iterates nbread from first using 1 thread.
102: */
103: public void testNavigationTh1Tx100De1() {
104: if (!interactive) {
105: performNavigation(1, 100, 100, 1000000);
106: }
107: }
108:
109: /**
110: * Tests 1.000 transactions where each of them iterates nbread from first using 1 thread.
111: */
112:
113: public void testNavigationTh1Tx1000De1() {
114: if (!interactive) {
115: performNavigation(1, 1000, 1000, 1000000);
116: }
117: }
118:
119: /**
120: * Tests 10.000 transactions where each of them iterates nbread from first using 1 thread.
121: * thread.
122: */
123:
124: public void testNavigationTh1Tx10000De1() {
125: if (!interactive) {
126: performNavigation(1, 10000, 10000, 1000000);
127: }
128: }
129:
130: /**
131: * Tests 100.000 transactions where each of them iterates nbread from first using 1 thread.
132: */
133:
134: public void testNavigationTh1Tx100000De1() {
135: if (!interactive) {
136: performNavigation(1, 100000, 100000, 1000000);
137: }
138: }
139:
140: /**
141: * Tests 100 transactions where each of them iterates nbread from first using 10 thread.
142: */
143: public void testNavigationTh10Tx100De1() {
144: if (!interactive) {
145: performNavigation(10, 100, 100, 1000000);
146: }
147: }
148:
149: /**
150: * Tests 1.000 transactions where each of them iterates nbread from first using 10 thread.
151: */
152:
153: public void testNavigationTh10Tx1000De1() {
154: if (!interactive) {
155: performNavigation(10, 1000, 1000, 1000000);
156: }
157: }
158:
159: /**
160: * Tests 10.000 transactions where each of them iterates nbread from first using 10 threads.
161: * thread.
162: */
163:
164: public void testNavigationTh10Tx10000De1() {
165: if (!interactive) {
166: performNavigation(10, 10000, 10000, 1000000);
167: }
168: }
169:
170: /**
171: * Tests 100.000 transactions where each of them iterates nbread from first using 10 threads.
172: */
173:
174: public void testNavigationTh10Tx100000De1() {
175: if (!interactive) {
176: performNavigation(10, 100000, 100000, 1000000);
177: }
178: }
179: }
|