Package org.apache.jmeter.samplers

Examples of org.apache.jmeter.samplers.SampleResult


         static final String TEST_PATTERN = ".*A.*\\.";
         public void run()
         {
            ResponseAssertion assertion =
               new ResponseAssertion(RESPONSE_DATA, CONTAINS, TEST_PATTERN);
            SampleResult response = new SampleResult();
            response.setResponseData(TEST_STRING.getBytes());
            for (int i = 0; i < 100; i++)
            {
               AssertionResult result;
               result = assertion.evaluateResponse(response);
               if (result.isFailure() || result.isError())
View Full Code Here


        {
          jmctx = JMeterContextService.getContext();
            extractor = new RegexExtractor();
            extractor.setThreadContext(jmctx);// This would be done by the run command
            extractor.setRefName("regVal");
            result = new SampleResult();
            String data =
                "<company-xmlext-query-ret>" +
                  "<row>" +
                    "<value field=\"RetCode\">LIS_OK</value>" +
                    "<value field=\"RetCodeExtension\"></value>" +
View Full Code Here

        }

        private SampleResult sample(String label, long start,
                long elapsed, boolean ok)
        {
            SampleResult res = SampleResult.createTestSample(start, start+elapsed);

            res.setSampleLabel(label);
            res.setSuccessful(ok);
            assertEquals(elapsed,res.getTime());
            return res;
        }
View Full Code Here

    Sampler returnValue = null;
      if (isFirst()) // must be the start of the subtree
      {
        log_debug("+++++++++++++++++++++++++++++");
        calls = 0;
        res = new SampleResult();
        res.sampleStart();
      }
     
      calls++;
     
View Full Code Here

        int leafIndex = 0;

        for (int i = 0; i < subResults.length; i++)
        {
            SampleResult child = subResults[i];

            if (log.isDebugEnabled())
            {
                log.debug("updateGui1 : child sample result - " + child);
            }
View Full Code Here

            statsDoc.remove(0, statsDoc.getLength());
      sampleDataField.setText("");
      results.setText("");
            if (node != null)
            {
                SampleResult res = (SampleResult) node.getUserObject();

                if (log.isDebugEnabled())
                {
                    log.debug("valueChanged1 : sample result - " + res);
                }

                if (res != null)
                {
                    // load time label

                    log.debug("valueChanged1 : load time - " + res.getTime());
                    if (res != null && res.getSamplerData() != null)
                    {
                      String sd;
                      String rh = res.getRequestHeaders();
                      if (rh==null)
                      {
                        sd=res.getSamplerData().trim();
                      } else {
              sd=res.getSamplerData().trim()
                 +"\n"+rh;
                      }
                        sampleDataField.setText(sd);
                    }

                    statsDoc.insertString(
                        statsDoc.getLength(),
                        "Load time: " + res.getTime() + "\n",
                        null);

                    String responseCode = res.getResponseCode();
                    log.debug(
                        "valueChanged1 : response code - " + responseCode);

                    int responseLevel = 0;
                    if (responseCode != null)
                    {
                        try
                        {
                            responseLevel =
                                Integer.parseInt(responseCode) / 100;
                        }
                        catch (NumberFormatException numberFormatException)
                        {
                            // no need to change the foreground color
                        }
                    }

                    Style style = null;
                    switch (responseLevel)
                    {
                        case 3 :
                            style = statsDoc.getStyle("Redirect");
                            break;
                        case 4 :
                            style = statsDoc.getStyle("ClientError");
                            break;
                        case 5 :
                            style = statsDoc.getStyle("ServerError");
                            break;
                    }
                    statsDoc.insertString(
                        statsDoc.getLength(),
                        "HTTP response code: " + responseCode + "\n",
                        style);

                    // response message label
                    String responseMsgStr = res.getResponseMessage();

                    log.debug(
                        "valueChanged1 : response message - " + responseMsgStr);
                    statsDoc.insertString(
                        statsDoc.getLength(),
                        "HTTP response message: " + responseMsgStr + "\n",
                        null);

          statsDoc.insertString(
            statsDoc.getLength(),
            "\nHTTP response headers:\n" + res.getResponseHeaders() + "\n",
            null);

          // get the text response and image icon
                    // to determine which is NOT null
                    if ((SampleResult.TEXT).equals(res.getDataType())) // equals(null) is OK
                    {
                      String response = getResponseAsString(res);
                      if (textMode)
                      {
                          showTextResponse(response);
                      }
                      else
                      {
                          showRenderedResponse(response,res);
                      }
                    }
                    else
                    {
                      byte[] responseBytes = res.getResponseData();
                      if (responseBytes != null)
                      {
                        showImage(new ImageIcon(responseBytes))
                      }
                    }
View Full Code Here

            {
                results.setText("");
                return;
            }

            SampleResult res = (SampleResult) node.getUserObject();
            String response = getResponseAsString(res);
            if (textMode)
            {
                showTextResponse(response);
            }
View Full Code Here

        add(mainSplit, BorderLayout.CENTER);
    }

    private Component createLeftPanel()
    {
        SampleResult rootSampleResult = new SampleResult();
        rootSampleResult.setSampleLabel("Root");
        rootSampleResult.setSuccessful(true);
        root = new DefaultMutableTreeNode(rootSampleResult);

        treeModel = new DefaultTreeModel(root);
        jTree = new JTree(treeModel);
        jTree.setCellRenderer(new ResultsNodeRenderer());
View Full Code Here

    Object remoteInterface = null;
    Object results = null;
    Object ref = null;
   
    SampleResult res = new SampleResult();
    SampleResult contextLookupRes = new SampleResult();
    contextLookupRes.putValue(SampleResult.DISPLAY_NAME, "Context Lookup");
    SampleResult lookupRes = new SampleResult();
    SampleResult homeMethodRes = null;
    SampleResult remoteMethodRes = null;
    Hashtable ht = new Hashtable();
    JndiConfig jndiConfig = null;
    InitialContext ctx = null;
    try
    {
      jndiConfig = (JndiConfig)e.getConfigElement(JndiConfig.class);
      // check if InitialContext is already obtained previously
      ctx = jndiConfig.getInitialContext();
      if(ctx == null)
      {
        // setup the hashtable
        for(int i = 0 ; i < JndiConfig.JNDI_PROPS.length; i++)
        {
          String value = jndiConfig.getValue(i);
          if(value != null)
          {
            if(log.isDebugEnabled())
            {
              log.debug("sample1 : JNDI env - " +
    JndiConfig.JNDI_PROPS[i] + " = " + value);
            }
            ht.put(JndiConfig.JNDI_PROPS[i], value);
          }
        }
        // initialize initial context
        start = System.currentTimeMillis();
        ctx = new InitialContext(ht);
        end = System.currentTimeMillis();
        log.info("sample1 : Got initial context");
        // store the initial context for reuse
        jndiConfig.setInitialContext(ctx);
      }
      // set the initial context lookup time
      ctxTime = end - start;
      contextLookupRes.setTime(ctxTime);

      // look up the name
      LookupConfig lookupConfig =
    (LookupConfig)e.getConfigElement(LookupConfig.class);
      String lookupName = null;
      if(lookupConfig != null)
      {
        lookupName = lookupConfig.getLookupName();
        if(log.isDebugEnabled())
        {
          log.debug("sample1 : LookupName - " + lookupName);
        }
        start = System.currentTimeMillis();
        ref = ctx.lookup(lookupName);
        end = System.currentTimeMillis();
        lookupTime = end - start;
        log.info("Got remote interface");
        lookupRes.setTime(lookupTime);
        lookupRes.putValue(SampleResult.DISPLAY_NAME,
    "Remote Interface Lookup - " + lookupName);
      }
      Class lookupNameClass = ref.getClass();
      // lookup method name
      MethodConfig methodConfig =
    (MethodConfig)e.getConfigElement(MethodConfig.class);
      // store all reflections result in the model of the gui and not the
      // MethodConfig obtained from getConfigElement() 'cos that's the clone.
      // To get the model of the MethodConfigGui, get the MethodConfigGui
      // from the MethodConfig clone first.  All MethodConfig clones cloned
      // from the same MethodConfig shares the same MethodConfigGui.
      MethodConfigGui methodConfigGui =  methodConfig.getGui();
      MethodConfig model = methodConfigGui.getModel();
      // Make all changes on the model of the gui and not the MethodConfig
      // obtained from getConfigElement() because that is the clone.
      int state = model.getState();
      reflectionStatus = model.getReflectionStatus();
      String[] strings = null;
      if(log.isDebugEnabled())
      {
        log.debug("sample1 : state - " + state);
        log.debug("sample1 : reflectionStatus - " + reflectionStatus);
      }
      // Perform only if :
      // 1. doing a reflection and in this state
      // 2. sampling does not perform this step
      if((state == MethodConfig.METHOD_GET_HOME_NAMES && reflectionStatus
  && !stateJustChanged))
//  || (state >= MethodConfig.METHOD_GET_HOME_NAMES && !reflectionStatus))
      {
        // for this state, get the list of all methods in the home
        // interface
        Method[] methods = lookupNameClass.getMethods();
        strings = new String[methods.length];
        for(int i = 0; i < methods.length; i++)
        {
          // create method name which includes method signatures
          strings[i] = getMethodSignature(methods[i]);
        }
        model.setMethodHomeList(strings);
        model.setState(MethodConfig.METHOD_GET_HOME_PARMS);
        stateJustChanged = true;
      }
      // Perform only if :
      // 1. doing a reflection and in this state
      // 2. sampling does not perform this step
      if((state == MethodConfig.METHOD_GET_HOME_PARMS && reflectionStatus
  && !stateJustChanged))
//  || (state >= MethodConfig.METHOD_GET_HOME_PARMS && !reflectionStatus))
      {
        // for this state, get all the required parms for the selected
        // method
        String methodHomeName = methodConfig.getMethodHomeName();
        if(log.isDebugEnabled())
        {
          log.debug("sample1 : selected methodHomeName - " +
    methodHomeName);
        }
        Vector returnValues =
    getMethodParmsTypes(methodHomeName, lookupNameClass);
        // the first object of returnValues will be the Method while the
        // the second object will be the parm types of Method
        Method method = (Method)returnValues.get(0);
        Class[] methodParmTypes = (Class[])returnValues.get(1);
        // once the method is obtained store the parms
        model.setMethodHomeParms(methodParmTypes);
        model.setHomeMethod(method);
        model.setState(MethodConfig.METHOD_INVOKE_HOME);
        stateJustChanged = true;
      }
      // Perform only if :
      // 1. doing a reflection and in this state
      // 2. sampling and reflection has been done at least this state
      //    if reflection has not been done till this state then user is not
      //    interested in sampling till this state
      if((state == MethodConfig.METHOD_INVOKE_HOME && reflectionStatus
  && !stateJustChanged)
  || (state >= MethodConfig.METHOD_INVOKE_HOME && !reflectionStatus))
      {
        log.debug("sample1 : METHOD_INVOKE_HOME");
        Method method = model.getHomeMethod();
        if(log.isDebugEnabled())
        {
          log.debug("sample1 : home method to be invoked - " + method);
        }
        // only initialize homeMethodRes if method execution is to be measured
        homeMethodRes = new SampleResult();
        // gather all parms from MethodConfigGui
        Object[] parmsArray = null;
        try
        {
          parmsArray = methodConfigGui.getMethodParmsValues(
    MethodConfig.METHOD_INVOKE_HOME);
          if(log.isDebugEnabled())
          {
            log.debug("sample1 : home method parms - " + parmsArray);
          }
          // invoke the method
          start = System.currentTimeMillis();
          remoteInterface = method.invoke(ref, parmsArray);
      log.info("return - " + remoteInterface);
        }
        catch(IllegalAccessException err)
        {
          log.error(err);
        }
        catch(InvocationTargetException err)
        {
          log.error(err);
        }
        catch(MethodConfigUserObjectException err)
        {
          log.error(err);
        }
        end = System.currentTimeMillis();
        if(!reflectionStatus)
        {
          // if sampling then get the time lapsed
          homeMethodTime = end - start;
          homeMethodRes.setTime(homeMethodTime);
          homeMethodRes.putValue(SampleResult.DISPLAY_NAME, "Home Method Execution - "
                + method.getName());
          homeMethodRes.putValue(SampleResult.SUCCESS, Boolean.TRUE);
        }
        else
        {
          // if reflection then get all the info required
          model.setState(MethodConfig.METHOD_GET_REMOTE_NAMES);
          stateJustChanged = true;
          // store list of remote interfaces returned
          model.setRemoteInterfaceList(remoteInterface);
        }
      }
      // Perform only if :
      // 1. doing a reflection and in this state
      // 2. sampling does NOT perform this step
      if((state == MethodConfig.METHOD_GET_REMOTE_NAMES && reflectionStatus
  && !stateJustChanged))
//  || (state >= MethodConfig.METHOD_GET_REMOTE_NAMES && !reflectionStatus))
      {
        // for this state, get the list of all methods in the remote
        // interface
        remoteInterface = model.getRemoteInterfaceType();
        Class remoteInterfaceClass = remoteInterface.getClass();
        if(log.isDebugEnabled())
        {
          log.debug("updateGui1 : remoteInterfaceClass - " +
    remoteInterfaceClass);
        }
        Method[] methods = remoteInterfaceClass.getMethods();
        strings = new String[methods.length];
        for(int i = 0; i < methods.length; i++)
        {
          strings[i] = getMethodSignature(methods[i]);
        }
        model.setMethodRemoteList(strings);
        model.setState(MethodConfig.METHOD_GET_REMOTE_PARMS);
        stateJustChanged = true;
      }
      // Perform only if :
      // 1. doing a reflection and in this state
      // 2. sampling does NOT perform this step
      if((state == MethodConfig.METHOD_GET_REMOTE_PARMS && reflectionStatus
  && !stateJustChanged))
//  || (state >= MethodConfig.METHOD_GET_REMOTE_PARMS && !reflectionStatus))
      {
        // for this state, get all the required parms for the selected
        // method
        String methodRemoteName = methodConfig.getMethodRemoteName();
        if(log.isDebugEnabled())
        {
          log.debug("sample1 : selected methodRemoteName - " +
    methodRemoteName);
        }
        Object selectedRemoteInterfaceType = model.getRemoteInterfaceType();
        Class selectedRemoteInterfaceTypeClass =
    selectedRemoteInterfaceType.getClass();
        Vector returnValues = getMethodParmsTypes(methodRemoteName,
    selectedRemoteInterfaceTypeClass);
        // the first object of returnValues contains the Method while the
        // the second object the parm types of the Method
        Method method = (Method)returnValues.get(0);
        Class[] methodParmTypes = (Class[])returnValues.get(1);
        // once the method is obtained store the parms
        model.setMethodRemoteParms(methodParmTypes);
        model.setRemoteMethod(method);
        model.setState(MethodConfig.METHOD_INVOKE_REMOTE);
        stateJustChanged = true;
      }
      // Perform only if :
      // 1. doing a reflection and in this state
      // 2. sampling and reflection has been done at least this state
      //    if reflection has not been done till this state then user is not
      //    interested in sampling till this state
      if((state == MethodConfig.METHOD_INVOKE_REMOTE && reflectionStatus
  && !stateJustChanged)
  || (state >= MethodConfig.METHOD_INVOKE_REMOTE && !reflectionStatus))
      {
        log.debug("sample1 : METHOD_INVOKE_REMOTE");
        Method method = model.getRemoteMethod();
        if(log.isDebugEnabled())
        {
          log.debug("sample1 : remote method to be invoked - " + method);
        }
        Object selectedRemoteInterfaceType = model.getRemoteInterfaceType();
        // only initialize homeMethodRes if method execution is to be measured
        remoteMethodRes = new SampleResult();
        // gather all parms from MethodConfigGui
        Object[] parmsArray = null;
        try
        {
          parmsArray = methodConfigGui.getMethodParmsValues(
    MethodConfig.METHOD_INVOKE_REMOTE);
          // invoke the method
          start = System.currentTimeMillis();
          results = method.invoke(selectedRemoteInterfaceType, parmsArray);
      log.info("return - " + results);
        }
        catch(IllegalAccessException err)
        {
          log.error(err);
        }
        catch(InvocationTargetException err)
        {
          log.error(err);
        }
        catch(MethodConfigUserObjectException err)
        {
          log.error(err);
        }
        end = System.currentTimeMillis();
        if(!reflectionStatus)
        {
          // if sampling get the time lapse
          remoteMethodTime = end - start;
          remoteMethodRes.setTime(remoteMethodTime);
          remoteMethodRes.putValue(SampleResult.DISPLAY_NAME, "Remote Method Execution - "
                + method.getName());
          String resultsString = results.toString();
          byte[] resultBytes = null;
          if(resultsString != null)
          {
            resultBytes = resultsString.getBytes();
          }
          remoteMethodRes.putValue(SampleResult.TEXT_RESPONSE, resultBytes);
          remoteMethodRes.putValue(SampleResult.SUCCESS, new Boolean(true));
        }
        else
        {
          // if reflection the set state
          model.setState(MethodConfig.METHOD_COMPLETE);
View Full Code Here

    }

    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

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.