KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > stress > StressHelper


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.stress;
19
20 import org.objectweb.speedo.SpeedoTestHelper;
21 import org.objectweb.speedo.api.SpeedoProperties;
22 import org.objectweb.speedo.api.ExceptionHelper;
23 import org.objectweb.util.monolog.api.BasicLevel;
24 import org.objectweb.jorm.api.PMapper;
25 import org.objectweb.jorm.api.PMapCluster;
26 import org.objectweb.perseus.cache.api.CacheAttributeController;
27
28 import javax.jdo.PersistenceManager;
29 import javax.jdo.JDOException;
30 import java.util.Vector JavaDoc;
31 import java.util.Properties JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Arrays JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Set JavaDoc;
37
38 /**
39  *
40  * @author S.Chassande-Barrioz
41  */

42 public abstract class StressHelper extends SpeedoTestHelper {
43
44     public static Vector JavaDoc rollbackExceptions = new Vector JavaDoc();
45     public static Vector JavaDoc errors = new Vector JavaDoc();
46     public final static String JavaDoc STRESS_LOG_NAME = LOG_NAME + ".stress";
47
48     protected String JavaDoc INTERACTIVE = getLoggerName() + ".interactive";
49     protected String JavaDoc THREAD = getLoggerName() + ".thread";
50     protected String JavaDoc TX = getLoggerName() + ".tx";
51     //protected String CREATION = getLoggerName() + ".creation";
52
protected String JavaDoc TIMEOUT = getLoggerName() + ".timeout";
53     protected String JavaDoc NBPRINT = getLoggerName() + ".nbprint";
54     protected boolean interactive;
55     protected boolean debug;
56     protected boolean hasRan = false;
57     protected static int nbPrint = 0;
58     protected static CacheAttributeController cac = null;
59     protected static int nbTest = 0;
60
61     public StressHelper(String JavaDoc s) {
62         super(s);
63         interactive = Boolean.getBoolean(INTERACTIVE);
64         logger.log(BasicLevel.DEBUG, "interactive="+interactive);
65         if (interactive) {
66             nbPrint = Integer.getInteger(NBPRINT, 0).intValue();
67             logger.log(BasicLevel.DEBUG, "nbPrint="+nbPrint);
68         }
69     }
70
71     /**
72      * @return the class name of to initialize
73      */

74     protected abstract String JavaDoc[] getClassNamesToInit();
75
76     protected String JavaDoc getLogPrefix() {
77         return "";
78     }
79
80     protected void cleanup() {
81         if (rollbackExceptions == null) {
82             rollbackExceptions = new Vector JavaDoc();
83         } else {
84             rollbackExceptions.clear();
85         }
86         if (errors == null) {
87             errors = new Vector JavaDoc();
88         } else {
89             errors.clear();
90         }
91     }
92
93     protected void initDataStructure(boolean clean) throws Exception JavaDoc {
94         String JavaDoc[] classNameToInit = getClassNamesToInit();
95         PMapper mapper = getMapper(getPMF());
96         PersistenceManager pm = getPMF().getPersistenceManager();
97         for(int i=0; i<classNameToInit.length; i++) {
98             pm.getObjectIdClass(Class.forName(classNameToInit[i]));
99             if (clean) {
100                 PMapCluster pmc = mapper.getPMapCluster(classNameToInit[i]);
101                 assertNotNull("No PMapCluster for the class: " + classNameToInit[i], pmc);
102                 pmc.deleteData();
103             }
104         }
105     }
106
107     public void setUp() throws Exception JavaDoc {
108         logger.log(BasicLevel.DEBUG, "setUp.");
109         cleanup();
110         initDataStructure(true);
111         debug = logger.isLoggable(BasicLevel.DEBUG);
112         logger.log(BasicLevel.DEBUG, "debug="+debug);
113     }
114
115     public void tearDown() {
116         logger.log(BasicLevel.DEBUG, "tearDown.");
117         if (hasRan) {
118             if (cac == null) {
119                 synchronized(StressHelper.class) {
120                     try {
121                         cac = getCacheAttributeController(pmf);
122                     } catch (Exception JavaDoc e) {
123                         logger.log(BasicLevel.ERROR,
124                                 "Cache manager unreachable: " + pmf, e);
125                         fail(e.getMessage());
126                     }
127                 }
128             }
129             logger.log(BasicLevel.DEBUG, getLogPrefix() + "\tCache eviction... (size=" + cac.getCurrentSize() + ")");
130             PersistenceManager pm = pmf.getPersistenceManager();
131             pm.evictAll();
132             pm.close();
133             int cachesize = cac.getCurrentSize();
134             if (cachesize > 0) {
135                 logger.log(BasicLevel.WARN, getLogPrefix()
136                         + "\tCache eviction finished, size=" + cachesize);
137             }
138         }
139     }
140
141     public Properties getPMFProperties() {
142         Properties p = super.getPMFProperties();
143         p.setProperty(SpeedoProperties.MAPPING_STRUCTURE,
144                 SpeedoProperties.MAPPING_STRUCTURE_DD);
145         return p;
146     }
147
148     /**
149      * Manages a set of tasks
150      */

151     public class TaskManager {
152
153         /**
154          * The tasks list
155          */

156         public Task[] tasks;
157
158         /**
159          * The timeout of tread waiting
160          */

161         public int timeout;
162
163         /**
164          * @param nbThread the number of task for each task
165          * @param nbTx the number of transaction for each task
166          * @param timeout the thread timeoout
167          * @param ctx the context of the test
168          */

169         public TaskManager(int[] nbThread, int[] nbTx, int timeout, Object JavaDoc ctx) {
170             tasks = new Task[nbThread.length];
171             this.timeout = timeout;
172             for(int i=0; i<nbThread.length; i++) {
173                 tasks[i] = newTask(i, nbTx[i], nbThread[i], this, ctx);
174             }
175         }
176         /**
177          * @param taskId the task identifier
178          * @param nbTx the number of transaction to run
179          * @param nbThread the number of thread executing transactions
180          * @param taskManager
181          * @param ctx the context of the test.
182          * @return a new Task instance
183          */

184         public Task newTask(int taskId,
185                             int nbTx,
186                             int nbThread,
187                             TaskManager taskManager,
188                             Object JavaDoc ctx) {
189             return new Task(taskId, nbTx, nbThread, taskManager);
190         }
191     }
192
193
194     /**
195      * A task of a test. A task uses threads to execute a transaction, one or
196      * several times. All thread are in concurrency to execute transactions.
197      */

198     public class Task {
199         /**
200          * Task identifier
201          */

202         public int taskId;
203
204         /**
205          * The threads executing transactions of the task
206          */

207         public Thread JavaDoc[] threads;
208
209         /**
210          * indicates for each tansaction if it must be execute or not (already
211          * done or in progress)
212          */

213         public boolean[] txToExecute;
214
215         /**
216          * The execution time of transactions
217          */

218         public long[] txExecTime;
219
220         public TaskManager taskManager;
221
222         public Task(int taskId, int nbTx, int nbThread, TaskManager taskManager) {
223             this.taskManager = taskManager;
224             this.taskId = taskId;
225             txToExecute = new boolean[nbTx];
226             txExecTime = new long[nbTx];
227             threads = new Thread JavaDoc[nbThread];
228             Arrays.fill(txToExecute, true);
229             Arrays.fill(txExecTime, (long) -1);
230         }
231
232         /**
233          * Finds (calculate) the next transaction id to execute
234          * @param threadId is the thread identifier requiring a transaction to
235          * execute
236          * @return an transaction identifier (index in the array 'txToExecute'
237          * and 'txExecTime'.
238          */

239         public int getTxId(int threadId) {
240             int txId = 0;
241             if (txToExecute.length == 0) {
242                 return 0;
243             }
244             synchronized (txToExecute) {
245                 for (txId = 0; txId < txToExecute.length; txId++) {
246                     if (txToExecute[txId]) {
247                         txToExecute[txId] = false;
248                         return txId;
249                     }
250                 }
251             }
252             return -1;
253         }
254     }
255
256     /**
257      * Represents a thread running a task
258      */

259     public class ThreadId {
260         public Task task;
261         public int threadId;
262
263         public ThreadId(Task task, int threadId) {
264             this.task = task;
265             this.threadId = threadId;
266         }
267
268         public String JavaDoc toString() {
269             return "(task=" + task.taskId + ", thread=" + threadId + ")";
270         }
271     }
272
273     /**
274      * Creates a task manager with several task
275      */

276     protected TaskManager newTaskManager(int nbTx, int nbThread, int timeout, Object JavaDoc ctx) {
277         return newTaskManager(new int[]{nbTx}, new int[]{nbThread}, timeout, ctx);
278     }
279
280     /**
281      * Creates a task manager with a single task
282      */

283     protected TaskManager newTaskManager(int nbTx[], int nbThread[], int timeout, Object JavaDoc ctx) {
284         return new TaskManager(nbTx, nbThread, timeout, ctx);
285     }
286
287
288     protected void perform(final int nbThread,
289                          final int nbTx,
290                          final int threadTimeout,
291                          final Object JavaDoc ctx) {
292         perform(new int[]{nbThread}, new int[]{nbTx}, threadTimeout, ctx);
293     }
294
295     /**
296      * Called before the test execution (like setup() method)
297      * @param tm the task manager running the test
298      * @param ctx the context of the test
299      */

300     protected void prepareTest(TaskManager tm, Object JavaDoc ctx) {
301     }
302
303     /**
304      * Called before a task execution (like setup() method)
305      * @param task which is going to be executed
306      * @param ctx the context of the test
307      */

308     protected void prepareTask(Task task, Object JavaDoc ctx) {
309     }
310
311     protected void logStatistic(TaskManager tm, long exectime, Object JavaDoc ctx) {
312         String JavaDoc prefix = getLogPrefix();
313         int nbAllTx = 0;
314         int nbCommittedTx = 0;
315         double averageTxTime = 0;
316         for(int taskId=0; taskId<tm.tasks.length; taskId++) {
317             final Task task = tm.tasks[taskId];
318             nbAllTx += task.txExecTime.length;
319             for (int txId = 0; txId < task.txExecTime.length; txId++) {
320                 if (task.txExecTime[txId] != -1) {
321                     nbCommittedTx++;
322                     averageTxTime += task.txExecTime[txId];
323                 }
324             }
325         }
326         averageTxTime /= nbAllTx;
327         displayMemory();
328         logger.log(BasicLevel.INFO, prefix + "\tTotal execution time= " + exectime
329                 + "ms, committedTx= " + nbCommittedTx +" ("
330                 + ((double) nbCommittedTx * 100) / nbAllTx + "%)");
331         logger.log(BasicLevel.INFO, prefix + "\tAverage execution time per transaction: "
332                 + averageTxTime + " ms)");
333         logger.log(BasicLevel.INFO, prefix + "\tTransaction throughput: "
334                 + ((double) nbCommittedTx / (double) exectime) * 1000 + " tx/sec");
335         if (errors.size() > 0) {
336             logger.log(BasicLevel.INFO, prefix + "\tThere are " + errors.size()
337                 + "/" + nbAllTx + " errors during the run");
338         }
339     }
340
341     /**
342      *
343      * Launch the threads to execute the transactions
344      *
345      * @param nbThread Number of threads per task
346      * @param nbTx Number of transactions per task
347      * @param timeout Time to wait for a thread to die (in milliseconds)
348      * @param ctx is a context helping the transaction execution
349      */

350     protected void perform(final int nbThread[],
351                          final int nbTx[],
352                          final int timeout,
353                          final Object JavaDoc ctx) {
354         final TaskManager tm = newTaskManager(nbThread, nbTx, timeout, ctx);
355         final String JavaDoc prefix = getLogPrefix();
356         prepareTest(tm, ctx);
357         //------------ Create thread for each tasks ------------//
358
for(int taskId=0; taskId<nbThread.length; taskId++) {
359             final Task task = tm.tasks[taskId];
360             logger.log(BasicLevel.INFO, prefix + "* TaskId=" + taskId
361                     + ", thread=" + nbThread[taskId]
362                     + ", tx=" + nbTx[taskId]
363                     + ", timeout=" + timeout + "ms"
364                     + ", context:" + ctx);
365             prepareTask(task, ctx);
366             for (int i = 0; i < nbThread[taskId]; i++) {
367                 final int threadId = i;
368                 task.threads[i] = new Thread JavaDoc(new Runnable JavaDoc() {
369                     public void run() {
370                         while (true) {
371                             int txId = task.getTxId(threadId);
372                             if (txId == -1) {
373                                 // All the transactions have been executed
374
break;
375                             } else if (txId == -2) {
376                                 continue;
377                             }
378                             hasRan = true;
379                             PerformResult pr = new PerformResult();
380                             while (pr.again) {
381                                 perform(task, threadId, txId, ctx, pr);
382                                 if (pr.ok) {
383                                     if (task.txExecTime.length != 0) {
384                                         task.txExecTime[txId] = pr.execTime;
385                                     }
386                                 }
387                             }
388                         }
389                     }
390                 });
391             }
392         }
393         //-------------- Launch all threads ------------//
394
long exectime = System.currentTimeMillis();
395         int nbAllThread = 0;
396         for(int taskId=0; taskId<nbThread.length; taskId++) {
397             Task task = tm.tasks[taskId];
398             nbAllThread += task.threads.length;
399             for (int threadId = 0; threadId < nbThread[taskId]; threadId++) {
400                 logger.log(BasicLevel.DEBUG, prefix + "Start thread " + threadId);
401                 task.threads[threadId].start();
402             }
403         }
404         try {
405             //------------ wait threads ------------//
406
ArrayList JavaDoc al = new ArrayList JavaDoc(nbAllThread);
407             for(int taskId=0; taskId<nbThread.length; taskId++) {
408                 final Task task = tm.tasks[taskId];
409                 for (int threadId = 0; threadId < task.threads.length; threadId++) {
410                     task.threads[threadId].join(task.taskManager.timeout);
411                     if (task.threads[threadId].isAlive()) {
412                         ThreadId tid = new ThreadId(task, threadId);
413                         al.add(tid);
414                         logger.log(BasicLevel.DEBUG, prefix + "Thread " + tid
415                                 + " is not finished after the delay, it could be blocked");
416                     }
417                 }
418             }
419             if (al.size() > 0) {
420                 for (Iterator JavaDoc it = al.iterator(); it.hasNext();) {
421                     ThreadId tid = (ThreadId) it.next();
422                     if (!tid.task.threads[tid.threadId].isAlive()) {
423                         logger.log(BasicLevel.DEBUG, prefix + "Thread " + tid
424                                 + " is late but ok.");
425                         it.remove();
426                     }
427                 }
428                 if (al.size() > 0) {
429                     fail("Thread " + al + " is blocked!");
430                 }
431             }
432         } catch (InterruptedException JavaDoc e) {
433             fail(e.getMessage());
434         } finally {
435             exectime = System.currentTimeMillis() - exectime;
436             logStatistic(tm, exectime, ctx);
437         }
438     }
439
440     /**
441      * Allocate a PersistenceManager
442      */

443     protected PersistenceManager getPM(Task task, int threadId, int txId) {
444         PersistenceManager pm = pmf.getPersistenceManager();
445         if (debug) {
446             logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId
447                     + ", tx " + txId + ", task " + task.taskId
448                     + ") got a PersistenceManager");
449         }
450         return pm;
451     }
452
453     /**
454      *Starts a JDO transaction
455      */

