Package org.apache.jmeter.samplers

Examples of org.apache.jmeter.samplers.SampleResult


            result.setContentType("text/css");
            assertFalse("Should not allow text/css", control.filterContentType(result));
        }
       
        public void testContentTypeExclude() throws Exception {
            SampleResult result = new SampleResult();
            control.setContentTypeExclude("text/css");

            result.setContentType(null);
            assertTrue("Should allow if no content-type present", control.filterContentType(result));          
            result.setContentType("text/html; charset=utf-8");
            assertTrue("Should allow text/html", control.filterContentType(result));           
            result.setContentType("text/css");
            assertFalse("Should not allow text/css", control.filterContentType(result));
        }
View Full Code Here


            result.setContentType("text/css");
            assertFalse("Should not allow text/css", control.filterContentType(result));
        }
       
        public void testContentTypeIncludeAndExclude() throws Exception {
            SampleResult result = new SampleResult();
            // Simple inclusion and exclusion filter
            control.setContentTypeInclude("text/html|text/ascii");
            control.setContentTypeExclude("text/css");

            result.setContentType(null);
            assertTrue("Should allow if no content-type present", control.filterContentType(result));          
            result.setContentType("text/html; charset=utf-8");
            assertTrue("Should allow text/html", control.filterContentType(result));           
            result.setContentType("text/css");
            assertFalse("Should not allow text/css", control.filterContentType(result));           
            result.setContentType("image/png");
            assertFalse("Should not allow image/png", control.filterContentType(result));
           
            // Allow all but images
            control.setContentTypeInclude(null);
            control.setContentTypeExclude("image/.*");
           
            result.setContentType(null);
            assertTrue("Should allow if no content-type present", control.filterContentType(result));          
            result.setContentType("text/html; charset=utf-8");
            assertTrue("Should allow text/html", control.filterContentType(result));           
            result.setContentType("text/css");
            assertTrue("Should allow text/css", control.filterContentType(result));        
            result.setContentType("image/png");
            assertFalse("Should not allow image/png", control.filterContentType(result));
        }
View Full Code Here

     * method.
     */
    public SampleResult sampleWithParser() {
        initFilter();
        instantiateParser();
        SampleResult res = null;
        try {

            if (PARSER == null) {
                throw new JMeterException("No Parser available");
            }
            /*
             * samp.setDomain(this.getDomain()); samp.setPort(this.getPort());
             */
            // we call parse with 1 to get only one.
            // this also means if we change the implementation
            // to use 2, it would use every other entry and
            // so on. Not that it is really useful, but a
            // person could use it that way if they have a
            // huge gigabyte log file and they only want to
            // use a quarter of the entries.
            int thisCount = PARSER.parseAndConfigure(1, this);
            if (thisCount < 0) // Was there an error?
            {
                return errorResult(new Error("Problem parsing the log file"), new HTTPSampleResult());
            }
            if (thisCount == 0) {
                if (count == 0 || filter == null) {
                    log.info("Stopping current thread");
                    JMeterContextService.getContext().getThread().stop();
                }
                if (filter != null) {
                    filter.reset();
                }
                CookieManager cm = getCookieManager();
                if (cm != null) {
                    cm.clear();
                }
                count = 0;
                return errorResult(new Error("No entries found"), new HTTPSampleResult());
            }
            count = thisCount;
            res = sample();
            res.setSampleLabel(toString());
        } catch (Exception e) {
            log.warn("Sampling failure", e);
            return errorResult(e, new HTTPSampleResult());
        }
        return res;
View Full Code Here

        catch (Exception ex)
        {
          ex.printStackTrace();
          running = false;
        }
        SampleResult result = sampler.sample(entry);
        checkAssertions(entry, result);
        notifyListeners(result);
      }
    }
  }
View Full Code Here

    long start;
    long end;
    long time;
    time = start = end = 0;
    SqlConfig sql = (SqlConfig)e.getConfigElement(SqlConfig.class);
    SampleResult res = new SampleResult();
    Connection con = null;
    ResultSet rs = null;
    Statement stmt = null;
    Data data = new Data();
    res.putValue(SampleResult.SAMPLE_LABEL, sql.getQuery());
    start = System.currentTimeMillis();
    try
    {
      while ((con = manager.getConnection(key)) == null)
      {
        try
        {
          Thread.sleep(10);
        }
        catch (Exception err)
        {
        }
      }
      stmt = con.createStatement();
      // Execute database query
      boolean retVal = stmt.execute(sql.getQuery());
      // Based on query return value, get results
      if (retVal)
      {
        rs = stmt.getResultSet();
        data = getDataFromResultSet(rs);
        rs.close();
      }
      else
      {
        int updateCount = stmt.getUpdateCount();
      }
      stmt.close();
      manager.releaseConnection(con);
    }
    catch (Exception ex)
    {
      if (rs != null)
      {
        try
        {
          rs.close();
        }
        catch (SQLException err)
        {
          rs = null;
        }
      }
      if (stmt != null)
      {
        try
        {
          stmt.close();
        }
        catch (SQLException err)
        {
          stmt = null;
        }
      }
      manager.releaseConnection(con);
      ex.printStackTrace();
    }
    // Calculate response time
    end = System.currentTimeMillis();
    time += end - start;
    res.setTime(time);
    res.putValue(SampleResult.TEXT_RESPONSE, data.toString().getBytes());
    return res;
  }
