Java Code Examples for org.apache.jmeter.samplers.SampleResult#setResponseOK()

The following examples show how to use org.apache.jmeter.samplers.SampleResult#setResponseOK() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HonoSenderSampler.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SampleResult sample(final Entry entry) {

    final SampleResult res = new SampleResult();
    res.setDataType(SampleResult.TEXT);
    res.setResponseOK();
    res.setResponseCodeOK();
    res.setSampleLabel(getName());
    if (getMessageCountPerSamplerRunAsInt() == 1) {
        honoSender.send(res, getDeviceId(), isWaitForDeliveryResult());
    } else {
        honoSender.send(res, getMessageCountPerSamplerRunAsInt(), getDeviceId(),
                isWaitForDeliveryResult());
    }
    return res;
}
 
Example 2
Source File: BlurSamplerClient.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult runTest(JavaSamplerContext context) {
  SampleResult sampleResult = new SampleResult();
  BlurResults blurResults = null;
  try {
    BlurQuery blurQuery = getBlurQuery();
    sampleResult.sampleStart();
    blurResults = _client.query(_table, blurQuery);
    sampleResult.sampleEnd();
    int size = getBytes(blurResults);
    sampleResult.setBytes(size);
    sampleResult.setSuccessful(true);
    sampleResult.setResponseOK();
  } catch (Throwable t) {
    sampleResult.setResponseMessage("Exception " + t.getMessage());
    sampleResult.setSuccessful(false);
    LOG.error("Unknown error.", t);
  } finally {
    processResults(blurResults);
  }
  return sampleResult;
}
 
Example 3
Source File: HonoReceiverSampler.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public SampleResult sample(final Entry entry) {
    final SampleResult res = new SampleResult();
    res.setResponseOK();
    res.setDataType(SampleResult.TEXT);
    res.setSampleLabel(getName());
    honoReceiver.sample(res);
    return res;
}
 
Example 4
Source File: HonoSender.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Publishes multiple messages to Hono.
 *
 * @param sampleResult The result object representing the combined outcome of the samples.
 * @param messageCount The number of messages to send
 * @param deviceId The identifier if the device to send a message for.
 * @param waitForDeliveryResult A flag indicating whether to wait for the result of the send operation.
 */
public void send(final SampleResult sampleResult, final int messageCount, final String deviceId,
                 final boolean waitForDeliveryResult) {
    final long sampleStart = System.currentTimeMillis();
    long addedSendDurations = 0;
    boolean isSuccessful = true;
    String firstResponseErrorMessage = "";
    String firstResponseErrorCode = "";
    long sentBytes = 0;
    int errorCount = 0;
    for (int i = 0; i < messageCount; i++) {
        final SampleResult subResult = new SampleResult();
        subResult.setDataType(SampleResult.TEXT);
        subResult.setResponseOK();
        subResult.setResponseCodeOK();
        subResult.setSampleLabel(sampleResult.getSampleLabel());
        // send the message
        send(subResult, deviceId, waitForDeliveryResult);
        // can't call sampleResult.addSubResult(subResult) here - this would prevent a later invocation of sampleResult.setStampAndTime()
        sampleResult.addRawSubResult(subResult);

        if (!subResult.isSuccessful()) {
            isSuccessful = false;
            errorCount++;
            if (firstResponseErrorMessage.isEmpty()) {
                firstResponseErrorMessage = subResult.getResponseMessage();
                firstResponseErrorCode = subResult.getResponseCode();
            }
        }
        sentBytes += subResult.getSentBytes();
        addedSendDurations += subResult.getTime();
    }
    sampleResult.setSuccessful(isSuccessful);
    final String responseMessage = MessageFormat.format("BatchResult {0}/{1}/{2}", sampler.getEndpoint(), sampler.getTenant(), deviceId);
    if (isSuccessful) {
        sampleResult.setResponseMessage(responseMessage);
    } else {
        sampleResult.setResponseMessage(responseMessage + ": " + errorCount + " errors - first: " + firstResponseErrorMessage);
        sampleResult.setResponseCode(firstResponseErrorCode);
    }
    sampleResult.setSentBytes(sentBytes);
    sampleResult.setSampleCount(messageCount);
    sampleResult.setErrorCount(errorCount); // NOTE: This method does nothing in JMeter 3.3/4.0
    final long averageElapsedTimePerMessage = addedSendDurations / messageCount;
    sampleResult.setStampAndTime(sampleStart, averageElapsedTimePerMessage);
}