Lines 21-28
Link Here
|
21 |
import java.io.Serializable; |
21 |
import java.io.Serializable; |
22 |
|
22 |
|
23 |
import org.apache.jmeter.samplers.SampleEvent; |
23 |
import org.apache.jmeter.samplers.SampleEvent; |
|
|
24 |
import org.apache.jmeter.samplers.SampleListener; |
24 |
import org.apache.jmeter.samplers.SampleResult; |
25 |
import org.apache.jmeter.samplers.SampleResult; |
25 |
import org.apache.jmeter.samplers.Sampler; |
26 |
import org.apache.jmeter.samplers.Sampler; |
|
|
27 |
import org.apache.jmeter.testelement.property.BooleanProperty; |
26 |
import org.apache.jmeter.threads.JMeterContext; |
28 |
import org.apache.jmeter.threads.JMeterContext; |
27 |
import org.apache.jmeter.threads.JMeterThread; |
29 |
import org.apache.jmeter.threads.JMeterThread; |
28 |
import org.apache.jmeter.threads.JMeterVariables; |
30 |
import org.apache.jmeter.threads.JMeterVariables; |
Lines 35-49
Link Here
|
35 |
* Transaction Controller to measure transaction times |
37 |
* Transaction Controller to measure transaction times |
36 |
* |
38 |
* |
37 |
*/ |
39 |
*/ |
38 |
public class TransactionController extends GenericController implements Controller, Serializable { |
40 |
public class TransactionController extends GenericController implements SampleListener, Controller, Serializable { |
39 |
protected static final Logger log = LoggingManager.getLoggerForClass(); |
41 |
protected static final Logger log = LoggingManager.getLoggerForClass(); |
40 |
|
42 |
|
|
|
43 |
private final static String REPORT_SAMPLES_NONE = "TransactionController.report_samples_none"; // $NON-NLS-1$ |
44 |
|
45 |
private final static String REPORT_SAMPLES_FAILING = "TransactionController.report_samples_failing"; // $NON-NLS-1$ |
46 |
|
47 |
private final static String REPORT_SAMPLES_ALL = "TransactionController.report_samples_all"; // $NON-NLS-1$ |
48 |
|
41 |
transient private String threadName; |
49 |
transient private String threadName; |
42 |
|
50 |
|
43 |
transient private ListenerNotifier lnf; |
51 |
transient private ListenerNotifier lnf; |
44 |
|
52 |
|
45 |
transient private SampleResult res; |
53 |
transient private SampleResult res; |
|
|
54 |
|
55 |
transient private int calls; |
46 |
|
56 |
|
|
|
57 |
transient private int noFailingSamples; |
58 |
|
47 |
/** |
59 |
/** |
48 |
* Creates a Transaction Controller |
60 |
* Creates a Transaction Controller |
49 |
*/ |
61 |
*/ |
Lines 62-87
Link Here
|
62 |
String n = this.getName(); |
74 |
String n = this.getName(); |
63 |
log.debug(threadName + " " + n + " " + s); |
75 |
log.debug(threadName + " " + n + " " + s); |
64 |
} |
76 |
} |
|
|
77 |
|
78 |
public void setReportSamplesNone(boolean value) { |
79 |
setProperty(new BooleanProperty(REPORT_SAMPLES_NONE, value)); |
80 |
} |
65 |
|
81 |
|
66 |
private int calls; |
82 |
public boolean getReportSamplesNone() { |
|
|
83 |
return getPropertyAsBoolean(REPORT_SAMPLES_NONE, true); |
84 |
} |
67 |
|
85 |
|
|
|
86 |
public void setReportSamplesFailing(boolean value) { |
87 |
setProperty(new BooleanProperty(REPORT_SAMPLES_FAILING, value)); |
88 |
} |
89 |
|
90 |
public boolean getReportSamplesFailing() { |
91 |
return getPropertyAsBoolean(REPORT_SAMPLES_FAILING, false); |
92 |
} |
93 |
|
94 |
public void setReportSamplesAll(boolean value) { |
95 |
setProperty(new BooleanProperty(REPORT_SAMPLES_ALL, value)); |
96 |
} |
97 |
|
98 |
public boolean getReportSamplesAll() { |
99 |
return getPropertyAsBoolean(REPORT_SAMPLES_ALL, false); |
100 |
} |
101 |
|
68 |
/** |
102 |
/** |
69 |
* @see org.apache.jmeter.control.Controller#next() |
103 |
* @see org.apache.jmeter.control.Controller#next() |
70 |
*/ |
104 |
*/ |
71 |
public Sampler next() { |
105 |
public Sampler next() { |
72 |
Sampler returnValue = null; |
|
|
73 |
if (isFirst()) // must be the start of the subtree |
106 |
if (isFirst()) // must be the start of the subtree |
74 |
{ |
107 |
{ |
75 |
log_debug("+++++++++++++++++++++++++++++"); |
108 |
log_debug("+++++++++++++++++++++++++++++"); |
76 |
calls = 0; |
109 |
calls = 0; |
|
|
110 |
noFailingSamples = 0; |
77 |
res = new SampleResult(); |
111 |
res = new SampleResult(); |
|
|
112 |
res.setSampleLabel(getName()); |
113 |
// Assume success |
114 |
res.setSuccessful(true); |
78 |
res.sampleStart(); |
115 |
res.sampleStart(); |
79 |
} |
116 |
} |
80 |
|
117 |
|
81 |
calls++; |
118 |
Sampler returnValue = super.next(); |
82 |
|
119 |
|
83 |
returnValue = super.next(); |
|
|
84 |
|
85 |
if (returnValue == null) // Must be the end of the controller |
120 |
if (returnValue == null) // Must be the end of the controller |
86 |
{ |
121 |
{ |
87 |
log_debug("-----------------------------" + calls); |
122 |
log_debug("-----------------------------" + calls); |
Lines 89-99
Link Here
|
89 |
log_debug("already called"); |
124 |
log_debug("already called"); |
90 |
} else { |
125 |
} else { |
91 |
res.sampleEnd(); |
126 |
res.sampleEnd(); |
92 |
res.setSuccessful(true); |
127 |
res.setResponseMessage("Number of samples in transaction : " + calls + ", number of failing samples : " + noFailingSamples); |
93 |
res.setSampleLabel(getName()); |
128 |
if(res.isSuccessful()) { |
94 |
res.setResponseCodeOK(); |
129 |
res.setResponseCodeOK(); |
95 |
res.setResponseMessage("Called: " + calls); |
130 |
} |
96 |
res.setThreadName(threadName); |
|
|
97 |
|
131 |
|
98 |
// TODO could these be done earlier (or just once?) |
132 |
// TODO could these be done earlier (or just once?) |
99 |
JMeterContext threadContext = getThreadContext(); |
133 |
JMeterContext threadContext = getThreadContext(); |
Lines 103-114
Link Here
|
103 |
if (pack == null) { |
137 |
if (pack == null) { |
104 |
log.warn("Could not fetch SamplePackage"); |
138 |
log.warn("Could not fetch SamplePackage"); |
105 |
} else { |
139 |
} else { |
106 |
lnf.notifyListeners(new SampleEvent(res, getName()), pack.getSampleListeners()); |
140 |
SampleEvent event = new SampleEvent(res, getName()); |
|
|
141 |
// We must set res to null now, before sending the event for the transaction, |
142 |
// so that we can ignore that event in our sampleOccured method |
143 |
res = null; |
144 |
lnf.notifyListeners(event, pack.getSampleListeners()); |
107 |
} |
145 |
} |
108 |
res = null; |
|
|
109 |
} |
146 |
} |
110 |
} |
147 |
} |
|
|
148 |
else { |
149 |
// We have sampled one of our children |
150 |
calls++; |
151 |
} |
111 |
|
152 |
|
112 |
return returnValue; |
153 |
return returnValue; |
113 |
} |
154 |
} |
|
|
155 |
|
156 |
public void sampleOccurred(SampleEvent se) { |
157 |
// Check if we have are still sampling our children |
158 |
if(res != null) { |
159 |
SampleResult sampleResult = se.getResult(); |
160 |
res.setThreadName(sampleResult.getThreadName()); |
161 |
res.setBytes(res.getBytes() + sampleResult.getBytes()); |
162 |
if(!sampleResult.isSuccessful()) { |
163 |
res.setSuccessful(false); |
164 |
noFailingSamples++; |
165 |
} |
166 |
// Check if we should include the sample in the transaction sample |
167 |
if(getReportSamplesAll() || (getReportSamplesFailing() && !sampleResult.isSuccessful())) { |
168 |
res.addSubResult(sampleResult); |
169 |
} |
170 |
} |
171 |
} |
172 |
|
173 |
public void sampleStarted(SampleEvent e) { |
174 |
} |
175 |
|
176 |
public void sampleStopped(SampleEvent e) { |
177 |
} |
114 |
} |
178 |
} |