[smart-load-test commit] r148 - 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:38:04 AM10/29/08
to smart-loa...@smartitengineering.com
Author: imyousuf
Date: Wed Oct 29 04:01:28 2008
New Revision: 148

Modified:

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

Log:
Fix batch creation & created end event firing

Previously the test case creation factory's get instance op was not
supported by batch creator thus limiting the possibility of having
singleton creation factories. This change adds that first test factory class
will be searched with getInstance op and then followed by no-args
constructor and if both fails then default factory will be used.

Add NPE checking for step and delay provider initialization.

Added batch ended event firing operation.

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/management/AbstracltTestCaseBatchCreator.java
==============================================================================
---
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/management/AbstracltTestCaseBatchCreator.java
(original)
+++
trunk/smart-load-test/smart-load-test-engine-impl/src/main/java/com/smartitengineering/loadtest/engine/impl/management/AbstracltTestCaseBatchCreator.java
Wed Oct 29 04:01:28 2008
@@ -24,7 +24,10 @@
import com.smartitengineering.loadtest.engine.UnitTestInstance;
import com.smartitengineering.loadtest.engine.events.BatchEvent;
import com.smartitengineering.loadtest.engine.events.TestCaseBatchListener;
+import
com.smartitengineering.loadtest.engine.impl.DefaultTestCaseCreationFactory;
import
com.smartitengineering.loadtest.engine.management.TestCaseBatchCreator;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
@@ -60,8 +63,13 @@
throw new IllegalArgumentException();
}
try {
- testCaseCreationFactory = (TestCaseCreationFactory)
Class.forName(
- testInstance.getInstanceFactoryClassName()).newInstance();
+ if
(StringUtils.isEmpty(testInstance.getDelayTimeProviderClassName()) ||
+ StringUtils.isEmpty(testInstance.
+ getIncrementSizeProviderClassName())) {
+ throw new IllegalArgumentException(
+ "Delay and Step provider must be provided!");
+ }
+ testCaseCreationFactory =
getTestCaseCreationFactory(testInstance);
delayProvider = (DelayProvider) Class.forName(testInstance.
getDelayTimeProviderClassName()).newInstance();
delayProvider.init(testInstance.getProperties());
@@ -164,6 +172,21 @@
}
}
}
+
+ /**
+ * Fire event for the batch event generated; one of its use cases is
when
+ * batch creation has finished
+ * @param event The event to use to notify observers
+ */
+ protected void fireBatchEndedEvent(BatchEvent event) {
+ if (event != null) {
+ for (TestCaseBatchListener listener : batchListeners) {
+ listener.batchCreationEnded(event);
+ }
+ }
+ }
+
+
protected void setNextBatchAvailable(boolean nextBatchAvailable) {
this.nextBatchAvailable = nextBatchAvailable;
}
@@ -186,5 +209,35 @@

protected Set<TestCaseBatchListener> getBatchListeners() {
return batchListeners;
+ }
+
+ private TestCaseCreationFactory getTestCaseCreationFactory(
+ UnitTestInstance testInstance)
+ throws ClassNotFoundException,
+ IllegalAccessException,
+ InstantiationException {
+ final String instanceFactoryClassName =
+ testInstance.getInstanceFactoryClassName();
+ if (!StringUtils.isEmpty(instanceFactoryClassName)) {
+ try {
+ final Class<? extends TestCaseCreationFactory>
classForName =
+ (Class<? extends TestCaseCreationFactory>)
Class.forName(
+ instanceFactoryClassName);
+ try {
+ Method method =
classForName.getDeclaredMethod("getInstance");
+ if(method != null &&
Modifier.isStatic(method.getModifiers())) {
+ return (TestCaseCreationFactory)
method.invoke(classForName);
+ }
+ }
+ catch(NoSuchMethodException exception) {
+ exception.printStackTrace();
+ }
+ return classForName.newInstance();
+ }
+ catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ }
+ return DefaultTestCaseCreationFactory.getInstance();
}
}

Reply all
Reply to author
Forward
0 new messages