示例#1
0
        private void Catch_exception_with_causality(Task task, FlowRuntimeException ex)
        {
            var c    = task.Message.Causalities.Peek();
            var cMsg = new Message(c.Port, ex, task.Message.CorrelationId)
            {
                Priority = 99
            };

            HandledException(cMsg);
        }
        public void Setup()
        {
            var frc = new FlowRuntimeConfiguration();

            frc.AddPushCausality("push");
            frc.AddPopCausality("pop");

            frc.AddFunc <int, int>("exOn0", i =>
            {
                if (i == 0)
                {
                    throw new ApplicationException("on0");
                }
                return(i);
            });
            frc.AddFunc <int, int>("exOn1", i =>
            {
                if (i == 1)
                {
                    throw new ApplicationException("on1");
                }
                return(i);
            });
            frc.AddAction <int>("exOn2", i =>
            {
                if (i == 2)
                {
                    throw new ApplicationException("on2");
                }
            });

            _exCausality = null;
            _are         = new AutoResetEvent(false);
            frc.AddAction <FlowRuntimeException>("handleEx", _ =>
            {
                _exCausality = _;
                _are.Set();
            });

            frc.AddStream(new Stream(".in", "push"));
            frc.AddStream(new Stream("push", "exOn0"));
            frc.AddStream(new Stream("push.exception", "handleEx"));
            frc.AddStream(new Stream("exOn0", "exOn1"));
            frc.AddStream(new Stream("exOn1", "pop"));
            frc.AddStream(new Stream("pop", "exOn2"));

            _fr = new FlowRuntime(frc);

            _exUnhandled            = null;
            _fr.UnhandledException += _ => {
                _exUnhandled = _;
                _are.Set();
            };
        }
        public void Async_EBC_method_throwing_exception()
        {
            var cache = new AsynchronizerCache();
            var sut   = new EBCOperation("math", new MyAsyncEbc(), null, cache);

            var are = new AutoResetEvent(false);
            FlowRuntimeException result = null;

            var input    = new Message("math.ThrowException", 41);
            var methodOp = sut.Create_method_operation(input);

            methodOp.Implementation(input, _ => { }, ex => { result = ex; are.Set(); });

            Assert.IsTrue(are.WaitOne(1000));
            Assert.IsInstanceOf <ApplicationException>(result.InnerException);
        }
示例#4
0
        public void Catch_exception_from_background()
        {
            var frc = new FlowRuntimeConfiguration()
                      .AddStream(new Stream(".in", "throw"))
                      .AddAction <string>("throw", (string _) => { throw new ApplicationException("xxx"); }).MakeAsync();

            using (var sut = new FlowRuntime(frc))
            {
                FlowRuntimeException ex = null;
                var are = new AutoResetEvent(false);
                sut.UnhandledException += _ =>
                {
                    ex = _;
                    are.Set();
                };

                sut.Process(new Message(".in", "hello"));

                Assert.IsTrue(are.WaitOne(1000));
                Assert.AreEqual("xxx", ex.InnerException.Message);
            }
        }
        public void Process_exception_in_operation()
        {
            var frc = new FlowRuntimeConfiguration()
                      .AddStream(new Stream(".process", "ThrowEx.in"))
                      .AddStream(new Stream("ThrowEx.out", ".out"))

                      .AddOperation(new Operation("ThrowEx", (input, outputCont, _) => { throw new NotImplementedException("xxx"); }));

            _sut.Configure(frc);

            FlowRuntimeException ex = null;

            _sut.UnhandledException += _ =>
            {
                ex = _;
                _are.Set();
            };

            _sut.Process(new Message(".process", "hello"));

            Assert.IsTrue(_are.WaitOne(1000));
            Assert.AreEqual("xxx", ex.InnerException.Message);
            Assert.AreEqual("ThrowEx.in", ex.Context.Port.Fullname);
        }
示例#6
0
 static void Handle_exception(FlowRuntimeException ex)
 {
     Console.WriteLine("*** Exception during file processing: {0}", ex.InnerException);
 }