Java Code Examples for org.apache.jmeter.gui.util.PowerTableModel#addRow()

The following examples show how to use org.apache.jmeter.gui.util.PowerTableModel#addRow() . 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: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeneric() {
    WeightedSwitchController obj = new WeightedSwitchController();
    obj.addTestElement(getSampler("0"));
    obj.addTestElement(getSampler("1"));
    obj.addTestElement(getSampler("2"));
    obj.addTestElement(getSampler("5"));
    PowerTableModel mdl = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    mdl.addRow(new String[]{"0", "0"});
    mdl.addRow(new String[]{"1", "1"});
    mdl.addRow(new String[]{"2", "2"});
    mdl.addRow(new String[]{"5", "5"});
    obj.setData(mdl);

    for (int n = 0; n < 800; n++) {
        Sampler s = obj.next();
        log.info("Sampler: " + s.getName());
        assertNotNull(s);
        assertNull(obj.next());
        assertNotEquals(s.getName(), "0");
    }
}
 
Example 2
Source File: JMeterPluginsUtils.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
public static void collectionPropertyToTableModelRows(CollectionProperty prop, PowerTableModel model, Class[] columnClasses) {
    model.clearData();
    for (int rowN = 0; rowN < prop.size(); rowN++) {
        ArrayList<StringProperty> rowStrings = (ArrayList<StringProperty>) prop.get(rowN).getObjectValue();
        ArrayList<Object> rowObject = new ArrayList<>(rowStrings.size());

        for (int i = 0; i < columnClasses.length && i < rowStrings.size(); i++) {
            rowObject.add(convertToClass(rowStrings.get(i), columnClasses[i]));
        }
        //for now work only if new fields are added at the end...
        //needed for retro compatibility if new fields added
        if (rowObject.size() < columnClasses.length) {
            for (int i = rowObject.size(); i < columnClasses.length; i++) {
                rowObject.add(new Object());
            }
        }
        model.addRow(rowObject.toArray());
    }
    model.fireTableDataChanged();
}
 
Example 3
Source File: UltimateThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private static void parseChunk(String chunk, PowerTableModel model) {
    log.debug("Parsing chunk: " + chunk);
    String[] parts = chunk.split("[(,]");
    String loadVar = parts[0].trim();

    if (loadVar.equalsIgnoreCase("spawn")) {
        Integer[] row = new Integer[5];
        row[START_THREADS_CNT_FIELD_NO] = Integer.parseInt(parts[1].trim());
        row[INIT_DELAY_FIELD_NO] = JMeterPluginsUtils.getSecondsForShortString(parts[2]);
        row[STARTUP_TIME_FIELD_NO] = JMeterPluginsUtils.getSecondsForShortString(parts[3]);
        row[HOLD_LOAD_FOR_FIELD_NO] = JMeterPluginsUtils.getSecondsForShortString(parts[4]);
        row[SHUTDOWN_TIME_FIELD_NO] = JMeterPluginsUtils.getSecondsForShortString(parts[5]);
        model.addRow(row);
    } else {
        throw new RuntimeException("Unknown load type: " + parts[0]);
    }
}
 
Example 4
Source File: UltimateThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
public static PowerTableModel getTestModel() {
    PowerTableModel ret = new PowerTableModel(UltimateThreadGroupGui.columnIdentifiers, UltimateThreadGroupGui.columnClasses);
    ret.addRow(new Integer[]
            {
                    1, 2, 3, 4, 44
            });
    ret.addRow(new Integer[]
            {
                    5, 6, 7, 8, 88
            });
    ret.addRow(new Integer[]
            {
                    9, 10, 11, 12, 122
            });

    return ret;
}
 
Example 5
Source File: VariableThroughputTimerGuiTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    dataModel = new PowerTableModel(VariableThroughputTimer.columnIdentifiers, VariableThroughputTimer.columnClasses);
    dataModel.addRow(new Integer[]{
                1, 10, 3
            });
    dataModel.addRow(new Integer[]{
                15, 15, 3
            });
    dataModel.addRow(new Integer[]{
                15, 1, 3
            });
    dataModel.addRow(new Integer[]{
                1, 1, 1
            });
}
 
