Detailed explanation of Jmeter (four)_16 logic controllers

Jmeter logic controller (Logic Controller) introduction:

1. The explanation of the logic controller on Jmeter's official website is: "Logic Controllers determine the order in which Samplers are processed.".

Meaning, the logic controller can control the execution order of the samplers . It can be seen that the controller needs to be used with the sampler, otherwise the controller is meaningless. All samplers placed under the controller will be treated as a whole and will be executed together when executed.

2. Logic Controllers in JMeter are divided into two categories:

  •   Control the logical execution sequence of nodes during the execution of the test plan , such as: Loop Controller, If Controller, etc.;
  •  Group the scripts in the test plan , facilitate JMeter to count the execution results and control the runtime of the scripts, such as: Throughput Controller, Transaction Controller.

3. Jmeter provides so many controllers as follows:

 

2

one of the jmeter controllers

 

 

1. Simple Controller:

  Function: This is the simplest controller in Jmeter, it allows us to organize our sampler and other logic controllers (grouping function), providing a block structure and control, without any logic control or operation time function.

 

2. Loop Controller:

  Function: Specify the number of times its child nodes run, you can use specific values ​​(as shown below, set to 5 times), or you can use variables

  1. Forever option: Checking this item means that the cycle will continue

  2. If the number of loops of the thread group and the number of loops of the loop controller are set at the same time, the number of times the child node of the loop controller runs is the result of multiplying the two values.

 

3. Once Only Controller:

  Role: During the execution of the test plan, the child nodes under the controller are executed only once for each thread, and this controller is often used in login scenarios.

  Note: Take the Once Only Controller as a child of the Loop Controller, and the Once Only Controller will be executed on the first iteration of each loop.

 

Fourth, ForEach Controller (ForEach Controller):

  Function: The ForEach controller is generally used with user-defined variables, which reads a series of related variables in the user-defined variables. The sampler or controller under this controller will be executed one or more times, each time reading a different variable value. As shown below:

parameter:

Input Variable Prefix: Input variable prefix

Output variable name: output variable name

· Start index for loop (exclusive): the index of the loop start (if not filled here, the default starts from 1, if there is no variable starting with 1, an error will be reported during execution)

End index for loop (inclusive): the index of the end of the loop

· Add "_" before number: Enter whether to use "_" for interval in the variable name.

 

User-defined variables:

  The variable name prefix is ​​the name defined by the Input variable prefix in ForEach Controller + underscore (we checked the underscore in the above figure) + number number

Results of the:

  A total of 3 executions are performed, and the obtained variable value is assigned to the output variable outNmae in each execution, and other places can be called through ${outNmae}.

 

5. Transaction Controller:

  Role: The transaction controller will produce an additional sampler to count all the time of the controller's child nodes.

· Application scenario: complete a complete page request or a group of requests

parameter:

  • Generate parent sample: After checking, all the results will be displayed in the parent node (selecting this parameter results will be displayed in the red box as shown in the figure below, otherwise it will be displayed in the blue box in the figure below)
  • Include duration of timer and pre-post processors in generated sample: Selecting this item will count the time of the timer (timer), otherwise only the time of the sampler (sample) will be counted

 

 

3

The second jmeter controller

 

Six, If Controller (If Controller):

  Function: Determine whether to execute the child nodes under the node according to the value of the given expression . By default, the syntax of javascript is used to judge (the text in the red box in the following figure).

parameter:

  • Interpret Condition as Variable Expression?: When this item is selected, it means: determine whether the variable value is equal to the string true (case insensitive)
  • Evaluate for all children: If this option is checked, the expression will be evaluated before each child node is executed 

Example 1: Use variable expressions to judge:

Example 2: Check Interpret Condition as Variable Expression? , using variables to judge

 I will do a demonstration here, first take out the response id in the previous interface

Determine whether the statement in the if controller is true, and if it is true, continue to execute

Here I wrote the id value to death, ran an observation result, and found that the interface of the service worker was executed

 

 

Seven, Switch Controller (Switch Controller):

  Role: The Switch controller specifies which sampler to run by assigning a value to the Value in the controller. There are two assignment methods:

· The first is the value, the child node under the Switch controller starts counting from 0, and determines which element to execute by specifying the value of the child node.

· The second is to directly specify the name of the child element, such as the name of the sampler, to match. When the specified name does not exist, no element is executed.

When Value is empty, the first child node element is executed by default. 

Example:

1. The value selected by Switch Controller is Customer Service Login