456     protected void beginTx(PersistenceManager pm, Task task, int threadId, int txId) {
457         pm.currentTransaction().begin();
458         if (debug) {
459             logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId
460                     + ", tx " + txId + ", task " + task.taskId
461                     + ") began a transaction.");
462         }
463     }
464
465     /**
466      * Commits a JDO transaction
467      */

468     protected void commitTx(PersistenceManager pm, Task task, int threadId, int txId) {
469         pm.currentTransaction().commit();
470         if (debug) {
471             logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId
472                     + ", tx " + txId + ", task " + task.taskId
473                     + ") committed a transaction.");
474         }
475     }
476
477     /**
478      * Rollbacks a JDO transaction due to an exception
479      */

480     protected void rollbackOnException(PersistenceManager pm,
481                                        Exception JavaDoc e,
482                                        PerformResult res,
483                                        Task task,
484                                        int threadId,
485                                        int txId) {
486         Exception JavaDoc ie = ExceptionHelper.getNested(e);
487         rollbackExceptions.add(ie);
488         res.ok = false;
489         pm.currentTransaction().rollback();
490         logger.log(BasicLevel.INFO, getLogPrefix() + "(Thread " + threadId
491                     + ", tx " + txId + ", task " + task.taskId
492                     + " has been rolledback: try again", ie);
493     }
494
495     /**
496      * Stop the transactions execution due to an error.
497      */

