本文整理汇总了Java中org.apache.jmeter.engine.StandardJMeterEngine类的典型用法代码示例。如果您正苦于以下问题:Java StandardJMeterEngine类的具体用法?Java StandardJMeterEngine怎么用?Java StandardJMeterEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardJMeterEngine类属于org.apache.jmeter.engine包,在下文中一共展示了StandardJMeterEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
public void start() {
log.debug("Start debugging");
frontend.started();
HashTree hashTree = getSelectedTree();
StandardJMeterEngine.register(new StateListener()); // oh, dear, they use static field then clean it...
engine = new DebuggerEngine(JMeterContextService.getContext());
engine.setStepper(this);
JMeter.convertSubTree(hashTree);
engine.configure(hashTree);
try {
engine.runTest();
} catch (JMeterEngineException e) {
log.error("Failed to pauseContinue debug", e);
stop();
}
}
示例2: loadControl1
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
@Test
public void loadControl1() throws Exception {
log.info("start loadControl1()");
// Initialize Properties, logging, locale, etc.
JMeterUtils.loadJMeterProperties(JMETER_HOME + "/bin/jmeter.properties");
JMeterUtils.setJMeterHome(JMETER_HOME);
JMeterUtils.initLocale();
// Initialize JMeter SaveService
SaveService.loadProperties();
// Load existing .jmx Test Plan
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("tutorial/jmeter/Tutorial6.jmx");
File file = new File(url.toURI());
HashTree testPlanTree = SaveService.loadTree(file);
// Run JMeter Test
StandardJMeterEngine jmeter = new StandardJMeterEngine();
jmeter.configure(testPlanTree);
jmeter.run();
}
示例3: runRealEngine
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
@Test
public void runRealEngine() throws Exception {
TestTreeProvider prov = new TestProvider();
HashTree hashTree = prov.getTestTree();
JMeter.convertSubTree(hashTree);
StandardJMeterEngine engine = new StandardJMeterEngine();
engine.configure(hashTree);
engine.runTest();
while (engine.isActive()) {
Thread.sleep(1000);
}
}
示例4: startEngine
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
/**
* Start JMeter engine
* @param noTimer ignore timers
*/
private void startEngine(boolean ignoreTimer) {
GuiPackage gui = GuiPackage.getInstance();
HashTree testTree = gui.getTreeModel().getTestPlan();
JMeter.convertSubTree(testTree);
testTree.add(testTree.getArray()[0], gui.getMainFrame());
log.debug("test plan before cloning is running version: "
+ ((TestPlan) testTree.getArray()[0]).isRunningVersion());
TreeCloner cloner = cloneTree(testTree, ignoreTimer);
engine = new StandardJMeterEngine();
engine.configure(cloner.getClonedTree());
try {
engine.runTest();
} catch (JMeterEngineException e) {
JOptionPane.showMessageDialog(gui.getMainFrame(), e.getMessage(),
JMeterUtils.getResString("error_occurred"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
}
log.debug("test plan after cloning and running test is running version: "
+ ((TestPlan) testTree.getArray()[0]).isRunningVersion());
}
示例5: makeThread
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
private DebuggingThread makeThread(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine, int i, JMeterContext context) {
// had to copy whole method because of this line
DebuggingThread jmeterThread = new DebuggingThread(threadGroupTree, this, notifier, context);
boolean onErrorStopTest = getOnErrorStopTest();
boolean onErrorStopTestNow = getOnErrorStopTestNow();
boolean onErrorStopThread = getOnErrorStopThread();
boolean onErrorStartNextLoop = getOnErrorStartNextLoop();
String groupName = getName();
jmeterThread.setThreadNum(i);
jmeterThread.setThreadGroup(this);
jmeterThread.setInitialContext(context);
String threadName = groupName + " " + (groupCount) + "-" + (i + 1);
jmeterThread.setThreadName(threadName);
jmeterThread.setEngine(engine);
jmeterThread.setOnErrorStopTest(onErrorStopTest);
jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
jmeterThread.setOnErrorStopThread(onErrorStopThread);
jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
return jmeterThread;
}
示例6: makeThread
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
private JMeterThread makeThread(int groupCount,
ListenerNotifier notifier, ListedHashTree threadGroupTree,
StandardJMeterEngine engine, int i,
JMeterContext context) { // N.B. Context needs to be fetched in the correct thread
boolean onErrorStopTest = getOnErrorStopTest();
boolean onErrorStopTestNow = getOnErrorStopTestNow();
boolean onErrorStopThread = getOnErrorStopThread();
boolean onErrorStartNextLoop = getOnErrorStartNextLoop();
String groupName = getName();
final JMeterThread jmeterThread = new JMeterThread(cloneTree(threadGroupTree), this, notifier);
jmeterThread.setThreadNum(i);
jmeterThread.setThreadGroup(this);
jmeterThread.setInitialContext(context);
final String threadName = groupName + " " + (groupCount) + "-" + (i + 1);
jmeterThread.setThreadName(threadName);
jmeterThread.setEngine(engine);
jmeterThread.setOnErrorStopTest(onErrorStopTest);
jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
jmeterThread.setOnErrorStopThread(onErrorStopThread);
jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
return jmeterThread;
}
示例7: executeMe
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
private JMeterResult executeMe() throws AutomationFrameworkException {
try {
addLogFile(testFile.getName());
} catch (IOException e) {
throw new AutomationFrameworkException("Can't add log file " + e.getMessage(), e);
}
Boolean resultState = true;
JMeterResult results;
String resultFile = executeTest(testFile);
try {
// Force shutdown
StandardJMeterEngine.stopEngineNow();
ShutdownClient.main(new String[]{"Shutdown"});
} catch (IOException ex) {
log.error(ex);
resultState = false;
}
results = resultValidator(resultFile);
results.setFileName(resultFile);
results.setExecutionState(resultState);
return results;
}
示例8: setupClass
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
@BeforeAll
static void setupClass() throws IOException {
jmeter = new StandardJMeterEngine();
//JMeter initialization (properties, log levels, locale, etc)
JMeterUtils.setJMeterHome("src/test/resources/");
JMeterUtils.loadJMeterProperties("src/test/resources/jmeter.properties");
JMeterUtils.initLocale();
}
示例9: handleSampleResults
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
@Override
public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
if (isInterruptedThroughUI) {
return;
}
accumulator.addAll(list);
JSONObject data = JSONConverter.convertToJSON(accumulator, list);
int counter = 0;
while (!apiClient.isTestStarted() && counter < 3) {
log.debug("Waiting for test starting");
makeDelay();
counter++;
}
try {
apiClient.sendOnlineData(data);
} catch (JMeterStopTestException ex) {
isInterruptedThroughUI = true;
StandardJMeterEngine.stopEngineNow();
} catch (IOException e) {
log.warn("Failed to send data: " + data, e);
}
makeDelay();
}
示例10: main
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
public static void main(String[] args) {
//JMeter Engine
StandardJMeterEngine jmeter = new StandardJMeterEngine();
//JMeter initialization (properties, log levels, locale, etc)
JMeterUtils.loadJMeterProperties("/path/to/your/jmeter/bin/jmeter.properties");
JMeterUtils.setLocale(Locale.ENGLISH);
// ??? 啥用
JMeterUtils.setJMeterHome("");
JMeterUtils.initLocale();
// JMeter Test Plan, basic all u JOrphan HashTree
HashTree testPlanTree = new HashTree();
// Java Sampler
JavaSampler javaSampler = new JavaSampler();
javaSampler.setClassname("这里设置要运行的case主类");
javaSampler.setName("");
javaSampler.setComment("这个采集器的描述信息");
// Loop Controller
LoopController loopController = new LoopController();
// 循环次数
loopController.setLoops(1);
loopController.addTestElement(javaSampler);
loopController.setFirst(true);
loopController.initialize();
// Thread Group
org.apache.jmeter.threads.ThreadGroup threadGroup = new org.apache.jmeter.threads.ThreadGroup();
// 设置线程数
threadGroup.setNumThreads(1);
//
threadGroup.setRampUp(1);
threadGroup.setSamplerController(loopController);
// Test Plan
TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");
// Construct Test Plan from previously initialized elements
testPlanTree.add("testPlan", testPlan);
testPlanTree.add("loopController", loopController);
testPlanTree.add("threadGroup", threadGroup);
testPlanTree.add("javaSampler", javaSampler);
// Run Test Plan
jmeter.configure(testPlanTree);
jmeter.run();
}
示例11: start
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
@Override
public void start(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
JMeterContext context = JMeterContextService.getContext();
DebuggingThread jmThread = makeThread(groupCount, notifier, threadGroupTree, engine, 0, context);
Thread newThread = new Thread(jmThread, jmThread.getThreadName());
if (engine instanceof DebuggerEngine) {
DebuggerEngine dbgEngine = (DebuggerEngine) engine;
dbgEngine.setTarget(jmThread);
dbgEngine.setThread(newThread);
this.jmeterThread = jmThread;
this.osThread = newThread;
}
newThread.start();
}
示例12: getHook
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
protected StepTrigger getHook() {
StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
if (engine instanceof DebuggerEngine) {
return ((DebuggerEngine) engine).getStepper();
}
throw new IllegalStateException();
}
示例13: start
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
@Override
public void start(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
running = true;
int numThreads = getNumThreads();
int rampUpPeriodInSeconds = getRampUp();
float perThreadDelayInMillis = ((float) (rampUpPeriodInSeconds * 1000) / (float) getNumThreads());
delayedStartup = isDelayedStartup(); // Fetch once; needs to stay constant
log.info("Starting thread group number " + groupCount
+ " threads " + numThreads
+ " ramp-up " + rampUpPeriodInSeconds
+ " perThread " + perThreadDelayInMillis
+ " delayedStart=" + delayedStartup);
if (delayedStartup) {
threadStarter = new Thread(new ThreadStarter(groupCount, notifier, threadGroupTree, engine), getName()+"-ThreadStarter");
threadStarter.setDaemon(true);
threadStarter.start();
// N.B. we don't wait for the thread to complete, as that would prevent parallel TGs
} else {
long now = System.currentTimeMillis(); // needs to be same time for all threads in the group
final JMeterContext context = JMeterContextService.getContext();
for (int i = 0; running && i < numThreads; i++) {
JMeterThread jmThread = makeThread(groupCount, notifier, threadGroupTree, engine, i, context);
scheduleThread(jmThread, now); // set start and end time
jmThread.setInitialDelay((int)(i * perThreadDelayInMillis));
Thread newThread = new Thread(jmThread, jmThread.getThreadName());
registerStartedThread(jmThread, newThread);
newThread.start();
}
}
log.info("Started thread group number "+groupCount);
}
示例14: ThreadStarter
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
public ThreadStarter(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
super();
this.groupCount = groupCount;
this.notifier = notifier;
this.threadGroupTree = threadGroupTree;
this.engine = engine;
// Store context from Root Thread to pass it to created threads
this.context = JMeterContextService.getContext();
}
示例15: JMeterRunner
import org.apache.jmeter.engine.StandardJMeterEngine; //导入依赖的package包/类
public JMeterRunner(String testPlanName, String jmeterResourceDir) {
this.jmeterResourceDir = jmeterResourceDir;
jmeter = new StandardJMeterEngine();
JMeterUtils.setJMeterHome(jmeterResourceDir);
readProperties();
JMeterUtils.initLogging();
JMeterUtils.initLocale();
testPlanTree = new ListedHashTree();
this.testPlanName = testPlanName;
this.testPlanFileName = testPlanName.toLowerCase().replaceAll("\\s+", "-");
createTestPlan();
}