Автоматизация контроллера пропускной способности в тесте JMeter?

Я работаю над проектом, в котором мне нужно автоматизировать тест JMeter в качестве серверной службы. Мой план тестирования такой

Thread Group
 -Throughput Controller1
       --sampler1

 -Throughput controller2
       --sampler2

Один из моих примеров реализации пропускной способности выглядит так. Здесь я сначала устанавливаю количество потоков равным 10, затем я хочу контролировать его до количества потоков 3 и других 7 для другого сэмплера.

TestPlan testPlan = new TestPlan();
testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());

SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setRampUp(1);
threadGroup.setNumThreads(10);

ThroughputController throughputController = new ThroughputController();
throughputController.setComment("Through Put");
throughputController.setName("Through put");
throughputController.setMaxThroughput(3);
throughputController.setStyle(1);
   :
   :
   :
HTTPSamplerProxy examplecomSampler = loadTestSampler(urlDetails);

ListedHashTree testPlanTree = new ListedHashTree();
HashTree tpConfig = testPlanTree.add(testPlan);
HashTree tgConfig = tpConfig.add(threadGroup);
tgConfig.add(throughputController);
tgConfig.add(examplecomSampler)

Когда я запускаю это, все 10 потоков вызывают examplecomSampler. но я хочу ограничить это до 3, а остальные 7 до другого семплера. Почему так?

Спасибо.


person dasun_001    schedule 22.01.2020    source источник


Ответы (1)


Я не думаю, что ваш способ инициализации контроллера пропускной способности правильный, более того, трудно сказать, что еще не так, не видя полный код вашего класса.

Имейте в виду, что вы должны создавать планы тестирования JMeter, используя GUI JMeter, другие способы официально не поддерживаются, однако вы можете попробовать использовать инструменты-оболочки, такие как Taurus.

Как правило, jmx-скрипты JMeter в основном представляют собой XML-файлы, поэтому вы можете сравнить план тестирования. вы создаете с помощью JMeter API с планом тестирования, полученным из графического интерфейса JMeter, определите различия и измените свой код, чтобы устранить их.


Если вы все еще хотите пойти в этом направлении программного создания скрипта JMeter, пример плана тестирования с 2 контроллерами пропускной способности и 2 семплерами, настроенными на 30% и 70% выполнения соответственно, будет выглядеть примерно так:

HashTree testPlanTree = new HashTree();

HTTPSamplerProxy examplecomSampler = new HTTPSamplerProxy();
examplecomSampler.setDomain("example.com");
examplecomSampler.setPort(80);
examplecomSampler.setPath("/");
examplecomSampler.setMethod("GET");
examplecomSampler.setName("Open example.com");
examplecomSampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
examplecomSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

HTTPSamplerProxy blazemetercomSampler = new HTTPSamplerProxy();
blazemetercomSampler.setDomain("blazemeter.com");
blazemetercomSampler.setPort(80);
blazemetercomSampler.setPath("/");
blazemetercomSampler.setMethod("GET");
blazemetercomSampler.setName("Open blazemeter.com");
blazemetercomSampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
blazemetercomSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

LoopController loopController = new LoopController();
loopController.setLoops(1);
loopController.setFirst(true);
loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
loopController.initialize();

ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("Example Thread Group");
threadGroup.setNumThreads(1);
threadGroup.setRampUp(1);
threadGroup.setSamplerController(loopController);
threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());

ThroughputController throughputController3 = new ThroughputController();
throughputController3.setComment("Through Put 3");
throughputController3.setName("Through put 3");
FloatProperty throughput3 = new FloatProperty();
throughput3.setName("ThroughputController.percentThroughput");
throughput3.setValue(30.0f);
throughputController3.setProperty(throughput3);
throughputController3.setProperty("ThroughputController.style", 1);
throughputController3.setProperty("ThroughputController.perThread", false);
throughputController3.setProperty(TestElement.TEST_CLASS, ThroughputController.class.getName());
throughputController3.setProperty(TestElement.GUI_CLASS, ThroughputControllerGui.class.getName());

ThroughputController throughputController7 = new ThroughputController();
throughputController7.setComment("Through Put 7");
throughputController7.setName("Through put 7");
FloatProperty throughput7 = new FloatProperty();
throughput7.setName("ThroughputController.percentThroughput");
throughput7.setValue(70.0f);
throughputController7.setProperty(throughput7);
throughputController7.setProperty("ThroughputController.style", 1);
throughputController7.setProperty("ThroughputController.perThread", false);
throughputController7.setProperty(TestElement.TEST_CLASS, ThroughputController.class.getName());
throughputController7.setProperty(TestElement.GUI_CLASS, ThroughputControllerGui.class.getName());

HashTree logicHashTree = new HashTree();

HashTree throughputController3Tree = new HashTree();
HashTree exampleComHashTree = new HashTree();

exampleComHashTree.add(examplecomSampler);
throughputController3Tree.add(throughputController3);
throughputController3Tree.add(throughputController3, exampleComHashTree);

HashTree throughputController7Tree = new HashTree();
HashTree blazemeterComHashTree = new HashTree();

blazemeterComHashTree.add(blazemetercomSampler);
throughputController7Tree.add(throughputController7);
throughputController7Tree.add(throughputController7, blazemeterComHashTree);


logicHashTree.add(throughputController3Tree);
logicHashTree.add(throughputController7Tree);

TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");
testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());

testPlanTree.add(testPlan);
HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
threadGroupHashTree.add(logicHashTree);

Ознакомьтесь с 5 способами запуска Тест JMeter без использования графического интерфейса JMeter для получения дополнительной информации о различных способах запуска теста JMeter, включая создание теста с нуля с использованием языка Java.

person Dmitri T    schedule 22.01.2020
comment
Согласно вашему фрагменту кода мой код контроллеров ThroughPut неверен. позвольте мне исправить это. Не могли бы вы поделиться ссылками на источники, на которые вы ссылаетесь? - person dasun_001; 22.01.2020
comment
Другая проблема заключается в том, что FlotProperty является абстрактным классом. Так что он не может инициировать вот так - person dasun_001; 22.01.2020
comment
Это не выглядит для меня абстрактным классом, более того, он имеет конструктор. Если вы не слишком знакомы с Java, я бы порекомендовал использовать Taurus для создания сценариев JMeter с использованием простого синтаксиса YAML. - person Dmitri T; 22.01.2020
comment
Я понимаю это. здесь свойство float поставляется вместе с JMeter. так что это не абстракция. Спасибо за помощь, я тоже выполнил задание. - person dasun_001; 23.01.2020