Examples of JMeterVariables


Examples of org.apache.jmeter.threads.JMeterVariables

        }
        String propertyValue = JMeterUtils.getPropDefault(propertyName, propertyDefault);
        if (values.length > 1) {
            String variableName = ((CompoundVariable) values[1]).execute();
            if (variableName.length() > 0) {// Allow for empty name
                final JMeterVariables variables = getVariables();
                if (variables != null) {
                    variables.put(variableName, propertyValue);
                }
            }
        }
        return propertyValue;
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

        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

Examples of org.apache.jmeter.threads.JMeterVariables

        Sampler currentSampler)
        throws InvalidVariableException
    {
        counter[0]++;

        JMeterVariables vars = getVariables();

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

        String varName =
            ((CompoundVariable) variables[variables.length - 1]).execute();
        String counterString = "";

        if (perThread)
        {
          counterString = vars.get(key);
          if (null==counterString){
            counterString= "1";
          }
          else
          {
            counterString = Integer.toString(Integer.parseInt(counterString)+1);
          }
          vars.put(key,counterString);
         
        }
        else
        {
            counterString = String.valueOf(counter[0]);
        }

        if (varName.length()>0) vars.put(varName, counterString);
        return counterString;
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

            return;
        }
        log.debug("RegexExtractor processing result");

        // Fetch some variables
    JMeterVariables vars = context.getVariables();
    String refName = getRefName();
    int matchNumber = getMatchNumber();

        vars.put(refName, getDefaultValue());
       
        Perl5Matcher matcher = (Perl5Matcher) localMatcher.get();
        PatternMatcherInput input =
            new PatternMatcherInput(
                useHeaders() ? context.getPreviousResult().getResponseHeaders()
                                 : new String(context.getPreviousResult().getResponseData())
        );
        log.debug("Regex = " + getRegex());
    try {
      Pattern pattern =
          patternCache.getPattern(getRegex(), Perl5Compiler.READ_ONLY_MASK);
      List matches = new ArrayList();
      int x = 0;
      boolean done = false;
            do
      {
          if (matcher.contains(input, pattern))
          {
              log.debug("RegexExtractor: Match found!");
              matches.add(matcher.getMatch());
          }
          else
          {
              done = true;
          }
          x++;
      }
      while (x != matchNumber && !done);

      try
      {
          MatchResult match;
          if (matchNumber >= 0){// Original match behaviour
            match = getCorrectMatch(matches, matchNumber);
            if (match != null)
            {
                vars.put(refName, generateResult(match));
                saveGroups(vars, refName, match);
            }
        }
        else // < 0 means we save all the matches
        {
          int prevCount = 0;
          String prevString=(String)vars.get(refName+"_matchNr");
          if (prevString != null)
                    {
                    try
                    {
                        prevCount = Integer.parseInt(prevString);
                    }
                    catch (NumberFormatException e1)
                    {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
          }
          vars.put(refName+"_matchNr", ""+matches.size());// Save the count
          for (int i=1;i<=matches.size();i++) {
            match = getCorrectMatch(matches, i);
            if (match != null)
            {
              vars.put(refName+"_"+i, generateResult(match));
              saveGroups(vars, refName+"_"+i, match);
            }
          }
          for (int i = matches.size()+1;i<=prevCount;i++)
          {
            vars.remove(refName+"_"+i);
            vars.remove(refName+"_"+i+"_g0");// Remove known groups ...
            vars.remove(refName+"_"+i+"_g1");// ...
            //TODO remove other groups if present?
          }
        }
      }
      catch (RuntimeException e)
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

                    "<value field=\"pinpositionvalue3\"></value>" +
                  "</row>" +
                "</company-xmlext-query-ret>";
            result.setResponseData(data.getBytes());
            result.setResponseHeaders("Header1: Value1\nHeader2: Value2");
            vars = new JMeterVariables();
            jmctx.setVariables(vars);
            jmctx.setPreviousResult(result);
        }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

    private JMeterContext jmctx = null;
  private JMeterVariables vars = null;
    public void setUp()
    {
      jmctx = JMeterContextService.getContext();
        jmctx.setVariables(new JMeterVariables());
      vars = jmctx.getVariables();
    }
View Full Code Here

Examples of org.apache.jmeter.threads.JMeterVariables

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

        JMeterVariables vars = getVariables();//Relatively expensive operation, so do it once
        vars.put(name, defaultValue);
        if (previousResult == null || previousResult.getResponseData() == null)
        {
            return defaultValue;
        }

        List collectAllMatches = new ArrayList();
        try
        {
            PatternMatcher matcher = (PatternMatcher) localMatcher.get();
            String responseText = new String(previousResult.getResponseData());
            PatternMatcherInput input = new PatternMatcherInput(responseText);
            while (matcher.contains(input, searchPattern))
            {
                MatchResult match = matcher.getMatch();
                collectAllMatches.add(match);
            }
        }
        catch (NumberFormatException e)
        {
            log.error("", e);
            return defaultValue;
        }
        catch (Exception e)
        {
            return defaultValue;
        }
        finally
    {
      vars.put(name+"_matchNr", ""+collectAllMatches.size());
        }

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

Examples of org.apache.jmeter.threads.JMeterVariables

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

Examples of org.apache.jmeter.threads.JMeterVariables

     * @see org.apache.jmeter.functions.Function#execute(SampleResult, Sampler)
     */
    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 (node instanceof TestPlan)
        {
            Map args= ((TestPlan)node).getUserDefinedVariables();
            replacer.setUserDefinedVariables(args);
            JMeterVariables vars= new JMeterVariables();
            vars.putAll(args);
            JMeterContextService.getContext().setVariables(vars);
        }
        else if (node instanceof TestElement)
        {
            try
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.