Example 6
Source File: ParallelHTTPSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void sample() throws Exception {
    ParallelHTTPSampler obj = new ParallelHTTPSamplerMock();
    obj.setName("parent");
    //obj.setConcurrentDwn(false); //FIXME: remove or comment this
    PowerTableModel dataModel = new PowerTableModel(ParallelHTTPSampler.columnIdentifiers, ParallelHTTPSampler.columnClasses);
    dataModel.addRow(new String[]{"http://localhost:8000/rtimes/const?delay=1"});
    dataModel.addRow(new String[]{"http://localhost:8000/rtimes/const?delay=2"});
    CollectionProperty prop = JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, ParallelHTTPSampler.DATA_PROPERTY);
    obj.setData(prop);
    SampleResult res = obj.sample();
    assertTrue(res.isSuccessful());
    assertEquals(2, res.getSubResults().length);
}
 
Example 7
Source File: JMeterPluginsUtils.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static void collectionPropertyToTableModelRows(CollectionProperty prop, PowerTableModel model) {
    model.clearData();
    for (int rowN = 0; rowN < prop.size(); rowN++) {
        ArrayList<String> rowObject = (ArrayList<String>) prop.get(rowN).getObjectValue();
        model.addRow(rowObject.toArray());
    }
    model.fireTableDataChanged();
}
 
Example 8
Source File: JMeterPluginsUtilsTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private PowerTableModel getTestModel() {
    String[] headers = {"col1", "col2"};
    Class[] classes = {String.class, String.class};
    PowerTableModel model = new PowerTableModel(headers, classes);
    String[] row1 = {"1", "2"};
    String[] row2 = {"3", "4"};
    model.addRow(row1);
    model.addRow(row2);
    return model;
}
 
Example 9
Source File: JMXMonTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    TestJMeterUtils.createJmeterEnv();
    dataModel = new PowerTableModel(JMXMonGui.columnIdentifiers, JMXMonGui.columnClasses);
    dataModel.addRow(new Object[]{PROBE1, URL, USERNAME, PASSWORD, OBJ_NAME1, ATTRIBUTE1, "", false, false});
    dataModel.addRow(new Object[]{PROBE2, URL, USERNAME, PASSWORD, OBJ_NAME2, ATTRIBUTE2, "", true, false});
}
 
Example 10
Source File: DbmonTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    TestJMeterUtils.createJmeterEnv();
    JMeterContextService.getContext().getVariables().putObject(TEST_CONNECTION, new TestDataSource());

    dataModel = new PowerTableModel(DbMonGui.columnIdentifiers, DbMonGui.columnClasses);
    dataModel.addRow(new Object[]{TEST_CONNECTION, PROBE1, false, QUERY1});
    dataModel.addRow(new Object[]{TEST_CONNECTION, PROBE2, true, QUERY2});
}
 
Example 11
Source File: VariableThroughputTimerTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    dataModel = new PowerTableModel(VariableThroughputTimer.columnIdentifiers, VariableThroughputTimer.columnClasses);
    dataModel.addRow(new Integer[]{
                1, 10, 3
            });
    dataModel.addRow(new Integer[]{
                15, 15, 3
            });
    dataModel.addRow(new Integer[]{
                15, 1, 3
            });
}
 
