1 package com.flexiblewebsolutions.xdriveunit.loadtest;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5
6 import junit.framework.Test;
7 import junit.textui.TestRunner;
8
9 import org.apache.log4j.Logger;
10
11 import com.flexiblewebsolutions.xdriveunit.LoadWebXDriveTestCase;
12
13 /***
14 * Each thread executes the test.
15 *
16 * @author Donavon Buss
17 */
18 public class TestThread extends Thread {
19 static Logger logger = Logger.getLogger(TestThread.class.getName());
20
21 private StringBuffer _TestConfig = null;
22
23 private String _ThreadName = null;
24
25 private LoadWebXDriveTestCase _TestCase = null;
26
27 private ThreadTracker _TT = null;;
28
29 /***
30 * Create thread instance
31 *
32 * @param pTestCase -
33 * An instance of the test class.
34 * @param pThreadName -
35 * Unique name for this thread
36 * @param pTestConfig -
37 * Config information needed by test
38 * @param pTT -
39 * Keeps track of all threads
40 */
41 public TestThread(LoadWebXDriveTestCase pTestCase, String pThreadName,
42 StringBuffer pTestConfig, ThreadTracker pTT) {
43 _TestCase = pTestCase;
44 _ThreadName = pThreadName;
45 _TestConfig = pTestConfig;
46 _TT = pTT;
47 }
48
49 /***
50 * execute test within the thread
51 */
52 public void run() {
53
54 _TT.registerThread(_ThreadName);
55 logger.info("Started " + _ThreadName + " at "
56 + +System.currentTimeMillis());
57 super.run();
58 try {
59
60 Class thisClass = _TestCase.getClass();
61
62 Method suiteMethod = thisClass.getMethod("suite", new Class[] {
63 StringBuffer.class, String.class });
64 TestRunner.run((Test) suiteMethod.invoke(null, new Object[] {
65 _TestConfig, _ThreadName }));
66 } catch (SecurityException e) {
67 logger.error("Error invoking suite.", e);
68 } catch (IllegalArgumentException e) {
69 logger.error("Error invoking suite.", e);
70 } catch (NoSuchMethodException e) {
71 logger.error("Error invoking suite.", e);
72 } catch (IllegalAccessException e) {
73 logger.error("Error invoking suite.", e);
74 } catch (InvocationTargetException e) {
75 logger.error("Error invoking suite.", e);
76 }
77
78 logger.info("Ended " + _ThreadName + " at "
79 + +System.currentTimeMillis());
80
81
82 _TT.deregisterThread(_ThreadName);
83 }
84 }