org.apache.jmeter.threads.AbstractThreadGroup Java Examples

The following examples show how to use org.apache.jmeter.threads.AbstractThreadGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UltimateThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(TestElement tg) {
    super.configure(tg);
    UltimateThreadGroup utg = (UltimateThreadGroup) tg;
    JMeterProperty threadValues = utg.getData();
    if (!(threadValues instanceof NullProperty)) {
        CollectionProperty columns = (CollectionProperty) threadValues;

        tableModel.removeTableModelListener(this);
        JMeterPluginsUtils.collectionPropertyToTableModelRows(columns, tableModel);
        tableModel.addTableModelListener(this);
        updateUI();
    } else {
        log.warn("Received null property instead of collection");
    }

    TestElement te = (TestElement) tg.getProperty(AbstractThreadGroup.MAIN_CONTROLLER).getObjectValue();
    if (te != null) {
        loopPanel.configure(te);
    }
    buttons.checkDeleteButtonStatus();
}
 
Example #2
Source File: SteppingThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(TestElement te) {
    super.configure(te);
    SteppingThreadGroup tg = (SteppingThreadGroup) te;
    totalThreads.setText(tg.getNumThreadsAsString());
    initialDelay.setText(tg.getThreadGroupDelay());
    incUserCount.setText(tg.getInUserCount());
    incUserCountBurst.setText(tg.getInUserCountBurst());
    incUserPeriod.setText(tg.getInUserPeriod());
    decUserCount.setText(tg.getOutUserCount());
    decUserPeriod.setText(tg.getOutUserPeriod());
    flightTime.setText(tg.getFlightTime());
    rampUp.setText(tg.getRampUp());

    TestElement controller = (TestElement) tg.getProperty(AbstractThreadGroup.MAIN_CONTROLLER).getObjectValue();
    if (controller != null) {
        loopPanel.configure(controller);
    }
}
 
Example #3
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Test
public void runDebugEngine() throws Exception {
    TestProvider prov = new TestProvider();

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(88, hook.cnt);
}
 
Example #4
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {
    log.debug("Showing dialog");
    if (GuiPackage.getInstance() != null) {
        savedDirty = GuiPackage.getInstance().isDirty();
    }
    this.debugger = new Debugger(this, this);
    tgCombo.removeAllItems();
    for (AbstractThreadGroup group : debugger.getThreadGroups()) {
        tgCombo.addItem(group);
    }

    AbstractThreadGroup selectedThreadGroup = debugger.getSelectedThreadGroup();
    if (selectedThreadGroup != null) {
        changeComboValue(selectedThreadGroup);
    }

    tgCombo.setEnabled(tgCombo.getItemCount() > 0);
    start.setEnabled(tgCombo.getItemCount() > 0);
    start.requestFocus();
    clearListeners();
}
 
Example #5
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void removeThreadGroupFromEngine(AbstractThreadGroup group) {
    try {
        StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
        Field groupsField = StandardJMeterEngine.class.getDeclaredField("groups");
        groupsField.setAccessible(true);
        List<AbstractThreadGroup> groups = (List<AbstractThreadGroup>) groupsField.get(engine);
        groups.remove(group);
    } catch (ReflectiveOperationException ex) {
        log.warn("Can not remove DummyThreadGroup from engine", ex);
    }
}
 
Example #6
Source File: ArrivalsThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static ListedHashTree getListedHashTree(AbstractThreadGroup atg, boolean stopThread) {
    ListedHashTree tree = new ListedHashTree();
    TestAction pauser = new TestAction();
    if (stopThread) {
        pauser.setAction(TestAction.STOP);
    } else {
        pauser.setAction(TestAction.PAUSE);
    }
    pauser.setTarget(TestAction.THREAD);

    pauser.setDuration(String.valueOf(300));
    tree.add(atg, pauser);
    return tree;
}
 
Example #7
Source File: TestPlanCheckTool.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void addNode(Object node, HashTree subTree) {
    if (node instanceof AbstractThreadGroup) {
        tGroups++;
    } else if (node instanceof Controller) {
        controllers++;
    } else if (node instanceof Sampler) {
        samplers++;
    } else if (node instanceof AbstractListenerElement) {
        listeners++;
    } else if (node instanceof PreProcessor) {
        preProc++;
    } else if (node instanceof PostProcessor) {
        postProc++;
    } else if (node instanceof Assertion) {
        assertions++;
    } else if (node instanceof Timer) {
        timers++;
    } else if (node instanceof ConfigElement) {
        configs++;
    } else if (node instanceof TestPlan) {
        log.debug("Ok, we got the root of test plan");
    } else if (node instanceof WorkBench) {
        log.debug("Ok, we got the root of test plan");
    } else {
        log.warn("Strange object in tree: " + node);
        others++;
    }
}
 
Example #8
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInControllers() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/loops.jmx", "loops.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(12, hook.cnt);

    assertEquals(3, listener.events.size());
}
 
