Package org.apache.jmeter.threads

Examples of org.apache.jmeter.threads.JMeterVariables


            else
            {
                result.append(match.group(((Integer) template[a]).intValue()));
            }
        }
        JMeterVariables vars = getVariables();
        vars.put(name, result.toString());
        return result.toString();
    }
View Full Code Here


        SampleResult previousResult,
        Sampler currentSampler)
        throws InvalidVariableException
    {

        JMeterVariables vars = getVariables();

        if (values.length >= PARAM_NAME)
        {
            myName = ((CompoundVariable) values[PARAM_NAME-1]).execute();
        }

        myValue = ERR_IND;
       
        /*
         * To avoid re-opening the file repeatedly after an error,
         * only try to open it in the first execute() call
         * (It may be re=opened at EOF, but that will cause at most
         * one failure.)
         */
        if (firstTime) {
          openFile();
          firstTime=false;
        }
       
        if (null != myBread)
        { // Did we open the file?
            try
            {
                String line = myBread.readLine();
                if (line == null && reopenFile)
                { // EOF, re-open file
                    log.info("Reached EOF on " + fileName);//$NON-NLS-1$
                    closeFile();
                    openFile();
                    if (myBread != null) {
            line = myBread.readLine();
                    } else {
                      line = ERR_IND;
                    }
                }
                myValue = line;
            }
            catch (Exception e)
            {
        String tn = Thread.currentThread().getName();
                log.error(tn + " error reading file " + e.toString());//$NON-NLS-1$
            }
        } else { // File was not opened successfully
          if (values.length >= PARAM_END){// Are we processing a file sequence?
            log.info("Detected end of sequence.");
            throw new RuntimeException("Stop Thread");//TODO there has to be a better way...
          }
        }

        if (myName.length() > 0){
      vars.put(myName, myValue);
        }
       
        if (log.isDebugEnabled()){
            log.debug(this +"::StringFromFile.execute() name:" //$NON-NLS-1$
                 + myName + " value:" + myValue);//$NON-NLS-1$
View Full Code Here

        SampleResult previousResult,
        Sampler currentSampler)
        throws InvalidVariableException
    {

        JMeterVariables vars = getVariables();

        String script  = ((CompoundVariable) values[0]).execute();
        String varName = "";
        if (values.length > 1){
      varName = ((CompoundVariable) values[1]).execute();
        }
       
        String resultStr = "";
       
    log.debug("Script="+script);

        try
        {

      // Pass in some variables
          if (currentSampler != null) {
        setObj.invoke(instance, new Object[] {"Sampler",currentSampler});
          }
     
      if (previousResult != null)
      {
        setObj.invoke(instance, new Object[] {"SampleResult",previousResult});
      }
       
      setObj.invoke(instance, new Object[] {"log",log});
      setObj.invoke(instance, new Object[] {"t",this});
     
            // Execute the script
            Object bshOut = eval.invoke(instance, new Object[]{script});
      if (bshOut != null) {
        resultStr = bshOut.toString();
      }
      if (varName.length() > 0)
      {
        vars.put(varName, resultStr);
      }
        }
    catch (Exception ex) // Mainly for bsh.EvalError
    {
      log.warn("",ex);
View Full Code Here

        SampleResult previousResult,
        Sampler currentSampler)
        throws InvalidVariableException
    {

        JMeterVariables vars = getVariables();

        String script = ((CompoundVariable) values[0]).execute();
        String varName =
            ((CompoundVariable) values[values.length - 1]).execute();
        String resultStr = "";

        Context cx = Context.enter();
        try
        {

            Scriptable scope = cx.initStandardObjects(null);
            Object result = cx.evaluateString(scope, script, "<cmd>", 1, null);

            resultStr = Context.toString(result);
            vars.put(varName, resultStr);

        }
        catch (JavaScriptException e)
        {
            throw new InvalidVariableException();
View Full Code Here

        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 = Integer.toString(vars.getIteration());
        }
        else
        {
            counterString = String.valueOf(counter[0]);
        }

        vars.put(varName, counterString);
        return counterString;
    }
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

      else
      {
        result.append(match.group(((Integer)template[a]).intValue()));
      }
    }
    JMeterVariables vars = getVariables();
    vars.put(name,result.toString());
    return result.toString();
  }
View Full Code Here

    }
   
    public void testVariableExtraction() throws Exception
    {
      variable.setParameters(URLEncoder.encode("<value field=\"(pinposition\\d+)\">(\\d+)</value>")+",$2$,2");
      variable.setJMeterVariables(new JMeterVariables());
      String match = variable.execute(result,null);
      assertEquals("5",match);     
    }
View Full Code Here

    }
   
    public void testVariableExtraction2() throws Exception
    {
      variable.setParameters(URLEncoder.encode("<value field=\"(pinposition\\d+)\">(\\d+)</value>")+",$1$,3");
      variable.setJMeterVariables(new JMeterVariables());
      String match = variable.execute(result,null);
      assertEquals("pinposition3",match);     
    }
View Full Code Here

    }
   
    public void testVariableExtraction5() throws Exception
    {
      variable.setParameters(URLEncoder.encode("<value field=\"(pinposition\\d+)\">(\\d+)</value>")+",$1$,ALL,_");
      variable.setJMeterVariables(new JMeterVariables());
      String match = variable.execute(result,null);
      assertEquals("pinposition1_pinposition2_pinposition3",match);     
    }
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.