Search in sources :

Example 1 with ThreadGroup

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);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) Controller(org.apache.jmeter.control.Controller) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 2 with ThreadGroup

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());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion) DebugSampler(org.apache.jmeter.sampler.DebugSampler) TestCompiler(org.apache.jmeter.threads.TestCompiler) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) JMeterThread(org.apache.jmeter.threads.JMeterThread) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) Test(org.junit.Test)

Example 3 with ThreadGroup

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());
    }
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestPlan(org.apache.jmeter.testelement.TestPlan) HttpGet(org.apache.http.client.methods.HttpGet) DefaultProxyRoutePlanner(org.apache.http.impl.conn.DefaultProxyRoutePlanner) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) HttpHost(org.apache.http.HttpHost) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) ThreadGroup(org.apache.jmeter.threads.ThreadGroup)

Example 4 with ThreadGroup

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;
    }
}
Also used : Backend(org.apache.jmeter.visualizers.backend.Backend) Timer(org.apache.jmeter.timers.Timer) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) LoopController(org.apache.jmeter.control.LoopController)

Example 5 with ThreadGroup

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;
}
Also used : ThreadGroup(org.apache.jmeter.threads.ThreadGroup) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup)

Aggregations

ThreadGroup (org.apache.jmeter.threads.ThreadGroup)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)2 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)2 AbstractThreadGroup (org.apache.jmeter.threads.AbstractThreadGroup)2 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HttpHost (org.apache.http.HttpHost)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultProxyRoutePlanner (org.apache.http.impl.conn.DefaultProxyRoutePlanner)1 ResponseAssertion (org.apache.jmeter.assertions.ResponseAssertion)1 Controller (org.apache.jmeter.control.Controller)1 LoopController (org.apache.jmeter.control.LoopController)1 GuiPackage (org.apache.jmeter.gui.GuiPackage)1 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)1 DebugSampler (org.apache.jmeter.sampler.DebugSampler)1 TestPlan (org.apache.jmeter.testelement.TestPlan)1 JMeterThread (org.apache.jmeter.threads.JMeterThread)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1