Package org.apache.jmeter.samplers

Examples of org.apache.jmeter.samplers.SampleResult$Test


    }

    public SampleResult sample(Entry e)// Entry tends to be ignored ...
    {
      log.debug(getLabel()+" "+getFilename()+" "+getUsername()+" "+getPassword());
        SampleResult res = new SampleResult();
        boolean isSuccessful = false;
        res.setSampleLabel(getName());//Use the test element name for the label
        res.setSamplerData("Host: "+getServer()+" Port: "+getPort());
        res.sampleStart();
        try
        {
      Socket sock = getSocket();
      if (sock == null){
        res.setResponseCode("500");
        res.setResponseMessage(getError());
      } else {
        InputStream is = sock.getInputStream();
        OutputStream os = sock.getOutputStream();
        String req = getRequestData();
        //TODO handle filenames
        res.setSamplerData(req);
        protocolHandler.write(os,req);
        String in = protocolHandler.read(is);
              res.setResponseData(in.getBytes());
              res.setDataType(SampleResult.TEXT);
              res.setResponseCode("200");
              res.setResponseMessage("OK");
              isSuccessful = true;
              //Reset the status code if the message contains one
              if (STATUS_PREFIX.length() > 0)
              {
                int i = in.indexOf(STATUS_PREFIX);
                int j = in.indexOf(STATUS_SUFFIX,i+STATUS_PREFIX.length());
                if (i != -1 && j > i)
                {
                  String rc = in.substring(i+STATUS_PREFIX.length(),j);
                  res.setResponseCode(rc);
                  isSuccessful = checkResponseCode(rc);
                  if (haveStatusProps)
                  {
                    res.setResponseMessage(
                        statusProps.getProperty(rc,"Status code not found in properties"));
                  }
                  else
                  {
                    res.setResponseMessage("No status property file");
                  }
                }
                else
                {
                  res.setResponseCode("999");
                    res.setResponseMessage("Status value not found");
                    isSuccessful=false;
                }
              }
      }
        }
        catch (Exception ex)
        {
          log.debug("",ex);
      res.setResponseCode("500");
            res.setResponseMessage(ex.toString());
        }

        // Calculate response time
        res.sampleEnd();

        // Set if we were successful or not
        res.setSuccessful(isSuccessful);

        return res;
    }
