public void Should_compensate_both_activities()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipFaulted>(message => handled.Set());

            Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>());

            ActivityTestContext testActivity  = GetActivityContext <TestActivity>();
            ActivityTestContext faultActivity = GetActivityContext <NastyFaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public async Task ShouldRetry_WhenMessageRetryIsUsed()
        {
            try
            {
                var testActivity = new ActivityTestContext <FirstFaultyActivity, FaultyArguments, FaultyLog>(
                    harness,
                    () => new FirstFaultyActivity(),
                    null,
                    null);
                harness.OnConfigureBus += bus => bus.UseMessageRetry(r => r.Immediate(2));

                await harness.Start();

                var routingSlipCompletedHandler = ConnectPublishHandler <RoutingSlipCompleted>(harness);

                var builder = new RoutingSlipBuilder(Guid.NewGuid());
                builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { });
                await harness.Bus.Execute(builder.Build());

                await routingSlipCompletedHandler;
            }
            finally
            {
                await harness.Stop();
            }
        }
Пример #3
0
        public async Task Should_compensate_with_the_log()
        {
            Task <ConsumeContext <RoutingSlipFaulted> >             faulted             = SubscribeHandler <RoutingSlipFaulted>();
            Task <ConsumeContext <RoutingSlipActivityCompleted> >   activity            = SubscribeHandler <RoutingSlipActivityCompleted>();
            Task <ConsumeContext <RoutingSlipActivityCompensated> > activityCompensated = SubscribeHandler <RoutingSlipActivityCompensated>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            var testActivity   = GetActivityContext <AddressActivity>();
            var faultyActivity = GetActivityContext <FaultyActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Address = new Uri("http://google.com/") });
            builder.AddActivity(faultyActivity.Name, faultyActivity.ExecuteUri);

            await Bus.Execute(builder.Build());

            await faulted;

            ConsumeContext <RoutingSlipActivityCompleted> consumeContext = await activity;

            Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult <string>("UsedAddress"));

            ConsumeContext <RoutingSlipActivityCompensated> context = await activityCompensated;

            Assert.AreEqual(new Uri("http://google.com/"), context.Message.GetResult <string>("UsedAddress"));
        }
Пример #4
0
        public async Task Setup()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            var testActivity   = GetActivityContext <TestActivity>();
            var secondActivity = GetActivityContext <SecondTestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value     = "Hello",
                NullValue = (string)null
            });

            builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");
            builder.AddVariable("Nothing", null);

            _routingSlip = builder.Build();

            await Bus.Execute(_routingSlip);

            var completed = (await _completed).Message;

            Assert.AreEqual(_routingSlip.TrackingNumber, completed.TrackingNumber);
        }
Пример #5
0
        public async Task Setup()
        {
            ActivityTestContext testActivity   = GetActivityContext <TestActivity>();
            ActivityTestContext secondActivity = GetActivityContext <SecondTestActivity>();

            _completed = SubscribeHandler <RoutingSlipCompleted>();
            _firstActivityCompleted =
                SubscribeHandler <RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(testActivity.Name));
            _secondActivityCompleted =
                SubscribeHandler <RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(secondActivity.Name));

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value     = "Hello",
                NullValue = (string)null,
            });

            builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");
            builder.AddVariable("Nothing", null);
            builder.AddVariable("ToBeRemoved", "Existing");

            _routingSlip = builder.Build();

            await Bus.Execute(_routingSlip);
        }
Пример #6
0
        public async Task Should_publish_the_completed_event()
        {
            Task <ConsumeContext <RoutingSlipCompleted> >         completed = SubscribeHandler <RoutingSlipCompleted>();
            Task <ConsumeContext <RoutingSlipActivityCompleted> > activity  = SubscribeHandler <RoutingSlipActivityCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext <AddressActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);

            builder.SetVariables(new
            {
                Address = new Uri("http://google.com/"),
            });

            await Bus.Execute(builder.Build());

            await completed;

            var consumeContext = await activity;

            Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult <string>("UsedAddress"));
        }