2. Execution result:

 

8. Throughput Controller:

  Function: Control the number of executions and load ratio distribution of the child nodes under it . Don't be confused by the name, it has nothing to do with throughput. There are also two ways:

 

  • Total Executions: Set the number of runs, the total number of executions in the entire test plan
  • Percent Executions: Set the running ratio (between 1 and 100), the total execution percentage in the entire test plan
  • Throughtput: Design value
  • Per User: According to the online instructions, when selecting Total Executions, the number of times it will be executed in each thread when checked. But trying to use in version 3.0 didn't work 

Example:

1. Set the thread group to loop 5 times:

  

2. The child node of Throughput Controller1 executes 3 times:,

 It turns out that a total of 3 runs

  

3. The child node of Throughput Controller2 is executed (40% * Thread group cycle times 5) = 2 times: pay attention to the percentage option, fill in the percentage !

Observe the running results and find that it has been run twice

 

Results of the:

 

9. Random Controller:

  Role: randomly execute a sub-node under it, and randomly select the request in the controller for execution

  Application Scenario: Random Access of Pages

Configuration instructions: ignore sub-controller blocks: ignore sub-controllers 

 

Execution result, one of the three logins is randomly selected

 

 

10. Random Order Controller:

  Role: randomly execute all child nodes under it

Different from the Random Controller, this controller will execute all the content that needs to be random first, but the order is not certain

· Application scenario: random access to pages, but all need to be accessed, and the order is not limited

 

 Run one more time, observe the results, and find that the order of the two runs is different, but each interface is run once

 

4

jmeter controller three

 

 

Eleven, Critical Section  Controller

Role: For the control of the core part, to ensure that the sampler or controller under its child node will only be executed once in a thread

Application Scenario: User Login

Preparation Instructions

Lock name: lock name, here you can fill in the name of the thread executed under its child node, this thread is stored as a global lock

 

12. Include Controller  references external test plan controllers

  • Application scenario: During the testing process, it is necessary to refer to the external test plan
  • Preparation Instructions

· Include Test Plan-Filename: Select the external test plan file to be imported 

 

Thirteen, Interleave Controller interval controller

  Also known as an alternate controller, so that the sampler steps contained in the controller are interleaved and executed in each loop, each thread user executes the request in the controller only once, and the thread user requests the number of requests in the controller according to the number of loops.

Configuration instructions: ignore sub-controller blocks: whether to ignore sub-controllers 

 

 

14. Module  Controller

· Module controller to jump to the selected controller location and execute the corresponding controller

· Application scenario: jump of business logic

· Preparation instructions

· Module to Run: Select the target controller to jump to 

 

Find target element:

  • Find the elements and modules in the test plan that require specific tests; it can also be understood that the controller can control the encapsulated module elements
  • A test plan consists of a controller and all test elements (samplers, etc.), the test plan can be in any thread group or workbench; if the plan is in a thread group, other controllers can be disabled to prevent the running test plan from being destroyed. Affects (except for module controllers)
  • The advantage of the module controller is that when there are multiple thread groups, the controller can be easily switched, and only the corresponding sampler needs to be selected, which is convenient and fast, and replaces the tedious operation of creating many test plans
  • The name of the controller used by any one module must be unique, because the name is used to find the target controller when reloading; for this reason, it is best to ensure that the controller names are different, otherwise unexpected test execution may occur
  • Module controllers and remote tests should not use or non-gui tests with workbench components, because the workbench test elements are not part of the test plan jmx file. Any such test will fail

 

15. Runtime Controller

· Runtime controller, set the requested runtime in the controller, in seconds

· Application scenario: limit the time of business requests

· Preparation instructions

· Runtime(seconds): Configure the running time to be set, in seconds 

 

 

Sixteen, While Controller loop controller

· Loop controller, consistent with the While function in the development language. Stop running until the condition is false

· Application scenario: Execute a request in a loop, and exit the loop only by judging one state

· Preparation instructions

· Condition(function or variable): can be configured as empty/LAST/variable or method 

 

Possible condition values ​​are:

  • Empty: Exit the loop when the last example loop fails
  • LAST: Exit the loop when the last example loop fails. If the last example before just failed the loop, don't enter the loop.
  • false: on exit (or without input) the loop condition is equal to the string "false"
  • Condition can be any variable or function that ultimately equals the string "false". It should be noted that the condition is evaluated twice, once before sampling, and once at random

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325251069&siteId=291194637