我创建了一个扩展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;
}
}
答案 0 :(得分:0)
你的班级很奇怪,你确定它会编译吗?
需要:
员工
EmployeeAgeComprator
因此,您必须首先确保它编译,然后将所有这些依赖项打包在JAR中。如果有任何其他依赖项将它们放在jmeter / lib文件夹中。