Modified:
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/LoadTestEngineImpl.java
Log:
Fix FINISHED state detection
Firstly, fixed the bug that instance finished in instance record is never
false.
Secondly, add currently active total thread count and check for FINISHED
state when this count is zero as that is the most probable scenario.
Signed-off-by: Imran M Yousuf <imyo...@smartitengineering.com>
Modified:
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/LoadTestEngineImpl.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/LoadTestEngineImpl.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/LoadTestEngineImpl.java
Wed Oct 29 04:02:06 2008
@@ -42,6 +42,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
+import org.apache.commons.lang.mutable.MutableInt;
/**
* Default implementation of the LoadTestEngine
@@ -286,7 +287,6 @@
if (testInstance != null) {
UnitTestInstanceRecord record =
instanceRecords.get(testInstance);
record.setIntanceFinished();
- executorService.submit(finishedDetector);
}
}
}
@@ -294,11 +294,20 @@
protected class TestCaseStateTransitionMonitor
implements TestCaseTransitionListener {
+
+ private MutableInt startedThreadCount;
+ public TestCaseStateTransitionMonitor() {
+ startedThreadCount = new MutableInt(0);
+ }
+
public void testCaseInitialized(TestCaseStateChangedEvent event) {
}
public void testCaseStarted(TestCaseStateChangedEvent event) {
+ synchronized (startedThreadCount) {
+ startedThreadCount.setValue(startedThreadCount.intValue()
+ 1);
+ }
}
public void testCaseFinished(TestCaseStateChangedEvent event) {
@@ -334,8 +343,11 @@
record.getTestCaseResult().getTestCaseInstanceResults().add(
instanceResult);
record.decrementCount();
- if (record.hasUnitTestInstanceFinished()) {
- executorService.submit(finishedDetector);
+ synchronized(startedThreadCount) {
+
startedThreadCount.setValue(startedThreadCount.intValue() - 1);
+ if (startedThreadCount.intValue() <= 0) {
+ executorService.submit(finishedDetector);
+ }
}
}
}
@@ -361,7 +373,7 @@
}
testCaseCount = 0;
testCaseResult = result;
- instanceFinished = true;
+ instanceFinished = false;
}
public synchronized void incrementCount() {