Пример #7
0
        public async Task Should_handle_the_failed_to_compensate_event_via_subscription()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            Task <ConsumeContext <RoutingSlipActivityCompensationFailed> > handledCompensationFailure =
                SubscribeHandler <RoutingSlipActivityCompensationFailed>(x => x.Message.TrackingNumber == builder.TrackingNumber);
            Task <ConsumeContext <RoutingSlipCompensationFailed> > handledRoutingSlipFailure =
                SubscribeHandler <RoutingSlipCompensationFailed>(x => x.Message.TrackingNumber == builder.TrackingNumber);

            var testActivity             = GetActivityContext <TestActivity>();
            var faultyCompensateActivity = GetActivityContext <FaultyCompensateActivity>();
            var faultActivity            = GetActivityContext <FaultyActivity>();

            builder.AddVariable("Value", "Hello");
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri);
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            builder.AddSubscription(
                Bus.Address,
                RoutingSlipEvents.CompensationFailed,
                RoutingSlipEventContents.All);

            builder.AddSubscription(
                Bus.Address,
                RoutingSlipEvents.ActivityCompensationFailed,
                RoutingSlipEventContents.All);

            await Bus.Execute(builder.Build());

            await handledRoutingSlipFailure;

            await handledCompensationFailure;
        }
Пример #8
0
        public async Task Evaluate()
        {
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder(_routingSlip);

            Build(builder);

            RoutingSlip routingSlip = builder.Build();

            await _publisher.PublishRoutingSlipActivityCompensated(_compensateContext.ActivityName, _compensateContext.ExecutionId,
                                                                   _compensateContext.Timestamp, _duration, _routingSlip.Variables, _compensateLog.Data).ConfigureAwait(false);

            if (HasMoreCompensations(routingSlip))
            {
                ISendEndpoint endpoint = await _compensateContext.GetSendEndpoint(routingSlip.GetNextCompensateAddress()).ConfigureAwait(false);

                await _compensateContext.ConsumeContext.Forward(endpoint, routingSlip).ConfigureAwait(false);
            }
            else
            {
                DateTime faultedTimestamp = _compensateContext.Timestamp + _duration;
                TimeSpan faultedDuration  = faultedTimestamp - _routingSlip.CreateTimestamp;

                await _publisher.PublishRoutingSlipFaulted(faultedTimestamp, faultedDuration, _routingSlip.Variables,
                                                           _routingSlip.ActivityExceptions.ToArray()).ConfigureAwait(false);
            }
        }
        public async Task Setup()
        {
            _faulted                 = SubscribeHandler <RoutingSlipFaulted>();
            _activityCompleted       = SubscribeHandler <RoutingSlipActivityCompleted>(x => x.Message.ActivityName.Equals("Test"));
            _activityCompensated     = SubscribeHandler <RoutingSlipActivityCompensated>(x => x.Message.ActivityName.Equals("Test"));
            _secondActivityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(x => x.Message.ActivityName.Equals("SecondTest"));
            _activityFaulted         = SubscribeHandler <RoutingSlipActivityFaulted>(x => x.Message.ActivityName.Equals("Faulty"));

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            var testActivity = GetActivityContext <TestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello" });

            testActivity = GetActivityContext <SecondTestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            testActivity = GetActivityContext <FaultyActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");

            await Bus.Execute(builder.Build());
        }
Пример #10
0
        public async Task Should_retry_and_eventually_compensate()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            var testActivity             = GetActivityContext <TestActivity>();
            var faultyCompensateActivity = GetActivityContext <FirstFaultyCompensateActivity>();
            var faultActivity            = GetActivityContext <FaultyActivity>();

            Task <ConsumeContext <RoutingSlipActivityCompensated> > compensated = await ConnectPublishHandler <RoutingSlipActivityCompensated>(
                context => context.Message.ActivityName.Equals(faultyCompensateActivity.Name));

            Task <ConsumeContext <RoutingSlipFaulted> > routingSlipFailure =
                await ConnectPublishHandler <RoutingSlipFaulted>(x => x.Message.TrackingNumber == builder.TrackingNumber);

            builder.AddVariable("Value", "Hello");
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri);
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            await Bus.Execute(builder.Build());

            await routingSlipFailure;

            await compensated;
        }
        CompensationResult Compensation <TLog> .Compensated()
        {
            var builder = new RoutingSlipBuilder(_routingSlip.TrackingNumber, _routingSlip.Itinerary,
                                                 _routingSlip.ActivityLogs.SkipLast(), _routingSlip.Variables, _routingSlip.ActivityExceptions);

            return(Compensated(builder.Build()));
        }