Example #9
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInAssertions() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/debug.jmx", "debug.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(4, hook.cnt);

    assertEquals(1, listener.events.size());
    SampleEvent event = listener.events.get(0);
    SampleResult result = event.getResult();
    AssertionResult[] assertionResults = result.getAssertionResults();
    assertEquals(1, assertionResults.length);

    AssertionResult assertionRes = assertionResults[0];
    assertNull(assertionRes.getFailureMessage());
}
 
Example #10
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesDebugEngine() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(8, hook.cnt);

    assertEquals(3, listener.events.size());
    for (SampleEvent event : listener.events) {
        SampleResult res = event.getResult();
        String label = res.getSampleLabel();
        assertTrue("Label: " + label + " must end with '123'", label.endsWith("123"));
        assertFalse("Variable ${VAR} must be changed to '123' value. label: " + label, label.contains("${VAR}"));
        assertTrue("label: '" + label + "' response: '" + res.getResponseMessage() +"'", res.isSuccessful());
    }
}
 
Example #11
Source File: ThreadGroupItemRenderer.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends AbstractThreadGroup> list, AbstractThreadGroup value, int index, boolean isSelected, boolean cellHasFocus) {
    String name = "";
    if (value != null) {
        name = value.getName();
    }
    //noinspection unchecked
    return originalRenderer.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
}
 
Example #12
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent event) {
    if (event.getStateChange() == ItemEvent.SELECTED) {
        log.debug("Item choice changed: " + event.getItem());
        if (event.getItem() instanceof AbstractThreadGroup) {
            selectThreadGroup((AbstractThreadGroup) event.getItem());
        }
    }
}
 
Example #13
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
    JMeterTreeNode node = (JMeterTreeNode) treeSelectionEvent.getPath().getLastPathComponent();
    TestElement wrpElm = node.getTestElement();
    if (wrpElm instanceof OriginalLink) {
        TestElement te = (TestElement) ((OriginalLink) wrpElm).getOriginal();
        if (!(te instanceof AbstractThreadGroup)) {
            wrpElm = te;
        }
    }

    displayElementGui(wrpElm);
}
 
Example #14
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void selectThreadGroup(AbstractThreadGroup tg) {
    debugger.selectThreadGroup(tg);
    treeModel.clearTestPlan();
    HashTree origTree = debugger.getSelectedTree();
    TreeCloner cloner = new TreeCloner();
    origTree.traverse(cloner);
    HashTree selectedTree = cloner.getClonedTree();

    // Hack to resolve ModuleControllers from JMeter.java
    SearchClass<ReplaceableController> replaceableControllers = new SearchClass<>(ReplaceableController.class);
    selectedTree.traverse(replaceableControllers);
    Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
    for (ReplaceableController replaceableController : replaceableControllersRes) {
        replaceableController.resolveReplacementSubTree((JMeterTreeNode) treeModel.getRoot());
    }

    JMeter.convertSubTree(selectedTree);
    try {
        treeModel.addSubTree(selectedTree, (JMeterTreeNode) treeModel.getRoot());
    } catch (IllegalUserActionException e) {
        throw new RuntimeException(e);
    }

    // select TG for visual convenience
    SearchByClass<DebuggingThreadGroup> tgs = new SearchByClass<>(DebuggingThreadGroup.class);
    selectedTree.traverse(tgs);
    for (DebuggingThreadGroup forSel : tgs.getSearchResults()) {
        Wrapper<AbstractThreadGroup> wtg = new ThreadGroupWrapper();
        wtg.setWrappedElement(forSel);
        selectTargetInTree(wtg);
    }
}
 
Example #15
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void changeComboValue(AbstractThreadGroup selectedThreadGroup) {
    ComboBoxModel<AbstractThreadGroup> model = this.tgCombo.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        if (model.getElementAt(i).equals(selectedThreadGroup)) {
            tgCombo.setSelectedIndex(i);
        }
    }
}
 
Example #16
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private TestElement getAlteredElement(TestElement cloned) {
    boolean isWrappable = !(cloned instanceof TransactionController) && !(cloned instanceof TestFragmentController) && !(cloned instanceof ReplaceableController);

    TestElement userObject = cloned;
    if (!isWrappable) {
        log.debug("Forcing unwrapped: " + cloned);
    } else if (cloned instanceof AbstractThreadGroup) {
        userObject = new DebuggingThreadGroup();
        userObject.setProperty(TestElement.GUI_CLASS, DebuggingThreadGroupGui.class.getCanonicalName());
    } else if (cloned instanceof Controller) {
        userObject = getController(cloned);
    } else if (cloned instanceof PreProcessor) {
        userObject = new PreProcessorDebug();
    } else if (cloned instanceof Timer) {
        userObject = new TimerDebug();
    } else if (cloned instanceof Sampler) {
        userObject = new SamplerDebug();
    } else if (cloned instanceof PostProcessor) {
        userObject = new PostProcessorDebug();
    } else if (cloned instanceof Assertion) {
        userObject = new AssertionDebug();
    } else if (cloned instanceof SampleListener) {
        userObject = new SampleListenerDebug();
    } else {
        log.debug("Keeping element unwrapped: " + cloned);
    }
    return userObject;
}
 
