Ejemplo n.º 1
0
        public void ExecuteWorkflows_OnDelayedAction_ResumesAfterDelay()
        {
            // set up the store and the workflows
            IWorkflowStore workflowStore = new MemoryWorkflowStore();

            DelayedWorkflow workflow = new DelayedWorkflow(DelayedWorkflow.State.Start);

            workflow.CreatedOn     = DateTime.UtcNow.AddMinutes(-2);
            workflow.ResumeTrigger = DelayedWorkflow.Trigger.DoStuff.ToString();
            workflowStore.Save(workflow);

            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);

            // execute
            workflowServer.ExecuteWorkflows(5);
            workflow = workflowStore.Get <DelayedWorkflow>(workflow.Id);
            Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState);

            // execute again - nothing should have changed
            workflowServer.ExecuteWorkflows(5);
            workflow = workflowStore.Get <DelayedWorkflow>(workflow.Id);
            Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState);

            // delay and run - should be now be complete
            Thread.Sleep(3100);
            workflowServer.ExecuteWorkflows(5);
            Assert.IsNull(workflowStore.GetOrDefault(workflow.Id));
            Assert.IsNotNull(workflowStore.GetCompletedOrDefault(workflow.Id));
        }
Ejemplo n.º 2
0
        public void OnWorkflowStateEntry_OnStateChange_Persisted()
        {
            BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start);

            workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString();

            // set up the workflow store
            IWorkflowStore workflowStore = Substitute.For <IWorkflowStore>();

            workflowStore.GetActive(Arg.Any <int>()).Returns(new[] { workflow });

            IWorkflowServer workflowEngine = new WorkflowServer(workflowStore);

            workflowEngine.ExecuteWorkflows(10);

            // We should have received TWO saves as the workflow moves between the states
            workflowStore.Received(2).Save(workflow);
        }
Ejemplo n.º 3
0
        void WorkerThreadFunc()
        {
            // fire up the server, this will run as part of the service (you can set the workflow store here)
            IWorkflowStore workflowStore = BootStrapper.MongoDbStore();
            //IWorkflowStore workflowStore = BootStrapper.MemoryStore();
            //IWorkflowStore workflowStore = BootStrapper.RavenDbEmbeddedStore();

            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);

            workflowServer.RegisterWorkflowType <FileCreationWorkflow>();

            // create a new example workflow if it hasn't been registered already
            FileCreationWorkflow workflow = new FileCreationWorkflow(FileCreationWorkflow.State.Start);

            workflow.RootFolder    = "C:\\Temp\\";
            workflow.ResumeTrigger = FileCreationWorkflow.Trigger.WriteFirstFile.ToString();
            workflow.Priority      = 5;
            workflowServer.RegisterWorkflow(workflow);

            while (!_shutdownEvent.WaitOne(0))
            {
                int executedCount = 0;

                try
                {
                    executedCount = workflowServer.ExecuteWorkflows(5);
                }
                catch (Exception)
                {
                    // do some logging!
                }

                // if no workflows were found, sleepy sleep - you should create an app setting for the poll
                // interval appropriate to you
                if (executedCount == 0)
                {
                    Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 4
0
        public void ExecuteWorkflows_ActionWithNoDefaultConstructorAndNoDependencyResolver_ThrowsException()
        {
            // set up the store and the workflows
            IWorkflowStore  workflowStore  = new MemoryWorkflowStore();
            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);

            DependencyInjectionWorkflow workflow = new DependencyInjectionWorkflow(DependencyInjectionWorkflow.State.Start);

            workflow.CreatedOn     = DateTime.UtcNow.AddMinutes(-2);
            workflow.ResumeOn      = DateTime.UtcNow.AddMinutes(-2);
            workflow.ResumeTrigger = DependencyInjectionWorkflow.Trigger.DoStuff.ToString();
            workflowStore.Save(workflow);

            Assert.AreEqual(0, workflow.RetryCount);

            // execute
            workflowServer.ExecuteWorkflows(10);

            // we won't get an error, but check the workflow to see if any error occurred
            Assert.AreEqual(1, workflow.RetryCount);
            Assert.IsTrue(workflow.LastException.Contains("MissingMethodException"));
        }
Ejemplo n.º 5
0
        public void ExecuteWorkflows_ActionWithNoDefaultConstructorAndDependencyResolver_ExecutesAction()
        {
            // set up the store and the workflows
            IWorkflowStore  workflowStore  = new MemoryWorkflowStore();
            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);

            DependencyInjectionWorkflow workflow = new DependencyInjectionWorkflow(DependencyInjectionWorkflow.State.Start);

            workflow.CreatedOn     = DateTime.UtcNow.AddMinutes(-2);
            workflow.ResumeOn      = DateTime.UtcNow.AddMinutes(-2);
            workflow.ResumeTrigger = DependencyInjectionWorkflow.Trigger.DoStuff.ToString();
            workflowStore.Save(workflow);

            MyDependencyResolver resolver = new MyDependencyResolver();// Substitute.For<IWorkflowEngineDependencyResolver>();

            //resolver.GetInstance<NoDefaultConstructorAction>().Returns(new NoDefaultConstructorAction("test", 1));
            workflowServer.DependencyResolver = resolver;

            // execute
            Assert.AreEqual(0, resolver.RunCount);
            workflowServer.ExecuteWorkflows(10);
            Assert.AreEqual(1, resolver.RunCount);
        }
