Example #1
0
        public void TestPersistenceWithDelayAndResultButNoPersist()
        {
            var a = new Fonlow.Activities.Calculation();

            a.XX = 3;
            a.YY = 7;

            bool completed1 = false;
            bool unloaded1  = false;

            AutoResetEvent syncEvent = new AutoResetEvent(false);

            var app = new WorkflowApplication(a);

            app.InstanceStore   = WFDefinitionStore.Instance.Store;
            app.PersistableIdle = (eventArgs) =>
            {
                return(PersistableIdleAction.None);
            };

            app.OnUnhandledException = (e) =>
            {
                return(UnhandledExceptionAction.Abort);
            };

            app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                completed1 = true;
                //   Assert.True(stopwatch.Elapsed.TotalSeconds > 3 && stopwatch.Elapsed.TotalSeconds < 5);
                syncEvent.Set();
            };

            app.Aborted = (eventArgs) =>
            {
            };

            app.Unloaded = (eventArgs) =>
            {
            };

            var id = app.Id;

            app.Run();
            syncEvent.WaitOne();


            Assert.True(completed1);
            Assert.False(unloaded1);
        }
Example #2
0
        public void TestPersistenceWithDelayAndResult()
        {
            var a = new Fonlow.Activities.Calculation();

            a.XX = 3;
            a.YY = 7;

            bool completed1 = false;
            bool unloaded1  = false;

            AutoResetEvent syncEvent = new AutoResetEvent(false);

            var definitionIdentity = new WorkflowIdentity("Cal", new Version(2, 0), null);
            var app = new WorkflowApplication(a, definitionIdentity);

            app.InstanceStore   = WFDefinitionStore.Instance.Store;
            app.PersistableIdle = (eventArgs) =>
            {
                return(PersistableIdleAction.Unload);//so persist and unload
            };

            app.OnUnhandledException = (e) =>
            {
                return(UnhandledExceptionAction.Abort);
            };

            app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                completed1 = true;
            };

            app.Aborted = (eventArgs) =>
            {
            };

            app.Unloaded = (eventArgs) =>
            {
                unloaded1 = true;
                syncEvent.Set();
            };

            var id = app.Id;

            stopwatch.Restart();
            stopwatch2.Restart();
            app.Run();
            syncEvent.WaitOne();

            stopwatch.Stop();
            Assert.True(stopwatch.ElapsedMilliseconds < 2500, String.Format("The first one is executed for {0} milliseconds", stopwatch.ElapsedMilliseconds));
            //the ellipsed time depends on the performance of the WF runtime when handling persistence. The first case of persistence is slow.

            Assert.False(completed1);
            Assert.True(unloaded1);

            stopwatch.Restart();
            var t = WFDefinitionIdentityStore.Instance.TryAdd(definitionIdentity, a);

            stopwatch.Stop();
            Trace.TraceInformation("It took {0} seconds to persist definition", stopwatch.Elapsed.TotalSeconds);

            //Now to use a new WorkflowApplication to load the persisted instance.
            var dic         = LoadAndCompleteLongRunning(id, definitionIdentity);
            var finalResult = (long)dic["Result"];

            Assert.Equal(21, finalResult);
        }
Example #3
0
        public void TestRunningWorkflowTwice()
        {
            var a = new Fonlow.Activities.Calculation();

            a.XX = 3;
            a.YY = 7;

            bool completed1 = false;
            bool unloaded1  = false;

            AutoResetEvent syncEvent = new AutoResetEvent(false);

            var app = new WorkflowApplication(a);

            app.InstanceStore   = WFDefinitionStore.Instance.Store;
            app.PersistableIdle = (eventArgs) =>
            {
                return(PersistableIdleAction.Unload);//so persist and unload
            };

            app.OnUnhandledException = (e) =>
            {
                return(UnhandledExceptionAction.Abort);
            };

            app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                completed1 = true;
            };

            app.Aborted = (eventArgs) =>
            {
            };

            app.Unloaded = (eventArgs) =>
            {
                unloaded1 = true;
                syncEvent.Set();
            };

            var id = app.Id;

            stopwatch.Restart();
            stopwatch2.Restart();
            app.Run();
            syncEvent.WaitOne();

            stopwatch.Stop();
            Assert.True(stopwatch.ElapsedMilliseconds < 2500, String.Format("The first one is executed for {0} milliseconds", stopwatch.ElapsedMilliseconds));
            //the ellipsed time depends on the performance of the WF runtime when handling persistence. The first case of persistence is slow.

            Assert.False(completed1);
            Assert.True(unloaded1);

            stopwatch.Restart();
            var t = WFDefinitionStore.Instance.TryAdd(id, a);

            stopwatch.Stop();
            Trace.TraceInformation("It took {0} seconds to persist definition", stopwatch.Elapsed.TotalSeconds);

            Assert.Throws <WorkflowApplicationUnloadedException>(() => app.Run());
        }