View Full Code Here


    public String execute()
    {
        if (isDynamic)
        {
            JMeterContext context = JMeterContextService.getContext();
            SampleResult previousResult = context.getPreviousResult();
            Sampler currentSampler = context.getCurrentSampler();
            return execute(previousResult, currentSampler);
        }
        else
        {
View Full Code Here

        throws InvalidVariableException;

    public String execute() throws InvalidVariableException
    {
        JMeterContext context = JMeterContextService.getContext();
        SampleResult previousResult = context.getPreviousResult();
        Sampler currentSampler = context.getCurrentSampler();
        return execute(previousResult, currentSampler);
    }
View Full Code Here

    {
      jmctx =JMeterContextService.getContext();
        variables = new HashMap();
        variables.put("my_regex", ".*");
        variables.put("server", "jakarta.apache.org");
        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());
View Full Code Here

    {
        Configuration[] samples = testResults.getChildren();

        for (int i = 0; i < samples.length; i++)
        {
            SampleResult result = SaveService.getSampleResult(samples[i]);

            sendToVisualizer(result);
            recordResult(result);
        }
    }
View Full Code Here

     * When a test result is received, display it and save it.
     * @param  e the sample event that was received
     */
    public void sampleOccurred(SampleEvent e)
    {
        SampleResult result = e.getResult();

        if (!isErrorLogging() || !result.isSuccessful())
        {
            sendToVisualizer(result);

            try
            {
View Full Code Here

   * Saves the sample result (and any sub results) in files
   *
   * @see org.apache.jmeter.samplers.SampleListener#sampleOccurred(org.apache.jmeter.samplers.SampleEvent)
   */
  public void sampleOccurred(SampleEvent e) {
    SampleResult s = e.getResult();
    saveSample(s);
    SampleResult []sr = s.getSubResults();
    for (int i = 0; i < sr.length; i++){
      saveSample(sr[i]);
    }
    }
View Full Code Here

     */
    public void process()
    {
      JMeterContext context = getThreadContext();
        Sampler sam = context.getCurrentSampler();
        SampleResult res = context.getPreviousResult();
        HTTPSamplerBase sampler = null;
        HTTPSampleResult result = null;
        if (res == null
            || !(sam instanceof HTTPSamplerBase)
            || !(res instanceof HTTPSampleResult))
View Full Code Here

  }

    public SampleResult sample(Entry e)// Entry tends to be ignored ...
    {
      //log.info(getLabel()+" "+getFilename());
        SampleResult res = new SampleResult();
        boolean isSuccessful = false;
        res.setSampleLabel(getLabel());
        res.sampleStart();
        try
        {
          String request=getScript();
          String fileName=getFilename();
          if (fileName.length() == 0) {
        res.setSamplerData(request)
          } else {
        res.setSamplerData(fileName);
          }
          // Has to be done after construction, otherwise fails serialisation check
          bshInterpreter.set("log",log)//$NON-NLS-1$

      bshInterpreter.set("Label",getLabel())//$NON-NLS-1$
      bshInterpreter.set("FileName",getFilename()); //$NON-NLS-1$
      bshInterpreter.set("SampleResult",res); //$NON-NLS-1$
      bshInterpreter.set("Parameters",getParameters());// as a single line//$NON-NLS-1$
      bshInterpreter.set("bsh.args",JOrphanUtils.split(getParameters()," "));

            // Set default values
      bshInterpreter.set("ResponseCode","200"); //$NON-NLS-1$
      bshInterpreter.set("ResponseMessage","OK");//$NON-NLS-1$
      bshInterpreter.set("IsSuccess",true);//$NON-NLS-1$
     
      Object bshOut;
     
      if (fileName.length() == 0){
        bshOut = bshInterpreter.eval(request);
      } else {
        bshOut = bshInterpreter.source(fileName);
      }
     
      String out;
      if (bshOut == null) {// Script did not return anything...
        out="";
      } else {
        out = bshOut.toString();
      }
          res.setResponseData(out.getBytes());
          res.setDataType(SampleResult.TEXT);
          res.setResponseCode(bshInterpreter.get("ResponseCode").toString());//$NON-NLS-1$
          res.setResponseMessage(bshInterpreter.get("ResponseMessage").toString());//$NON-NLS-1$
          isSuccessful = Boolean.valueOf(bshInterpreter.get("IsSuccess") //$NON-NLS-1$
              .toString()).booleanValue();
        }
/*
* To avoid class loading problems when bsh,jar is missing,
* we don't try to catch this error separately
*     catch (bsh.EvalError ex)
    {
      log.debug("",ex);
      res.setResponseCode("500");//$NON-NLS-1$
      res.setResponseMessage(ex.toString());
    }
*/
        // but we do trap this error to make tests work better
        catch(NoClassDefFoundError ex){
      log.error("BeanShell Jar missing? "+ex.toString());
      res.setResponseCode("501");//$NON-NLS-1$
      res.setResponseMessage(ex.toString());
      res.setStopThread(true); // No point continuing
        }
    catch (IOException ex)
    {
      log.warn(ex.toString());
      res.setResponseCode("500");//$NON-NLS-1$
      res.setResponseMessage(ex.toString());
    }
    catch (Exception ex) // Mainly for bsh.EvalError
    {
      log.warn(ex.toString());
      res.setResponseCode("500");//$NON-NLS-1$
      res.setResponseMessage(ex.toString());
    }

        res.sampleEnd();

        // Set if we were successful or not
        res.setSuccessful(isSuccessful);

        return res;
    }
View Full Code Here

         */
        public SampleResult runTest(JavaSamplerContext context)
        {
            log.debug(whoAmI() + "\trunTest");
            Thread.yield();
            SampleResult results = new SampleResult();
            results.setSuccessful(false);
            results.setResponseData(
                ("Class not found: " + getClassname()).getBytes());
            results.setSampleLabel("ERROR: " + getClassname());
            return results;
        }
View Full Code Here

TOP

Related Classes of org.apache.jmeter.samplers.SampleResult$Test

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.