View Full Code Here

   */
  public SampleResult sample(Entry e)
  {
    catClass.debug("Start : sample2");
    long totalTime = (long)0;
    SampleResult res = super.sample(e);
    String displayName = (String)res.getValue(SampleResult.SAMPLE_LABEL);
    res.putValue(SampleResult.DISPLAY_NAME, displayName);
    List loadBinaryList = new ArrayList();
    if (catClass.isDebugEnabled())
    {
      catClass.debug("sample2 : main page loading time - " + res.getTime());
    }
    totalTime += res.getTime();
    Document html = null;
    try
    {
      baseUrl = new URL((String)res.getValue(SampleResult.SAMPLE_LABEL));
      if (catClass.isDebugEnabled())
      {
        catClass.debug("sample2 : baseUrl - " + baseUrl.toString());
      }

      // now use parser to look for image tags
      html = (Document)getDOM(new String((byte[])res.getValue(SampleResult.TEXT_RESPONSE)));
    }
    catch(SAXException exception)
    {
      catClass.error("sample2 : Error parsing document - " + exception);
      catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
      res.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
      res.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
      res.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
      res.putValue(SampleResult.SUCCESS, new Boolean(false));
    }
    catch(MalformedURLException exception)
    {
      catClass.error("sample2 : Error creating URL - " + exception);
      catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
      res.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
      res.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
      res.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
      res.putValue(SampleResult.SUCCESS, new Boolean(false));
    }

    // sample result to store image from <img...> tags
    SampleResult imgRes = null;
    NodeList nodeList = html.getElementsByTagName("img");
    for(int i = 0; i < nodeList.getLength(); i++)
    {
      imgRes = new SampleResult();
      try
      {
        Node tempNode = nodeList.item(i);
        if(catClass.isDebugEnabled())
        {
          catClass.debug("sample2 : Image tags - " + tempNode);
        }

        // get the url of those images
        NamedNodeMap nnm = tempNode.getAttributes();
        Node namedItem = nnm.getNamedItem("src");
        String imgUrlStr = namedItem.getNodeValue();

        // set the baseUrl and imgUrl so that if error occurs
        // due to MalformedException then at least the values will be
        // visible to the user to aid correction
        imgRes.putValue(SampleResult.DISPLAY_NAME, baseUrl + "," + imgUrlStr);

        // download those images
        URL imgUrl = new URL(baseUrl, imgUrlStr);
        if (catClass.isDebugEnabled())
        {
          catClass.debug("sample2 : Image url without baseUrl - " + imgUrlStr);
          catClass.debug("sample2 : Image url with baseUrl - " + imgUrl);
        }

        imgRes.putValue(SampleResult.DISPLAY_NAME, imgUrl.toString());
        loadBinary(imgUrl, e, imgRes);
        ImageIcon image = new ImageIcon(imgUrl, imgUrl.toString());
        imgRes.putValue(IMAGE, image);
        totalTime += imgRes.getTime();
        imgRes.remove(SampleResult.TEXT_RESPONSE);
      }
      catch(IOException exception)
      {
        catClass.error("sample2 : Error reading from URL - " + exception);
        catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
        imgRes.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
        imgRes.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
        imgRes.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
        imgRes.putValue(SampleResult.SUCCESS, new Boolean(false));
      }

      loadBinaryList.add(imgRes);
    }

    SampleResult appRes = null;

    // use parser to look for applet tags
    nodeList = html.getElementsByTagName("applet");
    for(int i = 0; i < nodeList.getLength(); i++)
    {
      appRes = new SampleResult();
      try
      {
        Node tempNode = nodeList.item(i);
        if(catClass.isDebugEnabled())
        {
          catClass.debug("sample2 : Applet tags - " + tempNode);
        }

        // get the url of those applets
        NamedNodeMap nnm = tempNode.getAttributes();
        Node namedItem = nnm.getNamedItem("code");
        String appletUrlStr = namedItem.getNodeValue() + ".class";

        // set the baseUrl and imgUrl so that if error occurs
        // due to MalformedException then at least the values will be
        // visible to the user to aid correction
        appRes.putValue(SampleResult.DISPLAY_NAME, baseUrl + "," + appletUrlStr);

        // download those applet
        URL appletUrl = new URL(baseUrl, appletUrlStr);

        if(catClass.isDebugEnabled())
        {
          catClass.debug("sample2 : Applet url without baseUrl - " + appletUrlStr);
          catClass.debug("sample2 : Applet url with baseUrl - " + appletUrl);
        }

        appRes.putValue(SampleResult.DISPLAY_NAME, appletUrl.toString());
        appRes.putValue(SampleResult.TEXT_RESPONSE, loadBinary(appletUrl, e, appRes));
        totalTime += appRes.getTime();
      }
      catch(IOException exception)
      {
        catClass.error("sample2 : Error reading from URL - " + exception);
        catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
        appRes.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
        appRes.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
        appRes.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
        appRes.putValue(SampleResult.SUCCESS, new Boolean(false));
      }

      loadBinaryList.add(appRes);
    }

    // use parser to look for input tags with image types as well
    nodeList = html.getElementsByTagName("input");
    for(int i = 0; i < nodeList.getLength(); i++)
    {
      try
      {
        Node tempNode = nodeList.item(i);
        if(catClass.isDebugEnabled())
        {
          catClass.debug("sample2 : Input tags - " + tempNode);
        }

        // get the url of those images
        NamedNodeMap nnm = tempNode.getAttributes();
        Node namedItem = nnm.getNamedItem("type");
        if(namedItem != null)
        {
          String inputType = namedItem.getNodeValue();
          if(catClass.isDebugEnabled())
          {
            catClass.debug("sample2 : Input type - " +
              inputType);
          }

          if(inputType != null &&
            inputType.equalsIgnoreCase("image"))
          {
            imgRes = new SampleResult();
            namedItem = nnm.getNamedItem("src");
            String imgUrlStr = namedItem.getNodeValue();

            // set the baseUrl and imgUrl so that if error occurs
            // due to MalformedException then at least the values
View Full Code Here

   *@param  e  !ToDo (Parameter description)
   *@return    !ToDo (Return description)
   ***********************************************************/
  public SampleResult sample(Entry e)
  {
    SampleResult res = new SampleResult();
    Connection con = null;
    ResultSet rs = null;
    Statement stmt = null;
      boolean isSuccessful = false;
    FtpConfig ftpConfig = (FtpConfig)e.getConfigElement(FtpConfig.class);
      res.putValue(SampleResult.SAMPLE_LABEL,ftpConfig.getLabel());
      LoginConfig loginConfig = (LoginConfig)e.getConfigElement(LoginConfig.class);
    long start = System.currentTimeMillis();
    try
    {
        // removed the next two lines - System.out.println is a resource DOG, and putting this in the middle
        // of a timed operation skews the results big time. -- jkb
//      System.out.println("Connecting to "+ftpConfig.getServer()+" trying to get "+ftpConfig.getFilename());
//      System.out.println("Username = "+loginConfig.getUsername());
      FtpClient ftp = new FtpClient();
      ftp.connect(ftpConfig.getServer(), loginConfig.getUsername(),
          loginConfig.getPassword());
      ftp.setPassive(true); // this should probably come from the setup dialog
      String s = ftp.get(ftpConfig.getFilename());
      res.putValue(SampleResult.TEXT_RESPONSE,s.getBytes());
        // set the response code here somewhere
      ftp.disconnect();
        isSuccessful = true;
      //System.out.println(s);
    }
    catch (java.net.ConnectException cex)
    {
        // java.net.ConnectException -- 502 error code?
        // in the future, possibly define and place error codes into the
        // result so we know exactly what happened.
        res.putValue(SampleResult.TEXT_RESPONSE, cex.toString().getBytes());
    }
      catch (Exception ex) {
        // general exception
        res.putValue(SampleResult.TEXT_RESPONSE, ex.toString().getBytes());
      }

      // Calculate response time
    long end = System.currentTimeMillis();
      res.setTime(end - start);

      // Set if we were successful or not
      res.putValue(SampleResult.SUCCESS, new Boolean(isSuccessful));

    return res;
  }
View Full Code Here

     * Main processing method for the Proxy object
     */
    public void run()
    {
        HttpRequestHdr request = new HttpRequestHdr();
        SampleResult result = null;
        HeaderManager headers = null;

        HTTPSampler sampler = new HTTPSampler();
        try
        {
View Full Code Here

* usage of the TestBean features to podential TestBean developers. Note that only the class's
* introspector view matters: the methods do nothing -- nothing useful, in any case.
*/
public class Example1 extends TestBean implements Sampler {
  public SampleResult sample(Entry e) {
    return new SampleResult();
  }
View Full Code Here

     * @see org.apache.jmeter.samplers.Sampler#sample(org.apache.jmeter.samplers.Entry)
     */
    public SampleResult sample(Entry e)
    {
      trace("sample()");
    SampleResult res = new SampleResult();
    boolean isOK = false; // Did sample succeed?
    String data=getData(); // Sampler data
    String response=null;
   
    res.setSampleLabel(getTitle());
    /*
     * Perform the sampling
     */
    res.sampleStart(); //Start timing
    try {
     
      // Do something here ...
     
      response=Thread.currentThread().getName();
     
      /*
       * Set up the sample result details
       */
      res.setSamplerData(data);
      res.setResponseData(response.getBytes());
      res.setDataType(SampleResult.TEXT);
     
      res.setResponseCode("200");
      res.setResponseMessage("OK");
      isOK = true;
    }
    catch (Exception ex){
      log.debug("",ex);
      res.setResponseCode("500");
      res.setResponseMessage(ex.toString());
    }
    res.sampleEnd(); //End timimg
   
    res.setSuccessful(isOK);

        return res;
    }
View Full Code Here

TOP

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

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.