public async Task <UnitType> Execute(IOrchestrationContext context) { Console.WriteLine($"Starting worker for [{Start},{Start+Count})"); var pos = Start; while (pos < Start + Count) { var nextportionsize = Math.Min(PortionSize, (Start + Count) - pos); var results = await context.PerformActivity(new SearchPortion() { Target = Target, Start = pos, Count = nextportionsize, }); foreach (var c in results) { context.ForkEvent(new CollisionFoundEvent() { Collision = c }); } pos += nextportionsize; } await context.Finish(); Console.WriteLine($"Worker finished [{Start},{Start + Count})"); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { await context.DelayBy(Delay); context.ForkEvent(Event); return(UnitType.Value); }
public Task <UnitType> Execute(IOrchestrationContext context) { var startTime = DateTime.Now; context.ForkEvent(new PingEvent() { Message = $"Ping!", }); return(UnitType.CompletedTask); }
protected override async Task Run(IOrchestrationContext context) { // ------ global counter context.ForkEvent(new SomeEvent()); context.ForkEvent(new SomeEvent()); context.ForkEvent(new SomeEvent()); context.ForkEvent(new SomeEvent()); context.ForkEvent(new SomeEvent()); await context.Finish(); var count = await context.PerformRead(new ReadGlobalCounter()); Assert.Equal(5, count); // ------- account // get a fresh guid var guid = await context.NewGuid(); // reads and withdraws must fail try { await context.PerformRead(new ReadBalance() { AccountId = guid }); Assert.Fail("KeyNotFoundException expected"); } catch (KeyNotFoundException) { } try { await context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }); Assert.Fail("KeyNotFoundException expected"); } catch (KeyNotFoundException) { } // existence checks must fail because we don't hold the lock try { await context.StateExists <AccountState, IAccountAffinity, Guid>(guid); Assert.Fail("SynchronizationDisciplineException expected"); } catch (SynchronizationDisciplineException) { } // run a locked creation await context.PerformOrchestration(new CreateAccount() { AccountId = guid }); // existence checks must fail because we don't hold the lock try { await context.StateExists <AccountState, IAccountAffinity, Guid>(guid); Assert.Fail("SynchronizationDisciplineException expected"); } catch (SynchronizationDisciplineException) { } // reads should succeed and return the correct balance var amount = await context.PerformRead(new ReadBalance() { AccountId = guid }); Assert.Equal(11, amount); // deposit should succeed and create the account var tasks = new List <Task <bool> > { context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }), context.PerformUpdate(new TryWithdraw() { AccountId = guid, Amount = 2 }) }; await Task.WhenAll(tasks); Assert.Equal(5, tasks.Count(t => t.Result)); var bal = await context.PerformRead(new ReadBalance() { AccountId = guid }); Assert.Equal(1, bal); }