Package org.apache.jmeter.threads

Examples of org.apache.jmeter.threads.JMeterVariables


        }

        public void testParseExample4() throws Exception
        {
            function.setParameters("${non-existing function}");
            function.setJMeterVariables(new JMeterVariables());
            assertEquals(1, function.compiledComponents.size());
            assertTrue(function.hasFunction());
            assertTrue(!function.hasStatics());
            assertEquals(
                "${non-existing function}",
View Full Code Here


        }

        public void testParseExample6() throws Exception
        {
            function.setParameters("${server}");
            function.setJMeterVariables(new JMeterVariables());
            assertEquals(1, function.compiledComponents.size());
            assertTrue(!function.hasFunction());
            assertTrue(function.hasStatics());
            assertEquals("jakarta.apache.org", function.execute(null, null));
        }
View Full Code Here

        }

        public void testParseExample5() throws Exception
        {
            function.setParameters("");
            function.setJMeterVariables(new JMeterVariables());
            assertEquals(0, function.compiledComponents.size());
            assertTrue(!function.hasFunction());
            assertTrue(!function.hasStatics());
        }
View Full Code Here

        public void testNestedExample1() throws Exception
        {
            function.setParameters(
                "${__regexFunction(<html>(${my_regex})</html>,$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)</html>,$1$$3$)}");
            function.setJMeterVariables(new JMeterVariables());
            assertEquals(2, function.compiledComponents.size());
            assertTrue(function.hasFunction());
            assertTrue(function.hasStatics());
            assertEquals(
                "hello world",
View Full Code Here

        public void testNestedExample2() throws Exception
        {
            function.setParameters(
                "${__regexFunction(<html>(${my_regex})</html>,$1$)}");
            function.setJMeterVariables(new JMeterVariables());
            assertEquals(1, function.compiledComponents.size());
            assertEquals(
                "org.apache.jmeter.functions.RegexFunction",
                function.compiledComponents.getFirst().getClass().getName());
            assertTrue(function.hasFunction());
View Full Code Here

 
  private void setVariables()
  {
    Iterator namesIter = getNames().iterator();
    Iterator valueIter = getValues().iterator();
    JMeterVariables jmvars = vars.getVariables();
    while(namesIter.hasNext() && valueIter.hasNext())
    {
      String name = (String)namesIter.next();
      String value = (String)valueIter.next();
      jmvars.put(name,value);
    }
  }
View Full Code Here

                    + " field=\"pinpositionvalue2\"></value><value"
                    + " field=\"pinposition3\">6</value><value"
                    + " field=\"pinpositionvalue3\"></value>"
                    + "</row></company-xmlext-query-ret>";
            result.setResponseData(data.getBytes());
            vars = new JMeterVariables();
            jmctx.setVariables(vars);
            jmctx.setPreviousResult(result);
        }
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)
                { // EOF, re-open file
            String tn = Thread.currentThread().getName();
                    log.info(tn+" EOF on  file " + fileName);//$NON-NLS-1$
                    closeFile();
                    openFile();
                    if (myBread != null) {
            line = myBread.readLine();
                    } else {
                      line = ERR_IND;
                      if (myEnd != COUNT_UNUSED){// Are we processing a file sequence?
                        log.info(tn + " Detected end of sequence.");
                       throw new JMeterStopThreadException("End of sequence");
                      }
                    }
                }
                myValue = line;
            }
            catch (IOException e)
            {
        String tn = Thread.currentThread().getName();
                log.error(tn + " error reading file " + e.toString());//$NON-NLS-1$
            }
        } else { // File was not opened successfully
          if (myEnd != COUNT_UNUSED){// Are we processing a file sequence?
        String tn = Thread.currentThread().getName();
            log.info(tn + " Detected end of sequence.");
           throw new JMeterStopThreadException("End of sequence");
          }
        }

        if (myName.length() > 0){
      vars.put(myName, myValue);
        }
       
        if (log.isDebugEnabled()){
      String tn = Thread.currentThread().getName();
            log.debug(tn + " name:" //$NON-NLS-1$
View Full Code Here

      {
        throw new InvalidVariableException("BeanShell not found");
      }
     
      JMeterContext jmctx = JMeterContextService.getContext();
        JMeterVariables vars = jmctx.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)
          {
        bshInvoke(bshSet,"Sampler",currentSampler)//$NON-NLS-1$
          }
     
      if (previousResult != null)
      {
        bshInvoke(bshSet,"SampleResult",previousResult)//$NON-NLS-1$
      }
     
      // Allow access to context and variables directly
      bshInvoke(bshSet,"ctx",jmctx)//$NON-NLS-1$
      bshInvoke(bshSet,"vars",vars); //$NON-NLS-1$
      bshInvoke(bshSet,"threadName",Thread.currentThread().getName())//$NON-NLS-1$
     
            // Execute the script
            Object bshOut = bshInvoke(bshEval,script,null);
      if (bshOut != null) {
        resultStr = bshOut.toString();
      }
      if (varName.length() > 0)
      {
        vars.put(varName, resultStr);
      }
        }
    catch (Exception ex) // Mainly for bsh.EvalError
    {
      log.warn("Error running BSH script",ex);
View Full Code Here

        SampleResult previousResult,
        Sampler currentSampler)
        throws InvalidVariableException
    {

        JMeterVariables vars = getVariables();

        /*
        boolean fullHostName = false;
        if (((CompoundFunction) values[0])
            .execute()
            .toLowerCase()
            .equals("true"))
        {
            fullHostName = true;
        }
        */
       
        String varName =
            ((CompoundVariable) values[values.length - 1]).execute();
        String machineName = "";

        try
        {

            InetAddress Address = InetAddress.getLocalHost();

            //fullHostName disabled until we move up to 1.4 as the support jre
            //  if ( fullHostName ) {
            //      machineName = Address.getCanonicalHostName();

            //  } else {
            machineName = Address.getHostName();
            //  }

        }
        catch (UnknownHostException e)
        {
        }

        vars.put(varName, machineName);
        return machineName;

    }
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.