Skip to content

Commit ff63439

Browse files
committed
fix: store ThreadGroup.scheduler fields
This fixes a regression in 2782476
1 parent 6c2a009 commit ff63439

9 files changed

Lines changed: 270 additions & 77 deletions

File tree

src/components/src/main/java/org/apache/jmeter/control/IncludeController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.jmeter.services.FileServer;
2828
import org.apache.jmeter.testelement.TestElement;
2929
import org.apache.jmeter.testelement.TestPlan;
30+
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
3031
import org.apache.jmeter.util.JMeterUtils;
3132
import org.apache.jorphan.collections.HashTree;
3233
import org.slf4j.Logger;
@@ -37,8 +38,6 @@ public class IncludeController extends GenericController implements ReplaceableC
3738

3839
private static final long serialVersionUID = 241L;
3940

40-
private static final String INCLUDE_PATH = "IncludeController.includepath"; //$NON-NLS-1$
41-
4241
private static final String PREFIX =
4342
JMeterUtils.getPropDefault(
4443
"includecontroller.prefix", //$NON-NLS-1$
@@ -56,6 +55,16 @@ public IncludeController() {
5655
super();
5756
}
5857

58+
@Override
59+
public IncludeControllerSchema getSchema() {
60+
return IncludeControllerSchema.INSTANCE;
61+
}
62+
63+
@Override
64+
public PropertiesAccessor<? extends IncludeController, ? extends IncludeControllerSchema> getProps() {
65+
return new PropertiesAccessor<>(this, getSchema());
66+
}
67+
5968
@Override
6069
public Object clone() {
6170
// TODO - fix so that this is only called once per test, instead of at every clone
@@ -81,15 +90,15 @@ public Object clone() {
8190
* @param jmxfile The path to the JMX test plan to include
8291
*/
8392
public void setIncludePath(String jmxfile) {
84-
this.setProperty(INCLUDE_PATH,jmxfile);
93+
set(getSchema().getIncludePath(), jmxfile);
8594
}
8695

8796
/**
8897
* return the JMX file path.
8998
* @return the JMX file path
9099
*/
91100
public String getIncludePath() {
92-
return this.getPropertyAsString(INCLUDE_PATH);
101+
return get(getSchema().getIncludePath());
93102
}
94103

95104
/**

src/components/src/main/java/org/apache/jmeter/control/gui/IncludeControllerGui.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import javax.swing.JPopupMenu;
2121

2222
import org.apache.jmeter.control.IncludeController;
23+
import org.apache.jmeter.control.IncludeControllerSchema;
24+
import org.apache.jmeter.gui.FilePanelEntryBinding;
2325
import org.apache.jmeter.gui.TestElementMetadata;
2426
import org.apache.jmeter.gui.util.FilePanel;
2527
import org.apache.jmeter.gui.util.MenuFactory;
@@ -41,41 +43,17 @@ public class IncludeControllerGui extends AbstractControllerGui
4143
*/
4244
public IncludeControllerGui() {
4345
init();
46+
bindingGroup.add(new FilePanelEntryBinding(includePanel, IncludeControllerSchema.INSTANCE.getIncludePath()));
4447
}
4548

4649
@Override
4750
public String getLabelResource() {
4851
return "include_controller";//$NON-NLS-1$
4952
}
5053

51-
/**
52-
* {@inheritDoc}
53-
*/
54-
@Override
55-
public void configure(TestElement el) {
56-
super.configure(el);
57-
IncludeController controller = (IncludeController) el;
58-
this.includePanel.setFilename(controller.getIncludePath());
59-
}
60-
61-
/**
62-
* {@inheritDoc}
63-
*/
64-
@Override
65-
public TestElement createTestElement() {
66-
IncludeController mc = new IncludeController();
67-
configureTestElement(mc);
68-
return mc;
69-
}
70-
71-
/**
72-
* {@inheritDoc}
73-
*/
7454
@Override
75-
public void modifyTestElement(TestElement element) {
76-
configureTestElement(element);
77-
IncludeController controller = (IncludeController)element;
78-
controller.setIncludePath(this.includePanel.getFilename());
55+
public TestElement makeTestElement() {
56+
return new IncludeController();
7957
}
8058

8159
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.control
19+
20+
import org.apache.jmeter.testelement.schema.StringPropertyDescriptor
21+
import org.apiguardian.api.API
22+
23+
/**
24+
* Lists properties of a [IncludeController].
25+
* @since 5.6
26+
*/
27+
@API(status = API.Status.EXPERIMENTAL, since = "5.6")
28+
public abstract class IncludeControllerSchema : GenericControllerSchema() {
29+
public companion object INSTANCE : IncludeControllerSchema()
30+
31+
public val includePath: StringPropertyDescriptor<IncludeControllerSchema>
32+
by string("IncludeController.includepath")
33+
}

src/core/src/main/java/org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.jmeter.threads.AbstractThreadGroup;
4040
import org.apache.jmeter.threads.AbstractThreadGroupSchema;
4141
import org.apache.jmeter.util.JMeterUtils;
42+
import org.apiguardian.api.API;
4243

4344
import net.miginfocom.swing.MigLayout;
4445

@@ -203,16 +204,34 @@ private String onSampleError() {
203204
return AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE;
204205
}
205206

206-
@Override
207+
@Override
208+
public void assignDefaultValues(TestElement element) {
209+
super.assignDefaultValues(element);
210+
element.set(AbstractThreadGroupSchema.INSTANCE.getOnSampleError(), AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE);
211+
}
212+
213+
@Override
207214
public void configure(TestElement tg) {
208215
super.configure(tg);
209216
setSampleErrorBoxes((AbstractThreadGroup) tg);
210217
}
211218

219+
@Override
220+
public void modifyTestElement(TestElement element) {
221+
super.modifyTestElement(element);
222+
element.set(AbstractThreadGroupSchema.INSTANCE.getOnSampleError(), onSampleError());
223+
}
224+
225+
/**
226+
* {@inheritDoc}
227+
* @deprecated Override {@link #modifyTestElement(TestElement)} instead
228+
* @param tg the TestElement being configured.
229+
*/
212230
@Override
231+
@Deprecated
232+
@API(status = API.Status.DEPRECATED, since = "5.6.3")
213233
protected void configureTestElement(TestElement tg) {
214234
super.configureTestElement(tg);
215235
tg.set(AbstractThreadGroupSchema.INSTANCE.getOnSampleError(), onSampleError());
216236
}
217-
218237
}

src/core/src/main/java/org/apache/jmeter/threads/gui/ThreadGroupGui.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,13 @@ public TestElement makeTestElement() {
107107
return new ThreadGroup();
108108
}
109109

110-
@Override
111-
public TestElement createTestElement() {
112-
TestElement tg = makeTestElement();
113-
// modifyTestElement is here for backward compatibility
114-
modifyTestElement(tg);
115-
assignDefaultValues(tg);
116-
return tg;
117-
}
118-
119110
@Override
120111
public void assignDefaultValues(TestElement element) {
121112
super.assignDefaultValues(element);
122113
element.set(ThreadGroupSchema.INSTANCE.getNumThreads(), 1);
123114
element.set(ThreadGroupSchema.INSTANCE.getRampTime(), 1);
115+
element.set(AbstractThreadGroupSchema.INSTANCE.getSameUserOnNextIteration(), true);
116+
((AbstractThreadGroup) element).setSamplerController((LoopController) loopPanel.createTestElement());
124117
}
125118

126119
/**
@@ -130,17 +123,17 @@ public void assignDefaultValues(TestElement element) {
130123
*/
131124
@Override
132125
public void modifyTestElement(TestElement tg) {
133-
super.configureTestElement(tg);
126+
super.modifyTestElement(tg);
134127
if (tg instanceof AbstractThreadGroup) {
135128
((AbstractThreadGroup) tg).setSamplerController((LoopController) loopPanel.createTestElement());
136129
}
137-
toggleSchedulerFields();
138130
}
139131

140132
@Override
141133
public void configure(TestElement tg) {
142134
super.configure(tg);
143135
loopPanel.configure((TestElement) tg.getProperty(AbstractThreadGroup.MAIN_CONTROLLER).getObjectValue());
136+
toggleSchedulerFields();
144137
}
145138

146139
@Override

src/core/src/main/kotlin/org/apache/jmeter/gui/JTextComponentBinding.kt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
package org.apache.jmeter.gui
1919

2020
import org.apache.jmeter.testelement.TestElement
21+
import org.apache.jmeter.testelement.schema.BooleanPropertyDescriptor
22+
import org.apache.jmeter.testelement.schema.DoublePropertyDescriptor
23+
import org.apache.jmeter.testelement.schema.FloatPropertyDescriptor
24+
import org.apache.jmeter.testelement.schema.IntegerPropertyDescriptor
25+
import org.apache.jmeter.testelement.schema.LongPropertyDescriptor
2126
import org.apache.jmeter.testelement.schema.PropertyDescriptor
2227
import org.apiguardian.api.API
2328
import javax.swing.JPasswordField
@@ -38,7 +43,42 @@ public class JTextComponentBinding(
3843
is JPasswordField -> String(component.password)
3944
else -> component.text
4045
}
41-
testElement[propertyDescriptor] = text.takeIf { it.isNotEmpty() }
46+
if (text.isEmpty()) {
47+
testElement.removeProperty(propertyDescriptor)
48+
return
49+
}
50+
when (propertyDescriptor) {
51+
is IntegerPropertyDescriptor<*> ->
52+
text.toIntOrNull()?.let {
53+
testElement[propertyDescriptor] = it
54+
return
55+
}
56+
57+
is LongPropertyDescriptor<*> ->
58+
text.toLongOrNull()?.let {
59+
testElement[propertyDescriptor] = it
60+
return
61+
}
62+
63+
is FloatPropertyDescriptor<*> ->
64+
text.toFloatOrNull()?.let {
65+
testElement[propertyDescriptor] = it
66+
return
67+
}
68+
69+
is DoublePropertyDescriptor<*> ->
70+
text.toDoubleOrNull()?.let {
71+
testElement[propertyDescriptor] = it
72+
return
73+
}
74+
75+
is BooleanPropertyDescriptor<*> ->
76+
text.toBooleanStrictOrNull()?.let {
77+
testElement[propertyDescriptor] = it
78+
return
79+
}
80+
}
81+
testElement[propertyDescriptor] = text
4282
}
4383

4484
override fun updateUi(testElement: TestElement) {

0 commit comments

Comments
 (0)