@@ -23,7 +23,7 @@ public class VirtualUserController extends GenericController implements Iteratin
2323
2424 @ Override
2525 public Sampler next () {
26- updateIterationIndex (owner . getName (), ( int ) iterationNo );
26+ updateIterationIndex ();
2727 try {
2828 if (breakLoop || owner .isLimitReached ()) {
2929 setDone (true );
@@ -33,7 +33,7 @@ public Sampler next() {
3333 }
3434 hasArrived = true ;
3535 incrementLoopCount ();
36- updateIterationIndex (owner . getName (), ( int ) iterationNo );
36+ updateIterationIndex ();
3737 if (owner instanceof ArrivalsThreadGroup ) {
3838 getOwnerAsArrivals ().arrivalFact (JMeterContextService .getContext ().getThread (), iterationNo );
3939 if (!owner .isRunning ()) {
@@ -44,10 +44,16 @@ public Sampler next() {
4444 }
4545 return super .next ();
4646 } finally {
47- updateIterationIndex (owner . getName (), ( int ) iterationNo );
47+ updateIterationIndex ();
4848 }
4949 }
5050
51+ private void updateIterationIndex () {
52+ // This controller increment prior sample and ThreadGroup controllers do the opposite
53+ // We subtract one to JMeter IterationIndex to be aligned with TG (start with 0)
54+ updateIterationIndex (owner .getName (), getIterCount () - 1 );
55+ }
56+
5157 private boolean moveToPool (JMeterThread thread ) {
5258 if (thread instanceof DynamicThread ) {
5359 if (!owner .isLimitReached () && getOwnerAsArrivals ().movedToPool ((DynamicThread ) thread )) {
@@ -114,7 +120,7 @@ public void setOwner(AbstractDynamicThreadGroup owner) {
114120
115121 @ Override
116122 protected int getIterCount () {
117- return (int ) (iterationNo + 1 );
123+ return (int ) (iterationNo );
118124 }
119125
120126 public void startNextLoop () {
0 commit comments