498     protected void stopOnError(PersistenceManager pm,
499                                        Throwable JavaDoc t,
500                                        PerformResult res,
501                                        Task task,
502                                        int threadId,
503                                        int txId) {
504         if (t instanceof Exception JavaDoc) {
505             t = ExceptionHelper.getNested((Exception JavaDoc) t);
506         }
507         errors.add(t);
508         res.ok = false;
509         res.again = false; // do no try to re execute the transaction
510
logger.log(BasicLevel.ERROR, getLogPrefix() + "(Thread " + threadId
511                     + ", tx " + txId + ", task " + task.taskId
512                     + " has a problem", t);
513     }
514
515
516
517     /**
518      * Closes a persistence manager
519      */

520     protected void closePM(PersistenceManager pm,
521                            int threadId,
522                            int txId,
523                            Task task,
524                            PerformResult res) {
525         try {
526             if (pm != null && !pm.isClosed()) {
527                 try {
528                     if (pm.currentTransaction().isActive()) {
529                         pm.currentTransaction().rollback();
530                     }
531                 } finally {
532                     pm.close();
533                 }
534             }
535         } catch (JDOException e) {
536             logger.log(BasicLevel.ERROR, getLogPrefix() + "(Thread " + threadId
537                     + ", tx " + txId
538                     + ", task " + task.taskId + ") has been "
539                     + (res.ok ? "committed" : "rolledback")
540                     + " and the close occurs an error", e);
541             errors.add(e);
542             throw e;
543         }
544     }
545
546     /**
547      * executes a transaction
548      * @param task task asking the transaction execution
549      * @param threadId thread identifier running the transaction
550      * @param txId transaction identifier
551      * @param ctx context of the test
552      * @param res result of the transaction execution. This object must be
553      * filled/modified by the method.
554      */

