Examples of JMeterVariables


Examples of org.apache.jmeter.threads.JMeterVariables

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

        JMeterVariables vars = getVariables();

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

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

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

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

        return totalString;

    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        }
        if (node instanceof TestPlan) {
            ((TestPlan)node).prepareForPreCompile(); //A hack to make user-defined variables in the testplan element more dynamic
            Map<String, String> args = ((TestPlan) node).getUserDefinedVariables();
            replacer.setUserDefinedVariables(args);
            JMeterVariables vars = new JMeterVariables();
            vars.putAll(args);
            JMeterContextService.getContext().setVariables(vars);
        }

        if (node instanceof Arguments) {
            ((Arguments)node).setRunningVersion(true);
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

                    res.setResponseCodeOK();
                }

                // TODO could these be done earlier (or just once?)
                JMeterContext threadContext = getThreadContext();
                JMeterVariables threadVars = threadContext.getVariables();

                SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT);
                if (pack == null) {
                    log.warn("Could not fetch SamplePackage");
                } else {
                    SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars, true);
                    // We must set res to null now, before sending the event for the transaction,
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

     * @see org.apache.jmeter.functions.Function#execute
     */
    @Override
    public String toString() {
        String ret = null;
        JMeterVariables vars = getVariables();

        if (vars != null) {
            ret = vars.get(name);
        }

        if (ret == null) {
            return "${" + name + "}";
        }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        if (values.length > 1) {
            varName = ((CompoundVariable) values[1]).execute().trim();
        }

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

        try
        {
            Script script = ScriptFactory.createScript(exp);
            JexlContext jc = JexlHelper.createContext();
            @SuppressWarnings("unchecked")
            final Map<String, Object> jexlVars = jc.getVars();
            jexlVars.put("log", log); //$NON-NLS-1$
            jexlVars.put("ctx", jmctx); //$NON-NLS-1$
            jexlVars.put("vars", vars); //$NON-NLS-1$
            jexlVars.put("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
            // Previously mis-spelt as theadName
            jexlVars.put("threadName", Thread.currentThread().getName()); //$NON-NLS-1$
            jexlVars.put("sampler", currentSampler); //$NON-NLS-1$ (may be null)
            jexlVars.put("sampleResult", previousResult); //$NON-NLS-1$ (may be null)
            jexlVars.put("OUT", System.out);//$NON-NLS-1$

            // Now evaluate the script, getting the result
            Object o = script.execute(jc);
            if (o != null)
            {
                str = o.toString();
            }
            if (vars != null && varName.length() > 0) {// vars will be null on TestPlan
                vars.put(varName, str);
            }
        } catch (Exception e)
        {
            log.error("An error occurred while evaluating the expression \""
                    + exp + "\"\n",e);
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

         */

        String machineName = JMeterUtils.getLocalHostName();

        if (values.length >= 1){// we have a variable name
            JMeterVariables vars = getVariables();
            if (vars != null) {// May be null if function is used on TestPlan
                String varName = ((CompoundVariable) values[0]).execute().trim();
                if (varName.length() > 0) {
                    vars.put(varName, machineName);
                }
            }
        }
        return machineName;

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();

        String stringToSplit = ((CompoundVariable) values[0]).execute();
        String varNamePrefix = ((CompoundVariable) values[1]).execute().trim();
        String splitString = ",";

        if (values.length > 2) { // Split string provided
            splitString = ((CompoundVariable) values[2]).execute();
        }
        if (log.isDebugEnabled()){
            log.debug("Split "+stringToSplit+ " using "+ splitString+ " into "+varNamePrefix);
        }
        String parts[] = JOrphanUtils.split(stringToSplit, splitString, "?");// $NON-NLS-1$

        vars.put(varNamePrefix, stringToSplit);
        vars.put(varNamePrefix + "_n", "" + parts.length);// $NON-NLS-1$ // $NON-NLS-2$
        for (int i = 1; i <= parts.length; i++) {
            if (log.isDebugEnabled()){
                log.debug(parts[i-1]);
            }
            vars.put(varNamePrefix + "_" + i, parts[i - 1]);// $NON-NLS-1$
        }
        vars.remove(varNamePrefix + "_" + (parts.length+1));
        return stringToSplit;

    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

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

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

        String script = ((CompoundVariable) values[0]).execute();
        // Allow variable to be omitted
        String varName = values.length < 2 ? null : ((CompoundVariable) values[1]).execute().trim();
        String resultStr = "";

        Context cx = Context.enter();
        try {

            Scriptable scope = cx.initStandardObjects(null);

            // Set up some objects for the script to play with
            scope.put("log", scope, log); //$NON-NLS-1$
            scope.put("ctx", scope, jmctx); //$NON-NLS-1$
            scope.put("vars", scope, vars); //$NON-NLS-1$
            scope.put("props", scope, JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
            // Previously mis-spelt as theadName
            scope.put("threadName", scope, Thread.currentThread().getName()); //$NON-NLS-1$
            scope.put("sampler", scope, currentSampler); //$NON-NLS-1$
            scope.put("sampleResult", scope, previousResult); //$NON-NLS-1$

            Object result = cx.evaluateString(scope, script, "<cmd>", 1, null); //$NON-NLS-1$

            resultStr = Context.toString(result);
            if (varName != null && vars != null) {// vars can be null if run from TestPlan
                vars.put(varName, resultStr);
            }

        } catch (RhinoException e) {
            log.error("Error processing Javascript: [" + script + "]\n", e);
            throw new InvalidVariableException();
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

            SimpleDateFormat df = new SimpleDateFormat(fmt);// Not synchronised, so can't be shared
            datetime = df.format(new Date());
        }

        if (variable.length() > 0) {
            JMeterVariables vars = getVariables();
            if (vars != null){// vars will be null on TestPlan
                vars.put(variable, datetime);
            }
        }
        return datetime;
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

    }

    @Override
    public void setUp(){
        JMeterContext jmcx = JMeterContextService.getContext();
        jmcx.setVariables(new JMeterVariables());
        threadVars = jmcx.getVariables();       
        threadVars.put("b", "value");
    }
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.