Пример #12
0
        protected override async Task PublishActivityEvents(RoutingSlip routingSlip, RoutingSlipBuilder builder)
        {
            await base.PublishActivityEvents(routingSlip, builder).ConfigureAwait(false);

            await Publisher.PublishRoutingSlipRevised(Context.ExecutionId, Context.Timestamp, Context.Elapsed, routingSlip.Variables,
                                                      routingSlip.Itinerary, builder.SourceItinerary).ConfigureAwait(false);
        }
Пример #13
0
        protected override async Task PublishActivityEvents(RoutingSlip routingSlip, RoutingSlipBuilder builder)
        {
            await base.PublishActivityEvents(routingSlip, builder);

            await Publisher.PublishRoutingSlipTerminated(Context.ExecutionId, Context.Timestamp, Context.Elapsed, routingSlip.Variables,
                                                         builder.SourceItinerary);
        }
Пример #14
0
        public async Task Should_continue_with_the_source_itinerary()
        {
            var trackingNumber = Guid.NewGuid();

            var testActivity   = GetActivityContext <TestActivity>();
            var reviseActivity = GetActivityContext <ReviseItineraryActivity>();

            Task <ConsumeContext <RoutingSlipCompleted> > completed =
                ConnectPublishHandler <RoutingSlipCompleted>(context => context.Message.TrackingNumber == trackingNumber);

            Task <ConsumeContext <RoutingSlipActivityCompleted> > testActivityCompleted = ConnectPublishHandler <RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name));

            Task <ConsumeContext <RoutingSlipActivityCompleted> > reviseActivityCompleted = ConnectPublishHandler <RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(reviseActivity.Name));

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new { Value = "Time to add a new item!" });

            await Bus.Execute(builder.Build());

            await completed;
            await reviseActivityCompleted;
            ConsumeContext <RoutingSlipActivityCompleted> testActivityResult = await testActivityCompleted;

            testActivityResult.Message.GetArgument <string>("Value").ShouldBe("Added");
        }
Пример #15
0
        public async Task Should_complete_the_additional_item()
        {
            var trackingNumber = Guid.NewGuid();

            var testActivity   = GetActivityContext <TestActivity>();
            var reviseActivity = GetActivityContext <ReviseItineraryActivity>();

            Task <ConsumeContext <RoutingSlipCompleted> > completed =
                ConnectPublishHandler <RoutingSlipCompleted>(context => context.Message.TrackingNumber == trackingNumber);

            Task <ConsumeContext <RoutingSlipActivityCompleted> > testActivityCompleted = ConnectPublishHandler <RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name));

            Task <ConsumeContext <RoutingSlipActivityCompleted> > reviseActivityCompleted = ConnectPublishHandler <RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(reviseActivity.Name));

            Task <ConsumeContext <RoutingSlipRevised> > revised = ConnectPublishHandler <RoutingSlipRevised>(
                context => context.Message.TrackingNumber == trackingNumber);

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new { Value = "Time to add a new item!" });

            await Bus.Execute(builder.Build());

            await completed;
            await testActivityCompleted;
            await reviseActivityCompleted;

            ConsumeContext <RoutingSlipRevised> revisions = await revised;

            Assert.AreEqual(0, revisions.Message.DiscardedItinerary.Length);
        }
