|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package jtr.runners; |
|
8 |
| |
|
9 |
| import java.io.ByteArrayOutputStream; |
|
10 |
| import java.io.IOException; |
|
11 |
| import java.io.ObjectOutputStream; |
|
12 |
| import java.util.Date; |
|
13 |
| import jtr.config.ParametersMap; |
|
14 |
| import jtr.config.enterprise.EnterpriseConfig; |
|
15 |
| import jtr.pool.RunnerPool; |
|
16 |
| import jtr.assigner.IParamsAssigner; |
|
17 |
| import jtr.test.ITestCompletionListener; |
|
18 |
| import jtr.test.TestOutcomeTable; |
|
19 |
| import jtr.test.IOutcomeFactory; |
|
20 |
| import jtr.test.IOutcome; |
|
21 |
| import jtr.test.IOutcome.OutcomeType; |
|
22 |
| import static jtr.test.IOutcome.OutcomeType.*; |
|
23 |
| |
|
24 |
| import org.apache.log4j.Logger; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public abstract class AbstractRunnerAncestor implements IRunner { |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
15965
| public IRunnerClean clean() {
|
|
57 |
15966
| logger.debug("Cleaning state...");
|
|
58 |
15968
| setEnterprise(null);
|
|
59 |
15970
| setParameters(null);
|
|
60 |
15970
| setSleepTime(0L);
|
|
61 |
15969
| logger.debug("... done");
|
|
62 |
15969
| return (IRunnerClean) this;
|
|
63 |
| } |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
4900
| public void setEpoch(int epoch) {
|
|
72 |
4900
| this.epoch = epoch;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
10000
| public int getEpoch() {
|
|
81 |
10000
| return epoch;
|
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
98
| public void setName(String name) {
|
|
93 |
98
| this.name = name;
|
|
94 |
| } |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
116900
| public String getName() {
|
|
102 |
116899
| return name;
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
98
| public String getDefaultName() {
|
|
111 |
98
| return this.getClass().getName();
|
|
112 |
| } |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
34939
| public EnterpriseConfig getEnterprise() {
|
|
121 |
34937
| return this.enterpriseConfig;
|
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
32034
| public void setEnterprise(EnterpriseConfig enterprise) {
|
|
132 |
32038
| this.enterpriseConfig = enterprise;
|
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
16068
| public void setInstanceCount(int i) {
|
|
142 |
16068
| instanceCount = i;
|
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
9999
| public int getInstanceCount() {
|
|
152 |
9999
| return instanceCount;
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
98579
| public int getRuns() {
|
|
161 |
98592
| return runs;
|
|
162 |
| } |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
16068
| public void setRuns(int runs) {
|
|
171 |
16068
| this.runs = runs;
|
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
79000
| public long getSleepTime() {
|
|
182 |
79000
| return sleepTime;
|
|
183 |
| } |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
32037
| public void setSleepTime(long sleepTime) {
|
|
194 |
32037
| this.sleepTime = sleepTime;
|
|
195 |
| } |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
32037
| public void setParameters(ParametersMap params) {
|
|
204 |
32037
| this.params = params;
|
|
205 |
| } |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
0
| public ParametersMap getParameters() {
|
|
214 |
0
| return params;
|
|
215 |
| } |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
4998
| public IRunnerPooled setPool(RunnerPool pool) {
|
|
225 |
4998
| this.pool = pool;
|
|
226 |
4998
| return (IRunnerPooled) this;
|
|
227 |
| } |
|
228 |
| |
|
229 |
| |
|
230 |
| |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
0
| public RunnerPool getPool() {
|
|
235 |
0
| return pool;
|
|
236 |
| } |
|
237 |
| |
|
238 |
| |
|
239 |
| |
|
240 |
| |
|
241 |
| |
|
242 |
| |
|
243 |
| |
|
244 |
6272
| public IParamsAssigner getParamsAssigner() {
|
|
245 |
6272
| return paramsAssigner;
|
|
246 |
| } |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
| |
|
251 |
| |
|
252 |
| |
|
253 |
| |
|
254 |
| |
|
255 |
16068
| public void setParamsAssigner(IParamsAssigner paramsAssigner) {
|
|
256 |
16068
| this.paramsAssigner = paramsAssigner;
|
|
257 |
| } |
|
258 |
| |
|
259 |
| |
|
260 |
| |
|
261 |
| |
|
262 |
| |
|
263 |
| |
|
264 |
0
| public int getFailures() {
|
|
265 |
0
| return failedRuns;
|
|
266 |
| } |
|
267 |
| |
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
| |
|
272 |
| |
|
273 |
0
| public int getSuccesses() {
|
|
274 |
0
| return getCurrentRun() - getFailures();
|
|
275 |
| } |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
| |
|
282 |
0
| public TestOutcomeTable getTestOutcomeTable() {
|
|
283 |
0
| return testOutcomeTable;
|
|
284 |
| } |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
98
| public void setTestOutcomeTable(TestOutcomeTable testOutcomeTable) {
|
|
293 |
98
| this.testOutcomeTable = testOutcomeTable;
|
|
294 |
| } |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
0
| public IOutcomeFactory getOutcomeFactory() {
|
|
302 |
0
| return outcomeFactory;
|
|
303 |
| } |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
98
| public void setOutcomeFactory(IOutcomeFactory outcomeFactory) {
|
|
312 |
98
| this.outcomeFactory = outcomeFactory;
|
|
313 |
| } |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
98
| public void setTestCompletionListener(ITestCompletionListener testComplLsnr) {
|
|
325 |
98
| if(testCompletionLsnr==null)
|
|
326 |
98
| testCompletionLsnr = testComplLsnr;
|
|
327 |
| } |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
44380
| protected final void doRunTest() throws Throwable {
|
|
344 |
44389
| initializeTimers();
|
|
345 |
44391
| try {
|
|
346 |
44396
| test();
|
|
347 |
| } |
|
348 |
| finally { |
|
349 |
44380
| runDuration = System.currentTimeMillis() - runDuration;
|
|
350 |
44369
| if(testCompletionLsnr!=null)
|
|
351 |
22182
| testCompletionLsnr.updateLocalRuns();
|
|
352 |
| } |
|
353 |
32396
| IOutcome res = prepareOutcome(SUCCESS);
|
|
354 |
32396
| testOutcomeTable.put(getName(),res);
|
|
355 |
| } |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
44406
| protected final void initializeTimers() {
|
|
363 |
44407
| runDuration = System.currentTimeMillis();
|
|
364 |
44407
| timestamp = new Date(runDuration);
|
|
365 |
| } |
|
366 |
| |
|
367 |
| |
|
368 |
| |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
12003
| protected final void handleFailure(int run, Throwable t) {
|
|
385 |
12003
| failedRuns++;
|
|
386 |
12004
| String msg = "Exception occourred in IRunner " + getName() + " at thread run # " + run + " Actual parameters are: " + enterpriseConfig + " " + params + " "
|
|
387 |
| + ". Exception caught: proceeding with the next run..."; |
|
388 |
12004
| IOutcome outcome = prepareOutcome(FAILURE);
|
|
389 |
12002
| if(isSerializable(t)) {
|
|
390 |
11995
| outcome.setException(t);
|
|
391 |
| } else { |
|
392 |
0
| NotSerializableErrorException e = new NotSerializableErrorException("Original exception was not Serializable, reporting only the original top-level message:\n"+t.getMessage(),null);
|
|
393 |
0
| e.setStackTrace(t.getStackTrace());
|
|
394 |
0
| outcome.setException(e);
|
|
395 |
| } |
|
396 |
11997
| testOutcomeTable.put(getName(), outcome);
|
|
397 |
12004
| logger.error(msg, t);
|
|
398 |
12004
| receiveFailureNotification(t, "Exception occourred");
|
|
399 |
| } |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
| |
|
404 |
| |
|
405 |
12003
| private boolean isSerializable(Throwable t) {
|
|
406 |
12002
| boolean res = true;
|
|
407 |
12004
| try {
|
|
408 |
12004
| ObjectOutputStream os = new ObjectOutputStream(new ByteArrayOutputStream());
|
|
409 |
11997
| os.writeObject(t);
|
|
410 |
| } catch (IOException ex) { |
|
411 |
0
| res = false;
|
|
412 |
| } |
|
413 |
12000
| return res;
|
|
414 |
| } |
|
415 |
| |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
| |
|
420 |
44398
| private IOutcome prepareOutcome(OutcomeType type) {
|
|
421 |
44398
| IOutcome outcome = outcomeFactory.getInstance();
|
|
422 |
44396
| outcome.setEnterpriseConfig(enterpriseConfig);
|
|
423 |
44398
| outcome.setEpoch(epoch);
|
|
424 |
| |
|
425 |
44400
| outcome.setParametersMap(params);
|
|
426 |
44399
| outcome.setRun(getCurrentRun());
|
|
427 |
44400
| outcome.setRunDuration(runDuration);
|
|
428 |
44400
| outcome.setRunnerCategory(this.getClass());
|
|
429 |
44398
| outcome.setRunnerId(this.getName());
|
|
430 |
44400
| outcome.setTimeStamp(timestamp);
|
|
431 |
44400
| outcome.setType(type);
|
|
432 |
44399
| enrichOutcome(outcome);
|
|
433 |
44396
| return outcome;
|
|
434 |
| } |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
| |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
0
| public void enrichOutcome(IOutcome outcome) {
|
|
446 |
| |
|
447 |
| } |
|
448 |
| |
|
449 |
| private long runDuration; |
|
450 |
| private Date timestamp; |
|
451 |
| protected int epoch; |
|
452 |
| private int failedRuns; |
|
453 |
| private String name; |
|
454 |
| private EnterpriseConfig enterpriseConfig; |
|
455 |
| private int runs; |
|
456 |
| private int instanceCount; |
|
457 |
| private long sleepTime; |
|
458 |
| private ParametersMap params; |
|
459 |
| protected IParamsAssigner paramsAssigner; |
|
460 |
| protected RunnerPool pool; |
|
461 |
| protected Logger logger; |
|
462 |
| private TestOutcomeTable testOutcomeTable; |
|
463 |
| private IOutcomeFactory<? extends IOutcome> outcomeFactory; |
|
464 |
| |
|
465 |
| private ITestCompletionListener testCompletionLsnr; |
|
466 |
| } |