Ejemplo n.º 6
0
        public void ExecuteWorkflows_OnExecution_ReturnsNumberOfWorkflowsExecuted(int activeWorkflowCount)
        {
            const int executeCount   = 10;
            int       expectedResult = Math.Min(executeCount, activeWorkflowCount);
            // set up the store and the workflows
            IWorkflowStore workflowStore = new MemoryWorkflowStore();

            for (int i = 0; i < activeWorkflowCount; i++)
            {
                BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start);
                workflow.CreatedOn     = DateTime.UtcNow.AddMinutes(-2);
                workflow.ResumeOn      = DateTime.UtcNow.AddMinutes(-2);
                workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString();
                workflowStore.Save(workflow);
            }

            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);

            // execute
            int result = workflowServer.ExecuteWorkflows(10);

            Assert.AreEqual(expectedResult, result);
        }
        void WorkerThreadFunc()
        {
            // fire up the server, this will run as part of the service (you can set the workflow store here)
            //IWorkflowStore workflowStore = BootStrapper.MongoDbStore();
            //IWorkflowStore workflowStore = BootStrapper.MemoryStore();
            IWorkflowStore workflowStore = BootStrapper.RavenDbEmbeddedStore();
            
            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);
            workflowServer.RegisterWorkflowType<FileCreationWorkflow>();

            // create a new example workflow if it hasn't been registered already
            FileCreationWorkflow workflow = new FileCreationWorkflow(FileCreationWorkflow.State.Start);
            workflow.RootFolder = "C:\\Temp\\";
            workflow.ResumeTrigger = FileCreationWorkflow.Trigger.WriteFirstFile.ToString();
            workflowServer.RegisterWorkflow(workflow);


            while (!_shutdownEvent.WaitOne(0))
            {

                try
                {
                    workflowServer.ExecuteWorkflows(5);
                }
                catch (Exception)
                {
                    Thread.Sleep(1000);
                }

                // sleepy sleep
                Thread.Sleep(1000);
            }



        }
        public void OnWorkflowStateEntry_OnStateChange_Persisted()
        {
            BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start);
            workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString();

            // set up the workflow store
            IWorkflowStore workflowStore = Substitute.For<IWorkflowStore>();
            workflowStore.GetActive(Arg.Any<int>()).Returns(new[] { workflow });

            IWorkflowServer workflowEngine = new WorkflowServer(workflowStore);
            workflowEngine.ExecuteWorkflows(10);

            // We should have received TWO saves as the workflow moves between the states
            workflowStore.Received(2).Save(workflow);

        }
        public void ExecuteWorkflows_OnDelayedAction_ResumesAfterDelay()
        {
            // set up the store and the workflows
            IWorkflowStore workflowStore = new MemoryWorkflowStore();

            DelayedWorkflow workflow = new DelayedWorkflow(DelayedWorkflow.State.Start);
            workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2);
            workflow.ResumeTrigger = DelayedWorkflow.Trigger.DoStuff.ToString();
            workflowStore.Save(workflow);

            IWorkflowServer workflowServer = new WorkflowServer(workflowStore);

            // execute
            workflowServer.ExecuteWorkflows(5);
            workflow = workflowStore.Get<DelayedWorkflow>(workflow.Id);
            Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState);

            // execute again - nothing should have changed
            workflowServer.ExecuteWorkflows(5);
            workflow = workflowStore.Get<DelayedWorkflow>(workflow.Id);
            Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState);

            // delay and run - should be now be complete
            Thread.Sleep(3100);
            workflowServer.ExecuteWorkflows(5);
            Assert.IsNull(workflowStore.GetOrDefault(workflow.Id));
            Assert.IsNotNull(workflowStore.GetCompletedOrDefault(workflow.Id));

        }