Examples of JMeterVariables


Examples of org.apache.jmeter.threads.JMeterVariables

            throws InvalidVariableException {

        Integer.valueOf(1);
        globalCounter++;

        JMeterVariables vars = getVariables();

        boolean perThread = Boolean.valueOf(((CompoundVariable) variables[0]).execute()).booleanValue();

        String varName = ""; //$NON-NLS-1$
        if (variables.length >=2) {// Ensure variable has been provided
            varName = ((CompoundVariable) variables[1]).execute().trim();
        }

        String counterString = ""; //$NON-NLS-1$

        if (perThread) {
            int threadCounter;
            threadCounter = perThreadInt.get().intValue() + 1;
            perThreadInt.set(Integer.valueOf(threadCounter));
            counterString = String.valueOf(threadCounter);
        } else {
            counterString = String.valueOf(globalCounter);
        }

        // vars will be null on Test Plan
        if (vars != null && varName.length() > 0) {
            vars.put(varName, counterString);
        }
        return counterString;
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        function = new JexlFunction();
        result = new SampleResult();
        jmctx = JMeterContextService.getContext();
        String data = "The quick brown fox";
        result.setResponseData(data, null);
        vars = new JMeterVariables();
        jmctx.setVariables(vars);
        jmctx.setPreviousResult(result);
        params = new LinkedList<CompoundVariable>();
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        } catch (MalformedCachePatternException e) {
            throw new InvalidVariableException(e.toString());
        }

        // Relatively expensive operation, so do it once
        JMeterVariables vars = getVariables();

        if (vars == null){// Can happen if called during test closedown
            return defaultValue;
        }

        if (name.length() > 0) {
            vars.put(name, defaultValue);
        }

        String textToMatch=null;

        if (inputVariable.length() > 0){
            textToMatch=vars.get(inputVariable);
        } else if (previousResult != null){
            textToMatch = previousResult.getResponseDataAsString();
        }

        if (textToMatch == null || textToMatch.length() == 0) {
            return defaultValue;
        }

        List<MatchResult> collectAllMatches = new ArrayList<MatchResult>();
        try {
            PatternMatcher matcher = JMeterUtils.getMatcher();
            PatternMatcherInput input = new PatternMatcherInput(textToMatch);
            while (matcher.contains(input, searchPattern)) {
                MatchResult match = matcher.getMatch();
                collectAllMatches.add(match);
            }
        } catch (NumberFormatException e) {//TODO: can this occur?
            log.error("", e); //$NON-NLS-1$
            return defaultValue;
        } finally {
            if (name.length() > 0){
                vars.put(name + "_matchNr", "" + collectAllMatches.size()); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }

        if (collectAllMatches.size() == 0) {
            return defaultValue;
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

            log.warn("Could not read file: "+fileName+" "+e.getMessage());
            throw new JMeterStopThreadException("End of sequence");
        }

        if (myName.length() > 0) {
            JMeterVariables vars = getVariables();
            if (vars != null) {// Can be null if called from Config item testEnded() method
                vars.put(myName, myValue);
            }
        }

        if (log.isDebugEnabled()) {
            String tn = Thread.currentThread().getName();
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

    /** {@inheritDoc} */
    @Override
    public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
            throws InvalidVariableException {

        JMeterVariables vars = getVariables();

        long sum = 0;
        String varName = ((CompoundVariable) values[values.length - 1]).execute().trim();

        for (int i = 0; i < values.length - 1; i++) {
            sum += Long.parseLong(((CompoundVariable) values[i]).execute());
        }

        try {
            sum += Long.parseLong(varName);
            varName = null; // there is no variable name
        } catch (NumberFormatException ignored) {
        }

        String totalString = Long.toString(sum);
        if (vars != null && varName != null && varName.length() > 0){// vars will be null on TestPlan
            vars.put(varName, totalString);
        }

        return totalString;

    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

                throw new JMeterStopThreadException("End of sequence");
            }
        }

        if (myName.length() > 0) {
            JMeterVariables vars = getVariables();
            if (vars != null) {// Can be null if called from Config item testEnded() method
                vars.put(myName, myValue);
            }
        }

        if (log.isDebugEnabled()) {
            String tn = Thread.currentThread().getName();
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

    /** {@inheritDoc} */
    @Override
    public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
            throws InvalidVariableException {
        String variableName = ((CompoundVariable) values[0]).execute();
        final JMeterVariables vars = getVariables();
        if (vars == null){
            log.error("Variables have not yet been defined");
            return "**ERROR - see log file**";
        }
        String variableValue = vars.get(variableName);
        CompoundVariable cv = new CompoundVariable(variableValue);
        return cv.execute();
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        {
            throw new InvalidVariableException("BeanShell not found");
        }

        JMeterContext jmctx = JMeterContextService.getContext();
        JMeterVariables vars = jmctx.getVariables();

        String script = ((CompoundVariable) values[0]).execute();
        String varName = ""; //$NON-NLS-1$
        if (values.length > 1) {
            varName = ((CompoundVariable) values[1]).execute().trim();
        }

        String resultStr = ""; //$NON-NLS-1$

        log.debug("Script=" + script);

        try {

            // Pass in some variables
            if (currentSampler != null) {
                bshInterpreter.set("Sampler", currentSampler); //$NON-NLS-1$
            }

            if (previousResult != null) {
                bshInterpreter.set("SampleResult", previousResult); //$NON-NLS-1$
            }

            // Allow access to context and variables directly
            bshInterpreter.set("ctx", jmctx); //$NON-NLS-1$
            bshInterpreter.set("vars", vars); //$NON-NLS-1$
            bshInterpreter.set("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
            bshInterpreter.set("threadName", Thread.currentThread().getName()); //$NON-NLS-1$

            // Execute the script
            Object bshOut = bshInterpreter.eval(script);
            if (bshOut != null) {
                resultStr = bshOut.toString();
            }
            if (vars != null && varName.length() > 0) {// vars will be null on TestPlan
                vars.put(varName, resultStr);
            }
        } catch (Exception ex) // Mainly for bsh.EvalError
        {
            log.warn("Error running BSH script", ex);
        }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        variables.put("my_regex", ".*");
        variables.put("server", "jakarta.apache.org");
        result = new SampleResult();
        result.setResponseData("<html>hello world</html> costs: $3.47,$5.67", null);
        transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
        jmctx.setVariables(new JMeterVariables());
        jmctx.setSamplingStarted(true);
        jmctx.setPreviousResult(result);
        jmctx.getVariables().put("server", "jakarta.apache.org");
        jmctx.getVariables().put("my_regex", ".*");
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

            variables.addParameter("username", "jack");
            // The following used to be jacks_password, but the Arguments class uses
            // HashMap for which the order is not defined.
            variables.addParameter("password", "his_password");
            variables.addParameter("regex", ".*");
            JMeterVariables vars = new JMeterVariables();
            vars.put("server", "jakarta.apache.org");
            JMeterContextService.getContext().setVariables(vars);
            JMeterContextService.getContext().setSamplingStarted(true);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.