View | Details | Raw Unified | Return to bug 51868
Collapse All | Expand All

(-)src/core/org/apache/jmeter/control/IfController.java (+6 lines)
Lines 22-27 Link Here
22
22
23
import org.apache.jmeter.samplers.Sampler;
23
import org.apache.jmeter.samplers.Sampler;
24
import org.apache.jmeter.testelement.property.StringProperty;
24
import org.apache.jmeter.testelement.property.StringProperty;
25
import org.apache.jmeter.threads.JMeterContextService;
25
import org.apache.jorphan.logging.LoggingManager;
26
import org.apache.jorphan.logging.LoggingManager;
26
import org.apache.log.Logger;
27
import org.apache.log.Logger;
27
import org.mozilla.javascript.Context;
28
import org.mozilla.javascript.Context;
Lines 123-128 Link Here
123
            logger.debug("    >> evaluate Condition -  [ " + cond + "] results is  [" + result + "]");
124
            logger.debug("    >> evaluate Condition -  [ " + cond + "] results is  [" + result + "]");
124
        } catch (Exception e) {
125
        } catch (Exception e) {
125
            logger.error(getName()+": error while processing "+ "[" + cond + "]\n", e);
126
            logger.error(getName()+": error while processing "+ "[" + cond + "]\n", e);
127
            throw new IllegalStateException(getName()+": error while processing "+ "[" + cond + "]\n", e);
126
        } finally {
128
        } finally {
127
            Context.exit();
129
            Context.exit();
128
        }
130
        }
Lines 158-163 Link Here
158
     */
160
     */
159
    @Override
161
    @Override
160
    public Sampler next() {
162
    public Sampler next() {
163
        if(JMeterContextService.getContext().isWithinRestartNextLoop()) {
164
            // Suppose condition is true (make it a random choice ?)
165
            return super.next();
166
        }
161
        // We should only evalute the condition if it is the first
167
        // We should only evalute the condition if it is the first
162
        // time ( first "iteration" ) we are called.
168
        // time ( first "iteration" ) we are called.
163
        // For subsequent calls, we are inside the IfControllerGroup,
169
        // For subsequent calls, we are inside the IfControllerGroup,
(-)src/core/org/apache/jmeter/threads/JMeterContext.java (+35 lines)
Lines 49-54 Link Here
49
49
50
    private boolean isReinitSubControllers = false;
50
    private boolean isReinitSubControllers = false;
51
51
52
    private boolean isWithinRestartNextLoop = false;
53
52
    JMeterContext() {
54
    JMeterContext() {
53
        clear0();
55
        clear0();
54
    }
56
    }
Lines 66-71 Link Here
66
        threadNum = 0;
68
        threadNum = 0;
67
        thread = null;
69
        thread = null;
68
        isReinitSubControllers = false;
70
        isReinitSubControllers = false;
71
        isWithinRestartNextLoop = false;
69
    }
72
    }
70
73
71
    /**
74
    /**
Lines 187-190 Link Here
187
    public boolean isReinitializingSubControllers() {
190
    public boolean isReinitializingSubControllers() {
188
        return isReinitSubControllers;
191
        return isReinitSubControllers;
189
    }
192
    }
193
194
    /**
195
     * unset flag indicating that JMeterThread has met an error.
196
     * And is restarting next loop, for example IfController 
197
     * should not evaluate Condition, See bug 50032 
198
     */
199
    public void unsetIsWithinRestartNextLoop() {
200
        if (isWithinRestartNextLoop) {
201
            isWithinRestartNextLoop = false;
202
        }
203
    }
204
    
205
    /**
206
     * @return true if JMeterThread is restarting next loop
207
     */
208
    public boolean isWithinRestartNextLoop() {
209
        return isWithinRestartNextLoop;
210
    }
211
    
212
    /**
213
     * Set flag indicating that JMeterThread has met an error.
214
     * And is restarting next loop, for example IfController 
215
     * should not evaluate Condition, See bug 50032 
216
     * @return true if it is the first one to set
217
     */
218
    public boolean setIsWithinRestartNextLoop() {
219
        if (!isWithinRestartNextLoop) {
220
            isWithinRestartNextLoop = true;
221
            return true;
222
        }
223
        return false;
224
    }
190
}
225
}
(-)src/core/org/apache/jmeter/control/GenericController.java (+5 lines)
Lines 29-34 Link Here
29
import org.apache.jmeter.samplers.Sampler;
29
import org.apache.jmeter.samplers.Sampler;
30
import org.apache.jmeter.testelement.AbstractTestElement;
30
import org.apache.jmeter.testelement.AbstractTestElement;
31
import org.apache.jmeter.testelement.TestElement;
31
import org.apache.jmeter.testelement.TestElement;
32
import org.apache.jmeter.threads.JMeterContextService;
32
import org.apache.jorphan.logging.LoggingManager;
33
import org.apache.jorphan.logging.LoggingManager;
33
import org.apache.log.Logger;
34
import org.apache.log.Logger;
34
35
Lines 361-366 Link Here
361
    }
362
    }
362
363
363
    protected void fireIterationStart() {
364
    protected void fireIterationStart() {
365
        if(JMeterContextService.getContext().isWithinRestartNextLoop())
366
        {
367
            return;
368
        }
364
        Iterator<LoopIterationListener> iter = iterationListeners.iterator();
369
        Iterator<LoopIterationListener> iter = iterationListeners.iterator();
365
        LoopIterationEvent event = new LoopIterationEvent(this, getIterCount());
370
        LoopIterationEvent event = new LoopIterationEvent(this, getIterCount());
366
        while (iter.hasNext()) {
371
        while (iter.hasNext()) {
(-)src/core/org/apache/jmeter/threads/JMeterThread.java (-6 / +11 lines)
Lines 285-297 Link Here
285
                            process_sampler(sam, null, threadContext);
285
                            process_sampler(sam, null, threadContext);
286
                            sam = controller.next();
286
                            sam = controller.next();
287
                        } else {
287
                        } else {
288
                            // Last not ok. start get the begining of the tree
288
                            try{
289
                            sam = controller.next(); // need perfom a until loop for special case (tc as parent)
289
                                JMeterContextService.getContext().setIsWithinRestartNextLoop();
290
                            while (sam != null && !sam.equals(firstSampler)) { // while the thread is NOT on the begining of the tree
290
                                // Last not ok. start get the begining of the tree
291
                                sam = controller.next();
291
                                sam = controller.next(); // need perfom a until loop for special case (tc as parent)
292
                                while (sam != null && !sam.equals(firstSampler)) { // while the thread is NOT on the begining of the tree
293
                                    sam = controller.next();
294
                                }
295
                                // At this point: begining tree, thus Last must Ok
296
                                threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
297
                            } finally {
298
                                JMeterContextService.getContext().unsetIsWithinRestartNextLoop();                                
292
                            }
299
                            }
293
                            // At this point: begining tree, thus Last must Ok
294
                            threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
295
                        }
300
                        }
296
                    } else {
301
                    } else {
297
                        process_sampler(sam, null, threadContext);
302
                        process_sampler(sam, null, threadContext);

Return to bug 51868