Пример #16
0
            public void Should_fail_if_not_supported()
            {
                using (var provider = Aes.Create())
                {
                    provider.GenerateKey();
                    provider.GenerateIV();

                    using (ICryptoTransform encryptor = provider.CreateEncryptor())
                    {
                        byte[] bytes = Encoding.UTF8.GetBytes("secret");

                        byte[] password = encryptor.TransformFinalBlock(bytes, 0, bytes.Length);

                        var builder = new RoutingSlipBuilder(NewId.NextGuid());
                        builder.AddActivity("GetFile", new Uri("rabbitmq://localhost/execute_getfile"), new
                        {
                            Username = "******",
                            Password = password,
                        });

                        RoutingSlip routingSlip = builder.Build();

                        Console.WriteLine(routingSlip.ToJsonString());
                    }
                }
            }
        public async Task Execute(ConsumeContext <IDeleteUserCommand> context)
        {
            var builder           = new RoutingSlipBuilder(NewId.NextGuid());
            var deleteUserCommand = context.Message;

            builder.AddActivity(UserServiceConstants.ActivityDeleteAdUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IDeleteActiveDirectoryUserActivity)), _activityArgumentsMapper.MapDeleteActiveDirectoryUserArguments(deleteUserCommand));
            builder.AddActivity(UserServiceConstants.ActivityDeleteIsUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IDeleteIdentityServerUserActivity)), _activityArgumentsMapper.MapDeleteIdentityServerUserArguments(deleteUserCommand));

            builder.AddSubscription(UserServiceConstants.RoutingSlipEventObserverUri,
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var user = _userService.GetUser(context.Message.UserId);
            await builder.AddSubscription(Office365ServiceConstants.QueueOffice365UserRemoveLicenseUri,
                                          RoutingSlipEvents.Completed,
                                          x => x.Send <IOffice365UserRemoveLicenseCommand>(new
            {
                context.Message.CompanyId,
                UserPrincipalName = user.Email
            }));

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
Пример #18
0
        public async Task Should_publish_the_completed_event()
        {
            var startTime = DateTime.UtcNow;

            Task <ConsumeContext <RoutingSlipCompleted> >   completed   = SubscribeHandler <RoutingSlipCompleted>();
            Task <ConsumeContext <MyRoutingSlipCompleted> > myCompleted = SubscribeHandler <MyRoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);
            await builder.AddSubscription(Bus.Address, RoutingSlipEvents.Completed, x => x.Send <MyRoutingSlipCompleted>(new
            {
                builder.TrackingNumber,
                SomeValue = "Hello"
            }));

            var testActivity = GetActivityContext <TestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello" });

            await Bus.Execute(builder.Build());

            await completed;

            ConsumeContext <MyRoutingSlipCompleted> context = await myCompleted;

            Assert.That(context.Message.Timestamp, Is.GreaterThanOrEqualTo(startTime));

            Console.WriteLine(GetBodyString(context.ReceiveContext));
        }
        public async Task ShouldCreateOneSpans_WhenThreeRetriesAreUsedAndActivityFailsOnFirstAttempt()
        {
            try
            {
                var testActivity = new ActivityTestContext <FirstFaultyActivity, FaultyArguments, FaultyLog>(
                    harness,
                    () => new FirstFaultyActivity(),
                    cfg => cfg.UseRetry(r => r.Immediate(2)),
                    null);

                await harness.Start();

                var routingSlipCompletedHandler = ConnectPublishHandler <RoutingSlipCompleted>(harness);

                var builder = new RoutingSlipBuilder(Guid.NewGuid());
                builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { });
                await harness.Bus.Execute(builder.Build());

                await routingSlipCompletedHandler;
            }
            finally
            {
                await harness.Stop();
            }
        }
Пример #20
0
        public async Task Should_publish_the_faulted_routing_slip_event()
        {
            var testActivity  = GetActivityContext <TestActivity>();
            var faultActivity = GetActivityContext <FaultyActivity>();

            Task <ConsumeContext <RoutingSlipFaulted> >             handled     = SubscribeHandler <RoutingSlipFaulted>();
            Task <ConsumeContext <RoutingSlipActivityCompensated> > compensated = SubscribeHandler <RoutingSlipActivityCompensated>(
                context => context.Message.ActivityName.Equals(testActivity.Name));

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello"
            });
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri, new
            {
            });

            await Bus.Execute(builder.Build());

            await handled;

            await compensated;
        }
        public async Task <Guid> Publish(Uri reqUri)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("Validate", new Uri(_activityConfig.ValidateAddress));
            builder.AddActivity("PreProcess", new Uri(_activityConfig.PreProcessAddress));
            builder.AddActivity("Retrieve", new Uri(_activityConfig.RetrieveAddress));
            builder.AddActivity("PostProcess", new Uri(_activityConfig.PostProcessAddress));
            builder.AddActivity("Consent", new Uri(_activityConfig.ConsentAddress));

            builder.SetVariables(new
            {
                RequestId = NewId.NextGuid(),
                Address   = reqUri,
            });

            var routingSlip = builder.Build();

            await _bus.Publish <RoutingSlipCreated>(new
            {
                routingSlip.TrackingNumber,
                Timestamp = routingSlip.CreateTimestamp,
            });

            await _bus.Execute(routingSlip);

            return(routingSlip.TrackingNumber);
        }
