[smart-load-test commit] r139 - in trunk/smart-load-test: smart-load-test-engine-impl/src/main/java/com/smartitengineering...

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 29, 2008, 7:02:00 AM10/29/08
to smart-loa...@smartitengineering.com
Author: imyousuf
Date: Wed Oct 29 03:55:42 2008
New Revision: 139

Modified:

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

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/test/java/com/smartitengineering/loadtest/engine/impl/AbstractLoadTestEngineImplTest.java

trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/db/DatabasePersistenceEngineImplTest.java

trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/filesystem/xml/XMLPersistenceEngineImplTest.java

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

Log:
Add support for external batch creation observer addition

Previously it was not possible for external observers to observe batch
creation events. This change adds this support through load test engine.

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/AbstractLoadTestEngineImpl.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/AbstractLoadTestEngineImpl.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/AbstractLoadTestEngineImpl.java
Wed Oct 29 03:55:42 2008
@@ -22,6 +22,7 @@
import com.smartitengineering.loadtest.engine.UnitTestInstance;
import
com.smartitengineering.loadtest.engine.events.LoadTestEngineStateChangeListener;
import
com.smartitengineering.loadtest.engine.events.LoadTestEngineStateChangedEvent;
+import com.smartitengineering.loadtest.engine.events.TestCaseBatchListener;
import
com.smartitengineering.loadtest.engine.events.TestCaseStateChangedEvent;
import
com.smartitengineering.loadtest.engine.events.TestCaseTransitionListener;
import
com.smartitengineering.loadtest.engine.impl.management.ManagementFactory;
@@ -29,6 +30,7 @@
import
com.smartitengineering.loadtest.engine.management.TestCaseThreadManager;
import java.util.Date;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;

