[smart-load-test commit] r152 - trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loa...

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 29, 2008, 7:54:07 AM10/29/08
to smart-loa...@smartitengineering.com
Author: imyousuf
Date: Wed Oct 29 04:04:01 2008
New Revision: 152

Modified:

trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/LoadTestEngineImpl.java

Log:
Fix test result formation

Previously the test case result was not being added to the test result, this
change adds it to the test result when the batch has finished.

Instance number of a test case was not unique across test case, but rather
across the batch only, this change ensures that its unique across test case.

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:04:01 2008
@@ -66,7 +66,8 @@
protected void initializeBeforeCreatedState() {
setTestInstances(new HashSet<UnitTestInstance>());
creators = new HashMap<TestCaseBatchCreator, UnitTestInstance>();
- instanceRecords = new HashMap<UnitTestInstance,
UnitTestInstanceRecord>();
+ instanceRecords =
+ new HashMap<UnitTestInstance, UnitTestInstanceRecord>();
}

public void init(String testName,
@@ -193,7 +194,8 @@
TestCaseResult caseResult =
new TestCaseResult();
caseResult.setName(instance.getName());
-
caseResult.setInstanceFactoryClassName(instance.getInstanceFactoryClassName());
+ caseResult.setInstanceFactoryClassName(instance.
+ getInstanceFactoryClassName());
final Properties testProperties = instance.getProperties();
Set<TestProperty> testPropertySet =
new HashSet<TestProperty>(testProperties.size());
@@ -208,7 +210,8 @@
testPropertySet.add(property);
}
caseResult.setTestProperties(testPropertySet);
- caseResult.setTestCaseInstanceResults(new
HashSet<TestCaseInstanceResult>());
+ caseResult.setTestCaseInstanceResults(
+ new HashSet<TestCaseInstanceResult>());
UnitTestInstanceRecord record =
new UnitTestInstanceRecord(caseResult);
instanceRecords.put(instance, record);
@@ -285,7 +288,8 @@
UnitTestInstance testInstance =
creators.get(event.getBatch().
getBatchCreator());
if (testInstance != null) {
- UnitTestInstanceRecord record =
instanceRecords.get(testInstance);
+ UnitTestInstanceRecord record = instanceRecords.get(
+ testInstance);
record.setIntanceFinished();
}
}
@@ -294,13 +298,13 @@

protected class TestCaseStateTransitionMonitor
implements TestCaseTransitionListener {
-
+
private MutableInt startedThreadCount;

public TestCaseStateTransitionMonitor() {
startedThreadCount = new MutableInt(0);
}
-
+
public void testCaseInitialized(TestCaseStateChangedEvent event) {
}

@@ -323,15 +327,19 @@
caseRecords.remove(event.getSource());
if (record != null) {
TestCase testCase = event.getSource();
- TestCaseInstanceResult instanceResult = new
TestCaseInstanceResult();
+ TestCaseInstanceResult instanceResult =
+ new TestCaseInstanceResult();
instanceResult.setStartTime(testCase.getStartTimeOfTest());
instanceResult.setEndTime(testCase.getEndTimeOfTest());
instanceResult.setEndTestCaseState(testCase.getState());
-
instanceResult.setInstanceNumber(record.getTestCaseCount());
- Map<String, String> extraInfo =
testCase.getTestCaseResultExtraInfo();
- if(extraInfo != null) {
- Set<Map.Entry<String, String>> entries =
extraInfo.entrySet();
- Set<KeyedInformation> otherInfo = new
HashSet<KeyedInformation>(entries.size());
+
instanceResult.setInstanceNumber(record.getTotalTestCaseCount());
+ Map<String, String> extraInfo = testCase.
+ getTestCaseResultExtraInfo();
+ if (extraInfo != null && !extraInfo.isEmpty()) {
+ Set<Map.Entry<String, String>> entries =
+ extraInfo.entrySet();
+ Set<KeyedInformation> otherInfo =
+ new HashSet<KeyedInformation>(entries.size());
for (Map.Entry<String, String> extraInfoEntry :
entries) {
KeyedInformation information = new
KeyedInformation();
information.setKey(extraInfoEntry.getKey());
@@ -343,8 +351,13 @@

record.getTestCaseResult().getTestCaseInstanceResults().add(
instanceResult);
record.decrementCount();
- synchronized(startedThreadCount) {
-
startedThreadCount.setValue(startedThreadCount.intValue() - 1);
+ if (record.hasUnitTestInstanceFinished()) {
+ result.getTestCaseRunResults().add(
+ record.getTestCaseResult());
+ }
+ synchronized (startedThreadCount) {
+
startedThreadCount.setValue(startedThreadCount.intValue() -
+ 1);
if (startedThreadCount.intValue() <= 0) {
executorService.submit(finishedDetector);
}
@@ -366,12 +379,14 @@
private int testCaseCount;
private TestCaseResult testCaseResult;
private boolean instanceFinished;
+ private int totalTestCount;

public UnitTestInstanceRecord(TestCaseResult result) {
if (result == null) {
throw new IllegalArgumentException();
}
testCaseCount = 0;
+ totalTestCount = 0;
testCaseResult = result;
instanceFinished = false;
}
@@ -387,6 +402,11 @@
public int getTestCaseCount() {
return testCaseCount;
}
+
+ public synchronized int getTotalTestCaseCount() {
+ totalTestCount++;
+ return totalTestCount;
+ }

public boolean isInstanceFinished() {
return instanceFinished;
@@ -431,12 +451,14 @@
}

@Override
- protected TestCaseBatchCreator
getBatchCreatorForTestInstance(UnitTestInstance instance) {
- if(instance == null) {
+ protected TestCaseBatchCreator getBatchCreatorForTestInstance(
+ UnitTestInstance instance) {
+ if (instance == null) {
return null;
}
- for (Map.Entry<TestCaseBatchCreator, UnitTestInstance> entry :
creators.entrySet()) {
- if(entry.getValue().equals(instance)) {
+ for (Map.Entry<TestCaseBatchCreator, UnitTestInstance> entry :
creators.
+ entrySet()) {
+ if (entry.getValue().equals(instance)) {
return entry.getKey();
}
}
@@ -446,7 +468,7 @@
@Override
protected Set<TestCaseBatchCreator> getAllBatchCreators() {
final Set<TestCaseBatchCreator> allCreators = creators.keySet();
- if(allCreators == null) {
+ if (allCreators == null) {
return Collections.emptySet();
}
return allCreators;
@@ -454,9 +476,10 @@

@Override
protected Map<UnitTestInstance, TestCaseBatchCreator>
getAllBatchCreatorsForTestInstances() {
- Map<UnitTestInstance, TestCaseBatchCreator> resultMap
- = new HashMap<UnitTestInstance, TestCaseBatchCreator>();
- for (Map.Entry<TestCaseBatchCreator, UnitTestInstance> entry :
creators.entrySet()) {
+ Map<UnitTestInstance, TestCaseBatchCreator> resultMap =
+ new HashMap<UnitTestInstance, TestCaseBatchCreator>();
+ for (Map.Entry<TestCaseBatchCreator, UnitTestInstance> entry :
creators.
+ entrySet()) {
resultMap.put(entry.getValue(), entry.getKey());
}
return resultMap;

Reply all
Reply to author
Forward
0 new messages