Search in sources :

Example 6 with SampleEvent

use of org.apache.jmeter.samplers.SampleEvent in project jmeter by apache.

the class TestResultAction method testOnFailureStopTestNow.

@Test
public void testOnFailureStopTestNow() {
    sampleResult.setSuccessful(false);
    resultAction.setErrorAction(ResultAction.ON_ERROR_STOPTEST_NOW);
    resultAction.sampleOccurred(new SampleEvent(sampleResult, "JUnit-TG"));
    Assert.assertFalse(sampleResult.isStopTest());
    Assert.assertTrue(sampleResult.isStopTestNow());
    Assert.assertFalse(sampleResult.isStopThread());
    Assert.assertFalse(sampleResult.isStartNextThreadLoop());
}
Also used : SampleEvent(org.apache.jmeter.samplers.SampleEvent) Test(org.junit.Test)

Example 7 with SampleEvent

use of org.apache.jmeter.samplers.SampleEvent in project jmeter by apache.

the class TestResultAction method testSuccess.

@Test
public void testSuccess() {
    sampleResult.setSuccessful(true);
    resultAction.setErrorAction(ResultAction.ON_ERROR_STOPTEST);
    resultAction.sampleOccurred(new SampleEvent(sampleResult, "JUnit-TG"));
    Assert.assertFalse(sampleResult.isStopTest());
}
Also used : SampleEvent(org.apache.jmeter.samplers.SampleEvent) Test(org.junit.Test)

Example 8 with SampleEvent

use of org.apache.jmeter.samplers.SampleEvent in project jmeter by apache.

the class TestResultSaver method testSuccessWithVariable.

@Test
public void testSuccessWithVariable() {
    sampleResult.setSuccessful(true);
    resultSaver.setProperty(ResultSaver.NUMBER_PAD_LENGTH, "5");
    resultSaver.setProperty(ResultSaver.VARIABLE_NAME, "myVar");
    resultSaver.testStarted();
    resultSaver.sampleOccurred(new SampleEvent(sampleResult, "JUnit-TG"));
    String fileName = sampleResult.getResultFileName();
    Assert.assertNotNull(fileName);
    Assert.assertEquals("00001.unknown", fileName);
    File file = new File(FileServer.getDefaultBase(), fileName);
    Assert.assertTrue(file.exists());
    Assert.assertTrue(file.delete());
    Assert.assertEquals("00001.unknown", vars.get("myVar"));
}
Also used : File(java.io.File) SampleEvent(org.apache.jmeter.samplers.SampleEvent) Test(org.junit.Test)

Example 9 with SampleEvent

use of org.apache.jmeter.samplers.SampleEvent in project jmeter by apache.

the class TestResultSaver method testSuccessSaveErrorsOnly.

@Test
public void testSuccessSaveErrorsOnly() {
    sampleResult.setSuccessful(true);
    resultSaver.setProperty(ResultSaver.NUMBER_PAD_LENGTH, "5");
    resultSaver.setProperty(ResultSaver.VARIABLE_NAME, "myVar");
    resultSaver.setProperty(ResultSaver.ERRORS_ONLY, "true");
    resultSaver.testStarted();
    resultSaver.sampleOccurred(new SampleEvent(sampleResult, "JUnit-TG"));
    String fileName = sampleResult.getResultFileName();
    Assert.assertEquals("", fileName);
    Assert.assertNull(vars.get("myVar"));
}
Also used : SampleEvent(org.apache.jmeter.samplers.SampleEvent) Test(org.junit.Test)

Example 10 with SampleEvent

use of org.apache.jmeter.samplers.SampleEvent in project jmeter by apache.

the class ProxyControl method deliverSampler.

/**
     * Receives the recorded sampler from the proxy server for placing in the
     * test tree; this is skipped if the sampler is null (e.g. for recording SSL errors)
     * Always sends the result to any registered sample listeners.
     *
     * @param sampler the sampler, may be null
     * @param testElements the test elements to be added (e.g. header manager) under the Sampler
     * @param result the sample result, not null
     * TODO param serverResponse to be added to allow saving of the
     * server's response while recording.
     */
public synchronized void deliverSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, final SampleResult result) {
    boolean notifySampleListeners = true;
    if (sampler != null) {
        if (ATTEMPT_REDIRECT_DISABLING && (samplerRedirectAutomatically || samplerFollowRedirects) && result instanceof HTTPSampleResult) {
            final HTTPSampleResult httpSampleResult = (HTTPSampleResult) result;
            final String urlAsString = httpSampleResult.getUrlAsString();
            if (urlAsString.equals(LAST_REDIRECT)) {
                // the url matches the last redirect
                sampler.setEnabled(false);
                sampler.setComment("Detected a redirect from the previous sample");
            } else {
                // this is not the result of a redirect
                // so break the chain
                LAST_REDIRECT = null;
            }
            if (httpSampleResult.isRedirect()) {
                // Save Location so resulting sample can be disabled
                if (LAST_REDIRECT == null) {
                    sampler.setComment("Detected the start of a redirect chain");
                }
                LAST_REDIRECT = httpSampleResult.getRedirectLocation();
            } else {
                LAST_REDIRECT = null;
            }
        }
        if (filterContentType(result) && filterUrl(sampler)) {
            JMeterTreeNode myTarget = findTargetControllerNode();
            // OK, because find only returns correct element types
            @SuppressWarnings("unchecked") Collection<ConfigTestElement> defaultConfigurations = (Collection<ConfigTestElement>) findApplicableElements(myTarget, ConfigTestElement.class, false);
            // OK, because find only returns correct element types
            @SuppressWarnings("unchecked") Collection<Arguments> userDefinedVariables = (Collection<Arguments>) findApplicableElements(myTarget, Arguments.class, true);
            removeValuesFromSampler(sampler, defaultConfigurations);
            replaceValues(sampler, testElements, userDefinedVariables);
            sampler.setAutoRedirects(samplerRedirectAutomatically);
            sampler.setFollowRedirects(samplerFollowRedirects);
            sampler.setUseKeepAlive(useKeepAlive);
            sampler.setImageParser(samplerDownloadImages);
            String prefix = getPrefixHTTPSampleName();
            if (!StringUtils.isEmpty(prefix)) {
                sampler.setName(prefix + sampler.getName());
                result.setSampleLabel(prefix + result.getSampleLabel());
            }
            Authorization authorization = createAuthorization(testElements, sampler);
            if (authorization != null) {
                setAuthorization(authorization, myTarget);
            }
            placeSampler(sampler, testElements, myTarget);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Sample excluded based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
            }
            notifySampleListeners = notifyChildSamplerListenersOfFilteredSamples;
            result.setSampleLabel("[" + result.getSampleLabel() + "]");
        }
    }
    if (notifySampleListeners) {
        // SampleEvent is not passed JMeterVariables, because they don't make sense for Proxy Recording
        notifySampleListeners(new SampleEvent(result, "WorkBench"));
    } else {
        log.debug("Sample not delivered to Child Sampler Listener based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
    }
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Arguments(org.apache.jmeter.config.Arguments) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Collection(java.util.Collection) SampleEvent(org.apache.jmeter.samplers.SampleEvent) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Aggregations

SampleEvent (org.apache.jmeter.samplers.SampleEvent)17 Test (org.junit.Test)10 File (java.io.File)3 SampleResult (org.apache.jmeter.samplers.SampleResult)3 SampleSaveConfiguration (org.apache.jmeter.samplers.SampleSaveConfiguration)2 StatisticalSampleResult (org.apache.jmeter.samplers.StatisticalSampleResult)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Arguments (org.apache.jmeter.config.Arguments)1 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)1 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)1