use of org.apache.jmeter.threads.ThreadGroup in project jmeter by apache.
the class AddThinkTimeBetweenEachStep method doAction.
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
if (!(currentNode.getUserObject() instanceof Controller || currentNode.getUserObject() instanceof ThreadGroup)) {
Toolkit.getDefaultToolkit().beep();
return;
}
try {
addThinkTimeToChildren(guiPackage, currentNode);
} catch (Exception err) {
Toolkit.getDefaultToolkit().beep();
log.error("Failed to add think times", err);
JMeterUtils.reportErrorToUser("Failed to add think times", err);
}
}
use of org.apache.jmeter.threads.ThreadGroup in project jmeter by apache.
the class TestTransactionController method testIssue57958.
/**
* @see "http://bz.apache.org/bugzilla/show_bug.cgi?id=57958"
*/
@Test
public void testIssue57958() throws Exception {
JMeterContextService.getContext().setVariables(new JMeterVariables());
TestSampleListener listener = new TestSampleListener();
TransactionController transactionController = new TransactionController();
transactionController.setGenerateParentSample(true);
ResponseAssertion assertion = new ResponseAssertion();
assertion.setTestFieldResponseCode();
assertion.setToEqualsType();
assertion.addTestString("201");
DebugSampler debugSampler = new DebugSampler();
debugSampler.addTestElement(assertion);
LoopController loop = new LoopController();
loop.setLoops(1);
loop.setContinueForever(false);
ListedHashTree hashTree = new ListedHashTree();
hashTree.add(loop);
hashTree.add(loop, transactionController);
hashTree.add(transactionController, debugSampler);
hashTree.add(transactionController, listener);
hashTree.add(debugSampler, assertion);
TestCompiler compiler = new TestCompiler(hashTree);
hashTree.traverse(compiler);
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setNumThreads(1);
ListenerNotifier notifier = new ListenerNotifier();
JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
thread.setThreadGroup(threadGroup);
thread.setOnErrorStopThread(true);
thread.run();
assertEquals("Must one transaction samples with parent debug sample", 1, listener.events.size());
assertEquals("Number of samples in transaction : 1, number of failing samples : 1", listener.events.get(0).getResult().getResponseMessage());
}
use of org.apache.jmeter.threads.ThreadGroup in project jmeter by apache.
the class NonGuiProxySample method main.
public static void main(String[] args) throws IllegalUserActionException, IOException {
// Or wherever you put it.
JMeterUtils.setJMeterHome("./");
JMeterUtils.loadJMeterProperties(JMeterUtils.getJMeterBinDir() + "/jmeter.properties");
JMeterUtils.initLocale();
TestPlan testPlan = new TestPlan();
ThreadGroup threadGroup = new ThreadGroup();
ListedHashTree testPlanTree = new ListedHashTree();
testPlanTree.add(testPlan);
testPlanTree.add(threadGroup, testPlan);
// deliberate use of deprecated ctor
@SuppressWarnings("deprecation") JMeterTreeModel treeModel = new JMeterTreeModel(new Object());
JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
treeModel.addSubTree(testPlanTree, root);
ProxyControl proxy = new ProxyControl();
proxy.setNonGuiTreeModel(treeModel);
proxy.setTarget(treeModel.getNodeOf(threadGroup));
proxy.setPort(8282);
treeModel.addComponent(proxy, (JMeterTreeNode) root.getChildAt(1));
proxy.startProxy();
HttpHost proxyHost = new HttpHost("localhost", 8282);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
CloseableHttpClient httpclient = HttpClients.custom().setRoutePlanner(routePlanner).build();
try {
httpclient.execute(new HttpGet("http://example.invalid"));
} catch (Exception e) {
//
}
proxy.stopProxy();
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
SaveService.saveTree(treeModel.getTestPlan(), out);
out.close();
System.out.println(out.toString());
}
}
use of org.apache.jmeter.threads.ThreadGroup in project jmeter by apache.
the class TreeClonerForValidation method addNodeToTree.
/**
* @see org.apache.jmeter.engine.TreeCloner#addNodeToTree(java.lang.Object)
*/
@Override
protected Object addNodeToTree(Object node) {
if ((VALIDATION_IGNORE_TIMERS && node instanceof Timer) || (VALIDATION_IGNORE_BACKENDS && node instanceof Backend)) {
// don't add timer or backend
return node;
} else {
Object clonedNode = super.addNodeToTree(node);
if (clonedNode instanceof org.apache.jmeter.threads.ThreadGroup) {
ThreadGroup tg = (ThreadGroup) clonedNode;
tg.setNumThreads(VALIDATION_NUMBER_OF_THREADS);
tg.setScheduler(false);
tg.setProperty(ThreadGroup.DELAY, 0);
if (((AbstractThreadGroup) clonedNode).getSamplerController() instanceof LoopController) {
((LoopController) ((AbstractThreadGroup) clonedNode).getSamplerController()).setLoops(VALIDATION_ITERATIONS);
}
}
return clonedNode;
}
}
use of org.apache.jmeter.threads.ThreadGroup in project jmeter by apache.
the class ThreadGroupGui method createTestElement.
@Override
public TestElement createTestElement() {
ThreadGroup tg = new ThreadGroup();
modifyTestElement(tg);
return tg;
}
Aggregations