Tuesday, 19 June 2012

JMeter Bug Bean

I came across a potential bug in JMeter when adding support for MongoOptions within mongometer. It's not a big deal in itself as I worked around it, but it was slightly frustrating at the time.

Implementing the MongoOptions seemed rather innocuous at the time; after all it's just another bunch of properties the user can alter. I ended up just adding them all at once. Imagine my disappointment when the extension failed to load in Jmeter as intended. To keep a long story short, the offender was wTimeout. Now, wtimeout (is one of a group a rather poorly named variables, others include j and w ), but why was there an issue with wtimeout?

The error of my ways

This is the error that was generated when starting up JMeter:

ERROR - jmeter.testbeans.BeanInfoSupport: Cannot find property: wTimeout in class class jan.mongometer.ScriptSampler
view raw jme1.log hosted with ❤ by GitHub

This is how it was defined, firstly in ScriptSamplerBeanInfo.java

createPropertyGroup("options", new String[] {
"wTimeout",
"fsync",
"j",
"safe",
"w" });
...
p = property("wTimeout");
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "0");
view raw jme2.java hosted with ❤ by GitHub

Next, in ScriptSamplerResource.properties

wTimeout.displayName=wtimeout
wTimeout.shortDescription=The wtimeout value of the global WriteConcern. Default is 0.
view raw jme3.properties hosted with ❤ by GitHub

And finally, in ScriptSampler.java

public final static String W_TIMEOUT = "ScriptSampler.wTimeout"; //$NON-NLS-1$
...
public String getWTimeout() {
return getPropertyAsString(W_TIMEOUT);
}
public void setWTimeout(String wTimeout) {
setProperty(W_TIMEOUT, wTimeout);
}
view raw jme4.java hosted with ❤ by GitHub

I checked and double checked the spelling. It didn't really make sense, it should've been fine. Out of all the properties that were defined, the wTimeout property was the odd one out, in that it was the only one that had the pattern of lowercase{1}uppercase{N}. All the others were either lowercase{1}, lowercase{N} or lowercase{N}uppercase{N}. So long story, short; switching from wTimeout to doubleuTimeout resolved the issue.

createPropertyGroup("options", new String[] {
"doubleuTimeout",
"fsync",
"j",
"safe",
"w" });
...
p = property("doubleuTimeout");
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "0");
view raw jme5.java hosted with ❤ by GitHub

Next, in ScriptSamplerResource.properties

doubleuTimeout.displayName=wtimeout
doubleuTimeout.shortDescription=The wtimeout value of the global WriteConcern. Default is 0.
view raw jme6.properties hosted with ❤ by GitHub

And finally, in ScriptSampler.java

public final static String W_TIMEOUT = "ScriptSampler.doubleuTimeout"; //$NON-NLS-1$
...
public String getDoubleuTimeout() {
return getPropertyAsString(W_TIMEOUT);
}
public void setDoubleuTimeout(String doubleuTimeout) {
setProperty(W_TIMEOUT, doubleuTimeout);
}
view raw jme7.java hosted with ❤ by GitHub

It seems that when performing the creation of the property, if there is only a single lowercase character followed by an uppercase character, we get an error.

The moral of the story

Hmmmm. I don't really do morals, but if this is a bug, then it needs to be fixed. Either way j, w and wtimeout are really rather poor names for variables.

1 comment: