public void registers_a_CurrentChain_service_for_diagnostic_purposes() { var chain = new HandlerChain(); var context = new FubuTransportation.Runtime.Invocation.InvocationContext(ObjectMother.EnvelopeWithMessage(), chain); context.Get<ICurrentChain>().Current.ShouldBeTheSameAs(chain); }
public override void Configure(HandlerChain handlerChain) { handlerChain.MaximumAttempts = 2; handlerChain.OnException<UnauthorizedAccessException>() .RespondWithMessage((ex, envelope) => new RespondToSender(new ErrorResponse { Message = ex.Message })) .Then.MoveToErrorQueue(); }
public override void Configure(HandlerChain handlerChain) { handlerChain.MaximumAttempts = 5; handlerChain.OnException<UnauthorizedAccessException>() .ContinueWith<CounterContinuation>() .Then.Retry(); }
public ExceptionHandlerBehavior(IActionBehavior behavior, HandlerChain chain, Envelope envelope, IInvocationContext context, ILogger logger, IFubuRequest request) { _behavior = behavior; _chain = chain; _envelope = envelope; _context = context; _logger = logger; _request = request; }
public void move_to_error_queue() { var chain = new HandlerChain(); chain.OnException<NotSupportedException>() .MoveToErrorQueue(); chain.ErrorHandlers.Single().ShouldBeOfType<MoveToErrorQueueHandler<NotSupportedException>>(); }
public override void Configure(HandlerChain handlerChain) { //when retrying, do so a maximum of 5 times handlerChain.MaximumAttempts = 3; //retry now handlerChain.OnException <DivideByZeroException>() .RetryLater(5.Seconds()); }
protected override void beforeEach() { theEnvelope = ObjectMother.Envelope(); theInvoker = MockFor <IChainInvoker>(); theChain = new HandlerChain(); theInvoker.Stub(x => x.FindChain(theEnvelope)) .Return(theChain); }
public ExceptionHandlerBehavior(IActionBehavior behavior, HandlerChain chain, Envelope envelope, IInvocationContext context, ILogger logger, IFubuRequest request) { _behavior = behavior; _chain = chain; _envelope = envelope; _context = context; _logger = logger; _request = request; }
public void is_async_negative() { var chain = new HandlerChain(); chain.IsAsync.ShouldBeFalse(); chain.AddToEnd(HandlerCall.For<GreenHandler>(x => x.Handle(new Message1()))); chain.IsAsync.ShouldBeFalse(); }
public void respond_with_message() { var chain = new HandlerChain(); chain.OnException<NotImplementedException>() .RespondWithMessage((ex, env) => new object()); chain.ErrorHandlers.Single().ShouldBeOfType<RespondWithMessageHandler<NotImplementedException>>(); }
public void is_saga_chain_is_true_for_handler_chain_with_a_saga_handler() { var call = HandlerCall.For<SimpleSagaHandler>(x => x.Last(null)); var chain = new HandlerChain(); chain.AddToEnd(call); StatefulSagaConvention.IsSagaChain(chain) .ShouldBeTrue(); }
public override void TearDown() { _runtime.Dispose(); _graph = null; _chain = null; _transport = null; _bus = null; _runtime = null; }
public static ChainModel For(HandlerChain chain) { return(new ChainModel { MessageType = new MessageTypeModel(chain.MessageType), GeneratedTypeName = chain.TypeName, Description = chain.ToString(), SourceCode = chain.SourceCode }); }
public void is_async_negative() { var chain = new HandlerChain(); chain.IsAsync.ShouldBeFalse(); chain.AddToEnd(HandlerCall.For <GreenHandler>(x => x.Handle(new Message1()))); chain.IsAsync.ShouldBeFalse(); }
public static void ShouldHandleExceptionWith <TEx, TContinuation>(this HandlerChain chain) where TEx : Exception where TContinuation : IContinuation { ShouldBeBooleanExtensions.ShouldBeTrue(chain.ErrorHandlers.OfType <ErrorHandler>() .Where(x => x.Conditions.Count() == 1 && x.Conditions.Single() is ExceptionTypeMatch <TEx>) .SelectMany(x => x.Sources) .OfType <ContinuationSource>() .Any(x => x.Continuation is TContinuation)); }
public void is_saga_chain_is_false_for_handler_chain_with_no_saga_handlers() { var call = HandlerCall.For<SimpleHandler<OneMessage>>(x => x.Handle(null)); var chain = new HandlerChain(); chain.AddToEnd(call); StatefulSagaConvention.IsSagaChain(chain) .ShouldBeFalse(); }
public override void TearDown() { _host.Dispose(); _graph = null; _chain = null; _transport = null; _bus = null; _host = null; }
public static void ShouldNotHaveHandler <T>(this HandlerChain chain, Expression <Action <T> > expression) { if (chain == null) { return; } var method = ReflectionHelper.GetMethod(expression); ShouldBeBooleanExtensions.ShouldBeFalse(chain.Handlers.Any(x => x.Method.Name == method.Name && x.HandlerType == typeof(T))); }
private static void addExceptionCell(TableRowTag row, HandlerChain chain) { var exceptionCell = row.Cell(); var node = chain.OfType<ExceptionHandlerNode>().FirstOrDefault(); if (node != null) { var description = Description.For(node); var descriptionTag = new DescriptionBodyTag(description); exceptionCell.Append(descriptionTag); } }
public void create_by_static_method() { var chain = HandlerChain.For <Target>(nameof(Target.GoStatic)); chain.MessageType.ShouldBe(typeof(Message2)); var methodCall = chain.Handlers.Single(); methodCall.HandlerType.ShouldBe(typeof(Target)); methodCall.Method.Name.ShouldBe(nameof(Target.GoStatic)); }
public void create_by_method() { var chain = HandlerChain.For <Target>(x => x.Go(null)); chain.MessageType.ShouldBe(typeof(Message1)); var methodCall = chain.Handlers.Single(); methodCall.HandlerType.ShouldBe(typeof(Target)); methodCall.Method.Name.ShouldBe(nameof(Target.Go)); }
public IContinuation DetermineContinuation(Exception exception, HandlerChain handlerChain, HandlerGraph graph) { if (Envelope.Attempts >= handlerChain.MaximumAttempts) { return(new MoveToErrorQueue(exception)); } return(handlerChain.DetermineContinuation(Envelope, exception) ?? graph.DetermineContinuation(Envelope, exception) ?? new MoveToErrorQueue(exception)); }
public static void ShouldNotHaveHandler <T>(this HandlerChain chain, Expression <Action <T> > expression) { if (chain == null) { return; } var method = ReflectionHelper.GetMethod(expression); chain.Handlers.Any(x => x.Method == method).ShouldBeFalse(); }
public void requeue() { var chain = new HandlerChain(); chain.OnException<NotSupportedException>() .Requeue(); var handler = chain.ErrorHandlers.Single().ShouldBeOfType<ErrorHandler>(); handler.Conditions.Single().ShouldBeOfType<ExceptionTypeMatch<NotSupportedException>>(); handler.Continuation().ShouldBeOfType<RequeueContinuation>(); }
private static void addExceptionCell(TableRowTag row, HandlerChain chain) { var exceptionCell = row.Cell(); var node = chain.OfType <ExceptionHandlerNode>().FirstOrDefault(); if (node != null) { var description = Description.For(node); var descriptionTag = new DescriptionBodyTag(description); exceptionCell.Append(descriptionTag); } }
public override void Configure(HandlerChain chain) { chain.MaximumAttempts = 3; chain.OnException <DivideByZeroException>().Requeue(); chain.OnException <InvalidOperationException>().Retry(); chain.OnException <NotSupportedException>() .MoveToErrorQueue() .Then.RespondWithMessage((ex, env) => new ErrorMessage { Message = ex.Message }); }
public void retry_now() { var chain = new HandlerChain(); chain.OnException <NotImplementedException>() .Retry(); var handler = chain.ErrorHandlers.Single().ShouldBeOfType <ErrorHandler>(); handler.Conditions.Single().ShouldBeOfType <ExceptionTypeMatch <NotImplementedException> >(); handler.Continuation(null, null).ShouldBeOfType <RetryNowContinuation>(); }
public void requeue() { var chain = new HandlerChain(); chain.OnException <NotSupportedException>() .Requeue(); var handler = chain.ErrorHandlers.Single().ShouldBeOfType <ErrorHandler>(); handler.Conditions.Single().ShouldBeOfType <ExceptionTypeMatch <NotSupportedException> >(); handler.Continuation(null, null).ShouldBeOfType <RequeueContinuation>(); }
private void addRow(TableRowTag row, HandlerChain chain) { addMessageCell(row, chain); addExceptionCell(row, chain); addOthersCell(row, chain); row.Cell().Add("ul", ul => { chain.OfType<HandlerCall>().Each(call => { ul.Add("li").Text(call.Description); }); }); }
private void addRow(TableRowTag row, HandlerChain chain) { addMessageCell(row, chain); addExceptionCell(row, chain); addOthersCell(row, chain); row.Cell().Add("ul", ul => { chain.OfType <HandlerCall>().Each(call => { ul.Add("li").Text(call.Description); }); }); }
public void retry_later() { var chain = new HandlerChain(); chain.OnException<NotSupportedException>() .RetryLater(10.Minutes()); var handler = chain.ErrorHandlers.Single().ShouldBeOfType<ErrorHandler>(); handler.Conditions.Single().ShouldBeOfType<ExceptionTypeMatch<NotSupportedException>>(); handler.Continuation().ShouldBeOfType<DelayedRetryContinuation>() .Delay.ShouldEqual(10.Minutes()); }
protected override void beforeEach() { theEnvelope = ObjectMother.Envelope(); theInvoker = MockFor <IChainInvoker>(); theChain = new HandlerChain(); theChain.AddToEnd(HandlerCall.For <TaskHandler>(x => x.AsyncHandle(null))); theChain.IsAsync.ShouldBeTrue(); theInvoker.Stub(x => x.FindChain(theEnvelope)) .Return(theChain); theContinuation = ClassUnderTest.Handle(theEnvelope); }
public void retry_later() { var chain = new HandlerChain(); chain.OnException <NotSupportedException>() .RetryLater(10.Minutes()); var handler = chain.ErrorHandlers.Single().ShouldBeOfType <ErrorHandler>(); handler.Conditions.Single().ShouldBeOfType <ExceptionTypeMatch <NotSupportedException> >(); handler.Continuation(null, null).ShouldBeOfType <DelayedRetryContinuation>() .Delay.ShouldBe(10.Minutes()); }
public void add_multiple_continuations() { var chain = new HandlerChain(); chain.OnException<NotSupportedException>() .RetryLater(10.Minutes()) .Then .ContinueWith<TellTheSenderHeSentSomethingWrong>(); var handler = chain.ErrorHandlers.Single().ShouldBeOfType<ErrorHandler>(); var continuation = handler.Continuation().ShouldBeOfType<CompositeContinuation>(); continuation.Select(x => x.GetType()) .ShouldHaveTheSameElementsAs(typeof(DelayedRetryContinuation), typeof(TellTheSenderHeSentSomethingWrong)); }
public ChainExecutionWatcher(ILogger logger, HandlerChain chain, Envelope envelope) { _logger = logger; _chain = chain; _envelope = envelope; _logger.DebugMessage(() => new ChainExecutionStarted { ChainId = chain.UniqueId, Envelope = envelope.ToToken() }); _stopwatch.Start(); }
protected override void theContextIs() { theBehavior = MockFor <IDisposableBehavior>(); theChain = new HandlerChain(); _invocationContext = new FubuMVC.Core.ServiceBus.Runtime.Invocation.InvocationContext(theEnvelope, new HandlerChain()); MockFor <IServiceFactory>().Stub(x => x.BuildBehavior(_invocationContext, theChain.UniqueId)) .Return(theBehavior); Services.Inject(new BehaviorGraph()); ClassUnderTest.ExecuteChain(theEnvelope, theChain); }
public ChainExecutionWatcher(ILogger logger, HandlerChain chain, Envelope envelope) { _logger = logger; _chain = chain; _envelope = envelope; _logger.DebugMessage(() => new ChainExecutionStarted { ChainId = chain.UniqueId, Envelope = envelope.ToToken() }); _stopwatch.Start(); }
protected override Frame buildPersistenceFrame(IContainer container, HandlerChain chain, SagaStateExistence existence, ref Variable sagaId, Type sagaStateType, Variable existingState, ref Variable loadedState) { var frame = new InMemorySagaPersistenceFrame(sagaStateType, sagaId, existence); if (existence == SagaStateExistence.Existing) { loadedState = frame.Document; } return(frame); }
public void add_multiple_continuations() { var chain = new HandlerChain(); chain.OnException <NotSupportedException>() .RetryLater(10.Minutes()) .Then .ContinueWith <TellTheSenderHeSentSomethingWrong>(); var handler = chain.ErrorHandlers.Single().ShouldBeOfType <ErrorHandler>(); var continuation = handler.Continuation(null, null).ShouldBeOfType <CompositeContinuation>(); continuation.Select(x => x.GetType()) .ShouldHaveTheSameElementsAs(typeof(DelayedRetryContinuation), typeof(TellTheSenderHeSentSomethingWrong)); }
public InvocationContext(Envelope envelope, HandlerChain chain) { if (envelope == null) throw new ArgumentNullException("envelope"); var currentChain = new CurrentChain(chain, _emptyDictionary); Set(typeof(ICurrentChain), currentChain); _envelope = envelope; var inputType = envelope.Message.GetType(); var request = new InMemoryFubuRequest(); request.Set(inputType, _envelope.Message); Set(typeof(IFubuRequest), request); Set(typeof(IInvocationContext), this); Set(typeof(Envelope), envelope); }
public Frame DeterminePersistenceFrame(IContainer container, HandlerChain chain, MethodCall sagaHandler, SagaStateExistence existence, ref Variable sagaId, Type sagaStateType, Variable existingState, out Variable loadedState) { loadedState = existingState; if (existence == SagaStateExistence.New) { var prop = findIdProperty(sagaStateType); sagaId = new Variable(prop.PropertyType, existingState.Usage + "." + prop.Name); } var frame = buildPersistenceFrame(container, chain, existence, ref sagaId, sagaStateType, existingState, ref loadedState); return(frame); }
public IContinuation ExecuteChain(Envelope envelope, HandlerChain chain) { try { var context = _invoker.ExecuteChain(envelope, chain); return context.Continuation ?? new ChainSuccessContinuation(context); } catch (EnvelopeDeserializationException ex) { return new DeserializationFailureContinuation(ex); } catch (Exception ex) { // TODO -- might be nice to capture the Chain return new ChainFailureContinuation(ex); } }
public IContinuation ExecuteChain(Envelope envelope, HandlerChain chain) { try { var context = _invoker.ExecuteChain(envelope, chain); return(context.Continuation ?? new ChainSuccessContinuation(context)); } catch (EnvelopeDeserializationException ex) { return(new DeserializationFailureContinuation(ex)); } catch (Exception ex) { // TODO -- might be nice to capture the Chain return(new ChainFailureContinuation(ex)); } }
public IInvocationContext ExecuteChain(Envelope envelope, HandlerChain chain) { using (new ChainExecutionWatcher(_logger, chain, envelope)) { var context = new InvocationContext(envelope, chain); var behavior = _factory.BuildBehavior(context, chain.UniqueId); try { behavior.Invoke(); } finally { (behavior as IDisposable).CallIfNotNull(x => x.SafeDispose()); } return(context); } }
private void applyToChain(HandlerChain chain) { foreach (var handler in chain.Handlers) { var method = handler.HandlerType.GetMethod(OpenSessionMethodName); if (method == null) { continue; } if (method.ReturnType != typeof(IDocumentSession)) { continue; } var @call = new MethodCall(handler.HandlerType, method); chain.Middleware.Add(@call); } }
public override void Configure(HandlerChain handlerChain) { //when retrying, do so a maximum of 5 times handlerChain.MaximumAttempts = 5; //retry now handlerChain.OnException<ConcurrencyException>() .Retry(); //retry again 5 seconds from now handlerChain.OnException<ConcurrencyException>() .RetryLater(TimeSpan.FromSeconds(5)); //immediately move the error and original message to //the error queue handlerChain.OnException<FileNotFoundException>() .MoveToErrorQueue(); //retries, but puts at the end of the line allowing other //messages to be processed handlerChain.OnException<Exception>() .Requeue(); }
public ExceptionHandlerNode(HandlerChain chain) { _chain = chain; }
/// <summary> /// Override this for the alteration to each HandlerChain /// </summary> /// <param name="handlerChain"></param> public abstract void Configure(HandlerChain handlerChain);
public override void Configure(HandlerChain handlerChain) { handlerChain.MaximumAttempts = 5; handlerChain.OnException<DBConcurrencyException>() .Retry(); }
public void retry_now() { var chain = new HandlerChain(); chain.OnException<NotImplementedException>() .Retry(); var handler = chain.ErrorHandlers.Single().ShouldBeOfType<ErrorHandler>(); handler.Conditions.Single().ShouldBeOfType<ExceptionTypeMatch<NotImplementedException>>(); handler.Continuation().ShouldBeOfType<RetryNowContinuation>(); }
public override bool Matches(HandlerChain chain) { return chain.IsAsync; }
public override void Configure(HandlerChain handlerChain) { var firstCall = handlerChain.OfType<HandlerCall>().First(); firstCall.AddBefore(new AsyncHandlingNode()); }
public void url_category_is_handler() { var chain = new HandlerChain(); chain.UrlCategory.Category.ShouldEqual("Handler"); }
private static void addMessageCell(TableRowTag row, HandlerChain chain) { var messageCell = row.Cell().AddClass("message"); messageCell.Add("h4").Text(chain.InputType().Name); messageCell.Add("p").Text(chain.InputType().Namespace); }
/// <summary> /// Override this to control the applicability of this policy to /// each chain. Default is to always apply /// </summary> /// <param name="chain"></param> /// <returns></returns> public virtual bool Matches(HandlerChain chain) { return true; }