在Jmeter中执行Java时出现异常

时间:2014-06-17 21:05:08

标签: java performance jmeter jmeter-plugins

我试图在我的Jmeter性能中执行用Java编写的预处理器,但是这样做时我可以得到以下异常 我按照以下http://heshans.blogspot.com/2014/03/fixing-javalangclassnotfoundexception.html

中的步骤操作
java.io.FileNotFoundException: ./BSFJava4.class (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at org.apache.bsf.util.BSFClassLoader.loadClassData(BSFClassLoader.java:65)
at org.apache.bsf.util.BSFClassLoader.loadClass(BSFClassLoader.java:50)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.bsf.util.EngineUtils.loadClass(EngineUtils.java:372)
at org.apache.bsf.engines.java.JavaEngine.eval(JavaEngine.java:241)
at org.apache.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java:141)
at org.apache.jmeter.util.BSFTestElement.processFileOrScript(BSFTestElement.java:101)
at org.apache.jmeter.modifiers.BSFPreProcessor.process(BSFPreProcessor.java:41)
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:749)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:413)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
at java.lang.Thread.run(Thread.java:745) 

unable to load class 'BSFJava4':java.lang.ClassNotFoundException: BSFJava4: java.lang.ClassNotFoundException: BSFJava4
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

这是我的代码

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SplitRequestLogs
{

public static void main(String[] args)
{

    class Group
    {
        String fileName;
        List<String> urls = new ArrayList<String>();
        Group(String fileName)
        {
            this.fileName = fileName;
        }
    }

    Map<Set<String>, Group> params = new HashMap<Set<String>, Group>();

    params.put(new HashSet<String>(Arrays.asList(new String[] { "lat", "lng", "radius" })), new Group("6_params_40.csv"));
    params.put(new HashSet<String>(Arrays.asList(new String[] { "lat", "lng", "radius", "page_number", "items_per_page" })), new Group("5_params_17.csv"));
    params.put(new HashSet<String>(Arrays.asList(new String[] { "lat", "lng", "radius", "page_number", "items_per_page", "eligibility_cc", "quality_filter" })), new Group("7_params_17.csv"));

    try
    {

        File dir = new File("/Users/akushe/POINT_SRC_CODE/places/perftest/jmeter/v3");
        File out_dir = new File("/Users/akushe/POINT_SRC_CODE/places/perftest/jmeter/v3/files");

        BufferedReader br = new BufferedReader(new FileReader(new File(dir, "allRequests.log")));
        String s = null;
        while ((s = br.readLine()) != null)
        {
            URI url = new URI(s);
            Set<String> paramVal;
            if (url.getQuery() != null && !url.getQuery().isEmpty())
            {
                paramVal = new HashSet<String>

(Arrays.asList(url.getQuery().split("&")));
            }
            else
            {
                paramVal = new HashSet<String>(Arrays.asList(url.getPath()));
            }
            for (Set<String> paramsSet : params.keySet())
            {
                if (paramVal.size() == paramsSet.size())
                {
                    boolean found = true;

                    for (String param : paramsSet)
                    {
                        if (!s.contains(param))
                        {
                            found = false;
                            break;
                        }
                    }

                    if (found)
                    {
                        params.get(paramsSet).urls.add(s);
                        break;
                    }

                }
            }

        }
        br.close();

        for (Group group : params.values())
        {
            List<String> urls = group.urls;

            PrintWriter pw = new PrintWriter(out_dir.getCanonicalPath() + "/" + group.fileName);

            for (String url : urls)
            {
                pw.println(url);
            }

            pw.close();
        }
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (URISyntaxException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

0 个答案:

没有答案