Пример #22
0
        public void Should_handle_the_failed_to_compensate_event()
        {
            var handledCompensationFailure = new ManualResetEvent(false);
            var handledRoutingSlipFailure  = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipActivityCompensationFailed>(message => handledCompensationFailure.Set());
            LocalBus.SubscribeHandler <RoutingSlipCompensationFailed>(message => handledRoutingSlipFailure.Set());

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompensationFailed>());
            Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompensationFailed>());

            ActivityTestContext testActivity             = GetActivityContext <TestActivity>();
            ActivityTestContext faultyCompensateActivity = GetActivityContext <FaultyCompensateActivity>();
            ActivityTestContext faultActivity            = GetActivityContext <FaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddVariable("Value", "Hello");
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri);
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handledRoutingSlipFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
            Assert.IsTrue(handledCompensationFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
Пример #23
0
        public async Task Execute(ConsumeContext <IOffice365ResendTxtRecordsCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var resendTxtRecordsCommand = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityGetOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetCustomerDomainTxtRecordsActivity)), _activityOffice365CustomerArgumentsMapper.MapGetCustomerTxtRecords(resendTxtRecordsCommand));
            builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendCustomerDomainTxtRecordsActivity)), _activityOffice365CustomerArgumentsMapper.MapSendCustomerTxtRecords(resendTxtRecordsCommand));

            builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri,
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.ResendOffice365DomainTxtRecords.ToString()
            });

            await context.Execute(routingSlip);
        }
Пример #24
0
        public async Task Should_publish_the_faulted_routing_slip_event()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity       = GetActivityContext <TestActivity>();
            ActivityTestContext secondTestActivity = GetActivityContext <SecondTestActivity>();
            ActivityTestContext faultActivity      = GetActivityContext <FaultyActivity>();

            Task <ConsumeContext <RoutingSlipFaulted> >             handled     = ConnectPublishHandler <RoutingSlipFaulted>(x => x.Message.TrackingNumber == builder.TrackingNumber);
            Task <ConsumeContext <RoutingSlipActivityCompensated> > compensated = ConnectPublishHandler <RoutingSlipActivityCompensated>(
                context => context.Message.ActivityName.Equals(testActivity.Name));

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });
            builder.AddActivity(secondTestActivity.Name, secondTestActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri, new
            {
            });

            await Bus.Execute(builder.Build());

            await handled;

            await compensated;
        }
        public async Task Consume(ConsumeContext <SubmitOrder> context)
        {
            LogContext.Info?.Log("Submitting Order: {OrderId}", context.Message.OrderId);
            using (var client = new HttpClient())
                await client.GetAsync("https://www.google.com");
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            if (!EndpointConvention.TryGetDestinationAddress <ProcessOrderArguments>(out var activityAddress))
            {
                throw new ConfigurationException("No endpoint address for activity");
            }

            builder.AddActivity("Process", activityAddress);

            if (!EndpointConvention.TryGetDestinationAddress <OrderProcessed>(out var eventAddress))
            {
                throw new ConfigurationException("No endpoint address for activity");
            }

            await builder.AddSubscription(eventAddress, RoutingSlipEvents.Completed, endpoint =>
                                          endpoint.Send <OrderProcessed>(context.Message));

            await context.Execute(builder.Build());

            await context.Publish <OrderSubmitted>(context.Message, x => x.ResponseAddress = context.ResponseAddress);
        }
