1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package jtr.remote.test; |
8 |
| |
9 |
| import java.rmi.RemoteException; |
10 |
| import jtr.assigner.MissingStdParameterException; |
11 |
| import jtr.assigner.UnknownAssignmentPolicyException; |
12 |
| import jtr.config.TestConfig; |
13 |
| import jtr.enterprise.LocatorException; |
14 |
| import jtr.pool.RunnerPool; |
15 |
| import jtr.remote.pool.RemoteRunnerPoolFiller; |
16 |
| import jtr.remote.utils.RmiUtil; |
17 |
| import jtr.runners.IRunnerCreationException; |
18 |
| import jtr.runners.IRunnerParameterized; |
19 |
| import jtr.runners.IRunnerPooled; |
20 |
| import jtr.test.SystemProperties; |
21 |
| import jtr.test.TestFailedException; |
22 |
| import jtr.test.TestOutcomeTable; |
23 |
| import jtr.test.TestRunManager; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class RemoteTestRunManager extends TestRunManager { |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
1
| public RemoteTestRunManager(TestConfig tc, final NodeInfo serverCL, final NodeInfo testOutcomeCollector) {
|
44 |
1
| super(tc);
|
45 |
1
| this.serverCL = serverCL;
|
46 |
1
| this.testOutcomeCollector = testOutcomeCollector;
|
47 |
1
| this.hostNode = new NodeInfo(SystemProperties.TEST_GW_SERVICE_NAME);
|
48 |
1
| super.testOutcomeTable = new TestOutcomeTable(hostNode);
|
49 |
| } |
50 |
| |
51 |
1
| public void startTest() throws TestFailedException {
|
52 |
1
| try {
|
53 |
1
| logger.debug("Starting test...");
|
54 |
1
| pool = initializePool(testConfig);
|
55 |
1
| logger.debug("Pool initialized...");
|
56 |
1
| initialPoolSize = pool.size();
|
57 |
1
| logger.debug("Initial pool size is " + initialPoolSize + ", starting the threads...");
|
58 |
1
| testOutcomeTable.setStartTime();
|
59 |
1
| startThreads();
|
60 |
1
| logger.debug("... threads all started");
|
61 |
| } catch (IRunnerCreationException e) { |
62 |
0
| String msg = "The test failed at run " + partialCount + " due to an IRunnerCreationException";
|
63 |
0
| TestFailedException tfe = new TestFailedException(msg, e);
|
64 |
0
| logger.fatal(msg, tfe);
|
65 |
0
| throw tfe;
|
66 |
| } catch (UnknownAssignmentPolicyException e) { |
67 |
0
| String msg = "The test failed at run " + partialCount + " due to an UnknownAssignmentPolicyException";
|
68 |
0
| TestFailedException tfe = new TestFailedException(msg, e);
|
69 |
0
| logger.fatal(msg, tfe);
|
70 |
0
| throw tfe;
|
71 |
| } catch (MissingStdParameterException e) { |
72 |
0
| String msg = "The test failed at run " + partialCount + " due to a MissingStdParameterException";
|
73 |
0
| TestFailedException tfe = new TestFailedException(msg, e);
|
74 |
0
| logger.fatal(msg, tfe);
|
75 |
0
| throw tfe;
|
76 |
| } |
77 |
| } |
78 |
| |
79 |
1
| protected RunnerPool initializePool(TestConfig testConfig) throws IRunnerCreationException, UnknownAssignmentPolicyException {
|
80 |
1
| RunnerPool pool = new RunnerPool(this);
|
81 |
1
| logger.debug("Pool of IRunners created...");
|
82 |
1
| RemoteRunnerPoolFiller.fillPool(testConfig, pool, serverCL);
|
83 |
1
| logger.debug("... and filled in");
|
84 |
1
| return pool;
|
85 |
| } |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
50
| protected synchronized void startThreads() {
|
92 |
50
| logger.info("Starting run # " + partialCount);
|
93 |
50
| logger.info("ThreadGroup " + runnersThreadGroup.getName() + " active-threads count before run " + partialCount + " is: " + runnersThreadGroup.activeCount());
|
94 |
50
| System.gc();
|
95 |
50
| IRunnerPooled[] runners = pool.removeAll();
|
96 |
50
| for (int i = 0; i < runners.length; i++) {
|
97 |
| |
98 |
| |
99 |
| |
100 |
2450
| if (partialCount == 0) {
|
101 |
49
| runners[i].setTestOutcomeTable(testOutcomeTable);
|
102 |
49
| logger.info("Set outcomeTable for IRunner " + runners[i].getName());
|
103 |
| } |
104 |
2450
| runners[i].setEpoch(partialCount);
|
105 |
2450
| Thread thRunner = new Thread(runnersThreadGroup, runners[i], runners[i].getName());
|
106 |
| |
107 |
| |
108 |
2450
| thRunner.setContextClassLoader(runners[i].getClass().getClassLoader());
|
109 |
| |
110 |
| |
111 |
2450
| thRunner.start();
|
112 |
2450
| logger.debug("Created & started thread [" + i + "] " + thRunner.getName());
|
113 |
| } |
114 |
50
| logger.debug("ThreadGroup " + runnersThreadGroup.getName() + " active-threads count after starting run " + partialCount + " is: " + runnersThreadGroup.activeCount());
|
115 |
50
| partialCount++;
|
116 |
50
| runners = null;
|
117 |
| } |
118 |
| |
119 |
2450
| public synchronized void backIntoPool(IRunnerParameterized pRunner) {
|
120 |
2450
| if (partialCount < epochs) {
|
121 |
| |
122 |
2401
| synchronized (pool) {
|
123 |
2401
| logger.debug("Received a request for putting an IRunner back into the pool for the next global run");
|
124 |
2401
| pool.add(handleReinitialization(pRunner));
|
125 |
2401
| logger.debug("Put back into the pool");
|
126 |
2401
| if (pool.size() == initialPoolSize) {
|
127 |
| |
128 |
| |
129 |
49
| logger.info("Pool size has grown to " + initialPoolSize + " (the initial pool size)" + "Total run number not reached yet (" + partialCount + " of " + epochs
|
130 |
| + "): starting the next one..."); |
131 |
49
| startThreads();
|
132 |
| } |
133 |
| } |
134 |
| } else { |
135 |
| |
136 |
| |
137 |
| |
138 |
49
| pool.add(pRunner);
|
139 |
49
| if (++completedRunners != initialPoolSize) {
|
140 |
48
| logger.info("Total run number reached (" + partialCount + " of " + epochs + "). Test not completed: " + completedRunners + "/" + initialPoolSize
|
141 |
| + " threads are back into the pool, waiting for other " + (initialPoolSize - completedRunners) + " threads"); |
142 |
| } else { |
143 |
1
| testOutcomeTable.setEndTime();
|
144 |
1
| logger.info("Total run number reached (" + partialCount + " of " + epochs + "): test completed!");
|
145 |
1
| disposeResources();
|
146 |
1
| sendTestOutcome(testOutcomeTable);
|
147 |
| } |
148 |
| } |
149 |
| } |
150 |
| |
151 |
1
| private void sendTestOutcome(TestOutcomeTable outcome) {
|
152 |
1
| try {
|
153 |
1
| TestOutcomeCollector collector = (TestOutcomeCollector) RmiUtil.lookupServer(testOutcomeCollector);
|
154 |
1
| collector.provideTestOutcome(hostNode,outcome);
|
155 |
| } catch (RemoteException e) { |
156 |
0
| logger.error("Unable to provide the test outcome to "+SystemProperties.TEST_OUTCOME_COLLECTOR_SERVICE_NAME,e);
|
157 |
| } catch (LocatorException e) { |
158 |
0
| logger.fatal("Unable to connect to "+testOutcomeCollector,e);
|
159 |
| } |
160 |
| } |
161 |
| |
162 |
| private NodeInfo serverCL; |
163 |
| private NodeInfo testOutcomeCollector; |
164 |
| private NodeInfo hostNode; |
165 |
| } |