Skip to content

Commit

Permalink
Custom Thread Groups - "Same user on each iteration" support for JMet…
Browse files Browse the repository at this point in the history
…er 5.2 onwards (#690)

* Upgrade to JMeter 5.2 and add "Same user on each iteration" support

* Revert name and description change

* Ad Workaround for new JMeters

* Fix ss.prop path on saveservice_properties and upgrade_properties

* Use new jmeter-plugins-emulators 0.5 and remove WA

* Move addNewThread to parent Abstract

* Fix text case

* Set default value for "Same User On Each Iteration"

* Clean code

* Clean code for more "Unwanted changes"
  • Loading branch information
3dgiordano authored Jan 22, 2025
1 parent 5b4fd9b commit a71be53
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion infra/emulators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-emulators</artifactId>
<version>0.4</version>
<version>0.5</version>

<name>Emulators library</name>
<description>Classes for plugins unit tests</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public static void createJmeterEnv() {
threadGroup.setName("test thread group");
JMeterContextService.getContext().setThreadGroup(threadGroup);
JMeterUtils.setProperty("sample_variables", "TEST1,TEST2,TEST3"); // for Flexible File Writer Test
JMeterUtils.setProperty("saveservice_properties", "/ss.props");
JMeterUtils.setProperty("upgrade_properties", "/ss.props");
JMeterUtils.setProperty("saveservice_properties", JMeterUtils.getJMeterHome() + "/ss.props");
JMeterUtils.setProperty("upgrade_properties", JMeterUtils.getJMeterHome() + "/ss.props");
JMeterUtils.setProperty("sampleresult.default.encoding", StandardCharsets.UTF_8.name()); // enable multibyte
}

Expand Down
9 changes: 7 additions & 2 deletions plugins/casutg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-casutg</artifactId>
<version>2.10</version>
<version>3.0</version>

<name>Custom Thread Groups</name>
<description>Custom Thread Groups</description>
Expand Down Expand Up @@ -62,8 +62,13 @@
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-emulators</artifactId>
<version>0.2</version>
<version>0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.2.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public void start(int groupIndex, ListenerNotifier listenerNotifier, ListedHashT

protected abstract Thread getThreadStarter(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine);

@Override
public JMeterThread addNewThread(int i, StandardJMeterEngine standardJMeterEngine) {
// TODO: Will not be implemented as the semantics of the API is unclear
return null;
}

@Override
public void threadFinished(JMeterThread jMeterThread) {
if(log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class AbstractDynamicThreadGroupModel extends AbstractThreadGrou
public static final String RAMP_UP = "RampUp";
public static final String STEPS = "Steps";
public static final String ITERATIONS = "Iterations";
public static final String SAME_USER = "same_user_on_next_iteration";
public static final String HOLD = "Hold";
protected transient Set<DynamicThread> threads = Collections.newSetFromMap(new ConcurrentHashMap<DynamicThread, Boolean>());
protected final ResultCollector logFile = new FlushingResultCollector();
Expand Down Expand Up @@ -173,10 +174,18 @@ public String getIterationsLimit() {
return getPropertyAsString(ITERATIONS);
}

public Boolean getSameUser() {
return getPropertyAsBoolean(SAME_USER, true);
}

public void setIterationsLimit(String val) {
setProperty(ITERATIONS, val);
}

public void setSameUser(Boolean val) {
setProperty(SAME_USER, val);
}

private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected DynamicThread makeThread(long threadIndex) {
boolean onErrorStopTestNow = owner.getOnErrorStopTestNow();
boolean onErrorStopThread = owner.getOnErrorStopThread();
boolean onErrorStartNextLoop = owner.getOnErrorStartNextLoop();
final DynamicThread jmeterThread = new DynamicThread(treeClone, this.owner, notifier);
final DynamicThread jmeterThread = new DynamicThread(treeClone, this.owner, notifier, owner.getSameUser());
jmeterThread.setThreadNum((int) threadIndex);
jmeterThread.setThreadGroup(this.owner);
jmeterThread.setInitialContext(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class AdditionalFieldsPanel extends ArrangedLabelFieldPanel implements ParamsPanel {
protected JTextField logFile = new JTextField();
protected JTextField iterations = new JTextField();
private final JCheckBox sameUserBox = new JCheckBox();
protected JTextField concurrLimit = new JTextField();
protected ButtonGroup unitGroup = new ButtonGroup();
protected JRadioButton unitSeconds = new JRadioButton("seconds");
Expand All @@ -28,6 +29,7 @@ public AdditionalFieldsPanel(boolean showConcurrencyLimit) {
add("Time Unit: ", groupPanel);

add("Thread Iterations Limit: ", iterations);
add("Same User On Each Iteration", sameUserBox);
add("Log Threads Status into File: ", logFile);

if (showConcurrencyLimit) {
Expand All @@ -38,6 +40,7 @@ public AdditionalFieldsPanel(boolean showConcurrencyLimit) {
public void modelToUI(AbstractDynamicThreadGroup tg) {
logFile.setText(tg.getLogFilename());
iterations.setText(tg.getIterationsLimit());
sameUserBox.setSelected(tg.getSameUser());
concurrLimit.setText("1000");
unitMinutes.setSelected(true);
if (tg instanceof ArrivalsThreadGroup) {
Expand All @@ -57,6 +60,7 @@ public void modelToUI(AbstractDynamicThreadGroup tg) {
public void UItoModel(AbstractDynamicThreadGroup tg, JMeterVariableEvaluator evaluator) {
tg.setLogFilename(evaluator.evaluate(logFile.getText()));
tg.setIterationsLimit(evaluator.evaluate(iterations.getText()));
tg.setSameUser(sameUserBox.isSelected());
if (unitGroup.getSelection() != null) {
tg.setUnit(unitGroup.getSelection().getActionCommand());
}
Expand All @@ -70,6 +74,7 @@ public void UItoModel(AbstractDynamicThreadGroup tg, JMeterVariableEvaluator eva
public void clearUI() {
logFile.setText("");
iterations.setText("");
sameUserBox.setSelected(true);
concurrLimit.setText("1000");
unitMinutes.setSelected(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class DynamicThread extends JMeterThread {
private Thread osThread;
private boolean stopping = false;

public DynamicThread(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier note) {
super(test, monitor, note);
public DynamicThread(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier note,
Boolean isSameUserOnNextIteration) {
super(test, monitor, note, isSameUserOnNextIteration);
}

public void setOSThread(Thread OSThread) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public boolean stopThread(String threadName, boolean now) {
return false;
}

@Override
public JMeterThread addNewThread(int i, StandardJMeterEngine standardJMeterEngine) {
// TODO: Will not be implemented as the semantics of the API is unclear
return null;
}

@Override
public void threadFinished(JMeterThread thread) {
log.debug("Ending thread " + thread.getThreadName());
Expand Down

0 comments on commit a71be53

Please sign in to comment.