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 ShowConcurrencyErrors extends MainLauncher { 47 57 public static void main(String [] args) throws JDOException, Exception { 58 ShowConcurrencyErrors ml = new ShowConcurrencyErrors(); 59 ml.initPMF(); 60 ml.doTest(); 61 } 62 63 private static final int NUMBER_OF_THREAD = 3; 64 private static final int NUMBER_OF_GET_BY_ID = 100; 65 private static final int NUMBER_OF_QUERIES = 100; 66 private static final int NUMBER_OF_REMOVE = 20; 67 private static final int NUMBER_OF_CREATE = 20; 68 private static final int NUMBER_OF_SPLIT = 40; 69 70 80 public void doTest() throws JDOException, Exception { 81 final int nbThread = NUMBER_OF_THREAD; 82 Thread ts[] = new Thread [nbThread]; 83 final int nbTx = nbThread; 84 final List methodsList = new ArrayList (); 85 86 for (int i = 0; i < NUMBER_OF_GET_BY_ID; i++) 87 methodsList.add(DatabaseImpl.PARAMETER_GET_PROJECT); 88 for (int i = 0; i < NUMBER_OF_QUERIES; i++) 89 methodsList.add(DatabaseImpl.PARAMETER_QUERY_PROJECTS); 90 for (int i = 0; i < NUMBER_OF_CREATE; i++) 91 methodsList.add(DatabaseImpl.PARAMETER_NEW_PROJECT); 92 for (int i = 0; i < NUMBER_OF_SPLIT; i++) 93 methodsList.add(DatabaseImpl.PARAMETER_SPLIT_PROJECT); 94 for (int i = 0; i < NUMBER_OF_REMOVE; i++) 95 methodsList.add(DatabaseImpl.PARAMETER_REM_PROJECT); 96 97 for (int thread = 0; thread < nbThread; thread++) { 98 ts[thread] = new Thread (new Runnable () { 99 public void run() { 100 String action = null; 101 String returnStr = null; 102 Iterator iter = null; 103 PersistenceManagerFactory pmf = 104 JDOHelper.getPersistenceManagerFactory(p); 105 PMHolder pmHolder = new PMHolder(pmf); 106 107 DatabaseImpl databaseImpl = new DatabaseImpl(pmHolder); 108 109 int j = 0; 110 111 for (int i = 0; i < nbTx; i++) { 112 logger.log(BasicLevel.INFO, "Start loop " + i); 113 Collections.shuffle(methodsList); 114 iter = methodsList.iterator(); 115 while (iter.hasNext()) { 116 if (0 == (j++ % 100.0)) 117 logger.log( 118 BasicLevel.INFO, 119 j + " actions called..."); 120 action = (String ) iter.next(); 121 logger.log( 123 BasicLevel.DEBUG, 124 "Calls method:" + action); 125 try { 126 returnStr = databaseImpl.doAction(action, true); 127 } catch (JDOFatalException e) { 128 logger.log( 129 BasicLevel.WARN, 130 "Action '" 131 + action 132 + "' throws a JDOFatalException exception :", 133 e); 134 } catch (JDOException e) { 135 logger.log( 136 BasicLevel.WARN, 137 "Action '" 138 + action 139 + "' throws a JDO exception :", 140 e); 141 } catch (Exception e) { 142 logger.log( 143 BasicLevel.WARN, 144 "Action '" 145 + action 146 + "' throws an exception :", 147 e); 148 } 149 150 logger.log( 151 BasicLevel.DEBUG, 152 "The method " 153 + action 154 + " returns:\n" 155 + returnStr); 156 } 157 } 158 logger.log(BasicLevel.INFO, j + " actions called "); 159 } 160 }); 161 } 162 for (int thread = 0; thread < nbThread; thread++) { 164 ts[thread].start(); 165 } 166 } 167 } 168 | Popular Tags |