Example #17
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private boolean isIgnored(Object node) {
    if (node instanceof JMeterTreeNode) {
        Object te = ((JMeterTreeNode) node).getUserObject();
        return te instanceof AbstractThreadGroup && te != onlyTG;
    }
    return false;
}
 
Example #18
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private AbstractThreadGroup getSelectedThreadGroup(AbstractThreadGroup[] grps) {
    JMeterTreeNode currentElement = GuiPackage.getInstance().getCurrentNode();
    if (currentElement != null) {
        SearchParentClass<AbstractThreadGroup> searcher = new SearchParentClass(currentElement, AbstractThreadGroup.class);
        treeProvider.getTestTree().traverse(searcher);
        return searcher.hasResults() ? searcher.getSearchResults().get(0) : grps[0];
    }
    return grps[0];
}
 
Example #19
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
public AbstractThreadGroup getSelectedThreadGroup() {
    AbstractThreadGroup[] grps = getThreadGroups();
    if (grps.length > 0) {
        return getSelectedThreadGroup(grps);
    } else {
        log.debug("Empty test plan");
        return null;
    }
}
 
Example #20
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void addThreadGroupToEngine(AbstractThreadGroup group) {
    try {
        StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
        Field groupsField = StandardJMeterEngine.class.getDeclaredField("groups");
        groupsField.setAccessible(true);
        List<AbstractThreadGroup> groups = (List<AbstractThreadGroup>) groupsField.get(engine);
        groups.add(group);
    } catch (ReflectiveOperationException ex) {
        log.warn("Can not add DummyThreadGroup to engine", ex);
    }
}
 
Example #21
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
private AbstractThreadGroup getFirstTG(HashTree tree) {
    SearchClass<AbstractThreadGroup> searcher = new SearchClass<>(AbstractThreadGroup.class);
    tree.traverse(searcher);
    Collection<AbstractThreadGroup> searchResults = searcher.getSearchResults();
    return searchResults.toArray(new AbstractThreadGroup[0])[0];
}
 
Example #22
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public TreeClonerTG(AbstractThreadGroup tg) {
    this.onlyTG = tg;
}
 
Example #23
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public void selectThreadGroup(AbstractThreadGroup tg) {
    log.debug("Selecting thread group " + tg.getName() + ": " + tg);
    cloner = new TreeClonerTG(tg);
    treeProvider.getTestTree().traverse(cloner);
}
 
Example #24
Source File: TestProvider.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public AbstractThreadGroup getTG(int i) {
    SearchClass<AbstractThreadGroup> searcher = new SearchClass<>(AbstractThreadGroup.class);
    mdl.getTestPlan().traverse(searcher);
    Collection<AbstractThreadGroup> searchResults = searcher.getSearchResults();
    return searchResults.toArray(new AbstractThreadGroup[0])[i];
}
 
Example #25
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public AbstractThreadGroup[] getThreadGroups() {
    SearchClass<AbstractThreadGroup> searcher = new SearchClass<>(AbstractThreadGroup.class);
    treeProvider.getTestTree().traverse(searcher);
    return searcher.getSearchResults().toArray(new AbstractThreadGroup[0]);
}
 
Example #26
Source File: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartNextLoop() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());

    TestSampleListener listener = new TestSampleListener();

    DebugSampler beforeSampler = new DebugSamplerExt();
    beforeSampler.setName("Before Test Action sampler");

    TestAction testAction = new TestAction();
    testAction.setAction(TestAction.RESTART_NEXT_LOOP);

    DebugSampler afterSampler = new DebugSamplerExt();
    afterSampler.setName("After Test Action sampler");


    ConcurrencyThreadGroup ctg = new ConcurrencyThreadGroup();
    ctg.setProperty(new StringProperty(AbstractThreadGroup.ON_SAMPLE_ERROR, AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE));
    ctg.setRampUp("0");
    ctg.setTargetLevel("1");
    ctg.setSteps("0");
    ctg.setHold("5"); // TODO: increase this value for debugging
    ctg.setIterationsLimit("10");
    ctg.setUnit("S");

    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg);
    hashTree.add(ctg, beforeSampler);
    hashTree.add(ctg, testAction);
    hashTree.add(ctg, afterSampler);
    hashTree.add(ctg, listener);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ListenerNotifier notifier = new ListenerNotifier();

    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());

    ctg.waitThreadsStopped();

    for (SampleEvent event : listener.events) {
        assertEquals("Before Test Action sampler", event.getResult().getSampleLabel());
    }
}