Bug 62752 - Add to Documentation: ctx.getThreadNum() 0-based and ${__threadNum} 1-based
Summary: Add to Documentation: ctx.getThreadNum() 0-based and ${__threadNum} 1-based
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.13
Hardware: All All
: P3 enhancement (vote)
Target Milestone: JMETER_5.1
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2018-09-21 10:44 UTC by Ivan Rancati
Modified: 2018-11-04 11:50 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Rancati 2018-09-21 10:44:12 UTC
ctx.getThreadNum() returns a 0-based thread number, 
the variable __threadNum is 1-based

Reproducible in JMeter 4 and 5 with a simple test plan:
a thread group, 
a constant throughput timer
a JSR223 sampler which just logs

log.info("from ctx:"+ctx.getThreadNum())
log.info("from variable: ${__threadNum}")

in jmeter.log I see for example for the first thread

2018-09-18 22:45:07,610 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
...
2018-09-18 22:45:08,085 INFO o.a.j.p.j.s.JSR223Sampler: from ctx:0
2018-09-18 22:45:08,085 INFO o.a.j.p.j.s.JSR223Sampler: from variable: 1

It's probably late to change this without potentially breaking backward
compatibility, so a documentation update can be used to clarify this small inconsistency

Documentation for ctx.getThreadNum
http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterThread.html#getThreadNum--

Documentation for the JMeter variables
http://jmeter.apache.org/usermanual/functions.html#__threadNum
Comment 1 Philippe Mouawad 2018-11-03 22:48:56 UTC
Author: pmouawad
Date: Sat Nov  3 22:47:02 2018
New Revision: 1845700

URL: http://svn.apache.org/viewvc?rev=1845700&view=rev
Log:
Bug 62752 - Add to Documentation: ctx.getThreadNum() 0-based and ${__threadNum} 1-based
Bugzilla Id: 62752

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml
Comment 2 Felix Schumacher 2018-11-04 11:50:50 UTC
Date: Sun Nov  4 11:37:54 2018
New Revision: 1845725

URL: http://svn.apache.org/viewvc?rev=1845725&view=rev
Log:
Add location of JMeterContext API to link and write out numbers as words

Follow-up to r1845700
Bug 62752 - Add to Documentation: ctx.getThreadNum() 0-based and
${__threadNum} 1-based

Bugzilla Id: 62752