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 java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.jdo.JDOFatalException;
023: import javax.jdo.PersistenceManager;
024:
025: import junit.framework.Assert;
026:
027: import org.objectweb.speedo.pobjects.collection.AllCollection;
028: import org.objectweb.util.monolog.api.BasicLevel;
029:
030: /**
031: * Stress the collection access function of Speedo.
032: *
033: * @author S.Rodiere
034: */
035: public class TestCollection extends StressHelper {
036: static private int nbBeginTest = 0;
037:
038: public TestCollection(String s) {
039: super (s);
040: }
041:
042: protected String[] getClassNamesToInit() {
043: return new String[] { AllCollection.class.getName() };
044: }
045:
046: protected String getLoggerName() {
047: return STRESS_LOG_NAME + ".TestCollection";
048: }
049:
050: protected void perform(Task task, int threadId, int txId,
051: Object ctx, PerformResult res) {
052: synchronized (this ) {
053: nbBeginTest++;
054: }
055: long oids = (nbBeginTest * 6);
056: PersistenceManager pm = getPM(task, threadId, txId);
057: try {
058: res.beginTest();
059: // Execute first transaction on persistent Collections
060: beginTx(pm, task, threadId, txId);
061: long[] ls = new long[] { oids, oids + 1, oids + 2,
062: oids + 3, oids + 4, oids + 5 };
063: long[] reverse = new long[] { oids + 5, oids + 4, oids + 3,
064: oids + 2, oids + 1, oids };
065: AllCollection ac = new AllCollection("stressCollection"
066: + nbBeginTest);
067: ac.setLongs(ls);
068: ac.setRefs(new Object[] { ac });
069: pm.makePersistent(ac);
070: commitTx(pm, task, threadId, txId);
071:
072: // Reverse the data
073: ac.setLongs(reverse);
074: ac.setRefs(new Object[] { ac });
075:
076: // Verify result
077: List expectedLong = new ArrayList(reverse.length);
078: for (int i = 0; i < reverse.length; i++) {
079: expectedLong.add(new Long(reverse[i]));
080: }
081:
082: List expectedRef = new ArrayList(1);
083: expectedRef.add(ac);
084:
085: //Collection
086: Assert.assertNotNull("The collection of Long is null", ac
087: .getCol_Long());
088: assertSameCollection("The collection of Long",
089: expectedLong, ac.getCol_Long());
090: Assert.assertNotNull("The collection of reference is null",
091: ac.getCol_ref());
092: assertSameCollection("The collection of ref", expectedRef,
093: ac.getCol_ref());
094:
095: //HashSet
096: Assert.assertNotNull("The Hashset of Long is null", ac
097: .getHset_Long());
098: assertSameCollection("The Hashset of Long", expectedLong,
099: ac.getHset_Long());
100: Assert.assertNotNull("The Hashset of reference is null", ac
101: .getHset_ref());
102: assertSameCollection("The Hashset of ref", expectedRef, ac
103: .getHset_ref());
104:
105: //List
106: Assert.assertNotNull("The list of Long is null", ac
107: .getList_Long());
108: assertSameList("The list of Long", expectedLong, ac
109: .getList_Long());
110: Assert.assertNotNull("The list of reference is null", ac
111: .getList_ref());
112: assertSameList("The list of reference", expectedRef, ac
113: .getList_ref());
114:
115: //Set
116: Assert.assertNotNull("The set of Long is null", ac
117: .getSet_Long());
118: assertSameCollection("The set of Long", expectedLong, ac
119: .getSet_Long());
120: Assert.assertNotNull("The set of reference is null", ac
121: .getSet_ref());
122: assertSameCollection("The set of ref", expectedRef, ac
123: .getSet_ref());
124:
125: // Execute second transaction on persistent Collections
126: beginTx(pm, task, threadId, txId);
127: logger.log(BasicLevel.DEBUG, ac.getId()
128: + " is being deleted");
129: pm.deletePersistent(ac);
130: commitTx(pm, task, threadId, txId);
131: res.endTest();
132:
133: } catch (JDOFatalException e) {
134: rollbackOnException(pm, e, res, task, threadId, txId);
135: } catch (Throwable e) {
136: stopOnError(pm, e, res, task, threadId, txId);
137: } finally {
138: closePM(pm, threadId, txId, task, res);
139: }
140: }
141:
142: /**
143: * Tests the read of a lot of persistent objects, with interactive setting
144: * of test parameteres (see file userconf/project.properties).
145: */
146: public void testCollection() {
147: if (interactive) {
148: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
149: .getInteger(TX, 9).intValue(), Integer.getInteger(
150: TIMEOUT, 200000).intValue(), null);
151: }
152: }
153:
154: /**
155: * Tests 100 transactions which stress collections using 1 thread.
156: */
157: public void testCollectionTh1Tx100() {
158: if (!interactive) {
159: logger.log(BasicLevel.INFO, "testCollectionTh1Tx100");
160: perform(1, 100, 1000000, null);
161: }
162: }
163:
164: /**
165: * Tests 1.000 transactions which stress collections using 1 thread.
166: */
167: public void testCollectionTh1Tx1000() {
168:
169: if (!interactive) {
170: logger.log(BasicLevel.INFO, "testCollectionTh1Tx1000");
171: perform(1, 1000, 1000000, null);
172: }
173: }
174:
175: /**
176: * Tests 10.000 transactions which stress collections using 1 thread.
177: */
178: public void testCollectionTh1Tx10000() {
179:
180: if (!interactive) {
181: logger.log(BasicLevel.INFO, "testCollectionTh1Tx10000");
182: perform(1, 10000, 1000000, null);
183: }
184: }
185:
186: /**
187: * Tests 100.000 transactions which stress collections using 1 thread.
188: */
189: public void _testCollectionTh1Tx100000() {
190:
191: if (!interactive) {
192: logger.log(BasicLevel.INFO, "testCollectionTh1Tx100000");
193: perform(1, 100000, 1000000, null);
194: }
195: }
196:
197: /**
198: * Tests 100 transactions which stress collections using 2 thread.
199: */
200: public void testCollectionTh2Tx100() {
201:
202: if (!interactive) {
203: logger.log(BasicLevel.INFO, "testCollectionTh2Tx100");
204: perform(2, 100, 1000000, null);
205: }
206: }
207:
208: /**
209: * Tests 1000 transactions which stress collections using 2 thread.
210: */
211: public void testCollectionTh2Tx1000() {
212:
213: if (!interactive) {
214: logger.log(BasicLevel.INFO, "testCollectionTh2Tx1000");
215: perform(2, 1000, 1000000, null);
216: }
217: }
218:
219: /**
220: * Tests 10.000 transactions which stress collections using 2 thread.
221: */
222: public void testCollectionTh2Tx10000() {
223:
224: if (!interactive) {
225: logger.log(BasicLevel.INFO, "testCollectionTh2Tx10000");
226: perform(2, 10000, 1000000, null);
227: }
228: }
229:
230: /**
231: * Tests 100.000 transactions which stress collections using 2 thread.
232: */
233: public void _testCollectionTh2Tx100000() {
234:
235: if (!interactive) {
236: logger.log(BasicLevel.INFO, "testCollectionTh2Tx100000");
237: perform(2, 100000, 1000000, null);
238: }
239: }
240:
241: /**
242: * Tests 1000 transactions which stress collections using 10 thread.
243: */
244: public void testCollectionTh10Tx1000() {
245:
246: if (!interactive) {
247: logger.log(BasicLevel.INFO, "testCollectionTh10Tx1000");
248: perform(10, 1000, 1000000, null);
249: }
250: }
251:
252: /**
253: * Tests 10.000 transactions which stress collections using 10 thread.
254: */
255: public void testCollectionTh10Tx10000() {
256:
257: if (!interactive) {
258: logger.log(BasicLevel.INFO, "testCollectionTh10Tx10000");
259: perform(10, 10000, 1000000, null);
260: }
261: }
262:
263: /**
264: * Tests 100.000 transactions which stress collections using 10 thread.
265: */
266: public void _testCollectionTh10Tx100000() {
267:
268: if (!interactive) {
269: logger.log(BasicLevel.INFO, "testCollectionTh10Tx100000");
270: perform(10, 100000, 1000000, null);
271: }
272: }
273:
274: /**
275: * Tests 100 transactions which stress collections using 100 thread.
276: */
277: public void testCollectionTh100Tx100() {
278:
279: if (!interactive) {
280: logger.log(BasicLevel.INFO, "testCollectionTh100Tx100");
281: perform(100, 100, 1000000, null);
282: }
283: }
284:
285: /**
286: * Tests 1000 transactions which stress collections using 1000 thread.
287: */
288: public void testCollectionTh1000Tx1000() {
289:
290: if (!interactive) {
291: logger.log(BasicLevel.INFO, "testCollectionTh1000Tx1000");
292: perform(1000, 1000, 1000000, null);
293: }
294: }
295:
296: }
|