Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log errors happening while JMeter starts the test #6193

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import java.io.Serializable;

import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.engine.event.LoopIterationListener;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.util.JMeterUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ class UniformRandomTimerSpec extends Specification {
def sut = new UniformRandomTimer()

def "default delay is 0"() {
given:
sut.iterationStart(null)
when:
def computedDelay = sut.delay()
then:
computedDelay == 0L
}

def "default range is 0"() {
given:
sut.iterationStart(null)
when:
def actualRange = sut.range
then:
Expand All @@ -45,7 +41,6 @@ class UniformRandomTimerSpec extends Specification {
def "delay can be set via a String"() {
given:
sut.setDelay("1")
sut.iterationStart(null)
when:
def computedDelay = sut.delay()
then:
Expand All @@ -57,7 +52,6 @@ class UniformRandomTimerSpec extends Specification {
given:
sut.setDelay(delay)
sut.setRange(range)
sut.iterationStart(null)
when:
def computedDelay = sut.delay()
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ void testUniformRandomTimer() throws Exception {
UniformRandomTimer timer = new UniformRandomTimer();
timer.setDelay("1000");
timer.setRange(100d);
timer.iterationStart(null);
long delay = timer.delay();
assertBetween(1000, 1100, delay);
}
Expand All @@ -142,7 +141,6 @@ private static void assertBetween(long expectedLow, long expectedHigh, long actu
void testConstantTimer() throws Exception {
ConstantTimer timer = new ConstantTimer();
timer.setDelay("1000");
timer.iterationStart(null);
Assertions.assertEquals(1000, timer.delay());
}

Expand All @@ -151,7 +149,6 @@ void testPoissonRandomTimerRangeHigherThan30() throws Exception {
PoissonRandomTimer timer = new PoissonRandomTimer();
timer.setDelay("300");
timer.setRange(100d);
timer.iterationStart(null);
long delay = timer.delay();
assertBetween(356, 457, delay);
}
Expand All @@ -161,7 +158,6 @@ void testPoissonRandomTimerRangeLowerThan30() throws Exception {
PoissonRandomTimer timer = new PoissonRandomTimer();
timer.setDelay("300");
timer.setRange(30d);
timer.iterationStart(null);
long delay = timer.delay();
assertBetween(305, 362, delay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,21 @@ private static void removeThreadGroups(List<?> elements) {

private void notifyTestListenersOfStart(SearchByClass<? extends TestStateListener> testListeners) {
for (TestStateListener tl : testListeners.getSearchResults()) {
if (tl instanceof TestBean) {
TestBeanHelper.prepare((TestElement) tl);
}
if (host == null) {
tl.testStarted();
} else {
tl.testStarted(host);
try {
if (tl instanceof TestBean) {
TestBeanHelper.prepare((TestElement) tl);
}
if (host == null) {
tl.testStarted();
} else {
tl.testStarted(host);
}
} catch (Throwable e) {
// TODO: we should not be logging the exceptions multiple times, however, currently GUI does not
// monitor if the running test fails, so we log the exception for the users to see in the logs
log.error("Unable to execute testStarted({}) for test element {}", host, tl, e);
throw new IllegalStateException(
"Unable to execute testStarted(" + host + ") for test element " + tl, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,25 @@ public static void prepare(TestElement el) {
try {
for (CachedPropertyDescriptor desc : GOOD_PROPS.get(el.getClass())) {
// Obtain a value of the appropriate type for this property.
JMeterProperty jprop = el.getProperty(desc.descriptor.getName());
Class<?> type = desc.propertyType;
Object value = unwrapProperty(desc.descriptor, jprop, type);

JMeterProperty jprop;
Object value;
try {
jprop = el.getProperty(desc.descriptor.getName());
value = unwrapProperty(desc.descriptor, jprop, type);
} catch (OutOfMemoryError | StackOverflowError e) {
throw e;
} catch (Throwable e) {
String elementName;
try {
elementName = el.getName();
} catch(Throwable ignore) {
elementName = el.getClass().getName();
}
throw new IllegalStateException(
"Can't retrieve property '" + desc.descriptor.getName() + "' of element " + elementName, e);
}

if (log.isDebugEnabled()) {
log.debug("Setting {}={}", jprop.getName(), value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ public class TimeFunction extends AbstractFunction implements TestStateListener
long div = Long.parseLong(fmt.substring(1)); // should never case NFE
return () -> Long.toString(System.currentTimeMillis() / div);
}
DateTimeFormatter df = DateTimeFormatter
.ofPattern(fmt)
.withZone(ZoneId.systemDefault());
DateTimeFormatter df;
try {
df = DateTimeFormatter
.ofPattern(fmt)
.withZone(ZoneId.systemDefault());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unable to parse date format " + fmt, e);
}
if (isPossibleUsageOfUInFormat(df, fmt)) {
log.warn(
MessageFormat.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.save.CSVSaveService;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.testelement.TestStateListener;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
Expand All @@ -57,7 +56,7 @@
* A base class for all JDBC test elements handling the basics of a SQL request.
*
*/
public abstract class AbstractJDBCTestElement extends AbstractTestElement implements TestStateListener{
public abstract class AbstractJDBCTestElement extends AbstractTestElement {
private static final long serialVersionUID = 235L;

private static final Logger log = LoggerFactory.getLogger(AbstractJDBCTestElement.class);
Expand Down Expand Up @@ -819,40 +818,4 @@ public String getResultVariable() {
public void setResultVariable(String resultVariable) {
this.resultVariable = resultVariable;
}


/**
* {@inheritDoc}
* @see org.apache.jmeter.testelement.TestStateListener#testStarted()
*/
@Override
public void testStarted() {
testStarted("");
}

/**
* {@inheritDoc}
* @see org.apache.jmeter.testelement.TestStateListener#testStarted(java.lang.String)
*/
@Override
public void testStarted(String host) {
}

/**
* {@inheritDoc}
* @see org.apache.jmeter.testelement.TestStateListener#testEnded()
*/
@Override
public void testEnded() {
testEnded("");
}

/**
* {@inheritDoc}
* @see org.apache.jmeter.testelement.TestStateListener#testEnded(java.lang.String)
*/
@Override
public void testEnded(String host) {
}

}