org.apache.jmeter.control.GenericController Java Examples

The following examples show how to use org.apache.jmeter.control.GenericController. 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: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void sample() throws Exception {
    JMeterThread dummy = new JMeterThread(new HashTree(new GenericController()), null, null);
    JMeterContextService.getContext().setEngine(new StandardJMeterEngine());
    JMeterContextService.getContext().setThread(dummy);
    JMeterThread thr = JMeterContextService.getContext().getThread();
    for (int n = 0; n < 1000; n++) {// we're doing good check here because of multi-threads
        log.debug("\n\n\nTry #" + n);
        EmulSampler.instances = 0;
        EmulSampler.count.set(0);
        ParallelSampler obj = new ParallelSampler();
        obj.threadStarted();
        obj.setGenerateParent(true);

        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));

        SampleResult res = obj.sample(null);
        assertEquals(5, EmulSampler.count.get());
        if (res.getSubResults().length < 5) {
            throw new AssertionError();
        }

        assertEquals(5, res.getSubResults().length);
    }
}
 
Example #2
Source File: WeightedSwitchController.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void resetController(Controller element) {
    if (element instanceof TransactionController) {
        if (element.getPropertyAsBoolean("TransactionController.parent")) {
            // we should skip org.apache.jmeter.control.TransactionController.triggerEndOfLoop(),
            // because org.apache.jmeter.control.TransactionController.transactionSampler is NULL,
            // but we should call GenericController.triggerEndOfLoop() or GenericController.reInitialize()
            // for reInit this controller
            reInitializeController((TransactionController) element);
            return;
        } else {
            // when currentCopy != current && result != null we should
            // set org.apache.jmeter.control.TransactionController.res = null
            // because if it is not null org.apache.jmeter.control.TransactionController.triggerEndOfLoop()
            // will generate new parent Sample
            nullifyRes((TransactionController) element);
        }
    } else if (element instanceof GenericController) {
        // reset all nested controllers
        GenericController ctrl = (GenericController) element;
        List<TestElement> subControllersAndSamplers = getSubControllersAndSamplers(ctrl);
        for (TestElement te : subControllersAndSamplers) {
            if (te instanceof Controller) {
                resetController((Controller) te);
            }
        }
    }
    element.triggerEndOfLoop();
}
 
Example #3
Source File: WeightedSwitchController.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private List<TestElement> getSubControllersAndSamplers(GenericController ctrl) {
    try {
        Field subControllersAndSamplers = GenericController.class.getDeclaredField("subControllersAndSamplers");
        subControllersAndSamplers.setAccessible(true);
        return (List<TestElement>) subControllersAndSamplers.get(ctrl);
    } catch (Throwable ex) {
        log.warn("Failed to get SubControllers And Samplers", ex);
        return Collections.emptyList();
    }
}
 
Example #4
Source File: WeightedSwitchController.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void reInitializeController(TransactionController element) {
    try {
        Method reInitialize = GenericController.class.getDeclaredMethod("reInitialize");
        reInitialize.setAccessible(true);
        reInitialize.invoke(element);
    } catch (Throwable ex) {
        log.warn("Failed to reInitialize TransactionController", ex);
    }
}
 
Example #5
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedSimpleControllers() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"ex1", "10"});
    topPTM.addRow(new String[]{"ex2", "20"});
    topWSC.setData(topPTM);


    // first child: simple controller
    GenericController ex1 = new GenericController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: simple controller
    GenericController ex2 = new GenericController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(60);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    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();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(120, listener.events.size());
    assertEquals(20, (int) totalResults.get("example1_1"));
    assertEquals(20, (int) totalResults.get("example1_2"));
    assertEquals(40, (int) totalResults.get("example2_1"));
    assertEquals(40, (int) totalResults.get("example2_2"));
}
 
Example #6
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testResetTransactionControllerUnderSimpleController() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"simple1", "100"});
    topPTM.addRow(new String[]{"simple2", "100"});
    topWSC.setData(topPTM);

    GenericController simple1 = new GenericController();
    simple1.setName("simple1");

    GenericController simple2 = new GenericController();
    simple2.setName("simple2");

    // first child: transaction controller
    TransactionController ex1 = new TransactionController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: transaction controller
    TransactionController ex2 = new TransactionController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(4);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, simple1);
    hashTree.add(simple1, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, simple2);
    hashTree.add(simple2, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    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();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(12, listener.events.size());
    assertEquals(2, (int) totalResults.get("example1_1"));
    assertEquals(2, (int) totalResults.get("example1_2"));
    assertEquals(2, (int) totalResults.get("example2_1"));
    assertEquals(2, (int) totalResults.get("example2_2"));
    assertEquals(2, (int) totalResults.get("ex1")); // transaction result
    assertEquals(2, (int) totalResults.get("ex2")); // transaction result
}
 
Example #7
Source File: GenericControllerDebug.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public GenericController getWrappedElement() {
    return wrapped;
}
 
Example #8
Source File: GenericControllerDebug.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public void setWrappedElement(GenericController te) {
    this.wrapped = te;
}
 
Example #9
Source File: GenericControllerDebug.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public GenericController getOriginal() {
    return original;

}
 
Example #10
Source File: GenericControllerDebug.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public void setOriginal(GenericController orig) {
    original = orig;
}