1 24 package org.objectweb.speedo.j2eedo.test; 25 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import javax.jdo.JDOException; 32 import javax.jdo.JDOFatalException; 33 import javax.jdo.JDOHelper; 34 import javax.jdo.PersistenceManagerFactory; 35 36 import org.objectweb.speedo.j2eedo.bo.DatabaseImpl; 37 import org.objectweb.speedo.j2eedo.common.PMHolder; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 46 public class BasicTest extends MainLauncher { 47 48 private static final int NUMBER_OF_TEST = 20; 49 50 59 public static void main(String [] args) throws JDOException, Exception { 60 BasicTest ml = new BasicTest(); 61 ml.initPMF(); 62 ml.doTest(); 63 } 64 65 69 public void doTest() throws JDOException, Exception { 70 final List methodsList = new ArrayList (); 71 72 for (int i = 0; i < DatabaseImpl.actionArray.length; i++) 73 for (int j = 0; j < NUMBER_OF_TEST; j++) 74 methodsList.add(DatabaseImpl.actionArray[i]); 75 76 String action = null; 77 String returnStr = null; 78 Iterator iter = null; 79 PersistenceManagerFactory pmf = 80 JDOHelper.getPersistenceManagerFactory(p); 81 PMHolder pmHolder = new PMHolder(pmf); 82 83 DatabaseImpl databaseImpl = new DatabaseImpl(pmHolder); 84 85 int j = 0; 86 87 Collections.shuffle(methodsList); 88 iter = methodsList.iterator(); 89 while (iter.hasNext()) { 90 if (0 == (j++ % 100.0)) 91 logger.log( 92 BasicLevel.INFO, 93 j + " actions called..."); 94 action = (String ) iter.next(); 95 logger.log(BasicLevel.DEBUG, "Calls method:" + action); 97 try { 98 returnStr = databaseImpl.doAction(action, true); 99 } catch (JDOFatalException e) { 100 logger.log( 101 BasicLevel.WARN, 102 "Action '" 103 + action 104 + "' throws a JDOFatalException exception :", 105 e); 106 } catch (JDOException e) { 107 logger.log( 108 BasicLevel.WARN, 109 "Action '" + action + "' throws a JDO exception :", 110 e); 111 } catch (Exception e) { 112 logger.log( 113 BasicLevel.WARN, 114 "Action '" + action + "' throws an exception :", 115 e); 116 } 117 118 logger.log( 119 BasicLevel.DEBUG, 120 "The method " + action + " returns:\n" + returnStr); 121 } 122 } 123 } 124 | Popular Tags |