Skip to content

Commit

Permalink
fix: store ThreadGroup.scheduler fields
Browse files Browse the repository at this point in the history
This fixes a regression in 2782476
  • Loading branch information
vlsi committed Jan 1, 2024
1 parent 6c2a009 commit ff63439
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
import org.slf4j.Logger;
Expand All @@ -37,8 +38,6 @@ public class IncludeController extends GenericController implements ReplaceableC

private static final long serialVersionUID = 241L;

private static final String INCLUDE_PATH = "IncludeController.includepath"; //$NON-NLS-1$

private static final String PREFIX =
JMeterUtils.getPropDefault(
"includecontroller.prefix", //$NON-NLS-1$
Expand All @@ -56,6 +55,16 @@ public IncludeController() {
super();
}

@Override
public IncludeControllerSchema getSchema() {
return IncludeControllerSchema.INSTANCE;
}

@Override
public PropertiesAccessor<? extends IncludeController, ? extends IncludeControllerSchema> getProps() {
return new PropertiesAccessor<>(this, getSchema());
}

@Override
public Object clone() {
// TODO - fix so that this is only called once per test, instead of at every clone
Expand All @@ -81,15 +90,15 @@ public Object clone() {
* @param jmxfile The path to the JMX test plan to include
*/
public void setIncludePath(String jmxfile) {
this.setProperty(INCLUDE_PATH,jmxfile);
set(getSchema().getIncludePath(), jmxfile);
}

/**
* return the JMX file path.
* @return the JMX file path
*/
public String getIncludePath() {
return this.getPropertyAsString(INCLUDE_PATH);
return get(getSchema().getIncludePath());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import javax.swing.JPopupMenu;

import org.apache.jmeter.control.IncludeController;
import org.apache.jmeter.control.IncludeControllerSchema;
import org.apache.jmeter.gui.FilePanelEntryBinding;
import org.apache.jmeter.gui.TestElementMetadata;
import org.apache.jmeter.gui.util.FilePanel;
import org.apache.jmeter.gui.util.MenuFactory;
Expand All @@ -41,41 +43,17 @@ public class IncludeControllerGui extends AbstractControllerGui
*/
public IncludeControllerGui() {
init();
bindingGroup.add(new FilePanelEntryBinding(includePanel, IncludeControllerSchema.INSTANCE.getIncludePath()));
}

@Override
public String getLabelResource() {
return "include_controller";//$NON-NLS-1$
}

/**
* {@inheritDoc}
*/
@Override
public void configure(TestElement el) {
super.configure(el);
IncludeController controller = (IncludeController) el;
this.includePanel.setFilename(controller.getIncludePath());
}

/**
* {@inheritDoc}
*/
@Override
public TestElement createTestElement() {
IncludeController mc = new IncludeController();
configureTestElement(mc);
return mc;
}

/**
* {@inheritDoc}
*/
@Override
public void modifyTestElement(TestElement element) {
configureTestElement(element);
IncludeController controller = (IncludeController)element;
controller.setIncludePath(this.includePanel.getFilename());
public TestElement makeTestElement() {
return new IncludeController();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jmeter.control

import org.apache.jmeter.testelement.schema.StringPropertyDescriptor
import org.apiguardian.api.API

/**
* Lists properties of a [IncludeController].
* @since 5.6
*/
@API(status = API.Status.EXPERIMENTAL, since = "5.6")
public abstract class IncludeControllerSchema : GenericControllerSchema() {
public companion object INSTANCE : IncludeControllerSchema()

public val includePath: StringPropertyDescriptor<IncludeControllerSchema>
by string("IncludeController.includepath")
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.jmeter.threads.AbstractThreadGroup;
import org.apache.jmeter.threads.AbstractThreadGroupSchema;
import org.apache.jmeter.util.JMeterUtils;
import org.apiguardian.api.API;

import net.miginfocom.swing.MigLayout;

Expand Down Expand Up @@ -203,16 +204,34 @@ private String onSampleError() {
return AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE;
}

@Override
@Override
public void assignDefaultValues(TestElement element) {
super.assignDefaultValues(element);
element.set(AbstractThreadGroupSchema.INSTANCE.getOnSampleError(), AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE);
}

@Override
public void configure(TestElement tg) {
super.configure(tg);
setSampleErrorBoxes((AbstractThreadGroup) tg);
}

@Override
public void modifyTestElement(TestElement element) {
super.modifyTestElement(element);
element.set(AbstractThreadGroupSchema.INSTANCE.getOnSampleError(), onSampleError());
}

/**
* {@inheritDoc}
* @deprecated Override {@link #modifyTestElement(TestElement)} instead
* @param tg the TestElement being configured.
*/
@Override
@Deprecated
@API(status = API.Status.DEPRECATED, since = "5.6.3")
protected void configureTestElement(TestElement tg) {
super.configureTestElement(tg);
tg.set(AbstractThreadGroupSchema.INSTANCE.getOnSampleError(), onSampleError());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,13 @@ public TestElement makeTestElement() {
return new ThreadGroup();
}

@Override
public TestElement createTestElement() {
TestElement tg = makeTestElement();
// modifyTestElement is here for backward compatibility
modifyTestElement(tg);
assignDefaultValues(tg);
return tg;
}

@Override
public void assignDefaultValues(TestElement element) {
super.assignDefaultValues(element);
element.set(ThreadGroupSchema.INSTANCE.getNumThreads(), 1);
element.set(ThreadGroupSchema.INSTANCE.getRampTime(), 1);
element.set(AbstractThreadGroupSchema.INSTANCE.getSameUserOnNextIteration(), true);
((AbstractThreadGroup) element).setSamplerController((LoopController) loopPanel.createTestElement());
}

/**
Expand All @@ -130,17 +123,17 @@ public void assignDefaultValues(TestElement element) {
*/
@Override
public void modifyTestElement(TestElement tg) {
super.configureTestElement(tg);
super.modifyTestElement(tg);
if (tg instanceof AbstractThreadGroup) {
((AbstractThreadGroup) tg).setSamplerController((LoopController) loopPanel.createTestElement());
}
toggleSchedulerFields();
}

@Override
public void configure(TestElement tg) {
super.configure(tg);
loopPanel.configure((TestElement) tg.getProperty(AbstractThreadGroup.MAIN_CONTROLLER).getObjectValue());
toggleSchedulerFields();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
package org.apache.jmeter.gui

import org.apache.jmeter.testelement.TestElement
import org.apache.jmeter.testelement.schema.BooleanPropertyDescriptor
import org.apache.jmeter.testelement.schema.DoublePropertyDescriptor
import org.apache.jmeter.testelement.schema.FloatPropertyDescriptor
import org.apache.jmeter.testelement.schema.IntegerPropertyDescriptor
import org.apache.jmeter.testelement.schema.LongPropertyDescriptor
import org.apache.jmeter.testelement.schema.PropertyDescriptor
import org.apiguardian.api.API
import javax.swing.JPasswordField
Expand All @@ -38,7 +43,42 @@ public class JTextComponentBinding(
is JPasswordField -> String(component.password)
else -> component.text
}
testElement[propertyDescriptor] = text.takeIf { it.isNotEmpty() }
if (text.isEmpty()) {
testElement.removeProperty(propertyDescriptor)
return
}
when (propertyDescriptor) {
is IntegerPropertyDescriptor<*> ->
text.toIntOrNull()?.let {
testElement[propertyDescriptor] = it
return
}

is LongPropertyDescriptor<*> ->
text.toLongOrNull()?.let {
testElement[propertyDescriptor] = it
return
}

is FloatPropertyDescriptor<*> ->
text.toFloatOrNull()?.let {
testElement[propertyDescriptor] = it
return
}

is DoublePropertyDescriptor<*> ->
text.toDoubleOrNull()?.let {
testElement[propertyDescriptor] = it
return
}

is BooleanPropertyDescriptor<*> ->
text.toBooleanStrictOrNull()?.let {
testElement[propertyDescriptor] = it
return
}
}
testElement[propertyDescriptor] = text
}

override fun updateUi(testElement: TestElement) {
Expand Down
Loading

0 comments on commit ff63439

Please sign in to comment.