use of org.apache.jmeter.samplers.SampleResult in project ACS by ACS-Community.
the class CCSampler method runTest.
/**
* Perform a single sample.
* Perform a single sample for each iteration. This method
* returns a <code>SampleResult</code> object.
* <code>SampleResult</code> has many fields which can be
* used. At a minimum, the test should use
* <code>SampleResult.sampleStart</code> and
* <code>SampleResult.sampleEnd</code>to set the time that
* the test required to execute. It is also a good idea to
* set the sampleLabel and the successful flag.
*
* @see org.apache.jmeter.samplers.SampleResult#sampleStart()
* @see org.apache.jmeter.samplers.SampleResult#sampleEnd()
* @see org.apache.jmeter.samplers.SampleResult#setSuccessful(boolean)
* @see org.apache.jmeter.samplers.SampleResult#setSampleLabel(String)
*
* @param context the context to run with. This provides access
* to initialization parameters.
*
* @return a SampleResult giving the results of this
* sample.
*/
public SampleResult runTest(JavaSamplerContext context) {
String managerLoc = context.getParameter("Manager", DEFAULT_MANAGER);
String clientName = context.getParameter("ClientName", CLIENT_NAME);
long init = context.getLongParameter("Initialize", INITIALIZE);
SampleResult results = new SampleResult();
try {
if (init != 0) {
ComponentClientSingleton.prepareInstance(null, managerLoc, clientName);
results.setSampleLabel("Initializing ComponentClient!");
} else {
ComponentClientSingleton.destroyInstance();
results.setSampleLabel("Finalizing ComponentClient!");
}
results.setTime(0);
results.setSuccessful(true);
} catch (Exception e) {
results.setSuccessful(false);
results.setResponseCode(e.getMessage());
results.setSampleLabel("ERROR: " + e.getMessage());
getLogger().error(this.getClass().getName() + ": Error during sample", e);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug(whoAmI() + "\trunTest()" + "\tTime:\t" + results.getTime());
listParameters(context);
}
return results;
}
use of org.apache.jmeter.samplers.SampleResult in project ACS by ACS-Community.
the class T22Sampler method runTest.
/**
* Perform a single sample.
* Perform a single sample for each iteration. This method
* returns a <code>SampleResult</code> object.
* <code>SampleResult</code> has many fields which can be
* used. At a minimum, the test should use
* <code>SampleResult.sampleStart</code> and
* <code>SampleResult.sampleEnd</code>to set the time that
* the test required to execute. It is also a good idea to
* set the sampleLabel and the successful flag.
*
* @see org.apache.jmeter.samplers.SampleResult#sampleStart()
* @see org.apache.jmeter.samplers.SampleResult#sampleEnd()
* @see org.apache.jmeter.samplers.SampleResult#setSuccessful(boolean)
* @see org.apache.jmeter.samplers.SampleResult#setSampleLabel(String)
*
* @param context the context to run with. This provides access
* to initialization parameters.
*
* @return a SampleResult giving the results of this
* sample.
*/
public SampleResult runTest(JavaSamplerContext context) {
long sizeOfSet = context.getLongParameter("SizeOfSet", SIZE_OF_SET);
long delay = context.getLongParameter("Delay", DELAY);
SampleResult results = new SampleResult();
boolean b = true;
try {
switch(m_test.charAt(0)) {
case '1':
b = m_client.getPropertyAsync(sizeOfSet, delay);
break;
case '2':
b = m_client.setPropertyAsync(sizeOfSet, delay);
break;
case '3':
b = m_client.actionAsync(sizeOfSet, delay);
break;
default:
throw new Exception("Invalid TEST selection!");
}
switch(m_test.charAt(2)) {
case '1':
results.setTime(m_client.getMidTime() - m_client.getStartTime());
break;
case '2':
results.setTime(m_client.getEndTime() - m_client.getStartTime());
break;
default:
throw new Exception("Invalid TEST selection!");
}
results.setSuccessful(b);
results.setSampleLabel(m_testName + "(" + sizeOfSet + ", " + delay + ") @" + m_instanceID);
} catch (Exception e) {
results.setSuccessful(false);
results.setResponseCode(e.getMessage());
results.setSampleLabel("ERROR: " + e.getMessage());
getLogger().error(this.getClass().getName() + ": Error during sample", e);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug(whoAmI() + "\trunTest()" + "\tTime:\t" + results.getTime());
listParameters(context);
}
return results;
}
use of org.apache.jmeter.samplers.SampleResult in project ACS by ACS-Community.
the class T26Sampler method runTest.
/**
* Perform a single sample.
* Perform a single sample for each iteration. This method
* returns a <code>SampleResult</code> object.
* <code>SampleResult</code> has many fields which can be
* used. At a minimum, the test should use
* <code>SampleResult.sampleStart</code> and
* <code>SampleResult.sampleEnd</code>to set the time that
* the test required to execute. It is also a good idea to
* set the sampleLabel and the successful flag.
*
* @see org.apache.jmeter.samplers.SampleResult#sampleStart()
* @see org.apache.jmeter.samplers.SampleResult#sampleEnd()
* @see org.apache.jmeter.samplers.SampleResult#setSuccessful(boolean)
* @see org.apache.jmeter.samplers.SampleResult#setSampleLabel(String)
*
* @param context the context to run with. This provides access
* to initialization parameters.
*
* @return a SampleResult giving the results of this
* sample.
*/
public SampleResult runTest(JavaSamplerContext context) {
long sizeOfSet = context.getLongParameter("SizeOfSet", SIZE_OF_SET);
SampleResult results = new SampleResult();
try {
m_client.getCOB(sizeOfSet);
results.setTime(m_client.getEndTime() - m_client.getStartTime());
results.setSuccessful(true);
results.setSampleLabel(m_testName + "(" + sizeOfSet + ") @" + m_instanceID);
} catch (Exception e) {
results.setSuccessful(false);
results.setResponseCode(e.getMessage());
results.setSampleLabel("ERROR: " + e.getMessage());
getLogger().error(this.getClass().getName() + ": Error during sample", e);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug(whoAmI() + "\trunTest()" + "\tTime:\t" + results.getTime());
listParameters(context);
}
return results;
}
use of org.apache.jmeter.samplers.SampleResult in project ACS by ACS-Community.
the class T23Sampler method runTest.
/**
* Perform a single sample.
* Perform a single sample for each iteration. This method
* returns a <code>SampleResult</code> object.
* <code>SampleResult</code> has many fields which can be
* used. At a minimum, the test should use
* <code>SampleResult.sampleStart</code> and
* <code>SampleResult.sampleEnd</code>to set the time that
* the test required to execute. It is also a good idea to
* set the sampleLabel and the successful flag.
*
* @see org.apache.jmeter.samplers.SampleResult#sampleStart()
* @see org.apache.jmeter.samplers.SampleResult#sampleEnd()
* @see org.apache.jmeter.samplers.SampleResult#setSuccessful(boolean)
* @see org.apache.jmeter.samplers.SampleResult#setSampleLabel(String)
*
* @param context the context to run with. This provides access
* to initialization parameters.
*
* @return a SampleResult giving the results of this
* sample.
*/
public SampleResult runTest(JavaSamplerContext context) {
long sizeOfSet = context.getLongParameter("SizeOfSet", SIZE_OF_SET);
SampleResult results = new SampleResult();
boolean b = true;
String label = m_testName;
try {
switch(m_test.charAt(0)) {
case '1':
b = m_client.getNextMonitorResponse();
label += "(" + sizeOfSet + ", " + m_delay + ") @";
break;
case '2':
b = m_client.monitors(sizeOfSet, m_delay);
label += "(" + sizeOfSet + ", " + m_delay + ") @";
break;
case '3':
m_client.createMonitor(sizeOfSet);
label += "(" + sizeOfSet + ") @";
break;
default:
throw new Exception("Invalid TEST selection!");
}
results.setTime(m_client.getEndTime() - m_client.getStartTime());
results.setSuccessful(b);
results.setSampleLabel(label + m_instanceID);
} catch (Exception e) {
results.setSuccessful(false);
results.setResponseCode(e.getMessage());
results.setSampleLabel("ERROR: " + e.getMessage());
getLogger().error(this.getClass().getName() + ": Error during sample", e);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug(whoAmI() + "\trunTest()" + "\tTime:\t" + results.getTime());
listParameters(context);
}
return results;
}
use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.
the class CSVSaveService method resultToDelimitedString.
/**
* Convert a result into a string, where the fields of the result are
* separated by a specified String.
*
* @param event
* the sample event to be converted
* @param delimiter
* the separation string
* @return the separated value representation of the result
*/
public static String resultToDelimitedString(SampleEvent event, final String delimiter) {
StringQuoter text = new StringQuoter(delimiter.charAt(0));
SampleResult sample = event.getResult();
SampleSaveConfiguration saveConfig = sample.getSaveConfig();
if (saveConfig.saveTimestamp()) {
if (saveConfig.printMilliseconds()) {
text.append(sample.getTimeStamp());
} else if (saveConfig.threadSafeLenientFormatter() != null) {
String stamp = saveConfig.threadSafeLenientFormatter().format(new Date(sample.getTimeStamp()));
text.append(stamp);
}
}
if (saveConfig.saveTime()) {
text.append(sample.getTime());
}
if (saveConfig.saveLabel()) {
text.append(sample.getSampleLabel());
}
if (saveConfig.saveCode()) {
text.append(sample.getResponseCode());
}
if (saveConfig.saveMessage()) {
text.append(sample.getResponseMessage());
}
if (saveConfig.saveThreadName()) {
text.append(sample.getThreadName());
}
if (saveConfig.saveDataType()) {
text.append(sample.getDataType());
}
if (saveConfig.saveSuccess()) {
text.append(sample.isSuccessful());
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
String message = null;
AssertionResult[] results = sample.getAssertionResults();
if (results != null) {
// Find the first non-null message
for (AssertionResult result : results) {
message = result.getFailureMessage();
if (message != null) {
break;
}
}
}
if (message != null) {
text.append(message);
} else {
// Need to append something so delimiter is
text.append("");
// added
}
}
if (saveConfig.saveBytes()) {
text.append(sample.getBytesAsLong());
}
if (saveConfig.saveSentBytes()) {
text.append(sample.getSentBytes());
}
if (saveConfig.saveThreadCounts()) {
text.append(sample.getGroupThreads());
text.append(sample.getAllThreads());
}
if (saveConfig.saveUrl()) {
text.append(sample.getURL());
}
if (saveConfig.saveFileName()) {
text.append(sample.getResultFileName());
}
if (saveConfig.saveLatency()) {
text.append(sample.getLatency());
}
if (saveConfig.saveEncoding()) {
text.append(sample.getDataEncodingWithDefault());
}
if (saveConfig.saveSampleCount()) {
// Need both sample and error count to be any use
text.append(sample.getSampleCount());
text.append(sample.getErrorCount());
}
if (saveConfig.saveHostname()) {
text.append(event.getHostname());
}
if (saveConfig.saveIdleTime()) {
text.append(event.getResult().getIdleTime());
}
if (saveConfig.saveConnectTime()) {
text.append(sample.getConnectTime());
}
for (int i = 0; i < SampleEvent.getVarCount(); i++) {
text.append(event.getVarValue(i));
}
return text.toString();
}
Aggregations