/*
* Speedo: an implementation of JDO compliant personality on top of JORM
* generic I/O sub-system. Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Release: 1.0
*
* Created on Apr 19, 2004 @author franck.milleville@cgey.com
*
*/
package org.objectweb.speedo.j2eedo.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.jdo.JDOException;
import javax.jdo.JDOFatalException;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;
import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
import org.objectweb.speedo.j2eedo.common.PMHolder;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* Exceute 20 times all {@link org.objectweb.speedo.j2eedo.bo.DatabaseImpl
* DatabaseImpl actions}
* @author fmillevi@yahoo.com
* @see MainLauncher
*/
public class BasicTest extends MainLauncher {
private static final int NUMBER_OF_TEST = 20;
/**
* This method connects to the database using the default speedo properties
* file and calls the test method doTest
*
* @param args not used
* @throws JDOException
* @throws Exception
* @see #doTest()
*/
public static void main(String[] args) throws Exception {
BasicTest ml = new BasicTest();
ml.initPMF();
ml.doTest();
}
/**
* It calls several times each known actions
* @see org.objectweb.speedo.j2eedo.test.MainLauncher#doTest()
*/
public void doTest() {
final List methodsList = new ArrayList(DatabaseImpl.actionArray.length * NUMBER_OF_TEST);
for (int i = 0; i < DatabaseImpl.actionArray.length; i++) {
for (int j = 0; j < NUMBER_OF_TEST; j++) {
methodsList.add(DatabaseImpl.actionArray[i]);
}
}
PMHolder pmHolder = new PMHolder(JDOHelper.getPersistenceManagerFactory(p));
Collections.shuffle(methodsList);
int j = 0;
String action = null;
String returnStr = null;
for(Iterator iter = methodsList.iterator(); iter.hasNext();) {
if (0 == (j++ % 100.0)) {
logger.log(BasicLevel.INFO, j + " actions called...");
}
action = (String) iter.next();
// check if the action need to start a transaction
logger.log(BasicLevel.DEBUG, "Calls method:" + action);
try {
returnStr = DatabaseImpl.instance.doAction(action, true, pmHolder);
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Action '" + action
+ "' throws an exception :", e);
}
logger.log(BasicLevel.DEBUG,
"The method " + action + " returns:\n" + returnStr);
}
}
}