555     protected abstract void perform(Task task,
556                                     int threadId,
557                                     int txId,
558                                     Object JavaDoc ctx,
559                                     PerformResult res);
560
561     private static synchronized void incNbTest() {
562         nbTest++;
563     }
564     
565     private static boolean printStatistic() {
566         return ((nbPrint != 0) && (nbTest % nbPrint) == 0);
567     }
568     /**
569      * It is used for transactions executions.
570      */

571     class PerformResult {
572         /**
573          * Indicates if the transaction must be played again
574          */

575         public boolean again;
576
577         /**
578          * Indicates if the out of the transaction is ok
579          */

580         public boolean ok;
581
582         /**
583          * is the execution time of the transaction
584          */

585         public long execTime;
586
587         public PerformResult() {
588             again = true;
589         }
590
591         /**
592          * Demarcates the real begin the transaction
593          */

594         public void beginTest() {
595             execTime = System.currentTimeMillis();
596             logger.log(BasicLevel.DEBUG, "beginTest nbTest=" + nbTest);
597         }
598
599         /**
600          * Demarcates the real and right end of the transaction
601          */

602         public void endTest() {
603             execTime = System.currentTimeMillis() - execTime;
604             again = false;
605             ok = true;
606             StressHelper.incNbTest();
607             logger.log(BasicLevel.DEBUG, "endTest nbTest=" + nbTest);
608             if (StressHelper.printStatistic()) {
609                 logger.log(BasicLevel.INFO, getLogPrefix() + "\tTest" +nbTest+ ": execution time=" + execTime + "ms");
610                 if (rollbackExceptions.size() > 0) {
611                     logger.log(BasicLevel.INFO, getLogPrefix() + "\tThere are " + rollbackExceptions.size() + " rollbacks during the run");
612                 }
613                 if (errors.size() > 0) {
614                     logger.log(BasicLevel.INFO, getLogPrefix() + "\tThere are " + errors.size() + " errors during the run");
615                 }
616             }
617         }
618     }
619
620     /**
621      * Logs the memory informations
622      */

