私はJavaコードからJMeterテストを示すクラスを持っています。JavaコードからJMeter - 私のテストにConstantThroughputTimerを追加するには
テストの目的は、毎秒N要求を設定することです。
JMeterが作成している最大RPS(要求数/秒)を設定するために、ConstantThroughputTimerをテストに追加します。
guiとそのうまくいく作業の中で作成されましたが、私はJavaコードから実行したいと思います。私は永遠にスレッドグループ「ループ回数」を設定する方法がわからない
- :
は、今私は2つの問題を持っています。 (スクリーンショットを参照)
- ConstantThroughputTimerをテストプランに追加できませんでした。
私は検索しましたが、それについてのドキュメントもコード例も見つかりませんでした。
ご協力いただければ幸いです。
マイコード:
public static void main(String[] args) {
StandardJMeterEngine jMeterEngine = new StandardJMeterEngine();
//Setting JMeter Properties
File properties = JmeterUtils.getPropertiesFile();
File home = JmeterUtils.getHomePath();
JMeterUtils.setJMeterHome(home.getPath());
JMeterUtils.loadJMeterProperties(properties.getPath());
JMeterUtils.initLocale();
//Creating HashTreeTestPlan
HashTree testPlanTree = new HashTree();
//Creating HttpSampler
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
sampler.setMethod("GET");
sampler.setDomain("example.com");
sampler.setUseKeepAlive(true);
sampler.setFollowRedirects(true);
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
sampler.setEnabled(true);
//Creating LoopController
LoopController loopController = new LoopController();
loopController.setContinueForever(true);
loopController.setLoops(10000);
loopController.setFirst(true);
loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
loopController.initialize();
loopController.setEnabled(true);
//Creating the number of Threads (clients)
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("threadGroup");
threadGroup.setNumThreads(10);
threadGroup.setScheduler(true);
threadGroup.setRampUp(0);
threadGroup.setDuration(60);
threadGroup.setSamplerController(loopController);
threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());
threadGroup.setEnabled(true);
//Adding Constant Throughput Timer - This is what i want to add
ConstantThroughputTimer timer = new ConstantThroughputTimer();
timer.setProperty(TestElement.TEST_CLASS, ConstantThroughputTimer.class.getName());
timer.setName("constantTimer");
double rpsCalc = 10 * 60;
timer.setThroughput(rpsCalc);
timer.setEnabled(true);
timer.setCalcMode(2);
//NOT WORKING//
//NOT WORKING//
threadGroup.addTestElement(timer);
//Test Plan
TestPlan testPlan = new TestPlan("Test Plan");
testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());
// Construct Test Plan from previously initialized elements
testPlanTree.add(testPlan);
jMeterEngine.configure(testPlanTree);
try {
jMeterEngine.runTest();
} catch (JMeterEngineException e) {
e.printStackTrace();
}
}
「//動作していない//」とはどのように正確ですか?それはコンパイルしましたか?ランタイムエラーが発生しますか?何が起こっている? –
申し訳ありません。テストは実行中だが、タイマーなしであることを忘れた - 要求が行われ、rpsがタイマーに設定されたものよりもはるかに大きいことを意味する。 – razrog
私は基本的にあなたのシステムアンダーテストを全く確信していない。ループコントローラをスレッドグループに追加したのが分かりますが、サンプラをループコントローラに追加した瞬間を見つけることはできません。あなたのスレッドグループをテストプランに追加する瞬間もそうです。ここに表示されているコードと、実行しようとしているコードとは異なっていますか? –