Package org.apache.jmeter.threads

Examples of org.apache.jmeter.threads.JMeterVariables


            variables = new TestPlan();
            variables.addParameter("server", "jakarta.apache.org");
            variables.addParameter("username", "jack");
            variables.addParameter("password", "jacks_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


      log.debug("Condition string:"+cnd);
      boolean res;
      // If blank, only check previous sample when in loop
      if ((inLoop && cnd.length() == 0)
          || "LAST".equalsIgnoreCase(cnd)) {// $NON-NLS-1$
          JMeterVariables threadVars =
            JMeterContextService.getContext().getVariables();
          // Use !false rather than true, so that null is treated as true
             res = !"false".equalsIgnoreCase(threadVars.get(JMeterThread.LAST_SAMPLE_OK));// $NON-NLS-1$
      } else {
        // cnd may be blank if next() called us
        res = !"false".equalsIgnoreCase(cnd);// $NON-NLS-1$
      }
      log.debug("Condition value: "+res);
View Full Code Here

      {
            log.debug(Thread.currentThread().getName() + " Running up named: " + getName());//$NON-NLS-1$
      }
            PropertyIterator namesIter = getNames().iterator();
            PropertyIterator valueIter = getValues().iterator();
            JMeterVariables jmvars = getThreadContext().getVariables();
            while (namesIter.hasNext() && valueIter.hasNext())
            {
                String name = namesIter.next().getStringValue();
                String value = valueIter.next().getStringValue();
        if (log.isDebugEnabled())
        {
                    log.debug(Thread.currentThread().getName()+" saving variable: "+name+"="+value);//$NON-NLS-1$
        }
                jmvars.put(name, value);
            }
        }
    }
View Full Code Here

     * @see LoopIterationListener#iterationStart(LoopIterationEvent)
     */
    public synchronized void iterationStart(LoopIterationEvent event)
    {
      // Cannot use getThreadContext() as not cloned per thread
        JMeterVariables variables =
          JMeterContextService.getContext().getVariables();
        int start = getStart(), end = getEnd(), increment = getIncrement();
        if (!isPerUser())
        {
            if (globalCounter == -1 || globalCounter > end)
            {
                globalCounter = start;
            }
            variables.put(getVarName(), Integer.toString(globalCounter));
            globalCounter += increment;
        }
        else
        {
            String value = variables.get(getVarName());
            if (value == null)
            {
                variables.put(getVarName(), Integer.toString(start));
            }
            else
            {
                try
                {
                    int current = Integer.parseInt(value);
                    current += increment;
                    if (current > end)
                    {
                        current = start;
                    }
                    variables.put(getVarName(), Integer.toString(current));
                }
                catch (NumberFormatException e)
                {
                    log.info("Bad number in Counter config", e);
                }
View Full Code Here

      {
            log.debug(Thread.currentThread().getName() + " Running up named: " + getName());//$NON-NLS-1$
      }
            PropertyIterator namesIter = getNames().iterator();
            PropertyIterator valueIter = getValues().iterator();
            JMeterVariables jmvars = getThreadContext().getVariables();
            while (namesIter.hasNext() && valueIter.hasNext())
            {
                String name = namesIter.next().getStringValue();
                String value = valueIter.next().getStringValue();
        if (log.isDebugEnabled())
        {
                    log.debug(Thread.currentThread().getName()+" saving variable: "+name+"="+value);//$NON-NLS-1$
        }
                jmvars.put(name, value);
            }
        }
    }
View Full Code Here

     * @see LoopIterationListener#iterationStart(LoopIterationEvent)
     */
    public synchronized void iterationStart(LoopIterationEvent event)
    {
      // Cannot use getThreadContext() as not cloned per thread
        JMeterVariables variables =
          JMeterContextService.getContext().getVariables();
        int start = getStart(), end = getEnd(), increment = getIncrement();
        if (!isPerUser())
        {
            if (globalCounter == -1 || globalCounter > end)
            {
                globalCounter = start;
            }
            variables.put(getVarName(), Integer.toString(globalCounter));
            globalCounter += increment;
        }
        else
        {
            String value = variables.get(getVarName());
            if (value == null)
            {
                variables.put(getVarName(), Integer.toString(start));
                value = variables.get(getVarName());
            }
            else
            {
                try
                {
                    int current = Integer.parseInt(value);
                    current += increment;
                    if (current > end)
                    {
                        current = start;
                    }
                    variables.put(getVarName(), Integer.toString(current));
                }
                catch (NumberFormatException e)
                {
                    log.info("Bad number in Counter config", e);
                }
View Full Code Here

        SampleResult previousResult,
        Sampler currentSampler)
        throws InvalidVariableException
    {

        JMeterVariables vars = getVariables();

        int min = Integer.parseInt(minimum.execute().trim());
        int max = Integer.parseInt(maximum.execute().trim());

        int rand = (int) Math.round(min + Math.random() * (max - min));

        String randString = Integer.toString(rand);
        vars.put(varName.execute(), randString);

        return randString;

    }
View Full Code Here

   * @see org.apache.jmeter.functions.Function#execute(SampleResult, Sampler)
   */
  public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
    throws InvalidVariableException {
    counter++;
    JMeterVariables vars = getVariables();
    String falseCounterString = Integer.toString(counter);
    String trueCounterString = Integer.toString(vars.getIteration());
    vars.put(trueCount,trueCounterString);
    vars.put(falseCount,falseCounterString);
   
    if(perThread)
    {
      return trueCounterString;
    }
View Full Code Here

        {
            return defaultValue;
        }
        finally
    {
            JMeterVariables vars = getVariables();
      vars.put(name+"_matchNr", ""+collectAllMatches.size());
        }

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

    private void saveGroups(MatchResult result)
    {
        if (result != null)
        {
            JMeterVariables vars = getVariables();
            for (int x = 0; x < result.groups(); x++)
            {
                vars.put(name + "_g" + x, result.group(x));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jmeter.threads.JMeterVariables

Copyright © 2018 www.massapicom. 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.