Пример #26
0
        public void Should_handle_the_failed_to_compensate_event()
        {
            var handledCompensationFailure = new ManualResetEvent(false);
            var handledRoutingSlipFailure = new ManualResetEvent(false);

            LocalBus.SubscribeHandler<RoutingSlipActivityCompensationFailed>(message => { handledCompensationFailure.Set(); });
            LocalBus.SubscribeHandler<RoutingSlipCompensationFailed>(message => { handledRoutingSlipFailure.Set(); });

            Assert.IsTrue(WaitForSubscription<RoutingSlipCompensationFailed>());
            Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompensationFailed>());

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext faultyCompensateActivity = GetActivityContext<FaultyCompensateActivity>();
            ActivityTestContext faultActivity = GetActivityContext<FaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddVariable("Value", "Hello");
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri);
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handledRoutingSlipFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
            Assert.IsTrue(handledCompensationFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
Пример #27
0
        public void Should_compensate_both_activities()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler<RoutingSlipFaulted>(message => handled.Set());

            Assert.IsTrue(WaitForSubscription<RoutingSlipFaulted>());

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext faultActivity = GetActivityContext<NastyFaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
 protected override void BuildRoutingSlip(RoutingSlipBuilder builder, ConsumeContext <ISimpleRequest> request)
 {
     builder.AddActivity("Activity", new Uri("exchange:Activity_execute"));
     builder.AddActivity("Activity2", new Uri("exchange:Activity2_execute"), new {
         Name = request.Message.CustomerId,
         request.ResponseAddress,
     });
 }
Пример #29
0
        ExecutionResult Execution <TArguments> .CompletedWithoutLog(object variables)
        {
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder();

            builder.SetVariables(variables);

            return(Complete(builder.Build(), RoutingSlipBuilder.NoArguments));
        }
Пример #30
0
        ExecutionResult Execution <TArguments> .CompletedWithoutLog(IEnumerable <KeyValuePair <string, object> > variables)
        {
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder();

            builder.SetVariables(variables);

            return(Complete(builder.Build(), RoutingSlipBuilder.NoArguments));
        }
        RoutingSlip CreateFaultedRoutingSlip(string activityName, Uri hostAddress, Exception exception)
        {
            var builder = new RoutingSlipBuilder(_routingSlip.TrackingNumber, _routingSlip.Itinerary,
                _routingSlip.ActivityLogs, _routingSlip.Variables, _routingSlip.ActivityExceptions);
            builder.AddActivityException(activityName, hostAddress, _activityTrackingNumber, _timestamp, exception);

            return builder.Build();
        }
Пример #32
0
        RoutingSlip CreateFaultedRoutingSlip(string activityName, Uri hostAddress, Exception exception)
        {
            var builder = new RoutingSlipBuilder(_routingSlip.TrackingNumber, _routingSlip.Itinerary,
                                                 _routingSlip.ActivityLogs, _routingSlip.Variables, _routingSlip.ActivityExceptions);

            builder.AddActivityException(activityName, hostAddress, _activityTrackingNumber, _timestamp, exception);

            return(builder.Build());
        }
        public void Should_be_properly_serialized_as_a_message()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity("test", new Uri("loopback://localhost/mt_client"), new {});

            _bus.Publish(builder.Build());

            Assert.IsTrue(_received.WaitOne(8.Seconds()));
        }
