001: /*
002: * Speedo: an implementation of JDO compliant personality on top of JORM
003: * generic I/O sub-system. Copyright (C) 2001-2004 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Release: 1.0
020: *
021: * Created on Apr 19, 2004 @author franck.milleville@cgey.com
022: *
023: */
024: package org.objectweb.speedo.j2eedo.test;
025:
026: import java.util.ArrayList;
027: import java.util.Collections;
028: import java.util.Iterator;
029: import java.util.List;
030:
031: import javax.jdo.JDOException;
032: import javax.jdo.JDOFatalException;
033: import javax.jdo.JDOHelper;
034: import javax.jdo.PersistenceManagerFactory;
035:
036: import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
037: import org.objectweb.speedo.j2eedo.common.PMHolder;
038: import org.objectweb.util.monolog.api.BasicLevel;
039:
040: /**
041: * Exceute 20 times all {@link org.objectweb.speedo.j2eedo.bo.DatabaseImpl
042: * DatabaseImpl actions}
043: * @author fmillevi@yahoo.com
044: * @see MainLauncher
045: */
046: public class BasicTest extends MainLauncher {
047:
048: private static final int NUMBER_OF_TEST = 20;
049:
050: /**
051: * This method connects to the database using the default speedo properties
052: * file and calls the test method doTest
053: *
054: * @param args not used
055: * @throws JDOException
056: * @throws Exception
057: * @see #doTest()
058: */
059: public static void main(String[] args) throws Exception {
060: BasicTest ml = new BasicTest();
061: ml.initPMF();
062: ml.doTest();
063: }
064:
065: /**
066: * It calls several times each known actions
067: * @see org.objectweb.speedo.j2eedo.test.MainLauncher#doTest()
068: */
069: public void doTest() {
070: final List methodsList = new ArrayList(
071: DatabaseImpl.actionArray.length * NUMBER_OF_TEST);
072: for (int i = 0; i < DatabaseImpl.actionArray.length; i++) {
073: for (int j = 0; j < NUMBER_OF_TEST; j++) {
074: methodsList.add(DatabaseImpl.actionArray[i]);
075: }
076: }
077: PMHolder pmHolder = new PMHolder(JDOHelper
078: .getPersistenceManagerFactory(p));
079: Collections.shuffle(methodsList);
080: int j = 0;
081: String action = null;
082: String returnStr = null;
083: for (Iterator iter = methodsList.iterator(); iter.hasNext();) {
084: if (0 == (j++ % 100.0)) {
085: logger.log(BasicLevel.INFO, j + " actions called...");
086: }
087: action = (String) iter.next();
088: // check if the action need to start a transaction
089: logger.log(BasicLevel.DEBUG, "Calls method:" + action);
090: try {
091: returnStr = DatabaseImpl.instance.doAction(action,
092: true, pmHolder);
093: } catch (Exception e) {
094: logger.log(BasicLevel.WARN, "Action '" + action
095: + "' throws an exception :", e);
096: }
097: logger.log(BasicLevel.DEBUG, "The method " + action
098: + " returns:\n" + returnStr);
099: }
100: }
101: }
|