623     protected void displayMemory() {
624         Runtime JavaDoc r = Runtime.getRuntime();
625         // free memory
626
long free = r.freeMemory();
627         // Allocated and no allocated memory
628
long total = r.totalMemory();
629         // inused memory
630
long inuse = total - free;
631         logger.log(BasicLevel.INFO, getLogPrefix() +
632                 "\tMemory Size: " + total + ", availlable memory:" + inuse);
633     }
634
635
636     protected final static int ID_Th1 = 0;
637     protected final static int ID_Th1Tx10Cr1 = 1 + ID_Th1;
638     protected final static int ID_Th1Tx100Cr1 = 2 + ID_Th1;
639     protected final static int ID_Th1Tx1000Cr1 = 3 + ID_Th1;
640     protected final static int ID_Th1Tx10000Cr1 = 4 + ID_Th1;
641     protected final static int ID_Th1Tx100000Cr1 = 5 + ID_Th1;
642     protected final static int ID_Th1Tx10Cr10 = 6 + ID_Th1;
643     protected final static int ID_Th1Tx100Cr10 = 7 + ID_Th1;
644     protected final static int ID_Th1Tx1000Cr10 = 8 + ID_Th1;
645     protected final static int ID_Th1Tx10000Cr10 = 9 + ID_Th1;
646     protected final static int ID_Th1Tx100000Cr10 = 10 + ID_Th1;
647     protected final static int ID_Th1Tx10Cr100 = 11 + ID_Th1;
648     protected final static int ID_Th1Tx100Cr100 = 12 + ID_Th1;
649     protected final static int ID_Th1Tx1000Cr100 = 13 + ID_Th1;
650     protected final static int ID_Th1Tx10000Cr100 = 14 + ID_Th1;
651     protected final static int ID_Th1Tx10Cr500 = 15 + ID_Th1;
652     protected final static int ID_Th1Tx100Cr500 = 16 + ID_Th1;
653     protected final static int ID_Th1Tx1000Cr500 = 17 + ID_Th1;
654     protected final static int ID_Th1Tx10Cr1000 = 18 + ID_Th1;
655     protected final static int ID_Th1Tx100Cr1000 = 19 + ID_Th1;
656     protected final static int ID_Th1Tx1000Cr1000 = 20 + ID_Th1;
657     protected final static int ID_Th1Tx10Cr2000 = 21 + ID_Th1;
658     protected final static int ID_Th1Tx100Cr2000 = 22 + ID_Th1;
659     protected final static int ID_Th1Tx1000Cr2000 = 23 + ID_Th1;
660     protected final static int ID_Th1Tx10Cr10000 = 24 + ID_Th1;
661     protected final static int ID_Th1Tx100Cr10000 = 25 + ID_Th1;
662     protected final static int ID_Th2 = 25;
663     protected final static int ID_Th2Tx10Cr1 = 1 + ID_Th2;
664     protected final static int ID_Th2Tx100Cr1 = 2 + ID_Th2;
665     protected final static int ID_Th2Tx1000Cr1 = 3 + ID_Th2;
666     protected final static int ID_Th2Tx10000Cr1 = 4 + ID_Th2;
667     protected final static int ID_Th2Tx100000Cr1 = 5 + ID_Th2;
668     protected final static int ID_Th2Tx10Cr10 = 6 + ID_Th2;
669     protected final static int ID_Th2Tx100Cr10 = 7 + ID_Th2;
670     protected final static int ID_Th2Tx1000Cr10 = 8 + ID_Th2;
671     protected final static int ID_Th2Tx10000Cr10 = 9 + ID_Th2;
672     protected final static int ID_Th2Tx100000Cr10 = 10 + ID_Th2;
673     protected final static int ID_Th2Tx10Cr100 = 11 + ID_Th2;
674     protected final static int ID_Th2Tx100Cr100 = 12 + ID_Th2;
675     protected final static int ID_Th2Tx1000Cr100 = 13 + ID_Th2;
676     protected final static int ID_Th2Tx10000Cr100 = 14 + ID_Th2;
677     protected final static int ID_Th2Tx10Cr500 = 15 + ID_Th2;
678     protected final static int ID_Th2Tx100Cr500 = 16 + ID_Th2;
679     protected final static int ID_Th2Tx1000Cr500 = 17 + ID_Th2;
680     protected final static int ID_Th2Tx10Cr1000 = 18 + ID_Th2;
681     protected final static int ID_Th2Tx100Cr1000 = 19 + ID_Th2;
682     protected final static int ID_Th2Tx1000Cr1000 = 20 + ID_Th2;
683     protected final static int ID_Th2Tx10Cr2000 = 21 + ID_Th2;
684     protected final static int ID_Th2Tx100Cr2000 = 22 + ID_Th2;
685     protected final static int ID_Th2Tx1000Cr2000 = 23 + ID_Th2;
686     protected final static int ID_Th2Tx10Cr10000 = 24 + ID_Th2;
687     protected final static int ID_Th2Tx100Cr10000 = 25 + ID_Th2;
688     protected final static int ID_Th3 = 50;
689     protected final static int ID_Th3Tx10Cr1 = 1 + ID_Th3;
690     protected final static int ID_Th3Tx100Cr1 = 2 + ID_Th3;
691     protected final static int ID_Th3Tx1000Cr1 = 3 + ID_Th3;
692     protected final static int ID_Th3Tx10000Cr1 = 4 + ID_Th3;
693     protected final static int ID_Th3Tx100000Cr1 = 5 + ID_Th3;
694     protected final static int ID_Th3Tx10Cr10 = 6 + ID_Th3;
695     protected final static int ID_Th3Tx100Cr10 = 7 + ID_Th3;
696     protected final static int ID_Th3Tx1000Cr10 = 8 + ID_Th3;
697     protected final static int ID_Th3Tx10000Cr10 = 9 + ID_Th3;
698     protected final static int ID_Th3Tx100000Cr10 = 10 + ID_Th3;
699     protected final static int ID_Th3Tx10Cr100 = 11 + ID_Th3;
700     protected final static int ID_Th3Tx100Cr100 = 12 + ID_Th3;
701     protected final static int ID_Th3Tx1000Cr100 = 13 + ID_Th3;
702     protected final static int ID_Th3Tx10000Cr100 = 14 + ID_Th3;
703     protected final static int ID_Th3Tx10Cr500 = 15 + ID_Th3;
704     protected final static int ID_Th3Tx100Cr500 = 16 + ID_Th3;
705     protected final static int ID_Th3Tx1000Cr500 = 17 + ID_Th3;
706     protected final static int ID_Th3Tx10Cr1000 = 18 + ID_Th3;
707     protected final static int ID_Th3Tx100Cr1000 = 19 + ID_Th3;
708     protected final static int ID_Th3Tx1000Cr1000 = 20 + ID_Th3;
709     protected final static int ID_Th3Tx10Cr2000 = 21 + ID_Th3;
710     protected final static int ID_Th3Tx100Cr2000 = 22 + ID_Th3;
711     protected final static int ID_Th3Tx1000Cr2000 = 23 + ID_Th3;
712     protected final static int ID_Th3Tx10Cr10000 = 24 + ID_Th3;
713     protected final static int ID_Th3Tx100Cr10000 = 25 + ID_Th3;
714     protected final static int ID_Th4 = 75;
715     protected final static int ID_Th4Tx10Cr1 = 1 + ID_Th4;
716     protected final static int ID_Th4Tx100Cr1 = 2 + ID_Th4;
717     protected final static int ID_Th4Tx1000Cr1 = 3 + ID_Th4;
718     protected final static int ID_Th4Tx10000Cr1 = 4 + ID_Th4;
719     protected final static int ID_Th4Tx100000Cr1 = 5 + ID_Th4;
720     protected final static int ID_Th4Tx10Cr10 = 6 + ID_Th4;
721     protected final static int ID_Th4Tx100Cr10 = 7 + ID_Th4;
722     protected final static int ID_Th4Tx1000Cr10 = 8 + ID_Th4;
723     protected final static int ID_Th4Tx10000Cr10 = 9 + ID_Th4;
724     protected final static int ID_Th4Tx100000Cr10 = 10 + ID_Th4;
725     protected final static int ID_Th4Tx10Cr100 = 11 + ID_Th4;
726     protected final static int ID_Th4Tx100Cr100 = 12 + ID_Th4;
727     protected final static int ID_Th4Tx1000Cr100 = 13 + ID_Th4;
728     protected final static int ID_Th4Tx10000Cr100 = 14 + ID_Th4;
729     protected final static int ID_Th4Tx10Cr500 = 15 + ID_Th4;
730     protected final static int ID_Th4Tx100Cr500 = 16 + ID_Th4;
731     protected final static int ID_Th4Tx1000Cr500 = 17 + ID_Th4;
732     protected final static int ID_Th4Tx10Cr1000 = 18 + ID_Th4;
733     protected final static int ID_Th4Tx100Cr1000 = 19 + ID_Th4;
734     protected final static int ID_Th4Tx1000Cr1000 = 20 + ID_Th4;
735     protected final static int ID_Th4Tx10Cr2000 = 21 + ID_Th4;
736     protected final static int ID_Th4Tx100Cr2000 = 22 + ID_Th4;
737     protected final static int ID_Th4Tx1000Cr2000 = 23 + ID_Th4;
738     protected final static int ID_Th4Tx10Cr10000 = 24 + ID_Th4;
739     protected final static int ID_Th4Tx100Cr10000 = 25 + ID_Th4;
740     protected final static int ID_Th10 = 100;
741     protected final static int ID_Th10Tx10Cr1 = 1 + ID_Th10;
742     protected final static int ID_Th10Tx100Cr1 = 2 + ID_Th10;
743     protected final static int ID_Th10Tx1000Cr1 = 3 + ID_Th10;
744     protected final static int ID_Th10Tx10000Cr1 = 4 + ID_Th10;
745     protected final static int ID_Th10Tx100000Cr1 = 5 + ID_Th10;
746     protected final static int ID_Th10Tx10Cr10 = 6 + ID_Th10;
747     protected final static int ID_Th10Tx100Cr10 = 7 + ID_Th10;
748     protected final static int ID_Th10Tx1000Cr10 = 8 + ID_Th10;
749     protected final static int ID_Th10Tx10000Cr10 = 9 + ID_Th10;
750     protected final static int ID_Th10Tx100000Cr10 = 10 + ID_Th10;
751     protected final static int ID_Th10Tx10Cr100 = 11 + ID_Th10;
752     protected final static int ID_Th10Tx100Cr100 = 12 + ID_Th10;
753     protected final static int ID_Th10Tx1000Cr100 = 13 + ID_Th10;
754     protected final static int ID_Th10Tx10000Cr100 = 14 + ID_Th10;
755     protected final static int ID_Th10Tx10Cr500 = 15 + ID_Th10;
756     protected final static int ID_Th10Tx100Cr500 = 16 + ID_Th10;
757     protected final static int ID_Th10Tx1000Cr500 = 17 + ID_Th10;
758     protected final static int ID_Th10Tx10Cr1000 = 18 + ID_Th10;
759     protected final static int ID_Th10Tx100Cr1000 = 19 + ID_Th10;
760     protected final static int ID_Th10Tx1000Cr1000 = 20 + ID_Th10;
761     protected final static int ID_Th10Tx10Cr2000 = 21 + ID_Th10;
762     protected final static int ID_Th10Tx100Cr2000 = 22 + ID_Th10;
763     protected final static int ID_Th10Tx1000Cr2000 = 23 + ID_Th10;
764     protected final static int ID_Th10Tx10Cr10000 = 24 + ID_Th10;
765     protected final static int ID_Th10Tx100Cr10000 = 25 + ID_Th10;
766     protected final static int[] TESTNBC = { 0,
767             // ID_Th1
768
10, 100, 1000, 10000, 100000, // CR 1
769
100, 1000, 10000, 100000, 1000000, // CR 10
770
1000, 10000, 100000, 1000000, // CR 100
771
5000, 50000, 500000, // CR 500
772
10000, 100000, 1000000, // CR 1.000
773
20000, 200000, 2000000, // CR 2.000
774
100000, 1000000, // CR 10.000
775
// ID_Th2
776
10, 100, 1000, 10000, 100000, // CR 1
777
100, 1000, 10000, 100000, 1000000, // CR 10
778
1000, 10000, 100000, 1000000, // CR 100
779
5000, 50000, 500000, // CR 500
780
10000, 100000, 1000000, // CR 1.000
781
20000, 200000, 2000000, // CR 2.000
782
100000, 1000000, // CR 10.000
783
// ID_Th3
784
10, 100, 1000, 10000, 100000, // CR 1
785
100, 1000, 10000, 100000, 1000000, // CR 10
786
1000, 10000, 100000, 1000000, // CR 100
787
5000, 50000, 500000, // CR 500
788
10000, 100000, 1000000, // CR 1.000
789
20000, 200000, 2000000, // CR 2.000
790
100000, 1000000, // CR 10.000
791
// ID_Th4
792
10, 100, 1000, 10000, 100000, // CR 1
793
100, 1000, 10000, 100000, 1000000, // CR 10
794
1000, 10000, 100000, 1000000, // CR 100
795
5000, 50000, 500000, // CR 500
796
10000, 100000, 1000000, // CR 1.000
797
20000, 200000, 2000000, // CR 2.000
798
100000, 1000000, // CR 10.000
799
// ID_Th10
800
10, 100, 1000, 10000, 100000, // CR 1
801
100, 1000, 10000, 100000, 1000000, // CR 10
802
1000, 10000, 100000, 1000000, // CR 100
803
5000, 50000, 500000, // CR 500
804
10000, 100000, 1000000, // CR 1.000
805
20000, 200000, 2000000, // CR 2.000
806
100000, 1000000, // CR 10.000
807
-1 };
808
809     protected int getStartId(int testid) {
810         int res = 0;
811         while (testid > 0) {
812             testid--;
813             res += TESTNBC[testid];
814         }
815         return res;
816     }
817
818     public class ObjectStatistic {
819
820         HashMap JavaDoc oid2Touch = new HashMap JavaDoc();
821         long nbTouch = 0;
822
823         public synchronized void touch(Object JavaDoc oid) {
824             Integer JavaDoc i = (Integer JavaDoc) oid2Touch.get(oid);
825             if (i == null) {
826                 i = new Integer JavaDoc(1);
827             } else {
828                 i = new Integer JavaDoc(i.intValue() + 1);
829             }
830             nbTouch++;
831             oid2Touch.put(oid, i);
832         }
833
834         public Set JavaDoc getAccessedOid() {
835             return oid2Touch.keySet();
836         }
837
838         public long getNbAccess() {
839             return nbTouch;
840         }
841     }
842 }
843
Popular Tags