You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/12/23 21:45:29 UTC
svn commit: r1775911 -
/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
Author: pmouawad
Date: Fri Dec 23 21:45:29 2016
New Revision: 1775911
URL: http://svn.apache.org/viewvc?rev=1775911&view=rev
Log:
Sonar : Fix errors, code smells and false-positive
Also use Timer.isModifiable() introduced within Bug 60018
Bugzilla Id: 60018
Modified:
jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java?rev=1775911&r1=1775910&r2=1775911&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java Fri Dec 23 21:45:29 2016
@@ -53,6 +53,7 @@ import org.apache.jorphan.collections.Ha
import org.apache.jorphan.collections.HashTreeTraverser;
import org.apache.jorphan.collections.SearchByClass;
import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JMeterError;
import org.apache.jorphan.util.JMeterStopTestException;
import org.apache.jorphan.util.JMeterStopTestNowException;
import org.apache.jorphan.util.JMeterStopThreadException;
@@ -83,6 +84,8 @@ public class JMeterThread implements Run
*/
private static final float ONE_AS_FLOAT = 1.0f;
+ private static final boolean APPLY_TIMER_FACTOR = Float.compare(TIMER_FACTOR,ONE_AS_FLOAT) != 0;
+
private final Controller threadGroupLoopController;
private final HashTree testTree;
@@ -216,7 +219,7 @@ public class JMeterThread implements Run
private void stopSchedulerIfNeeded() {
long now = System.currentTimeMillis();
long delay = now - endTime;
- if ((delay >= 0)) {
+ if (delay >= 0) {
running = false;
log.info("Stopping because end time detected by thread: " + threadName);
}
@@ -227,7 +230,7 @@ public class JMeterThread implements Run
*
*/
private void startScheduler() {
- long delay = (startTime - System.currentTimeMillis());
+ long delay = startTime - System.currentTimeMillis();
delayBy(delay, "startScheduler");
}
@@ -256,11 +259,8 @@ public class JMeterThread implements Run
|| (onErrorStartNextLoop
&& !TRUE.equals(threadContext.getVariables().get(LAST_SAMPLE_OK))))
{
- if(log.isDebugEnabled()) {
- if(onErrorStartNextLoop
- && !threadContext.isRestartNextLoop()) {
+ if(log.isDebugEnabled() && onErrorStartNextLoop && !threadContext.isRestartNextLoop()) {
log.debug("StartNextLoop option is on, Last sample failed, starting next loop");
- }
}
triggerEndOfLoopOnParentControllers(sam, threadContext);
@@ -280,21 +280,19 @@ public class JMeterThread implements Run
}
}
// Might be found by contoller.next()
- catch (JMeterStopTestException e) {
- log.info("Stopping Test: " + e.toString());
+ catch (JMeterStopTestException e) { // NOSONAR
+ log.info("Stopping Test: " + e.toString());
stopTest();
}
- catch (JMeterStopTestNowException e) {
+ catch (JMeterStopTestNowException e) { // NOSONAR
log.info("Stopping Test Now: " + e.toString());
stopTestNow();
- } catch (JMeterStopThreadException e) {
+ } catch (JMeterStopThreadException e) { // NOSONAR
log.info("Stop Thread seen for thread " + getThreadName()+", reason:"+ e.toString());
- } catch (Exception e) {
+ } catch (Exception | JMeterError e) {
log.error("Test failed!", e);
} catch (ThreadDeath e) {
throw e; // Must not ignore this one
- } catch (Error e) {// Make sure errors are output to the log file
- log.error("Test failed!", e);
} finally {
currentSampler = null; // prevent any further interrupts
try {
@@ -422,10 +420,10 @@ public class JMeterThread implements Run
// checks the scheduler to stop the iteration
stopSchedulerIfNeeded();
}
- } catch (JMeterStopTestException e) {
+ } catch (JMeterStopTestException e) { // NOSONAR
log.info("Stopping Test: " + e.toString());
stopTest();
- } catch (JMeterStopThreadException e) {
+ } catch (JMeterStopThreadException e) { // NOSONAR
log.info("Stopping Thread: " + e.toString());
stopThread();
} catch (Exception e) {
@@ -466,17 +464,17 @@ public class JMeterThread implements Run
// Perform the actual sample
currentSampler = sampler;
if(!sampleMonitors.isEmpty()) {
- for(SampleMonitor monitor : sampleMonitors) {
- monitor.sampleStarting(sampler);
+ for(SampleMonitor sampleMonitor : sampleMonitors) {
+ sampleMonitor.sampleStarting(sampler);
}
}
SampleResult result = null;
try {
- result = sampler.sample(null); // TODO: remove this useless Entry parameter
+ result = sampler.sample(null);
} finally {
if(!sampleMonitors.isEmpty()) {
- for(SampleMonitor monitor : sampleMonitors) {
- monitor.sampleEnded(sampler);
+ for(SampleMonitor sampleMonitor : sampleMonitors) {
+ sampleMonitor.sampleEnded(sampler);
}
}
}
@@ -665,10 +663,12 @@ public class JMeterThread implements Run
@Override
public void subtractNode() {
+ // NOOP
}
@Override
public void processPath() {
+ // NOOP
}
}
@@ -695,7 +695,7 @@ public class JMeterThread implements Run
log.warn("No operation pending");
}
return found;
- } catch (Exception e) {
+ } catch (Exception e) { // NOSONAR
log.warn("Caught Exception interrupting sampler: "+e.toString());
}
} else if (samp != null){
@@ -767,7 +767,7 @@ public class JMeterThread implements Run
assertionResult = assertion.getResult(result);
} catch (ThreadDeath e) {
throw e;
- } catch (Error e) {
+ } catch (JMeterError e) {
log.error("Error processing Assertion ",e);
assertionResult = new AssertionResult("Assertion failed! See log file.");
assertionResult.setError(true);
@@ -804,10 +804,8 @@ public class JMeterThread implements Run
for (Timer timer : timers) {
TestBeanHelper.prepare((TestElement) timer);
long delay = timer.delay();
- if(TIMER_FACTOR != ONE_AS_FLOAT &&
- // TODO Improve this with Optional methods when migration to Java8 is completed
- ((timer instanceof ModifiableTimer)
- && ((ModifiableTimer)timer).isModifiable())) {
+ if(APPLY_TIMER_FACTOR &&
+ timer.isModifiable()) {
if(log.isDebugEnabled()) {
log.debug("Applying TIMER_FACTOR:"
+TIMER_FACTOR + " on timer:"
@@ -831,6 +829,7 @@ public class JMeterThread implements Run
TimeUnit.MILLISECONDS.sleep(totalDelay);
} catch (InterruptedException e) {
log.warn("The delay timer was interrupted - probably did not wait as long as intended.");
+ Thread.currentThread().interrupt();
}
}
}
@@ -877,7 +876,7 @@ public class JMeterThread implements Run
if (delay > 0) {
long start = System.currentTimeMillis();
long end = start + delay;
- long now=0;
+ long now;
long pause = RAMPUP_GRANULARITY;
while(running && (now = System.currentTimeMillis()) < end) {
long togo = end - now;
@@ -890,6 +889,7 @@ public class JMeterThread implements Run
if (running) { // NOSONAR Don't bother reporting stop test interruptions
log.warn(type+" delay for "+threadName+" was interrupted. Waited "+(now - start)+" milli-seconds out of "+delay);
}
+ Thread.currentThread().interrupt();
break;
}
}