Example 12
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedWSC() 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[]{"wsc1", "2"});
    topPTM.addRow(new String[]{"wsc2", "2"});
    topPTM.addRow(new String[]{"D_#1", "1"});
    topPTM.addRow(new String[]{"D_#2", "1"});
    topWSC.setData(topPTM);

    DebugSampler d1 = new DebugSampler();
    d1.setName("D_#1");
    DebugSampler d2 = new DebugSampler();
    d2.setName("D_#2");

    // first child WSC of top WSC
    WeightedSwitchController childWSC1 = new WeightedSwitchController();
    childWSC1.setName("wsc1");
    PowerTableModel childPTM1 = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    childPTM1.addRow(new String[]{"D1_#1", "1"});
    childPTM1.addRow(new String[]{"D1_#2", "1"});
    childWSC1.setData(childPTM1);

    DebugSampler d1_1 = new DebugSampler();
    d1_1.setName("D1_#1");
    DebugSampler d1_2 = new DebugSampler();
    d1_2.setName("D1_#2");

    // second child WSC of top WSC
    WeightedSwitchController childWSC2 = new WeightedSwitchController();
    childWSC2.setName("wsc2");
    PowerTableModel childPTM2 = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    childPTM2.addRow(new String[]{"D2_#1", "1"});
    childPTM2.addRow(new String[]{"D2_#2", "1"});
    childWSC2.setData(childPTM2);

    DebugSampler d2_1 = new DebugSampler();
    d2_1.setName("D2_#1");
    DebugSampler d2_2 = new DebugSampler();
    d2_2.setName("D2_#2");

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

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, childWSC1);
    hashTree.add(childWSC1, d1_1);
    hashTree.add(childWSC1, d1_2);
    hashTree.add(childWSC1, listener);
    hashTree.add(topWSC, childWSC2);
    hashTree.add(childWSC2, d2_1);
    hashTree.add(childWSC2, d2_2);
    hashTree.add(childWSC2, listener);
    hashTree.add(topWSC, d1);
    hashTree.add(topWSC, d2);

    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(6, listener.events.size());
    List<String> labels = new ArrayList<>();
    labels.add("D_#1");
    labels.add("D_#2");
    labels.add("D1_#1");
    labels.add("D1_#2");
    labels.add("D2_#1");
    labels.add("D2_#2");
    for (SampleEvent event : listener.events) {
        assertTrue(labels.contains(event.getResult().getSampleLabel()));
    }
}
 
Example 13
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 14
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedTransactionControllers() 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: 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(3);
    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(9, listener.events.size());
    assertEquals(1, (int) totalResults.get("example1_1"));
    assertEquals(1, (int) totalResults.get("example1_2"));
    assertEquals(2, (int) totalResults.get("example2_1"));
    assertEquals(2, (int) totalResults.get("example2_2"));
    assertEquals(1, (int) totalResults.get("ex1")); // transaction result
    assertEquals(2, (int) totalResults.get("ex2")); // transaction result
}
 
Example 15
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 16
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testRandomChoice() {
    LoggingManager.setPriority("INFO");
    try {
        final int iterations = 1000000;
        WeightedSwitchController obj = new WeightedSwitchController();
        obj.setIsRandomChoice(true);
        obj.addTestElement(getSampler("0"));
        obj.addTestElement(getSampler("1"));
        PowerTableModel mdl = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
        mdl.addRow(new String[]{"0", "95"});
        mdl.addRow(new String[]{"1", "5"});
        obj.setData(mdl);

        int sampler0Counter = 0;
        int sampler1Counter = 0;
        for (int n = 0; n < iterations; n++) {
            Sampler sampler = obj.next();
            assertNotNull(sampler);
            String name = sampler.getName();
            if ("0".equals(name)) {
                sampler0Counter++;
            } else {
                sampler1Counter++;
            }
            assertNull(obj.next());
        }

        double sampler0Percent = ((double) sampler0Counter / iterations) * 100;
        String msg0 = "Sampler 0 was ran " + sampler0Counter + " times. Total percent: " + sampler0Percent;
        assertTrue(msg0, 94.5 < sampler0Percent);
        assertTrue(msg0, 95.5 > sampler0Percent);

        double sampler1Percent = ((double) sampler1Counter / iterations) * 100;
        String msg1 = "Sampler 1 was ran " + sampler1Counter + " times. Total percent: " + sampler1Percent;
        assertTrue(msg1, 4.5 < sampler1Percent);
        assertTrue(msg1, 5.5 > sampler1Percent);
    } finally {
        LoggingManager.setPriority("DEBUG");
    }
}