View | Details | Raw Unified | Return to bug 58943
Collapse All | Expand All

(-)bin/jmeter.properties (+17 lines)
Lines 1281-1286 Link Here
1281
# Disabled by default
1281
# Disabled by default
1282
#testplan_validation.tpc_force_100_pct=false
1282
#testplan_validation.tpc_force_100_pct=false
1283
1283
1284
#---------------------------------------------------------------------------
1285
# Think Time configuration
1286
#---------------------------------------------------------------------------
1284
1287
1285
#
1288
#
1286
# Apply a factor on computed pauses by the following Timers:
1289
# Apply a factor on computed pauses by the following Timers:
Lines 1290-1295 Link Here
1290
#
1293
#
1291
#timer.factor=1.0f
1294
#timer.factor=1.0f
1292
1295
1296
# Default implementation that create the Timer structure to add to Test Plan
1297
# Implementation of interface org.apache.jmeter.gui.action.thinktime.ThinkTimeCreator
1298
#think_time_creator.impl=org.apache.jmeter.thinktime.DefaultThinkTimeCreator
1299
1300
# Default Timer GUI class added to Test Plan by DefaultThinkTimeCreator
1301
#think_time_creator.default_timer_implementation=org.apache.jmeter.timers.gui.UniformRandomTimerGui
1302
1303
# Default constant pause of Timer 
1304
#think_time_creator.default_constant_pause=1000
1305
1306
# Default range pause of Timer
1307
#think_time_creator.default_range=100
1308
1309
1293
# Change this parameter if you want to override the APDEX satisfaction threshold.
1310
# Change this parameter if you want to override the APDEX satisfaction threshold.
1294
jmeter.reportgenerator.apdex_satisfied_threshold=500
1311
jmeter.reportgenerator.apdex_satisfied_threshold=500
1295
1312
(-)src/components/org/apache/jmeter/thinktime/DefaultThinkTimeCreator.java (+83 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
package org.apache.jmeter.thinktime;
19
20
import org.apache.jmeter.exceptions.IllegalUserActionException;
21
import org.apache.jmeter.gui.GuiPackage;
22
import org.apache.jmeter.gui.action.thinktime.ThinkTimeCreator;
23
import org.apache.jmeter.gui.tree.JMeterTreeNode;
24
import org.apache.jmeter.sampler.TestAction;
25
import org.apache.jmeter.sampler.gui.TestActionGui;
26
import org.apache.jmeter.timers.RandomTimer;
27
import org.apache.jmeter.timers.gui.UniformRandomTimerGui;
28
import org.apache.jmeter.util.JMeterUtils;
29
30
/**
31
 * Default implementation of {@link ThinkTimeCreator}
32
 * @since 3.2
33
 */
34
public class DefaultThinkTimeCreator implements ThinkTimeCreator {
35
    private static final String DEFAULT_TIMER_IMPLEMENTATION = 
36
            JMeterUtils.getPropDefault(
37
                    "think_time_creator.default_timer_implementation", 
38
                    UniformRandomTimerGui.class.getName());
39
40
    private static final String DEFAULT_PAUSE = 
41
            JMeterUtils.getPropDefault(
42
                    "think_time_creator.default_constant_pause", 
43
                    "1000");
44
45
    private static final String DEFAULT_RANGE = 
46
            JMeterUtils.getPropDefault(
47
                    "think_time_creator.default_range", 
48
                    "100");
49
50
    /**
51
     */
52
    public DefaultThinkTimeCreator() {
53
        super();
54
    }
55
56
    /**
57
     * 
58
     * @param guiPackage {@link GuiPackage}
59
     * @param parentNode {@link JMeterTreeNode}
60
     * @return array of {@link JMeterTreeNode}
61
     * @throws IllegalUserActionException
62
     */
63
    @Override
64
    public JMeterTreeNode[] createThinkTime(GuiPackage guiPackage, JMeterTreeNode parentNode) 
65
            throws IllegalUserActionException {
66
        TestAction testAction = (TestAction) guiPackage.createTestElement(TestActionGui.class.getName());
67
        testAction.setAction(TestAction.PAUSE);
68
        testAction.setDuration("0");
69
        JMeterTreeNode thinkTimeNode = new JMeterTreeNode(testAction, guiPackage.getTreeModel());
70
        thinkTimeNode.setName("Think Time");
71
        RandomTimer randomTimer = (RandomTimer) 
72
                guiPackage.createTestElement(DEFAULT_TIMER_IMPLEMENTATION);
73
        randomTimer.setDelay(DEFAULT_PAUSE);
74
        randomTimer.setRange(DEFAULT_RANGE);
75
        randomTimer.setName("Pause");
76
        
77
        JMeterTreeNode urtNode = new JMeterTreeNode(randomTimer, guiPackage.getTreeModel());        
78
        return new JMeterTreeNode[] {
79
                thinkTimeNode,
80
                urtNode
81
        };
82
    }
83
}
(-)src/core/org/apache/jmeter/gui/action/ActionNames.java (+1 lines)
Lines 34-39 Link Here
34
    public static final String ADD_ALL          = "add_all"; // $NON-NLS-1$
34
    public static final String ADD_ALL          = "add_all"; // $NON-NLS-1$
35
    public static final String ADD_PARENT       = "Add Parent"; // $NON-NLS-1$
35
    public static final String ADD_PARENT       = "Add Parent"; // $NON-NLS-1$
36
    public static final String ANALYZE_FILE     = "Analyze File"; // $NON-NLS-1$
36
    public static final String ANALYZE_FILE     = "Analyze File"; // $NON-NLS-1$
37
    public static final String ADD_THINK_TIME_BETWEEN_EACH_STEP    = "Add Think Time between each step"; // $NON-NLS-1$
37
    public static final String CHANGE_LANGUAGE  = "change_language"; // $NON-NLS-1$
38
    public static final String CHANGE_LANGUAGE  = "change_language"; // $NON-NLS-1$
38
    public static final String CHANGE_PARENT    = "Change Parent"; // $NON-NLS-1$
39
    public static final String CHANGE_PARENT    = "Change Parent"; // $NON-NLS-1$
39
    public static final String CHECK_DIRTY      = "check_dirty"; // $NON-NLS-1$
40
    public static final String CHECK_DIRTY      = "check_dirty"; // $NON-NLS-1$
(-)src/core/org/apache/jmeter/gui/action/AddThinkTimeBetweenEachStep.java (+152 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.gui.action;
20
21
import java.awt.Toolkit;
22
import java.awt.event.ActionEvent;
23
import java.util.HashSet;
24
import java.util.Set;
25
26
import org.apache.jmeter.control.Controller;
27
import org.apache.jmeter.exceptions.IllegalUserActionException;
28
import org.apache.jmeter.gui.GuiPackage;
29
import org.apache.jmeter.gui.action.thinktime.ThinkTimeCreator;
30
import org.apache.jmeter.gui.tree.JMeterTreeNode;
31
import org.apache.jmeter.samplers.Sampler;
32
import org.apache.jmeter.threads.ThreadGroup;
33
import org.apache.jmeter.util.JMeterUtils;
34
import org.apache.jorphan.logging.LoggingManager;
35
import org.apache.log.Logger;
36
37
/**
38
 * Add ThinkTime (TestAction + UniformRandomTimer)
39
 * @since 3.2
40
 */
41
public class AddThinkTimeBetweenEachStep extends AbstractAction {
42
    private static final Logger log = LoggingManager.getLoggerForClass();
43
44
    private static final Set<String> commands = new HashSet<>();
45
    
46
    private static final String DEFAULT_IMPLEMENTATION = 
47
            JMeterUtils.getPropDefault("think_time_creator.impl", 
48
                    "org.apache.jmeter.thinktime.DefaultThinkTimeCreator");
49
    static {
50
        commands.add(ActionNames.ADD_THINK_TIME_BETWEEN_EACH_STEP);
51
    }
52
53
    /**
54
     * 
55
     */
56
    public AddThinkTimeBetweenEachStep() {
57
        super();
58
    }
59
60
    @Override
61
    public void doAction(ActionEvent e) {
62
        GuiPackage guiPackage = GuiPackage.getInstance();
63
        JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
64
        if (!
65
                (currentNode.getUserObject() instanceof Controller ||
66
                        currentNode.getUserObject() instanceof ThreadGroup)
67
                ) {
68
            Toolkit.getDefaultToolkit().beep();
69
            return;
70
        }
71
        try {
72
            addThinkTimeToChildren(guiPackage, currentNode);            
73
        } catch (Exception err) {
74
            Toolkit.getDefaultToolkit().beep();
75
            log.error("Failed to add think times", err);
76
            JMeterUtils.reportErrorToUser("Failed to add think times", err);
77
        }
78
    }
79
80
    /**
81
     * Add Think Time to children of parentNode
82
     * @param guiPackage {@link GuiPackage}
83
     * @param parentNode Parent node of elements on which we add think times
84
     * @throws IllegalUserActionException 
85
     */
86
    private void addThinkTimeToChildren(GuiPackage guiPackage, 
87
            JMeterTreeNode parentNode) throws IllegalUserActionException {
88
        guiPackage.updateCurrentNode();
89
        boolean insertThinkTime = false;
90
        try {
91
            int index = 0;
92
            while(true) {
93
                if(index == parentNode.getChildCount()) {
94
                    index++;
95
                    break;
96
                }
97
                JMeterTreeNode childNode = (JMeterTreeNode) parentNode.getChildAt(index);
98
                Object userObject = childNode.getUserObject();
99
                if(userObject instanceof Sampler ||
100
                        userObject instanceof Controller) {
101
                    insertThinkTime = true;                
102
                }
103
                if(insertThinkTime) {
104
                    JMeterTreeNode[] nodes = createThinkTime(guiPackage, parentNode);
105
                    if(nodes.length != 2) {
106
                        throw new IllegalArgumentException("Invalid Think Time, expected 2 nodes, got:"+nodes.length);
107
                    }
108
                    index++;
109
                    addNodesToTreeHierachically(guiPackage, parentNode, nodes, index);
110
                    insertThinkTime = false;
111
                }
112
                index++;
113
            }
114
        } catch(Exception ex) {
115
            throw new IllegalUserActionException("Cannot add think times", ex);
116
        }
117
    }
118
119
    /**
120
     * add nodes to JMeter Tree
121
     * @param guiPackage {@link GuiPackage}
122
     * @param parentNode {@link JMeterTreeNode}
123
     * @param childNodes Child nodes
124
     * @param index insertion index
125
     */
126
    private void addNodesToTreeHierachically(GuiPackage guiPackage, 
127
            JMeterTreeNode parentNode, 
128
            JMeterTreeNode[] childNodes, 
129
            int index) {
130
        guiPackage.getTreeModel().insertNodeInto(childNodes[0], parentNode, index);    
131
        guiPackage.getTreeModel().insertNodeInto(childNodes[1], childNodes[0], 0);
132
    }
133
134
    /**
135
     * 
136
     * @param guiPackage {@link GuiPackage}
137
     * @param parentNode {@link JMeterTreeNode}
138
     * @return array of {@link JMeterTreeNode}
139
     * @throws IllegalUserActionException
140
     */
141
    private JMeterTreeNode[] createThinkTime(GuiPackage guiPackage, JMeterTreeNode parentNode) 
142
        throws Exception {
143
        Class<?> clazz = Class.forName(DEFAULT_IMPLEMENTATION);
144
        ThinkTimeCreator thinkTimeCreator = (ThinkTimeCreator) clazz.newInstance();
145
        return thinkTimeCreator.createThinkTime(guiPackage, parentNode);
146
    }
147
    
148
    @Override
149
    public Set<String> getActionNames() {
150
        return commands;
151
    }
152
}
(-)src/core/org/apache/jmeter/gui/action/thinktime/ThinkTimeCreator.java (+39 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.gui.action.thinktime;
20
21
import org.apache.jmeter.exceptions.IllegalUserActionException;
22
import org.apache.jmeter.gui.GuiPackage;
23
import org.apache.jmeter.gui.tree.JMeterTreeNode;
24
25
/**
26
 * @since 3.2
27
 *
28
 */
29
public interface ThinkTimeCreator {
30
31
    /**
32
     * 
33
     * @param guiPackage
34
     * @param parentNode
35
     * @return array of 2 nodes
36
     * @throws IllegalUserActionException
37
     */
38
    JMeterTreeNode[] createThinkTime(GuiPackage guiPackage, JMeterTreeNode parentNode) throws IllegalUserActionException;
39
}
(-)src/core/org/apache/jmeter/gui/util/MenuFactory.java (+3 lines)
Lines 293-298 Link Here
293
        pop.add(makeMenus(MENU_PARENT_CONTROLLER,
293
        pop.add(makeMenus(MENU_PARENT_CONTROLLER,
294
                JMeterUtils.getResString("change_parent"),// $NON-NLS-1$
294
                JMeterUtils.getResString("change_parent"),// $NON-NLS-1$
295
                ActionNames.CHANGE_PARENT));
295
                ActionNames.CHANGE_PARENT));
296
        pop.add(MenuFactory.makeMenuItemRes("add_think_times",// $NON-NLS-1$
297
                ActionNames.ADD_THINK_TIME_BETWEEN_EACH_STEP));
298
296
        MenuFactory.addEditMenu(pop, true);
299
        MenuFactory.addEditMenu(pop, true);
297
        MenuFactory.addFileMenu(pop);
300
        MenuFactory.addFileMenu(pop);
298
        return pop;
301
        return pop;
(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 32-37 Link Here
32
add_user=Add User
32
add_user=Add User
33
add_value=Add Value
33
add_value=Add Value
34
addtest=Add test
34
addtest=Add test
35
add_think_times=Add Think Times to children
35
aggregate_graph=Statistical Graphs
36
aggregate_graph=Statistical Graphs
36
aggregate_graph_choose_color=Choose color
37
aggregate_graph_choose_color=Choose color
37
aggregate_graph_choose_foreground_color=Foreground color
38
aggregate_graph_choose_foreground_color=Foreground color
(-)src/core/org/apache/jmeter/resources/messages_fr.properties (+1 lines)
Lines 23-28 Link Here
23
add_parameter=Ajouter un param\u00E8tre
23
add_parameter=Ajouter un param\u00E8tre
24
add_pattern=Ajouter un motif \:
24
add_pattern=Ajouter un motif \:
25
add_test=Ajout
25
add_test=Ajout
26
add_think_times=Add Think Times to children
26
add_user=Ajouter un utilisateur
27
add_user=Ajouter un utilisateur
27
add_value=Ajouter valeur
28
add_value=Ajouter valeur
28
addtest=Ajout
29
addtest=Ajout
(-)src/core/org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java (-1 / +6 lines)
Lines 38-44 Link Here
38
import org.apache.jmeter.testelement.TestElement;
38
import org.apache.jmeter.testelement.TestElement;
39
import org.apache.jmeter.testelement.property.StringProperty;
39
import org.apache.jmeter.testelement.property.StringProperty;
40
import org.apache.jmeter.threads.AbstractThreadGroup;
40
import org.apache.jmeter.threads.AbstractThreadGroup;
41
import org.apache.jmeter.threads.JMeterContextService;
42
import org.apache.jmeter.util.JMeterUtils;
41
import org.apache.jmeter.util.JMeterUtils;
43
42
44
public abstract class AbstractThreadGroupGui extends AbstractJMeterGuiComponent {
43
public abstract class AbstractThreadGroupGui extends AbstractJMeterGuiComponent {
Lines 103-108 Link Here
103
            validateTg.addActionListener(ActionRouter.getInstance());
102
            validateTg.addActionListener(ActionRouter.getInstance());
104
            validateTg.setActionCommand(ActionNames.VALIDATE_TG);
103
            validateTg.setActionCommand(ActionNames.VALIDATE_TG);
105
            pop.add(validateTg);
104
            pop.add(validateTg);
105
106
            JMenuItem addThinkTimesToChildren = new JMenuItem(JMeterUtils.getResString("add_think_times"));
107
            addThinkTimesToChildren.setName("add_think_times");
108
            addThinkTimesToChildren.addActionListener(ActionRouter.getInstance());
109
            addThinkTimesToChildren.setActionCommand(ActionNames.ADD_THINK_TIME_BETWEEN_EACH_STEP);
110
            pop.add(addThinkTimesToChildren);
106
        }
111
        }
107
        
112
        
108
        MenuFactory.addEditMenu(pop, true);
113
        MenuFactory.addEditMenu(pop, true);
(-)xdocs/usermanual/properties_reference.xml (+17 lines)
Lines 1791-1796 Link Here
1791
    </ul>
1791
    </ul>
1792
    Defaults to: <code>1.0f</code>
1792
    Defaults to: <code>1.0f</code>
1793
</property>
1793
</property>
1794
<property name="think_time_creator.impl">
1795
    Default implementation that create the Timer structure to add to Test Plan. 
1796
    Implementation of interface org.apache.jmeter.gui.action.thinktime.ThinkTimeCreator
1797
    Defaults to: <code><a href="../api/org/apache/jmeter/thinktime/DefaultThinkTimeCreator.html"><code>org.apache.jmeter.thinktime.DefaultThinkTimeCreator</code></a></code>
1798
</property>
1799
<property name="think_time_creator.default_timer_implementation">
1800
    Default Timer GUI class added to Test Plan by DefaultThinkTimeCreator
1801
    Defaults to: <code><a href="../api/org/apache/jmeter/timers/gui/UniformRandomTimerGui.html"><code>org.apache.jmeter.timers.gui.UniformRandomTimerGui</code></a></code>
1802
</property>
1803
<property name="think_time_creator.default_constant_pause">
1804
    Default constant pause of Timer
1805
    Defaults to: <code>1000</code>
1806
</property>
1807
<property name="think_time_creator.default_range">
1808
    Default range pause of Timer
1809
    Defaults to: <code>100</code>
1810
</property>
1794
</properties>
1811
</properties>
1795
<a href="#">^</a>
1812
<a href="#">^</a>
1796
</section>
1813
</section>

Return to bug 58943