Search in sources :

Example 1 with SampleResult

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;
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 2 with SampleResult

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;
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 3 with SampleResult

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;
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 4 with SampleResult

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;
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 5 with SampleResult

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();
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) AssertionResult(org.apache.jmeter.assertions.AssertionResult) StatisticalSampleResult(org.apache.jmeter.samplers.StatisticalSampleResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Date(java.util.Date)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)381 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7