* the separation string
* @return the separated value representation of the result
*/
public static String resultToDelimitedString(SampleResult sample, String delimiter) {
StringBuffer text = new StringBuffer();
SampleSaveConfiguration saveConfig = sample.getSaveConfig();
if (saveConfig.saveTimestamp()) {
if (saveConfig.printMilliseconds()){
text.append(sample.getTimeStamp());
text.append(delimiter);
} else if (saveConfig.formatter() != null) {
String stamp = saveConfig.formatter().format(new Date(sample.getTimeStamp()));
text.append(stamp);
text.append(delimiter);
}
}
if (saveConfig.saveTime()) {
text.append(sample.getTime());
text.append(delimiter);
}
if (saveConfig.saveLabel()) {
text.append(sample.getSampleLabel());
text.append(delimiter);
}
if (saveConfig.saveCode()) {
text.append(sample.getResponseCode());
text.append(delimiter);
}
if (saveConfig.saveMessage()) {
text.append(sample.getResponseMessage());
text.append(delimiter);
}
if (saveConfig.saveThreadName()) {
text.append(sample.getThreadName());
text.append(delimiter);
}
if (saveConfig.saveDataType()) {
text.append(sample.getDataType());
text.append(delimiter);
}
if (saveConfig.saveSuccess()) {
text.append(sample.isSuccessful());
text.append(delimiter);
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
String message = null;
AssertionResult[] results = sample.getAssertionResults();
if (results != null) {
// Find the first non-null message
for (int i = 0; i < results.length; i++){
message = results[i].getFailureMessage();
if (message != null) break;
}
}
if (message != null) {
text.append(message);
}
text.append(delimiter);
}
if (saveConfig.saveBytes()) {
text.append(sample.getBytes());
text.append(delimiter);
}
if (saveConfig.saveThreadCounts()) {
org.apache.jmeter.threads.ThreadGroup
threadGroup=JMeterContextService.getContext().getThreadGroup();
int numThreads =0;
if (threadGroup != null) { // can be null for remote testing
numThreads = threadGroup.getNumberOfThreads();
}
text.append(numThreads);
text.append(delimiter);
text.append(JMeterContextService.getNumberOfThreads());
text.append(delimiter);
}
if (saveConfig.saveUrl()) {
text.append(sample.getURL());
text.append(delimiter);
}
if (saveConfig.saveFileName()) {
text.append(sample.getResultFileName());
text.append(delimiter);
}
if (saveConfig.saveLatency()) {
text.append(sample.getLatency());
text.append(delimiter);
}
if (saveConfig.saveEncoding()) {
text.append(sample.getDataEncoding());
text.append(delimiter);
}
if (saveConfig.saveSampleCount()) {// Need both sample and error count to be any use
text.append(sample.getSampleCount());
text.append(delimiter);
text.append(sample.getErrorCount());
text.append(delimiter);
}