0

我创建了一个扩展 AbstractJavaSamplerClient 的简单 Java 类。我也覆盖了它的runTest()方法。然后我创建了一个 jar 文件并将其粘贴到JMETER_HOME/lib/ext文件夹中。但是当我为 Java 请求创建测试计划时,我的类没有被填充到类名下拉列表中。请帮助我摆脱这个问题。

下面是代码示例:

/**
 * 
 */
package com.solar.dcp.client;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;

/**
 * @author dushyant.kumar.sahu
 * 
 */
@SuppressWarnings("serial")
public class BaseJavaSamplerClient extends AbstractJavaSamplerClient implements Serializable {

    /**
     * 
     */
    public BaseJavaSamplerClient() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     */
    private void simulateTest() {
        // TODO Auto-generated method stub
        List<Employee> employees = new ArrayList<Employee>();

        Employee emp1 = new Employee(34, "ShashiBhushan", 50000, 10475688);
        Employee emp2 = new Employee(29, "Anantha", 35000, 10765688);
        Employee emp3 = new Employee(32, "Nilesh", 60000, 10423688);
        Employee emp4 = new Employee(30, "Abhimanyu", 250000, 10983688);

        employees.add(emp1);
        employees.add(emp2);
        employees.add(emp3);
        employees.add(emp4);

        Collections.sort(employees, new EmployeeAgeComprator());
        System.out.println(
            "==============Sorting Employees by Age===============");

        for (Employee emp : employees) {
            System.out.println(emp.getName() + " : " + emp.getAge());
        }

        System.out.println("\n\n");

        System.out.println(
            "==============Sorting Employees by Name===============");

        Collections.sort(employees, new EmployeeNameComprator());

        for (Employee emp : employees) {
            System.out.println(emp.getName());
        }
    }

    @Override
    public SampleResult runTest(JavaSamplerContext arg0) {
        // TODO Auto-generated method stub
        SampleResult result = new SampleResult();

        try {

            result.sampleStart();
            System.out.println("Start the sample test");
            simulateTest();
            result.setSuccessful(true);

        } catch (Exception ex) {
            ex.printStackTrace();
            result.setSuccessful(false);
        } finally {
            result.sampleEnd();
        }

        return result;

    }

}
4

1 回答 1

0

你的课很奇怪,你确定它可以编译吗?

这个需要:

  • 员工

  • EmployeeAgeComprator

因此,您必须首先确保它可以编译,然后将所有这些依赖项打包到 JAR 中。如果有任何其他依赖项将它们放在 jmeter/lib 文件夹中。

于 2013-07-13T13:53:02.557 回答