Пример #34
0
        ExecutionResult Execution <TArguments> .Completed <TLog>(TLog log, object variables)
        {
            ActivityLog        activityLog;
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder(log, out activityLog);

            builder.SetVariables(variables);

            return(Complete(builder.Build(), activityLog.Results));
        }
        public void Should_immediately_complete_an_empty_list()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler<RoutingSlipCompleted>(message => { handled.Set(); });

            Assert.IsTrue(WaitForSubscription<RoutingSlipCompleted>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
Пример #36
0
        public void Should_capture_a_thrown_exception()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler<RoutingSlipFaulted>(message => handled.Set());

            Assert.IsTrue(WaitForSubscription<RoutingSlipFaulted>());

            ActivityTestContext faultActivity = GetActivityContext<NastyFaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public void Should_work_for_activity_arguments()
        {
            _intValue = 27;
            _stringValue = "Hello, World.";
            _decimalValue = 123.45m;

            var completed = new TaskCompletionSource<RoutingSlipCompleted>();
            var faulted = new TaskCompletionSource<RoutingSlipFaulted>();

            LocalBus.SubscribeHandler<RoutingSlipCompleted>(message => completed.TrySetResult(message));
            LocalBus.SubscribeHandler<RoutingSlipFaulted>(message => faulted.TrySetResult(message));

            Assert.IsTrue(WaitForSubscription<RoutingSlipCompleted>());
            Assert.IsTrue(WaitForSubscription<RoutingSlipFaulted>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity = GetActivityContext<ObjectGraphTestActivity>();
            ActivityTestContext testActivity2 = GetActivityContext<TestActivity>();

            var dictionary = new Dictionary<string, object>
                {
                    {"Outer", new OuterObjectImpl(_intValue, _stringValue, _decimalValue)},
                    {"Names", new[] {"Albert", "Chris"}},
                };
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, dictionary);
            builder.AddActivity(testActivity2.Name, testActivity2.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.AreNotEqual(WaitHandle.WaitTimeout,
                Task.WaitAny(new Task[] { completed.Task, faulted.Task }, Debugger.IsAttached
                                                                            ? 5.Minutes()
                                                                            : 30.Seconds()));

            if (faulted.Task.Status == TaskStatus.RanToCompletion)
            {
                Assert.Fail("Failed due to exception {0}", faulted.Task.Result.ActivityExceptions.Any()
                                                               ? faulted.Task.Result.ActivityExceptions.First()
                                                                        .ExceptionInfo.Message
                                                               : "Unknown");
            }

            Assert.AreEqual(TaskStatus.RanToCompletion, completed.Task.Status, "Did not complete");
        }
        public void Should_publish_the_completed_event()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler<RoutingSlipCompleted>(message => { handled.Set(); });

            Assert.IsTrue(WaitForSubscription<RoutingSlipCompleted>());

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
                {
                    Value = "Hello",
                });
            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public void Setup()
        {
            _faulted = new TaskCompletionSource<RoutingSlipFaulted>(TestCancellationToken);
            _firstActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>(TestCancellationToken);
            _firstActivityCompensated = new TaskCompletionSource<RoutingSlipActivityCompensated>(TestCancellationToken);

            LocalBus.SubscribeHandler<RoutingSlipFaulted>(x => _faulted.SetResult(x));
            Assert.IsTrue(WaitForSubscription<RoutingSlipFaulted>());

            LocalBus.SubscribeHandler<RoutingSlipActivityCompleted>(x =>
            {
                if (x.ActivityName.Equals("Test"))
                    _firstActivityCompleted.SetResult(x);
            });
            Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompleted>());

            LocalBus.SubscribeHandler<RoutingSlipActivityCompensated>(x =>
            {
                if (x.ActivityName.Equals("Test"))
                    _firstActivityCompensated.SetResult(x);
            });
            Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompensated>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });

            testActivity = GetActivityContext<SecondTestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            testActivity = GetActivityContext<FaultyActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");

            _routingSlip = builder.Build();

            LocalBus.Execute(_routingSlip);
        }
        public void Should_complete_the_additional_item()
        {
            var trackingNumber = Guid.NewGuid();
            var completed = new TaskCompletionSource<RoutingSlipCompleted>();
            var reviseActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>();
            var testActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>();

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext reviseActivity = GetActivityContext<ReviseItineraryActivity>();

            LocalBus.SubscribeHandler<RoutingSlipCompleted>(msg =>
            {
                if (msg.TrackingNumber == trackingNumber)
                    completed.SetResult(msg);
            });
            LocalBus.SubscribeHandler<RoutingSlipActivityCompleted>(msg =>
                {
                    if (msg.TrackingNumber == trackingNumber)
                    {
                        if (msg.ActivityName.Equals(testActivity.Name))
                            testActivityCompleted.SetResult(msg);
                        if (msg.ActivityName.Equals(reviseActivity.Name))
                            reviseActivityCompleted.SetResult(msg);
                    }
                });

            Assert.IsTrue(WaitForSubscription<RoutingSlipCompleted>());
            Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompleted>());

            var builder = new RoutingSlipBuilder(trackingNumber);
            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new
                {
                    Value = "Time to add a new item!",
                });
            LocalBus.Execute(builder.Build());

            Assert.IsTrue(completed.Task.Wait(TestTimeout), "RoutingSlip did not complete");
            Assert.IsTrue(reviseActivityCompleted.Task.Wait(TestTimeout), "Revise Activity did not complete");
            Assert.IsTrue(testActivityCompleted.Task.Wait(TestTimeout), "TestActivity did not complete");
        }
        public void Setup()
        {
            _test = TestFactory.ForConsumer<ExecuteActivityHost<TestActivity, TestArguments>>()
                               .InSingleBusScenario()
                               .New(x =>
                                   {
                                       x.ConstructUsing(
                                           () =>
                                               {
                                                   var compensateAddress = new Uri("loopback://localhost/mt_server");

                                                   return
                                                       new ExecuteActivityHost<TestActivity, TestArguments>(
                                                           compensateAddress,
                                                           new FactoryMethodExecuteActivityFactory
                                                               <TestActivity, TestArguments>(_ => new TestActivity()));
                                               });

                                       var builder = new RoutingSlipBuilder(Guid.NewGuid());
                                       builder.AddActivity("test", new Uri("loopback://localhost/mt_client"), new
                                           {
                                               Value = "Hello",
                                           });

                                       x.Send(builder.Build());
                                   });

            _test.Execute();
        }
        public async Task Setup()
        {
            _limit = 1;

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>();

            for (int i = 0; i < _limit; i++)
            {
                var builder = new RoutingSlipBuilder(Guid.NewGuid());
                builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
                builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri);

                RoutingSlip routingSlip = builder.Build();

                await Bus.Execute(routingSlip);

                _sentRoutingSlips.Add(routingSlip.TrackingNumber);
            }
        }
        public async Task Setup()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
                NullValue = (string)null,
            });

            builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");
            builder.AddVariable("Nothing", null);

            _routingSlip = builder.Build();

            await Bus.Execute(_routingSlip);

            Console.WriteLine("Routing slip executed");
        }
        public void Should_immediately_complete_an_empty_list()
        {
            Guid trackingNumber = Guid.NewGuid();

            var completed = new TaskCompletionSource<RoutingSlipCompleted>();
            var reviseActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>();
            var testActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>();

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext reviseActivity = GetActivityContext<ReviseToEmptyItineraryActivity>();

            LocalBus.SubscribeHandler<RoutingSlipCompleted>(msg =>
                {
                    if (msg.TrackingNumber == trackingNumber)
                        completed.SetResult(msg);
                });
            LocalBus.SubscribeHandler<RoutingSlipActivityCompleted>(msg =>
                {
                    if (msg.TrackingNumber == trackingNumber)
                    {
                        if (msg.ActivityName.Equals(testActivity.Name))
                            testActivityCompleted.SetResult(msg);
                        if (msg.ActivityName.Equals(reviseActivity.Name))
                            reviseActivityCompleted.SetResult(msg);
                    }
                });

            Assert.IsTrue(WaitForSubscription<RoutingSlipCompleted>());
            Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompleted>());

            var builder = new RoutingSlipBuilder(trackingNumber);
            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new
                {
                    Value = "Time to remove any remaining items!",
                });
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
                {
                    Value = "Hello",
                });
            LocalBus.Execute(builder.Build());

            Assert.IsTrue(completed.Task.Wait(TestTimeout), "RoutingSlip did not complete");
            Assert.IsTrue(reviseActivityCompleted.Task.Wait(TestTimeout), "Revise Activity did not complete");

            Assert.IsFalse(testActivityCompleted.Task.Wait(3.Seconds()), "Test Activity should not have completed");
        }
        public void Setup()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
                NullValue = (string)null,
            });

            builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");
            builder.AddVariable("Nothing", null);

            _routingSlip = builder.Build();

            Await(() => Bus.Execute(_routingSlip));
        }
        public void Setup()
        {
            _limit = 100;

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>();

            for (int i = 0; i < _limit; i++)
            {
                var builder = new RoutingSlipBuilder(Guid.NewGuid());
                builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
                builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri);
                builder.AddVariable("Value", "Hello");

                RoutingSlip routingSlip = builder.Build();

                Bus.Execute(routingSlip);

                _sentRoutingSlips.Add(routingSlip.TrackingNumber);
            }
        }