1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.mpt;
21
22
23
24
25 public class Runner {
26
27
28 private final ProtocolSession preElements = new ProtocolSession();
29
30
31 private final ProtocolSession testElements = new ProtocolSession();
32
33
34 private final ProtocolSession postElements = new ProtocolSession();
35
36 public void continueAfterFailure() {
37 preElements.setContinueAfterFailure(true);
38 testElements.setContinueAfterFailure(true);
39 postElements.setContinueAfterFailure(true);
40 }
41
42
43
44
45
46 public ProtocolInteractor getPostElements() {
47 return postElements;
48 }
49
50
51
52
53
54 public ProtocolInteractor getPreElements() {
55 return preElements;
56 }
57
58
59
60
61 public ProtocolInteractor getTestElements() {
62 return testElements;
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76 public void runSessions(final SessionFactory factory) throws Exception {
77 class SessionContinuation implements HostSystem.Continuation {
78
79 public ProtocolSession session;
80
81 public void doContinue() {
82 if (session != null) {
83 session.doContinue();
84 }
85 }
86
87 }
88 SessionContinuation continuation = new SessionContinuation();
89
90 Session[] sessions = new Session[testElements
91 .getSessionCount()];
92
93 for (int i = 0; i < sessions.length; i++) {
94 sessions[i] = factory.newSession(continuation);
95 sessions[i].start();
96 }
97 try {
98 continuation.session = preElements;
99 preElements.runSessions(sessions);
100 continuation.session = testElements;
101 testElements.runSessions(sessions);
102 continuation.session = postElements;
103 postElements.runSessions(sessions);
104 } finally {
105 for (int i = 0; i < sessions.length; i++) {
106 sessions[i].stop();
107 }
108 }
109 }
110
111
112
113
114
115
116
117
118 public String toString()
119 {
120 final String TAB = " ";
121
122 String result = "Runner ( "
123 + "preElements = " + this.preElements + TAB
124 + "testElements = " + this.testElements + TAB
125 + "postElements = " + this.postElements + TAB
126 + " )";
127
128 return result;
129 }
130
131
132 }