[smart-load-test commit] r137 - 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, 6:53:58 AM10/29/08
to smart-loa...@smartitengineering.com
Author: imyousuf
Date: Wed Oct 29 03:53:33 2008
New Revision: 137

Modified:

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

Log:
Reorganize to make it clearer and easy to read

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 03:53:33 2008
@@ -94,57 +94,10 @@
}
}
}
-
- engineBatchListener = new EngineBatchListener();
- semaphore = new Semaphore(getPermits());
- setTestName(testName);
-
- getTestInstances().addAll(testInstances);
- transitionListener = new TestCaseStateTransitionMonitor();
- addTestCaseTransitionListener(transitionListener);
- caseStateChangeListener = new TestCaseStateListenerImpl();
- caseRecords = new HashMap<TestCase, UnitTestInstanceRecord>();
-
- finishedDetector = new EngineJobFinishedDetector();
- executorService = Executors.newSingleThreadExecutor();
-
- result = new TestResult();
- result.setTestName(testName);
- HashSet<TestCaseResult> resultSet = new HashSet<TestCaseResult>();
- result.setTestCaseRunResults(resultSet);
- for (UnitTestInstance instance : testInstances) {
- try {
- TestCaseBatchCreator creator =
getTestCaseBatchCreatorInstance();
- creator.init(instance);
- creator.addBatchCreatorListener(engineBatchListener);
- creators.put(creator, instance);
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- TestCaseResult caseResult = new TestCaseResult();
- caseResult.setName(instance.getName());
- caseResult.setInstanceFactoryClassName(instance.
- getInstanceFactoryClassName());
- final Properties testProperties = instance.getProperties();
- Set<TestProperty> testPropertySet = new HashSet<TestProperty>(
- testProperties.size());
- final Iterator<Object> keySetIterator =
testProperties.keySet().
- iterator();
- while (keySetIterator.hasNext()) {
- TestProperty property = new TestProperty();
- final String key = keySetIterator.next().toString();
- property.setKey(key);
- property.setValue(testProperties.getProperty(key));
- testPropertySet.add(property);
- }
- caseResult.setTestProperties(testPropertySet);
- caseResult.setTestCaseInstanceResults(
- new HashSet<TestCaseInstanceResult>());
- UnitTestInstanceRecord record = new UnitTestInstanceRecord(
- caseResult);
- instances.put(instance, record);
- }
+ initializeInternals(testName);
+ initializeFinishDetector();
+ initializeResult(testName);
+ initializeTestInstances(testInstances);

setState(State.INITIALIZED);
}
@@ -183,6 +136,84 @@
semaphore = null;
engineBatchListener = null;
finishedDetector = null;
+ }
+
+ private void initializeFinishDetector() {
+
+ finishedDetector =
+ new EngineJobFinishedDetector();
+ executorService =
+ Executors.newSingleThreadExecutor();
+ }
+
+ private void initializeInternals(String testName) {
+
+ engineBatchListener =
+ new EngineBatchListener();
+ semaphore = new Semaphore(getPermits());
+ transitionListener =
+ new TestCaseStateTransitionMonitor();
+ caseStateChangeListener =
+ new TestCaseStateListenerImpl();
+ caseRecords =
+ new HashMap<TestCase, UnitTestInstanceRecord>();
+ setTestName(testName);
+ addTestCaseTransitionListener(transitionListener);
+ }
+
+ private void initializeResult(String testName) {
+
+ result = new TestResult();
+ result.setTestName(testName);
+ HashSet<TestCaseResult> resultSet =
+ new HashSet<TestCaseResult>();
+ result.setTestCaseRunResults(resultSet);
+ }
+
+ private void initializeTestInstances(Set<UnitTestInstance>
testInstances) {
+
+ getTestInstances().addAll(testInstances);
+ for (UnitTestInstance instance : getTestInstances()) {
+ registerToBatchCreator(instance);
+ createTestCaseResult(instance);
+ }
+ }
+
+ private void createTestCaseResult(UnitTestInstance instance) {
+ TestCaseResult caseResult =
+ new TestCaseResult();
+ caseResult.setName(instance.getName());
+
caseResult.setInstanceFactoryClassName(instance.getInstanceFactoryClassName());
+ final Properties testProperties = instance.getProperties();
+ Set<TestProperty> testPropertySet =
+ new HashSet<TestProperty>(testProperties.size());
+ final Iterator<Object> keySetIterator =
+ testProperties.keySet().iterator();
+ while (keySetIterator.hasNext()) {
+ TestProperty property =
+ new TestProperty();
+ final String key = keySetIterator.next().toString();
+ property.setKey(key);
+ property.setValue(testProperties.getProperty(key));
+ testPropertySet.add(property);
+ }
+ caseResult.setTestProperties(testPropertySet);
+ caseResult.setTestCaseInstanceResults(new
HashSet<TestCaseInstanceResult>());
+ UnitTestInstanceRecord record =
+ new UnitTestInstanceRecord(caseResult);
+ instances.put(instance, record);
+ }
+
+ private void registerToBatchCreator(UnitTestInstance instance) {
+ try {
+ TestCaseBatchCreator creator =
getTestCaseBatchCreatorInstance();
+ creator.init(instance);
+ creator.addBatchCreatorListener(engineBatchListener);
+ creators.put(creator, instance);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
}

protected class EngineBatchListener

Reply all
Reply to author
Forward
0 new messages