/**
@@ -47,6 +49,7 @@
private Set<UnitTestInstance> testInstances;
private Set<LoadTestEngineStateChangeListener> engineStateListeners;
private Set<TestCaseTransitionListener> testCaseTransitionListeners;
+ private Set<TestCaseBatchListener> batchListeners;
private Class<? extends TestCaseBatchCreator> batchCreatorClass;
private TestCaseThreadManager threadManager;
private String testName;
@@ -55,6 +58,7 @@
protected AbstractLoadTestEngineImpl() {
testCaseTransitionListeners = new
HashSet<TestCaseTransitionListener>();
engineStateListeners = new
HashSet<LoadTestEngineStateChangeListener>();
+ batchListeners = new HashSet<TestCaseBatchListener>();
initializeBeforeCreatedState();
setState(LoadTestEngine.State.CREATED);
}
@@ -140,6 +144,34 @@
testCaseTransitionListeners.remove(listener);
}

+ public void addTestCaseBatchListener(TestCaseBatchListener listener) {
+ if(listener == null) {
+ return;
+ }
+ if(!batchListeners.contains(listener)) {
+ batchListeners.add(listener);
+ final Set<TestCaseBatchCreator> allBatchCreators =
+ getAllBatchCreators();
+ for(TestCaseBatchCreator creator : allBatchCreators) {
+ creator.addBatchCreatorListener(listener);
+ }
+ }
+ }
+
+ public void removeTestCaseBatchListener(TestCaseBatchListener
listener) {
+ if(listener == null) {
+ return;
+ }
+ if(batchListeners.contains(listener)) {
+ batchListeners.remove(listener);
+ final Set<TestCaseBatchCreator> allBatchCreators =
+ getAllBatchCreators();
+ for(TestCaseBatchCreator creator : allBatchCreators) {
+ creator.removeBatchCreatrorListener(listener);
+ }
+ }
+ }
+
public void setTestCaseBatchCreator(
Class<? extends TestCaseBatchCreator> batchCreator) {
if (getState().getStateStep() >= LoadTestEngine.State.INITIALIZED.
@@ -163,8 +195,9 @@
}
try {
final Class<?> clazz = Class.forName(batchCreator);
- if(TestCaseBatchCreator.class.isAssignableFrom(clazz)) {
- batchCreatorClass = (Class<? extends
TestCaseBatchCreator>) clazz;
+ if (TestCaseBatchCreator.class.isAssignableFrom(clazz)) {
+ batchCreatorClass =
+ (Class<? extends TestCaseBatchCreator>) clazz;
}
else {
throw new ClassCastException();
@@ -300,4 +333,11 @@
protected Set<TestCaseTransitionListener>
getTestCaseTransitionListeners() {
return testCaseTransitionListeners;
}
+
+ protected abstract TestCaseBatchCreator getBatchCreatorForTestInstance(
+ final UnitTestInstance instance);
+
+ protected abstract Set<TestCaseBatchCreator> getAllBatchCreators();
+
+ protected abstract Map<UnitTestInstance, TestCaseBatchCreator>
getAllBatchCreatorsForTestInstances();
}

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:55:42 2008
@@ -408,4 +408,32 @@
}
}
}
+
+ @Override
+ protected TestCaseBatchCreator
getBatchCreatorForTestInstance(UnitTestInstance instance) {
+ if(instance == null) {
+ return null;
+ }
+ for (Map.Entry<TestCaseBatchCreator, UnitTestInstance> entry :
creators.entrySet()) {
+ if(entry.getValue().equals(instance)) {
+ return entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected Set<TestCaseBatchCreator> getAllBatchCreators() {
+ return creators.keySet();
+ }
+
+ @Override
+ protected Map<UnitTestInstance, TestCaseBatchCreator>
getAllBatchCreatorsForTestInstances() {
+ Map<UnitTestInstance, TestCaseBatchCreator> resultMap
+ = new HashMap<UnitTestInstance, TestCaseBatchCreator>();
+ for (Map.Entry<TestCaseBatchCreator, UnitTestInstance> entry :
creators.entrySet()) {
+ resultMap.put(entry.getValue(), entry.getKey());
+ }
+ return resultMap;
+ }
}

Modified:
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/AbstractLoadTestEngineImplTest.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/AbstractLoadTestEngineImplTest.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/AbstractLoadTestEngineImplTest.java
Wed Oct 29 03:55:42 2008
@@ -34,6 +34,7 @@
import com.smartitengineering.loadtest.engine.result.TestResult;
import java.util.Date;
import java.util.HashSet;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
import junit.framework.TestCase;
@@ -565,6 +566,21 @@

public TestResult getTestResult()
throws IllegalStateException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ protected TestCaseBatchCreator
getBatchCreatorForTestInstance(UnitTestInstance instance) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ protected Set<TestCaseBatchCreator> getAllBatchCreators() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ protected Map<UnitTestInstance, TestCaseBatchCreator>
getAllBatchCreatorsForTestInstances() {
throw new UnsupportedOperationException("Not supported yet.");
}
}

Modified:
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/db/DatabasePersistenceEngineImplTest.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/db/DatabasePersistenceEngineImplTest.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/db/DatabasePersistenceEngineImplTest.java
Wed Oct 29 03:55:42 2008
@@ -18,6 +18,7 @@
package com.smartitengineering.loadtest.engine.impl.persistence.db;

import com.smartitengineering.loadtest.engine.LoadTestEngine;
+import com.smartitengineering.loadtest.engine.events.TestCaseBatchListener;
import
com.smartitengineering.loadtest.engine.management.TestCaseBatchCreator;
import
com.smartitengineering.loadtest.engine.management.TestCaseThreadManager;
import
com.smartitengineering.loadtest.engine.management.TestCaseThreadPolicy;
@@ -220,6 +221,14 @@
}

public TestCaseThreadManager getTestCaseThreadManager() {
+ throw new UnsupportedOperationException("Not supported
yet.");
+ }
+
+ public void addTestCaseBatchListener(TestCaseBatchListener
listener) {
+ throw new UnsupportedOperationException("Not supported
yet.");
+ }
+
+ public void
removeTestCaseBatchListener(TestCaseBatchListener listener) {
throw new UnsupportedOperationException("Not supported
yet.");
}
};

Modified:
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/filesystem/xml/XMLPersistenceEngineImplTest.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/filesystem/xml/XMLPersistenceEngineImplTest.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine-impl/src/test/java/com/smartitengineering/loadtest/engine/impl/persistence/filesystem/xml/XMLPersistenceEngineImplTest.java
Wed Oct 29 03:55:42 2008
@@ -18,6 +18,7 @@
package
com.smartitengineering.loadtest.engine.impl.persistence.filesystem.xml;

import com.smartitengineering.loadtest.engine.LoadTestEngine;
+import com.smartitengineering.loadtest.engine.events.TestCaseBatchListener;
import
com.smartitengineering.loadtest.engine.management.TestCaseBatchCreator;
import
com.smartitengineering.loadtest.engine.management.TestCaseThreadManager;
import
com.smartitengineering.loadtest.engine.management.TestCaseThreadPolicy;
@@ -229,6 +230,14 @@
}

public TestCaseThreadManager getTestCaseThreadManager() {
+ throw new UnsupportedOperationException("Not supported
yet.");
+ }
+
+ public void addTestCaseBatchListener(TestCaseBatchListener
listener) {
+ throw new UnsupportedOperationException("Not supported
yet.");
+ }
+
+ public void
removeTestCaseBatchListener(TestCaseBatchListener listener) {
throw new UnsupportedOperationException("Not supported
yet.");
}
};

Modified:
trunk/smart-load-test/smart-load-test-engine/src/main/java/com/smartitengineering/loadtest/engine/LoadTestEngine.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine/src/main/java/com/smartitengineering/loadtest/engine/LoadTestEngine.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine/src/main/java/com/smartitengineering/loadtest/engine/LoadTestEngine.java
Wed Oct 29 03:55:42 2008
@@ -18,6 +18,7 @@
package com.smartitengineering.loadtest.engine;

import
com.smartitengineering.loadtest.engine.events.LoadTestEngineStateChangeListener;
+import com.smartitengineering.loadtest.engine.events.TestCaseBatchListener;
import
com.smartitengineering.loadtest.engine.events.TestCaseTransitionListener;
import
com.smartitengineering.loadtest.engine.management.TestCaseBatchCreator;
import
com.smartitengineering.loadtest.engine.management.TestCaseThreadManager;
@@ -162,6 +163,21 @@
TestCaseTransitionListener listener);

/**
+ * Add listener to monitor the batch creation events. It is to be
noted that
+ * since load test engine's batch listeners will be the first one's to
be
+ * added, creation of batch will mainly be on to it and rest of the
+ * listeners should limit themselves to monitor purpose only.
+ * @param listener Observer for test case batch creation
+ */
+ public void addTestCaseBatchListener(final TestCaseBatchListener
listener);
+
+ /**
+ * Removes observer from batch creators iff it was added.
+ * @param listener Observer to be removed
+ */
+ public void removeTestCaseBatchListener(final TestCaseBatchListener
listener);
+
+ /**
* Sets the batch creator class that is responsible for creating
batches of
* test case and thread tor execute. Please note that the batch creator
* must have no-args constructor.
@@ -185,7 +201,8 @@
* before init is invoked
*/
public void setTestCaseBatchCreator(String batchCreator)
- throws IllegalArgumentException, IllegalStateException;
+ throws IllegalArgumentException,
+ IllegalStateException;

/**
* Retreive the batch creator class for this test case engine. It is
to be

Reply all
Reply to author
Forward
0 new messages