Example #1
0
        /// <summary>
        /// Process the received <see cref="Event"/> using the specified <paramref name="eventHandler"/>.
        /// </summary>
        /// <param name="eventHandler">The <see cref="EventHandler"/> to be executed.</param>
        /// <param name="context">The underlying <see cref="EventContext"/> to use when executing the specified <paramref name="eventHandler"/>.</param>
        private void ExecuteHandler(EventHandler eventHandler, EventContext context)
        {
            var backoffContext = default(ExponentialBackoff);
            var done           = false;

            do
            {
                try
                {
                    eventHandler.Handle(context);

                    done = true;
                }
                catch (Exception ex)
                {
                    if (!transientErrorRegistry.IsTransient(ex))
                    {
                        throw;
                    }

                    backoffContext = backoffContext ?? new ExponentialBackoff(retryTimeout);
                    backoffContext.WaitOrTimeout(ex);
                    Log.Warn(ex.Message);
                }
            } while (!done);
        }
Example #2
0
            public void InvokeUnderlyingExecutorWithEventAndHandlerInstance()
            {
                var handled      = false;
                var e            = new FakeEvent();
                var handler      = new Object();
                var eventHandler = new EventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { handled = a == handler && b == e; }, () => handler);

                using (var context = new EventContext(GuidStrategy.NewGuid(), HeaderCollection.Empty, e))
                    eventHandler.Handle(context);

                Assert.True(handled);
            }
Example #3
0
            public void ContextCannotBeNull()
            {
                var eventHandler = new EventHandler(typeof(Object), typeof(FakeEvent), (h, e) => { }, () => new Object());

                Assert.Throws <ArgumentNullException>(() => eventHandler.Handle(null));
            }