public async Task Consume(ConsumeContext <SubmitOrder> context) { var routingSlipBuilder = new RoutingSlipBuilder(NewId.NextGuid()); var activityName = nameof(SaveOrderActivity).Replace("Activity", string.Empty); var sanitizedName = KebabCaseEndpointNameFormatter.Instance.SanitizeName(activityName); routingSlipBuilder.AddActivity( activityName, new Uri($"queue:{sanitizedName}_execute"), new { context.Message.OrderId } ); var routingSlipAddress = new Uri($"rabbitmq://localhost/{KebabCaseEndpointNameFormatter.Instance.Consumer<RoutingSlipEventConsumer>()}"); routingSlipBuilder.AddSubscription( routingSlipAddress, RoutingSlipEvents.Completed ); var routingSlip = routingSlipBuilder.Build(); await context.Execute(routingSlip); if (context.RequestId != null) { await context.RespondAsync <OrderSubmissionAccepted>(new { InVar.Timestamp, context.Message.OrderId }); } }
public async Task Should_properly_load() { _completed = SubscribeHandler <RoutingSlipCompleted>(); _faulted = SubscribeHandler <RoutingSlipFaulted>(); _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(Bus.Address, RoutingSlipEvents.All); ActivityTestContext testActivity = GetActivityContext <SetLargeVariableActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Key = "Name", Value = await _repository.PutString("Frank"), }); await Bus.Execute(builder.Build()); await Task.WhenAny(_completed, _faulted); if (_faulted.IsCompleted) { Console.WriteLine(string.Join(",", _faulted.Result.Message.ActivityExceptions.Select(x => x.ExceptionInfo.Message))); } Assert.That(_completed.Status, Is.EqualTo(TaskStatus.RanToCompletion)); }
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); }
public async Task Should_publish_the_faulted_routing_slip_event() { ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext secondTestActivity = GetActivityContext <SecondTestActivity>(); ActivityTestContext 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(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 <ActionResult> Test() { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("CreateGroup", new Uri("rabbitmq://localhost/vhost/operations.activities.accountinggroup.create_accounting_group")); builder.AddActivity("AssignOwnership", new Uri("rabbitmq://localhost/vhost/operations.activities.accountinggroup.assign_accounting_group_ownership")); builder.SetVariables(new { Id = Guid.NewGuid(), DisplayName = "Test", SaleStrategyId = Guid.Parse("{DDF6FE32-F6C7-42DA-0001-4FD368D0D8B9}"), OwnerUserId = Guid.Parse("{DDF6FE32-F6C7-42DA-0002-4FD368D0D8B9}") }); RoutingSlip routingSlip = builder.Build(); await _busControl.Publish <RoutingSlipCreated>(new { TrackingNumber = routingSlip.TrackingNumber, Timestamp = routingSlip.CreateTimestamp, }); await _busControl.Execute(routingSlip); return(new OkObjectResult(routingSlip.TrackingNumber)); }
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.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 Should_publish_the_completed_event() { _harness = new InMemoryTestHarness(); _activity = _harness.Activity <TestActivity, TestArguments, TestLog>(); await _harness.Start(); _completed = _harness.SubscribeHandler <RoutingSlipCompleted>(); _activityCompleted = _harness.SubscribeHandler <RoutingSlipActivityCompleted>(); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(_harness.BusAddress, RoutingSlipEvents.All); builder.AddActivity(_activity.Name, _activity.ExecuteAddress, new { Value = "Hello" }); builder.AddVariable("Variable", "Knife"); await _harness.Bus.Execute(builder.Build()); await _completed; }
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 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; }
public void 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); _routingSlip = builder.Build(); Bus.Execute(_routingSlip) .Wait(TestCancellationToken); }
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())); }
public async Task Consume(ConsumeContext <IFulfillOrder> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("AllocateInventory", new Uri("queue:allocate-inventory_execute"), new { ItemNumber = "ITEM123", Quantity = 10.0m }); builder.AddVariable("OrderId", context.Message.OrderId); builder.Build(); var routingSlip = builder.Build(); await context.Execute(routingSlip); }
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 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 = ConnectPublishHandler <RoutingSlipActivityCompensated>( context => context.Message.ActivityName.Equals(faultyCompensateActivity.Name)); Task <ConsumeContext <RoutingSlipFaulted> > routingSlipFailure = 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; }
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); ActivityTestContext testActivity = GetActivityContext <AddressActivity>(); ActivityTestContext 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; var consumeContext = await activity; Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult <string>("UsedAddress")); var context = await activityCompensated; Assert.AreEqual(new Uri("http://google.com/"), context.Message.GetResult <string>("UsedAddress")); }
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); }
public async Task Consume(ConsumeContext <ExecuteActivities> context) { // Инициация RoutingSlip var builder = new RoutingSlipBuilder(NewId.NextGuid()); // Операция списания денежных средств builder.AddActivity( nameof(ProcessOutflowActivity), new Uri("queue:process-outflow_execute"), new { AccountId = context.Message.SourceAccountId, context.Message.Sum, context.Message.CorrelationId }); // Операция зачисления денежных средств builder.AddActivity( nameof(ProcessInflowActivity), new Uri("queue:process-inflow_execute"), new { AccountId = context.Message.TargetAccountId, context.Message.Sum, context.Message.CorrelationId }); await context.Execute(builder.Build()); }
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); }
public void Should_fail_if_not_supported() { using (var provider = new AesCryptoServiceProvider()) { 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 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); }
public async Task Execute(ConsumeContext <IUpdateUserCommand> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); var updateUserCommand = context.Message; builder.AddActivity(UserServiceConstants.ActivityUpdateAdUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateActiveDirectoryUserActivity)), _activityArgumentsMapper.MapActiveDirectoryUserArguments(updateUserCommand)); builder.AddActivity(UserServiceConstants.ActivityUpdateIsUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateIdentityServerUserActivity)), _activityArgumentsMapper.MapIdentityServerUserArguments(updateUserCommand)); builder.AddSubscription(UserServiceConstants.RoutingSlipEventObserverUri, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted | RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.ActivityCompensated | RoutingSlipEvents.ActivityCompensationFailed); var routingSlip = builder.Build(); await context.Send <IRoutingSlipStarted>(UserServiceConstants.RoutingSlipUserStartedEventUri, new { builder.TrackingNumber, CreateTimestamp = DateTime.UtcNow, Arguments = context.Message, WorkflowActivityType = WorkflowActivityType.UpdateUser.ToString() }); await context.Execute(routingSlip); }
public void Setup() { _completed = new TaskCompletionSource <RoutingSlipCompleted>(TestCancellationToken); _activityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken); LocalBus.SubscribeHandler <RoutingSlipCompleted>(x => _completed.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x => _activityCompleted.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", }); builder.AddVariable("Variable", "Knife"); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
public async Task ExecuteRequest(ConsumeContext <ProcessRequest> context) { try { // podemos criar o build dependendo do tipo de context var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity(ConfigurationManager.AppSettings["CreateTaskActivityName"], new Uri(ConfigurationManager.AppSettings["CreateTaskExecuteAddress"])); builder.AddActivity(ConfigurationManager.AppSettings["IdentifyProductsActivityName"], new Uri(ConfigurationManager.AppSettings["IdentifyProductsExecuteAddress"])); builder.AddActivity(ConfigurationManager.AppSettings["SendToExternalActivityName"], new Uri(ConfigurationManager.AppSettings["SendToExternalExecuteAddress"])); builder.SetVariables(new { Id = context.Message.Id, Tenant = context.Message.Tenant }); var routingSlip = builder.Build(); await context.Execute(routingSlip); } catch (Exception ex) { throw ex; } }
public void 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); 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"); Await(() => Bus.Execute(builder.Build())); }
public async Task Consume(ConsumeContext <IFulfillOrder> context) { _logger.LogInformation($"Fulfilled order {context.Message.OrderId}"); var builder = new RoutingSlipBuilder(NewId.NextGuid()); var order = await _orderService.GetOrderAsync(context.Message.OrderId); builder.AddActivity("SubmitOrder", QueueNames.GetActivityUri(nameof(SubmitOrderActivity))); builder.AddActivity("ReserveProducts", QueueNames.GetActivityUri(nameof(ReserveProductsActivity)), new { order.OrderItems }); builder.AddActivity("Payment", QueueNames.GetActivityUri(nameof(PaymentActivity))); builder.AddActivity("Delivery", QueueNames.GetActivityUri(nameof(DeliveryActivity))); builder.AddVariable("CorrelationId", context.Message.CorrelationId); builder.AddVariable("OrderId", context.Message.OrderId); await builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <IOrderFulfillFaultedEvent>(new { context.Message.OrderId })); await builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <IOrderFulfillCompletedEvent>(new { context.Message.OrderId })); var routingSlip = builder.Build(); await context.Execute(routingSlip).ConfigureAwait(false); }
public async Task Should_publish_the_completed_event() { var startTime = DateTime.UtcNow; Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>(); var 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; var context = await myCompleted; Assert.That(context.Message.Timestamp, Is.GreaterThanOrEqualTo(startTime)); Console.WriteLine(GetBodyString(context.ReceiveContext)); }
public async Task Execute(FutureConsumeContext <TInput> context) { var factory = context.GetStateMachineActivityFactory(); IItineraryPlanner <TInput> itineraryPlanner = factory.GetService <IItineraryPlanner <TInput> >(context); var trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(trackingNumber); builder.AddVariable(nameof(FutureConsumeContext.FutureId), context.FutureId); builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted); await itineraryPlanner.PlanItinerary(context, builder).ConfigureAwait(false); var routingSlip = builder.Build(); await context.Execute(routingSlip).ConfigureAwait(false); if (TrackRoutingSlip) { context.Instance.Pending.Add(trackingNumber); } }
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 Should_continue_with_the_source_itinerary() { _trackingNumber = Guid.NewGuid(); var reviseActivity = GetActivityContext <ReviseItineraryActivity>(); 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"); ConsumeContext <RoutingSlipActivityCompleted> consumeContext = await _handled; Assert.That(consumeContext.Message.GetArgument <string>("Value"), Is.EqualTo("Added")); }
public async Task Should_continue_with_the_source_itinerary() { Guid trackingNumber = Guid.NewGuid(); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext reviseActivity = GetActivityContext <ReviseItineraryActivity>(); Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>(context => (context.Message.TrackingNumber == trackingNumber)); Task <ConsumeContext <RoutingSlipActivityCompleted> > testActivityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>( context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name)); Task <ConsumeContext <RoutingSlipActivityCompleted> > reviseActivityCompleted = SubscribeHandler <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"); }
ExecutionResult Execution <TArguments> .Completed <TLog>(TLog log) { ActivityLog activityLog; RoutingSlipBuilder builder = CreateRoutingSlipBuilder(log, out activityLog); return(Complete(builder.Build(), activityLog.Results)); }
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())); }
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())); }
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())); }
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 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); } }
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 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 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(); }