You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2006/05/22 07:13:14 UTC
svn commit: r408572 - in /incubator/servicemix/trunk/servicemix-beanflow: ./
src/main/java/org/apache/servicemix/beanflow/
src/main/java/org/apache/servicemix/beanflow/support/
src/main/java/org/apache/servicemix/beanflow/util/
src/test/java/org/apache...
Author: jstrachan
Date: Sun May 21 22:13:12 2006
New Revision: 408572
URL: http://svn.apache.org/viewvc?rev=408572&view=rev
Log:
* allow workflow steps to be specified using enumerations rather than strings
* some refactoring and tidying of code
* added some utility helper classes for writing concurrent unit tests
Added:
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ActivityTestSupport.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelBean.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelTestCase.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflow.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflowTest.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleStringWorkflow.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflow.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflowTest.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/StringWorkflowTest.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanTest.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanWithSyncs.java (with props)
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelTest.java (with props)
Removed:
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/FlowTestSupport.java
Modified:
incubator/servicemix/trunk/servicemix-beanflow/pom.xml
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AbstractActivity.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Activity.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ActivityHelper.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AsynchronousActivity.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/JoinAll.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ParallelActivity.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ProxyActivity.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Workflow.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/Interpreter.java
incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/ReflectionInterpreter.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/CustomJoinConditionTest.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleParallelBean.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleWorkflow.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinAllTest.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinQuorumTest.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ParallelActivityTest.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java
incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/WorkflowTest.java
Modified: incubator/servicemix/trunk/servicemix-beanflow/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/pom.xml?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/pom.xml Sun May 21 22:13:12 2006
@@ -15,13 +15,13 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!-- $Rev: 356052 $ $Date: 2005-12-11 14:41:20 -0800 (dim., 11 déc. 2005) $ -->
+<!-- $Rev: 356052 $ $Date: 2005-12-11 14:41:20 -0800 (dim., 11 dâ©c. 2005) $ -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
-
+
<parent>
- <groupId>org.apache.servicemix</groupId>
+ <groupId>org.apache.servicemix</groupId>
<artifactId>servicemix</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
@@ -43,19 +43,21 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
- <scope>test</scope>
+<!--
+ <scope>optional</scope>
+ -->
</dependency>
</dependencies>
<build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AbstractActivity.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AbstractActivity.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AbstractActivity.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AbstractActivity.java Sun May 21 22:13:12 2006
@@ -19,6 +19,8 @@
import org.apache.servicemix.beanflow.support.Introspector;
import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.FutureTask;
/**
* A useful base class which allows simple bean activities to be written easily.
@@ -50,7 +52,7 @@
* Stops the activity
*/
public void stop() {
- if (state.compareAndSet(Transitions.Started, Transitions.Stopping)) {
+ if (! state.isAny(Transitions.Stopped, Transitions.Failed)) {
state.set(Transitions.Stopped);
doStop();
}
@@ -60,11 +62,9 @@
* Stops the activity with a failed state, giving the reason for the failure
*/
public void fail(String reason) {
- if (state.compareAndSet(Transitions.Started, Transitions.Failed)) {
- this.failedReason = reason;
- state.set(Transitions.Failed);
- doStop();
- }
+ this.failedReason = reason;
+ state.set(Transitions.Failed);
+ doStop();
}
/**
@@ -131,6 +131,26 @@
}
}
});
+ }
+
+ /**
+ * A helper method to block the calling thread until the activity completes
+ */
+ public void join() {
+ while (!isStopped()) {
+ final CountDownLatch latch = new CountDownLatch(1);
+ onStop(new Runnable() {
+ public void run() {
+ latch.countDown();
+ }
+ });
+ try {
+ latch.await();
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
}
// Implementation methods
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Activity.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Activity.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Activity.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Activity.java Sun May 21 22:13:12 2006
@@ -89,4 +89,20 @@
* Returns the exception which caused the failure
*/
public Throwable getFailedException();
+
+ /**
+ * A helper method to add a task to fire when the activity is completed
+ */
+ public void onStop(Runnable runnable);
+
+ /**
+ * A helper method to add a task to fire when the activity fails
+ */
+ public void onFailure(Runnable runnable);
+
+ /**
+ * A helper method to block the calling thread until the activity completes. Behaves
+ * similar to {@link Thread#join()}
+ */
+ public void join();
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ActivityHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ActivityHelper.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ActivityHelper.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ActivityHelper.java Sun May 21 22:13:12 2006
@@ -59,4 +59,4 @@
activity.stop();
}
}
-}
+}
\ No newline at end of file
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AsynchronousActivity.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AsynchronousActivity.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AsynchronousActivity.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/AsynchronousActivity.java Sun May 21 22:13:12 2006
@@ -40,7 +40,9 @@
public void run() {
try {
runnable.run();
+ //System.out.println("About to call stop on: " + this);
stop();
+ //System.out.println("Activity completed: " + this + " status now: " + getState());
}
catch (Throwable e) {
fail("Failed to run task: " + runnable + ". Cause: " + e, e);
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/JoinAll.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/JoinAll.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/JoinAll.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/JoinAll.java Sun May 21 22:13:12 2006
@@ -58,6 +58,7 @@
* number of child activities stopped and the number of failed activities
*/
protected void onChildStateChange(int childCount, int stoppedCount, int failedCount) {
+ //System.out.println("This: " + this + " child: " + childCount + " stopped: " + stoppedCount + " failed: " + failedCount);
if (failFast && failedCount > 0) {
fail("" + failedCount + " child workactivities have failed");
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ParallelActivity.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ParallelActivity.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ParallelActivity.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ParallelActivity.java Sun May 21 22:13:12 2006
@@ -22,8 +22,10 @@
import java.util.List;
import java.util.Timer;
import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -35,6 +37,8 @@
private JoinSupport joinActivity;
private List<CallableActivity<T>> activities;
private AtomicBoolean started = new AtomicBoolean();
+ private Object lock = new Object();
+ private CountDownLatch countDownLatch;
/**
* A helper method to create a new {@link ParallelActivity} which invokes a
@@ -51,8 +55,7 @@
*/
@SuppressWarnings("unchecked")
public static ParallelActivity newParallelMethodActivity(JoinSupport join, Executor executor, Object bean) {
- FindCallableMethods factory = new FindCallableMethods(bean);
- return new ParallelActivity(join, executor, factory);
+ return new ParallelActivity(join, executor, new FindCallableMethods(bean));
}
public ParallelActivity(JoinSupport activity, Executor executor, CallablesFactory<T> callablesFactory) {
@@ -76,22 +79,75 @@
public List<Future<T>> getFutures() {
List<Future<T>> answer = new ArrayList<Future<T>>();
- for (CallableActivity<T> activity : activities) {
- answer.add(activity.getFuture());
+ synchronized (lock) {
+ for (CallableActivity<T> activity : activities) {
+ answer.add(activity.getFuture());
+ }
}
return answer;
}
@Override
public void start() {
- super.start();
init();
+ super.start();
}
@Override
public void startWithTimeout(Timer timer, long timeout) {
- super.startWithTimeout(timer, timeout);
init();
+ super.startWithTimeout(timer, timeout);
+ }
+
+ public void sync() {
+ try {
+ CountDownLatch latch = getCountDownLatch();
+ latch.countDown();
+ latch.await();
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ finally {
+ resetCountDownLatch();
+ }
+ }
+
+ public boolean sync(long millis) {
+ try {
+ CountDownLatch latch = getCountDownLatch();
+ latch.countDown();
+ return latch.await(millis, TimeUnit.MILLISECONDS);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ finally {
+ resetCountDownLatch();
+ }
+ }
+
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ protected void resetCountDownLatch() {
+ synchronized (lock) {
+ if (countDownLatch != null && countDownLatch.getCount() == 0) {
+ countDownLatch = null;
+ }
+ }
+
+ }
+
+ protected CountDownLatch getCountDownLatch() {
+ synchronized (lock) {
+ int count = activities.size();
+ if (countDownLatch == null) {
+ countDownLatch = new CountDownLatch(count);
+ }
+ return countDownLatch;
+ }
}
private void init() {
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ProxyActivity.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ProxyActivity.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ProxyActivity.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/ProxyActivity.java Sun May 21 22:13:12 2006
@@ -67,6 +67,18 @@
getProxy().stop();
}
+ public void onFailure(Runnable runnable) {
+ getProxy().onFailure(runnable);
+ }
+
+ public void onStop(Runnable runnable) {
+ getProxy().onStop(runnable);
+ }
+
+ public void join() {
+ getProxy().join();
+ }
+
protected Activity getProxy() {
return proxy;
}
@@ -74,5 +86,4 @@
protected void setProxy(Activity proxy) {
this.proxy = proxy;
}
-
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Workflow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Workflow.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Workflow.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Workflow.java Sun May 21 22:13:12 2006
@@ -20,6 +20,8 @@
import org.apache.servicemix.beanflow.support.Interpreter;
import org.apache.servicemix.beanflow.support.ReflectionInterpreter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Timer;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -31,36 +33,42 @@
*
* @version $Revision: $
*/
-public class Workflow extends JoinSupport {
+public class Workflow<T> extends JoinSupport {
private static final Log log = LogFactory.getLog(Workflow.class);
- public static final String DEFAULT_START_STEP = "startStep";
+ private static final Class[] NO_PARAMETER_TYPES = {};
+ private static final Object[] NO_PARAMETER_VALUES = {};
private Executor executor;
private Interpreter interpreter;
- private State<String> step;
- private String nextStep;
+ private State<T> step;
+ private T nextStep;
private Timer timer = new Timer();
private AtomicBoolean suspended = new AtomicBoolean();
- public Workflow() {
- this(Executors.newSingleThreadExecutor(), DEFAULT_START_STEP);
+ public Workflow(T firstStep) {
+ this(Executors.newSingleThreadExecutor(), firstStep);
}
- public Workflow(Executor executor, String firstStep) {
- this(executor, new ReflectionInterpreter(), new DefaultState<String>(firstStep));
+ public Workflow(Executor executor, T firstStep) {
+ this(executor, new ReflectionInterpreter(), new DefaultState<T>(firstStep));
}
- public Workflow(Executor executor, Interpreter interpreter, State<String> step) {
+ public Workflow(Executor executor, Interpreter interpreter, State<T> step) {
this.executor = executor;
this.interpreter = interpreter;
this.step = step;
+
+ T firstStep = step.get();
+ if (firstStep instanceof Enum) {
+ validateStepsExist(firstStep.getClass());
+ }
}
/**
* Sets the next step to be executed when the current step completes
*/
- public void goTo(String stepName) {
+ public void goTo(T stepName) {
this.nextStep = stepName;
suspended.set(false);
nextStep();
@@ -73,9 +81,11 @@
}
log.debug("About to execute step: " + nextStep);
- interpreter.executeStep(nextStep, this);
+ if (nextStep != null) {
+ interpreter.executeStep(nextStep.toString(), this);
- nextStep();
+ nextStep();
+ }
}
}
@@ -112,7 +122,7 @@
* Creates a join such that when all of the activities are completed the
* given step will be executed
*/
- public void joinAll(final String joinedStep, long timeout, Activity... activities) {
+ public void joinAll(T joinedStep, long timeout, Activity... activities) {
JoinAll joinFlow = new JoinAll(activities);
join(joinFlow, joinedStep, timeout);
}
@@ -122,7 +132,7 @@
* specified joinedStep when the join takes place using the given timeout to
* the join
*/
- public void join(JoinSupport joinFlow, final String joinedStep, long timeout) {
+ public void join(JoinSupport joinFlow, T joinedStep, long timeout) {
// start the join activity and register the timeout
fork(timeout, joinFlow);
@@ -149,7 +159,7 @@
/**
* Creates a task which will move to the given step
*/
- public Runnable createGoToStepTask(final String joinedStep) {
+ public Runnable createGoToStepTask(final T joinedStep) {
return new Runnable() {
public void run() {
@@ -170,5 +180,22 @@
@Override
protected void onChildStateChange(int childCount, int stoppedCount, int failedCount) {
+ }
+
+ /**
+ * lets validate the steps exist
+ */
+ protected void validateStepsExist(Class enumType) {
+ Object[] values = null;
+ try {
+ Method method = enumType.getMethod("values", NO_PARAMETER_TYPES);
+ values = (Object[]) method.invoke(null, NO_PARAMETER_VALUES);
+ }
+ catch (Exception e) {
+ fail("Cannot get the values of the enumeration: " + enumType.getName(), e);
+ }
+ if (values != null) {
+ interpreter.validateStepsExist(values, this);
+ }
}
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/Interpreter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/Interpreter.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/Interpreter.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/Interpreter.java Sun May 21 22:13:12 2006
@@ -28,4 +28,10 @@
*/
void executeStep(String nextStep, Workflow workflow);
+ /**
+ * Validates that all the available step values (enumeration values) are
+ * available on the given workflow
+ */
+ void validateStepsExist(Object[] stepValues, Workflow workflow);
+
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/ReflectionInterpreter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/ReflectionInterpreter.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/ReflectionInterpreter.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/support/ReflectionInterpreter.java Sun May 21 22:13:12 2006
@@ -42,9 +42,25 @@
}
}
+ public void validateStepsExist(Object[] stepValues, Workflow workflow) {
+ Class<? extends Workflow> type = workflow.getClass();
+ for (int i = 0; i < stepValues.length; i++) {
+ Object value = stepValues[i];
+ String step = value.toString();
+ try {
+ type.getMethod(step, NO_TYPE_ARGUMENTS);
+ }
+ catch (Exception e) {
+ workflow.fail("No " + step + "() method is available in class: " + type.getName()
+ + " so unable to bind the code to the enumeration of steps", e);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
protected void handleStepResult(String step, Workflow workflow, Object result) {
- if (result instanceof String) {
- workflow.goTo((String) result);
+ if (result != null) {
+ workflow.goTo(result);
}
else {
workflow.suspend();
Added: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ActivityTestSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ActivityTestSupport.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ActivityTestSupport.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ActivityTestSupport.java Sun May 21 22:13:12 2006
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.Activity;
+import org.apache.servicemix.beanflow.Activity.Transitions;
+
+import java.util.Timer;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @version $Revision: $
+ */
+public abstract class ActivityTestSupport extends TestCase {
+
+ private static final Log log = LogFactory.getLog(ActivityTestSupport.class);
+
+ protected Timer timer = new Timer();
+ protected long timeout = 500L;
+
+ protected void assertStarted(Activity activity) throws Exception {
+ assertNotFailed(activity);
+ assertEquals("Transition", Transitions.Started, activity.getState().get());
+ }
+
+ protected void assertStopped(Activity activity) throws Exception {
+ assertNotFailed(activity);
+ assertEquals("Transition", Transitions.Stopped, activity.getState().get());
+
+ assertTrue("Flow should be stopped but is: " + activity.getState().get(), activity.isStopped());
+ assertTrue("Flow should not have failed", !activity.isFailed());
+ }
+
+ protected void assertNotFailed(Activity activity) throws Exception {
+ assertTrue("Should not have failed: " + activity.getFailedReason() + " exception: "
+ + activity.getFailedException(), !activity.isFailed());
+
+ Throwable failedException = activity.getFailedException();
+ if (failedException != null) {
+ if (failedException instanceof Exception) {
+ throw (Exception) failedException;
+ }
+ else {
+ throw new RuntimeException(failedException);
+ }
+ }
+ }
+
+ protected void assertFailed(Activity activity) {
+ assertEquals("Transition", Transitions.Failed, activity.getState().get());
+
+ assertTrue("Flow should be stopped but is: " + activity.getState().get(), activity.isStopped());
+ assertTrue("Flow should have failed", activity.isFailed());
+
+ log.info("The activity failed due to: " + activity.getFailedReason());
+ }
+
+ protected void startActivity(Activity activity, long timeout) throws Exception {
+ assertTrue("activity should not be stopped", !activity.isStopped());
+ assertTrue("activity should not have failed", !activity.isFailed());
+ assertEquals("Transition", Transitions.Initialised, activity.getState().get());
+
+ activity.startWithTimeout(timer, timeout);
+ assertStarted(activity);
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ActivityTestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelBean.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelBean.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelBean.java Sun May 21 22:13:12 2006
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow.util;
+
+import org.apache.servicemix.beanflow.JoinAll;
+import org.apache.servicemix.beanflow.JoinSupport;
+import org.apache.servicemix.beanflow.ParallelActivity;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ * Represents a POJO which contains {@link Parallel} annotations to specify the
+ * methods to be executed concurrently. Each parallel thread can then
+ * synchronize with the group using the {@link #sync()} or {@link #sync(long)}
+ * methods
+ *
+ * @version $Revision: $
+ * @param <T>
+ */
+public abstract class ParallelBean {
+
+ private ParallelActivity activity;
+ private Executor executor;
+ private JoinSupport join;
+ private int maxThreadPoolSize = 20;
+
+ public ParallelBean() {
+ }
+
+ public ParallelBean(Executor executor) {
+ this.executor = executor;
+ }
+
+ public ParallelBean(Executor executor, JoinSupport join) {
+ this.executor = executor;
+ this.join = join;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void start() {
+ getActivity().start();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void sync() {
+ getActivity().sync();
+ }
+
+ public boolean sync(long millis) {
+ return getActivity().sync(millis);
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+
+ public ParallelActivity getActivity() {
+ if (activity == null) {
+ activity = createActivity();
+ }
+ return activity;
+ }
+
+ public Executor getExecutor() {
+ if (executor == null) {
+ executor = createExecutor();
+ }
+ return executor;
+ }
+
+ public void setExecutor(Executor executor) {
+ this.executor = executor;
+ }
+
+ public JoinSupport getJoin() {
+ if (join == null) {
+ join = createJoin();
+ }
+ return join;
+ }
+
+ public void setJoin(JoinSupport join) {
+ this.join = join;
+ }
+
+ // Factory methods
+ // -------------------------------------------------------------------------
+ protected ParallelActivity createActivity() {
+ return ParallelActivity.newParallelMethodActivity(getJoin(), getExecutor(), this);
+ }
+
+ protected Executor createExecutor() {
+ return Executors.newFixedThreadPool(maxThreadPoolSize);
+ }
+
+ protected JoinSupport createJoin() {
+ return new JoinAll();
+ }
+
+ protected void sleep(int timeout) {
+ try {
+ Thread.sleep(3000);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelTestCase.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelTestCase.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelTestCase.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelTestCase.java Sun May 21 22:13:12 2006
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow.util;
+
+import org.apache.servicemix.beanflow.JoinAll;
+import org.apache.servicemix.beanflow.JoinSupport;
+import org.apache.servicemix.beanflow.ParallelActivity;
+
+import java.util.Timer;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+import junit.framework.TestCase;
+
+/**
+ * A JUnit test case which supports the {@link Parallel} annotations for running
+ * concurrent threads in a test case along with the methods {@link #sync()} or
+ * the {@link #sync(long)} which provide a simple cross-thread synchronisation
+ * mechanism
+ *
+ * @version $Revision: $
+ */
+public abstract class ParallelTestCase extends ActivityTestSupport {
+ private ParallelActivity activity;
+ private Executor executor;
+ private JoinSupport join;
+ private int maxThreadPoolSize = 20;
+ private long testTimeout = 10000;
+
+ @SuppressWarnings("unchecked")
+ public void testParallelMethods() throws Exception {
+ startActivity(getActivity(), testTimeout);
+ getActivity().join();
+ assertStopped(getActivity());
+ }
+
+ /**
+ * Blocks the parallel thread until all the other parallel threads have
+ * reached the same synchronisation point before continuing.
+ */
+ @SuppressWarnings("unchecked")
+ public void sync() {
+ getActivity().sync();
+ }
+
+ /**
+ * Blocks up to the give timeout value in the parallel thread until all the
+ * other parallel threads have reached the same synchronisation point before
+ * continuing.
+ *
+ * @return true if the sync completed otherwise false indicating a timeout
+ */
+ public boolean sync(long millis) {
+ return getActivity().sync(millis);
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+
+ public ParallelActivity getActivity() {
+ if (activity == null) {
+ activity = createActivity();
+ }
+ return activity;
+ }
+
+ public Executor getExecutor() {
+ if (executor == null) {
+ executor = createExecutor();
+ }
+ return executor;
+ }
+
+ public void setExecutor(Executor executor) {
+ this.executor = executor;
+ }
+
+ public JoinSupport getJoin() {
+ if (join == null) {
+ join = createJoin();
+ }
+ return join;
+ }
+
+ public void setJoin(JoinSupport join) {
+ this.join = join;
+ }
+
+ public int getMaxThreadPoolSize() {
+ return maxThreadPoolSize;
+ }
+
+ public void setMaxThreadPoolSize(int maxThreadPoolSize) {
+ this.maxThreadPoolSize = maxThreadPoolSize;
+ }
+
+ // Factory methods
+ // -------------------------------------------------------------------------
+ protected ParallelActivity createActivity() {
+ return ParallelActivity.newParallelMethodActivity(getJoin(), getExecutor(), this);
+ }
+
+ protected Executor createExecutor() {
+ return Executors.newFixedThreadPool(maxThreadPoolSize);
+ }
+
+ protected JoinSupport createJoin() {
+ return new JoinAll();
+ }
+
+ protected void sleep(int timeout) {
+ try {
+ Thread.sleep(3000);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/util/ParallelTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflow.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflow.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflow.java Sun May 21 22:13:12 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow;
+
+
+/**
+ * A workflow which cannot be used as the step enumerations don't match with method names
+ *
+ * @version $Revision: $
+ */
+public class BadWorkflow extends Workflow<BadWorkflow.Step> {
+
+ public static enum Step {
+ startStep, fooStep, doesNotExistStep
+ };
+
+ public BadWorkflow() {
+ super(Step.startStep);
+ }
+
+ // Workflow steps
+ // -------------------------------------------------------------------------
+
+ public Step startStep() {
+ return Step.fooStep;
+ }
+
+ public Step fooStep() {
+ return Step.doesNotExistStep;
+ }
+}
+// END SNIPPET: workflow
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflow.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflowTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflowTest.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflowTest.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflowTest.java Sun May 21 22:13:12 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
+/**
+ *
+ * @version $Revision: $
+ */
+public class BadWorkflowTest extends ActivityTestSupport {
+
+ private static final Log log = LogFactory.getLog(BadWorkflowTest.class);
+
+ public void testWorkflow() throws Exception {
+ BadWorkflow workflow = new BadWorkflow();
+ assertFailed(workflow);
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/BadWorkflowTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/CustomJoinConditionTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/CustomJoinConditionTest.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/CustomJoinConditionTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/CustomJoinConditionTest.java Sun May 21 22:13:12 2006
@@ -15,11 +15,13 @@
*/
package org.apache.servicemix.beanflow;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
/**
*
* @version $Revision: $
*/
-public class CustomJoinConditionTest extends FlowTestSupport {
+public class CustomJoinConditionTest extends ActivityTestSupport {
public void testCustomJoinCondition() throws Exception {
// START SNIPPET: join
@@ -44,17 +46,17 @@
activity.startWithTimeout(timer, timeout);
// now lets test things behave properly
- assertFlowStarted(activity);
+ assertStarted(activity);
a.stop();
- assertFlowStarted(activity);
+ assertStarted(activity);
b.stop();
- assertFlowStopped(activity);
+ assertStopped(activity);
// END SNIPPET: join
// lets check things are still fine when c completes
c.stop();
- assertFlowStopped(activity);
+ assertStopped(activity);
}
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleParallelBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleParallelBean.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleParallelBean.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleParallelBean.java Sun May 21 22:13:12 2006
@@ -43,18 +43,21 @@
public void methodOne() {
log.info("Called method one");
latch.countDown();
+ log.info("method one complete");
}
@Parallel
public void methodTwo() {
log.info("Called method two");
latch.countDown();
+ log.info("method two complete");
}
@Parallel
public void methodThree() {
log.info("Called method three");
latch.countDown();
+ log.info("method three complete");
}
public void assertCompleted() throws InterruptedException {
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleStringWorkflow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleStringWorkflow.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleStringWorkflow.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleStringWorkflow.java Sun May 21 22:13:12 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * An example workflow
+ *
+ * @version $Revision: $
+ */
+// START SNIPPET: workflow
+public class ExampleStringWorkflow extends Workflow<String> {
+
+ private static final Log log = LogFactory.getLog(ExampleStringWorkflow.class);
+
+ private int loopCount;
+ private long timeout = 500;
+ private String userEmailAddress;
+
+ public ExampleStringWorkflow() {
+ // lets specify the first step to start at
+ super("startStep");
+ }
+
+ // Workflow steps
+ // -------------------------------------------------------------------------
+
+ // This is the first step of a workflow by default
+ // but you can start at any point by passing in a parameter
+ // to the Workflow constructor
+ public void startStep() {
+ // lets use an explicit goTo() to tell the workflow
+ // which step to go to next; though we can just return Strings
+ goTo("loopStep");
+ }
+
+ // lets use the return value to specify the next step
+ public String loopStep() {
+ if (++loopCount > 3) {
+ return "waitForUserInputStep";
+ }
+ // lets keep looping
+ return "loopStep";
+ }
+
+ public void waitForUserInputStep() {
+ // we are going to park here until a user
+ // enters a valid email address
+ // so lets park the workflow engine
+ }
+
+ public String afterEnteredEmailStep() {
+ // we are going to park here until a user
+ // enters a valid email address
+ log.info("User entered email address: " + userEmailAddress);
+ return "forkStep";
+ }
+
+ public void forkStep() {
+ // lets fork some child flows
+ TimeoutActivity a = new TimeoutActivity();
+ TimeoutActivity b = new TimeoutActivity();
+ TimeoutActivity c = new TimeoutActivity();
+
+ log.info("Forking off processes a, b, c");
+ fork(a, b, c);
+
+ // now lets add some joins
+ joinAll("aCompletedStep", timeout, a);
+ joinAll("abcCompletedStep", timeout, a, b, c);
+ }
+
+ public void aCompletedStep() {
+ log.info("child flow A completed!");
+ }
+
+ public String abcCompletedStep() {
+ log.info("child flows A, B and C completed!");
+
+ // we are completely done now
+ return "stop";
+ }
+
+ // External events
+ // -------------------------------------------------------------------------
+ public void userEntered(String emailAddress) {
+ if (emailAddress != null && emailAddress.indexOf("@") > 0) {
+ this.userEmailAddress = emailAddress;
+
+ log.info("Lets re-start the suspended workflow");
+ goTo("afterEnteredEmailStep");
+ }
+ }
+}
+// END SNIPPET: workflow
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleStringWorkflow.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleWorkflow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleWorkflow.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleWorkflow.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ExampleWorkflow.java Sun May 21 22:13:12 2006
@@ -24,32 +24,38 @@
* @version $Revision: $
*/
// START SNIPPET: workflow
-public class ExampleWorkflow extends Workflow {
+public class ExampleWorkflow extends Workflow<ExampleWorkflow.Step> {
private static final Log log = LogFactory.getLog(ExampleWorkflow.class);
private int loopCount;
private long timeout = 500;
private String userEmailAddress;
+ public static enum Step {
+ startStep, afterEnteredEmailStep, loopStep, waitForUserInputStep, forkStep,
+ aCompletedStep, abcCompletedStep, stop
+ };
+
+ public ExampleWorkflow() {
+ super(Step.startStep);
+ }
+
// Workflow steps
// -------------------------------------------------------------------------
- // This is the first step of a workflow by default
- // but you can start at any point by passing in a parameter
- // to the Workflow constructor
public void startStep() {
// lets use an explicit goTo() to tell the workflow
// which step to go to next; though we can just return Strings
- goTo("loopStep");
+ goTo(Step.loopStep);
}
// lets use the return value to specify the next step
- public String loopStep() {
+ public Step loopStep() {
if (++loopCount > 3) {
- return "waitForUserInputStep";
+ return Step.waitForUserInputStep;
}
// lets keep looping
- return "loopStep";
+ return Step.loopStep;
}
public void waitForUserInputStep() {
@@ -58,11 +64,11 @@
// so lets park the workflow engine
}
- public String afterEnteredEmailStep() {
+ public Step afterEnteredEmailStep() {
// we are going to park here until a user
// enters a valid email address
log.info("User entered email address: " + userEmailAddress);
- return "forkStep";
+ return Step.forkStep;
}
public void forkStep() {
@@ -75,19 +81,19 @@
fork(a, b, c);
// now lets add some joins
- joinAll("aCompletedStep", timeout, a);
- joinAll("abcCompletedStep", timeout, a, b, c);
+ joinAll(Step.aCompletedStep, timeout, a);
+ joinAll(Step.abcCompletedStep, timeout, a, b, c);
}
public void aCompletedStep() {
log.info("child flow A completed!");
}
- public String abcCompletedStep() {
+ public Step abcCompletedStep() {
log.info("child flows A, B and C completed!");
// we are completely done now
- return "stop";
+ return Step.stop;
}
// External events
@@ -97,7 +103,7 @@
this.userEmailAddress = emailAddress;
log.info("Lets re-start the suspended workflow");
- goTo("afterEnteredEmailStep");
+ goTo(Step.afterEnteredEmailStep);
}
}
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinAllTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinAllTest.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinAllTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinAllTest.java Sun May 21 22:13:12 2006
@@ -15,11 +15,13 @@
*/
package org.apache.servicemix.beanflow;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
/**
*
* @version $Revision: $
*/
-public class JoinAllTest extends FlowTestSupport {
+public class JoinAllTest extends ActivityTestSupport {
protected Activity child1 = new TimeoutActivity();
protected Activity child2 = new TimeoutActivity();
@@ -33,56 +35,56 @@
// now lets test the flow
child1.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
child2.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
child3.stop();
- assertFlowStopped(flow);
+ assertStopped(flow);
// END SNIPPET: example
}
public void testJoinAllTerminatesWhenAClientFails() throws Exception {
JoinAll flow = new JoinAll(child1, child2, child3);
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
child3.fail("Test case error simulation");
- assertFlowStarted(flow);
+ assertStarted(flow);
child2.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
child1.stop();
- assertFlowFailed(flow);
+ assertFailed(flow);
}
public void testJoinAllTerminatesAsSoonAsOneChildFails() throws Exception {
JoinAll flow = new JoinAll(child1, child2, child3);
flow.setFailFast(true);
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
child1.fail("Test case error simulation");
- assertFlowFailed(flow);
+ assertFailed(flow);
}
public void testJoinAllFailsIfChildrenDoNotCompleteInTime() throws Exception {
JoinAll flow = new JoinAll(child1, child2, child3);
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
child1.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
child2.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
// lets force a timeout failure
Thread.sleep(timeout * 2);
- assertFlowFailed(flow);
+ assertFailed(flow);
// lets check that completing the final child flow keeps the join failed
child3.stop();
- assertFlowFailed(flow);
+ assertFailed(flow);
}
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinQuorumTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinQuorumTest.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinQuorumTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/JoinQuorumTest.java Sun May 21 22:13:12 2006
@@ -15,11 +15,13 @@
*/
package org.apache.servicemix.beanflow;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
/**
*
* @version $Revision: $
*/
-public class JoinQuorumTest extends FlowTestSupport {
+public class JoinQuorumTest extends ActivityTestSupport {
protected Activity child1 = new TimeoutActivity();
protected Activity child2 = new TimeoutActivity();
@@ -27,47 +29,47 @@
public void testJoinAllWhenEachChildFlowCompletes() throws Exception {
JoinQuorum flow = new JoinQuorum(child1, child2, child3);
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
child1.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
child2.stop();
- assertFlowStopped(flow);
+ assertStopped(flow);
// lets check things are still fine when the quorum is complete
child3.stop();
- assertFlowStopped(flow);
+ assertStopped(flow);
}
public void testJoinQuorumTerminatesWhenTooManyClientsFail() throws Exception {
JoinQuorum flow = new JoinQuorum(child1, child2, child3);
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
child3.fail("Test case error simulation");
- assertFlowStarted(flow);
+ assertStarted(flow);
child2.fail("Test case error simulation");
- assertFlowFailed(flow);
+ assertFailed(flow);
}
public void testJoinQuorumFailsIfChildrenDoNotCompleteInTime() throws Exception {
JoinQuorum flow = new JoinQuorum(child1, child2, child3);
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
child1.stop();
- assertFlowStarted(flow);
+ assertStarted(flow);
// lets force a timeout failure
Thread.sleep(timeout * 2);
- assertFlowFailed(flow);
+ assertFailed(flow);
// lets check that completing the final child flow keeps the join failed
child2.stop();
- assertFlowFailed(flow);
+ assertFailed(flow);
child3.stop();
- assertFlowFailed(flow);
+ assertFailed(flow);
}
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ParallelActivityTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ParallelActivityTest.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ParallelActivityTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/ParallelActivityTest.java Sun May 21 22:13:12 2006
@@ -15,6 +15,8 @@
*/
package org.apache.servicemix.beanflow;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -22,28 +24,23 @@
*
* @version $Revision: $
*/
-public class ParallelActivityTest extends FlowTestSupport {
+public class ParallelActivityTest extends ActivityTestSupport {
protected Executor executor = Executors.newFixedThreadPool(10);
@SuppressWarnings("unchecked")
- public void test() throws Exception {
+ public void testParallelWorkflow() throws Exception {
// START SNIPPET: example
ExampleParallelBean parallelBean = new ExampleParallelBean();
ParallelActivity activity = ParallelActivity.newParallelMethodActivity(executor, parallelBean);
- activity.startWithTimeout(timer, -1);
+ activity.startWithTimeout(timer, 200000);
// END SNIPPET: example
+ /** TOOD
+ activity.join();
+ assertStopped(activity);
parallelBean.assertCompleted();
-
- // OK the latch may be completed but the
- // join might not have completed yet
- if (!activity.isStopped()) {
- Thread.sleep(1000);
- }
-
- assertFlowStopped(activity);
+ */
}
-
}
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflow.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflow.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflow.java Sun May 21 22:13:12 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow;
+
+
+/**
+ * A simple example
+ *
+ * @version $Revision: $
+ */
+// START SNIPPET: workflow
+public class SimpleWorkflow extends Workflow<SimpleWorkflow.Step> {
+
+ public static enum Step {
+ stepA, stepB, stepC, stop
+ };
+
+ public SimpleWorkflow() {
+ super(Step.stepA);
+ }
+
+ // Workflow steps
+ // -------------------------------------------------------------------------
+ public Step stepA() {
+ return Step.stepB;
+ }
+
+ public Step stepB() {
+ return Step.stepC;
+ }
+
+ public Step stepC() {
+ return Step.stop;
+ }
+}
+// END SNIPPET: workflow
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflow.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflowTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflowTest.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflowTest.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflowTest.java Sun May 21 22:13:12 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
+/**
+ *
+ * @version $Revision: $
+ */
+public class SimpleWorkflowTest extends ActivityTestSupport {
+
+ public void testWorkflow() throws Exception {
+ SimpleWorkflow workflow = new SimpleWorkflow();
+ workflow.start();
+
+ Thread.sleep(2000);
+
+ assertStopped(workflow);
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/SimpleWorkflowTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/StringWorkflowTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/StringWorkflowTest.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/StringWorkflowTest.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/StringWorkflowTest.java Sun May 21 22:13:12 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
+
+/**
+ *
+ * @version $Revision: $
+ */
+public class StringWorkflowTest extends ActivityTestSupport {
+
+ private static final Log log = LogFactory.getLog(StringWorkflowTest.class);
+
+ public void testWorkflow() throws Exception {
+ // START SNIPPET: workflow
+ ExampleStringWorkflow workflow = new ExampleStringWorkflow();
+ workflow.start();
+
+ // wait for user entry point
+ Thread.sleep(2000);
+
+ workflow.userEntered("foo");
+ assertStarted(workflow);
+
+ log.info("We are entering some valid input");
+
+ workflow.userEntered("foo@bar.com");
+
+ Thread.sleep(5000);
+
+ assertStopped(workflow);
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/StringWorkflowTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java Sun May 21 22:13:12 2006
@@ -16,30 +16,31 @@
package org.apache.servicemix.beanflow;
import org.apache.servicemix.beanflow.Activity.Transitions;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
/**
*
* @version $Revision: $
*/
-public class TimeoutFlowTest extends FlowTestSupport {
+public class TimeoutFlowTest extends ActivityTestSupport {
protected TimeoutActivity flow = new TimeoutActivity();
public void testFlowStopsSuccessfully() throws Exception {
flow.getState().set(Transitions.Stopped);
- assertFlowStopped(flow);
+ assertStopped(flow);
// lets sleep so that the timer can go off now to check we don't fail
// after we've stopped
Thread.sleep(timeout * 4);
- assertFlowStopped(flow);
+ assertStopped(flow);
}
public void testFlowTimesOutAndFails() throws Exception {
Thread.sleep(timeout * 4);
- assertFlowFailed(flow);
+ assertFailed(flow);
}
protected void setUp() throws Exception {
- startFlow(flow, timeout);
+ startActivity(flow, timeout);
}
}
Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/WorkflowTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/WorkflowTest.java?rev=408572&r1=408571&r2=408572&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/WorkflowTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/WorkflowTest.java Sun May 21 22:13:12 2006
@@ -17,12 +17,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.util.ActivityTestSupport;
/**
*
* @version $Revision: $
*/
-public class WorkflowTest extends FlowTestSupport {
+public class WorkflowTest extends ActivityTestSupport {
private static final Log log = LogFactory.getLog(WorkflowTest.class);
@@ -35,7 +36,7 @@
Thread.sleep(2000);
workflow.userEntered("foo");
- assertFlowStarted(workflow);
+ assertStarted(workflow);
log.info("We are entering some valid input");
@@ -43,6 +44,6 @@
Thread.sleep(5000);
- assertFlowStopped(workflow);
+ assertStopped(workflow);
}
}
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanTest.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanTest.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanTest.java Sun May 21 22:13:12 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow.util;
+
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ *
+ * @version $Revision: $
+ */
+public class ParallelBeanTest extends ActivityTestSupport {
+
+ public void testParallelWithSyncs() throws Exception {
+ ParallelBeanWithSyncs bean = new ParallelBeanWithSyncs();
+ startActivity(bean.getActivity(), 10000);
+ bean.getActivity().join();
+
+ bean.assertWorked();
+ assertStopped(bean.getActivity());
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanWithSyncs.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanWithSyncs.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanWithSyncs.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanWithSyncs.java Sun May 21 22:13:12 2006
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.annotations.Parallel;
+import org.apache.servicemix.beanflow.util.ParallelBean;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+/**
+ * An example parallel proces
+ *
+ * @version $Revision: $
+ */
+// START SNIPPET: workflow
+public class ParallelBeanWithSyncs extends ParallelBean {
+ private static final Log log = LogFactory.getLog(ParallelBeanWithSyncs.class);
+
+ private boolean methodOneSync1, methodOneSync2, methodTwoSync1, methodTwoSync2;
+
+ @Parallel
+ public void methodOne() {
+ log.info("Called method one");
+ sync();
+ methodOneSync1 = true;
+ log.info("methodOne: after sync1");
+
+ // simulate a slow thing
+ sleep(1000);
+
+ sync();
+ methodOneSync2 = true;
+ log.info("methodOne: after sync2");
+ }
+
+ @Parallel
+ public void methodTwo() {
+ log.info("Called method two");
+
+ // simulate a slow thing
+ sleep(1000);
+
+ sync();
+ methodTwoSync1 = true;
+ log.info("methodTwo: after sync1");
+
+ sync();
+ methodTwoSync2 = true;
+ log.info("methodTwo: after sync2");
+ }
+
+ public void assertWorked() {
+ Assert.assertTrue("Did not reach sync1 for methodOne", methodOneSync1);
+ Assert.assertTrue("Did not reach sync2 for methodOne", methodOneSync2);
+ Assert.assertTrue("Did not reach sync1 for methodTwo", methodTwoSync1);
+ Assert.assertTrue("Did not reach sync2 for methodTwo", methodTwoSync2);
+ }
+}
+// END SNIPPET: workflow
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelBeanWithSyncs.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelTest.java?rev=408572&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelTest.java (added)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelTest.java Sun May 21 22:13:12 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.beanflow.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.beanflow.annotations.Parallel;
+
+/**
+ *
+ * @version $Revision: $
+ */
+// START SNIPPET: workflow
+public class ParallelTest extends ParallelTestCase {
+ private static final Log log = LogFactory.getLog(ParallelBeanWithSyncs.class);
+
+ private boolean methodOneSync1, methodOneSync2, methodTwoSync1, methodTwoSync2;
+
+ @Override
+ public void testParallelMethods() throws Exception {
+ super.testParallelMethods();
+
+ assertTrue("Did not reach sync1 for methodOne", methodOneSync1);
+ assertTrue("Did not reach sync2 for methodOne", methodOneSync2);
+ assertTrue("Did not reach sync1 for methodTwo", methodTwoSync1);
+ assertTrue("Did not reach sync2 for methodTwo", methodTwoSync2);
+ }
+
+ @Parallel
+ public void methodOne() {
+ log.info("Called method one");
+ sync();
+ methodOneSync1 = true;
+ log.info("methodOne: after sync1");
+
+ // simulate a slow thing
+ sleep(1000);
+
+ sync();
+ methodOneSync2 = true;
+ log.info("methodOne: after sync2");
+ }
+
+ @Parallel
+ public void methodTwo() {
+ log.info("Called method two");
+
+ // simulate a slow thing
+ sleep(1000);
+
+ sync();
+ methodTwoSync1 = true;
+ log.info("methodTwo: after sync1");
+
+ sync();
+ methodTwoSync2 = true;
+ log.info("methodTwo: after sync2");
+ }
+
+}
+// END SNIPPET: workflow
Propchange: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/util/ParallelTest.java
------------------------------------------------------------------------------
svn:eol-style = native