public async Task <UnitType> Execute(IOrchestrationContext context) { // we want to check that none of the ids clash with existing ones var userExists = context.StateExists <UserState, IUserAffinity, string>(UserId); var checkingExists = context.StateExists <AccountState, IAccountAffinity, Guid>(CheckingAccountId); var savingsExists = context.StateExists <AccountState, IAccountAffinity, Guid>(SavingsAccountId); // we want to record a timestamp for the creation var timestamp = await context.ReadDateTimeUtcNow(); if (await userExists) { throw new Exception("user already exists"); } if (await checkingExists || await savingsExists) { throw new Exception("account id already exists"); } await context.PerformEvent(new UserSignedUp() { UserId = UserId, FullName = FullName, InitialCredentials = InitialCredentials, Timestamp = timestamp, CheckingAccountId = CheckingAccountId, SavingsAccountId = SavingsAccountId, }); return(UnitType.Value); }
#pragma warning restore S4144 private async Task PublishContentEvent( IOrchestrationContext context, ContentEventType eventType) { if (!_eventGridConfiguration.CurrentValue.PublishEvents) { _logger.LogInformation("Event grid publishing is disabled. No events will be published."); return; } try { IContentItemVersion contentItemVersion = eventType switch { ContentEventType.Published => _publishedContentItemVersion, ContentEventType.Draft => _previewContentItemVersion, _ => _neutralEventContentItemVersion }; string userId = _syncNameProvider.GetEventIdPropertyValue( context.ContentItem.Content.GraphSyncPart, contentItemVersion); ContentEvent contentEvent = new ContentEvent(context.ContentItem, userId, eventType); await _eventGridContentClient.Publish(contentEvent); } catch (Exception publishException) { _logger.LogError(publishException, "The event grid event could not be published."); await context.Notifier.Add("Warning: the event grid event could not be published. Composite apps might not show your changes.", "Exception", publishException, type : NotifyType.Warning); } }
public async Task <UnitType> Execute(IOrchestrationContext context) { Console.WriteLine($"Starting job for [{Start},{Start + Count})"); // divide the search space evenly among workers var portionSize = ((ulong)Count + (NumberWorkers - 1)) / NumberWorkers; // create one task per worker var workertasks = new List <Task>(); var pos = Start; for (uint i = 0; i < NumberWorkers; i++) { var nextportionsize = Math.Min((long)portionSize, (Start + Count) - pos); workertasks.Add(context.PerformOrchestration(new SearchWorker() { Target = Target, Start = pos, Count = nextportionsize, WorkerNumber = i })); pos += nextportionsize; } await Task.WhenAll(workertasks); // read the results var collisions = await context.PerformRead(new GetResults()); collisions.Sort(); Console.WriteLine($"Finished job for [{Start},{Start + Count}), {collisions.Count()} collisions found: {string.Join(", ", collisions)}"); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { await context.PerformOrchestration(new Initialization() { NumberGenerators = NumberGenerators, NumberGeneratorProcesses = NumberProcesses, Workload = Workload }); var time = await context.ReadDateTimeUtcNow(); context.Logger.LogInformation($"Starting workload."); var tasks = new List <Task>(); for (uint i = 0; i < NumberGenerators; i++) { tasks.Add(context.PerformOrchestration(new RequestSequence() { GeneratorNumber = i, NumberRequests = (NumberRequests + NumberGenerators - 1) / NumberGenerators, OperationFactory = Workload, StartTime = time + TimeSpan.FromSeconds(Stagger.TotalSeconds * i / NumberGenerators), })); } await Task.WhenAll(tasks); context.Logger.LogInformation($"Experiment complete."); context.GlobalShutdown(); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { // do an initial ping to all processes to make sure they are running var tasks = new List <Task>(); for (uint i = 0; i < NumberGeneratorProcesses; i++) { tasks.Add(context.PerformOrchestration(new InitialPing() { ProcessId = i, })); } await Task.WhenAll(tasks); // initialize workload tasks = new List <Task>(); for (uint i = 0; i < NumberGenerators; i++) { tasks.Add(context.PerformOrchestration(new InitWorkload() { GeneratorNumber = i, Workload = Workload })); } await Task.WhenAll(tasks); return(UnitType.Value); }
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) { var targetCounter = GeneratorNumber % TotalNumberOfCounters; switch (Implementation) { case CounterImplementation.EventBased: await context.PerformEvent(new Counter.Service.IncrementEvent() { CounterId = targetCounter, }); break; case CounterImplementation.UpdateBased: await context.PerformUpdate(new Counter.Service.IncrementUpdate() { CounterId = targetCounter, }); break; } return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { context.Logger.LogInformation($"Counter.TestSuite Start"); await context.PerformOrchestration(new TestStates()); await context.PerformOrchestration(new TestEvents()); await context.PerformOrchestration(new TestEventsWithInit()); await context.PerformOrchestration(new TestLocks()); await Task.WhenAll( context.PerformOrchestration(new TestRandomActivityCount()), context.PerformOrchestration(new TestRandomActivityCount()), context.PerformOrchestration(new TestRandomActivityCount()) ); await context.PerformOrchestration(new TestForks()); var m = await context.PerformOrchestration(new SimpleLoadTest.Service.LoadTestOrchestration() { Depth = 2, UseSmallerTest = true }); context.Logger.LogInformation($"volume: {m.Volume} machines: {string.Join(",", m.Hosts)}"); context.Logger.LogInformation($"Counter.TestSuite End"); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { await context.DelayBy(Delay); await context.PerformActivity(Activity); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { var read = await context.PerformRead(new GetBalance { Place = Place }); await context.PerformUpdate(new SetBalance { Place = Place, NewBalance = read + 1 }); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { await context.DelayBy(Delay); context.ForkOrchestration(Orchestration); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { var random = await context.NewRandom(); return(await context.PerformOrchestration(new ExecuteEventAt() { Place = (Places)random.Next(3), Event = Event })); }
public async Task <bool> Execute(IOrchestrationContext context) { // perform authentication await context.PerformRead(new Authentication() { UserId = UserId, Credentials = Credentials }); // check all involved state so we can validate preconditions var t1 = context.PerformRead(new CheckAccount() { AccountId = FromAccount }); var t2 = context.PerformRead(new CheckAccount() { AccountId = ToAccount }); // get a timestamp var timestamp = await context.ReadDateTimeUtcNow(); // wait for the checks to complete. This ensures both accounts exist. // (otherwise an exception is thrown) var fromAccount = await t1; var toAccount = await t2; if (fromAccount == null) { throw new KeyNotFoundException($"no such account: {fromAccount}"); } if (toAccount == null) { throw new KeyNotFoundException($"no such account: {toAccount}"); } if (fromAccount.Owner != UserId) { throw new InvalidOperationException("only owner of account can issue transfer"); } else if (fromAccount.Balance < Amount) { return(false); } else { await context.PerformEvent(new AmountTransferred() { TransferRequest = this, Timestamp = timestamp }); return(true); } }
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) { await context.Finish(); context.ForkUpdate(new IncrementThenRead() { CounterId = 0 }); await context.Finish(); context.ForkUpdate(new IncrementThenRead() { CounterId = 1 }); context.ForkUpdate(new IncrementThenRead() { CounterId = 2 }); await context.Finish(); for (uint i = 0; i < 100; i++) { context.ForkUpdate(new IncrementThenRead() { CounterId = 100 + i }); } var f1 = context.Finish(); for (uint i = 0; i < 100; i++) { context.ForkUpdate(new IncrementThenRead() { CounterId = 200 + i }); } var f2 = context.Finish(); for (uint i = 0; i < 100; i++) { context.ForkUpdate(new IncrementThenRead() { CounterId = 300 + i }); } await Task.WhenAll(f1, f2); await context.Finish(); }
public async Task <UnitType> Execute(IOrchestrationContext context) { var config = context.GetConfiguration <HelloWorldTestConfiguration>() ?? new HelloWorldTestConfiguration(); for (int i = 0; i < config.NumberRepetitions; i++) { await context.PerformOrchestration(new HelloWorldOrchestration()); } return(UnitType.Value); }
public static async Task DelayBy(this IOrchestrationContext context, TimeSpan delay) { CheckTimeArgument(delay); if (delay != TimeSpan.Zero) { var currentTime = await context.ReadDateTimeUtcNow(); await context.PerformActivity(new Extensions.StableDelay() { TargetTime = currentTime + delay, }); } }
public async Task <UnitType> Execute(IOrchestrationContext context) { context.Logger.LogInformation($"Counter.TestSuite Start"); //await context.PerformOrchestration(new TestRandomActivityCount()); await context.PerformOrchestration(new TestForks()); await context.PerformOrchestration(new TestForks()); context.Logger.LogInformation($"Counter.TestSuite End"); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { for (int i = 0; i < 100000; i++) { context.ForkOrchestration(new CopyBlob() { From = $"A{i}", To = $"B{i}" }); } await context.Finish(); return(UnitType.Value); }
protected override async Task Run(IOrchestrationContext context) { await context.PerformOrchestration(new LockedMultiEventOrchestration() { AccountIds = new int[] { 0, 1, 2 }, Places = new Places[] { Places.B, Places.C } }); await context.PerformOrchestration(new LockedMultiEventOrchestration() { AccountIds = new int[] { 3, 4, 5, 6, 7, 8, 9, 10 }, Places = new Places[] { Places.B } }); }
public async Task <UnitType> Execute(IOrchestrationContext context) { // account does not exist yet var exists = await context.StateExists <AccountState, IAccountAffinity, Guid>(AccountId); Assert.Equal(false, exists); // thus reads and withdraws must fail try { await context.PerformRead(new ReadBalance() { AccountId = AccountId }); Assert.Fail("KeyNotFoundException expected"); } catch (KeyNotFoundException) { } try { await context.PerformUpdate(new TryWithdraw() { AccountId = AccountId, Amount = 2 }); Assert.Fail("KeyNotFoundException expected"); } catch (KeyNotFoundException) { } // deposit should succeed and create the account await context.PerformUpdate(new Deposit() { AccountId = AccountId, Amount = 1 }); // account does now exist exists = await context.StateExists <AccountState, IAccountAffinity, Guid>(AccountId); Assert.Equal(true, exists); // account contains correct balance var amount = await context.PerformRead(new ReadBalance() { AccountId = AccountId }); Assert.Equal(11, amount); return(UnitType.Value); }
static void BurnUnneededValues(IEnumerable <IEvent> initialEvents, IOrchestrationContext context) { foreach (var @event in initialEvents) { if (@event is GuidGenerated) { context.NewGuid(); } if (@event is DateTimeRetrieved) { context.DateTimeUtcNow(); } } }
public async Task <UnitType> Execute(IOrchestrationContext context) { context.Logger.LogTrace($"Harness.RequestSequence {GeneratorNumber} Start"); await context.DelayUntil(StartTime); for (uint i = 0; i < NumberRequests; i++) { await context.PerformOrchestration(OperationFactory.GenerateRequest(GeneratorNumber, i)); } context.Logger.LogTrace($"Harness.RequestSequence {GeneratorNumber} Done"); return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { State = new TState(); // start with default constructor if (Singleton) { await((IInitialize)State).OnInitialize((IInitializationContext)context); } else { await((IInitialize <TKey>)State).OnInitialize((IInitializationContext)context, PartitionKey.Key); } return(UnitType.Value); }
async Task IOrchestration.Execute(object input, IOrchestrationContext context, IEnumerable <IEvent> events, ICallSerializer serializer) { this._serializer = serializer; this._context = context; _recorded = new Queue <IEvent>(events); await Execute((TInput)input).ConfigureAwait(false); OrchestrationEnded end; if (TryPop(out end) == false) { Append(OrchestrationEnded.Instance); } }
public static async Task DelayUntil(this IOrchestrationContext context, DateTime utcTime) { if (utcTime.Kind != DateTimeKind.Utc) { throw new ArgumentException("must use UTC time", nameof(utcTime)); } if ((utcTime - DateTime.UtcNow).TotalMilliseconds > int.MaxValue) { throw new System.ArgumentOutOfRangeException(nameof(utcTime), "The scheduled time cannot be later than Int32.MaxValue milliseconds from now"); } await context.PerformActivity(new Extensions.StableDelay() { TargetTime = utcTime, }); }
protected override async Task Run(IOrchestrationContext context) { await context.PerformEvent(new MultiEventThree() { Places = Places, AccountIds = AccountIds }); foreach (var a in AccountIds) { var result1 = await context.PerformRead(new ReadBalance1() { AccountId = a }); var result2 = await context.PerformRead(new ReadBalance2() { AccountId = a }); Assert.Equal(101, result1); Assert.Equal(101, result2); } foreach (var p in Places) { var result = await context.PerformUpdate(new SetBalance() { Place = p, NewBalance = 1000 }); } foreach (var p in Places) { var result = await context.PerformRead(new GetBalance() { Place = p }); Assert.Equal(1000, result); } foreach (var p in Places) { var result = await context.PerformUpdate(new SetBalance() { Place = p, NewBalance = 0 }); } }
public async Task <UnitType> Execute(IOrchestrationContext context) { var nearbyArea = AvailableDriver.CurrentAvailability.Value.GetNearbyAreas(); RiderEvent candidate = null; foreach (var location in nearbyArea) { candidate = await context.PerformRead(new GetAvailableRider() { Location = location }); if (candidate != null) { break; } } if (candidate == null) { // there are no matches. So we just wait until someone joins and gets matched to us. return(UnitType.Value); } try { var result = await context.PerformOrchestration(new TryFinalizeMatch() { AvailableDriver = AvailableDriver, AvailableRider = candidate }); if (result == TryFinalizeMatch.Response.DriverRemainsUnmatched) { // retry in order to find another match context.ForkOrchestration(this); } } catch (TransactionException) { // transaction ran into trouble for some reason... retry this orchestration context.ForkOrchestration(this); } return(UnitType.Value); }
public async Task <UnitType> Execute(IOrchestrationContext context) { await context.PerformOrchestration(new Initialization() { NumberGenerators = NumberGenerators, NumberGeneratorProcesses = NumberGeneratorProcesses, Workload = Workload }); for (uint i = 0; i < NumberGenerators; i++) { // schedule events to stop load generation after the test duration context.ScheduleLocalUpdate(Duration, new StopGenerator() { GeneratorNumber = i }); } var DelayBetweenRequests = TimeSpan.FromSeconds(NumberGenerators / Rate); context.Logger.LogInformation($"Starting workload."); for (uint i = 0; i < NumberGenerators; i++) { var stagger = TimeSpan.FromSeconds(i / Rate); context.ScheduleLocalUpdate(stagger, new GeneratorIteration() { GeneratorNumber = i, Iteration = 0, DelayBetweenRequests = DelayBetweenRequests, Workload = Workload, }); } await context.DelayBy(Duration); context.Logger.LogInformation($"Entering Cooldown."); await context.DelayBy(Cooldown); context.Logger.LogInformation($"Experiment complete."); context.GlobalShutdown(); return(UnitType.Value); }
public async Task <Response> Execute(IOrchestrationContext context) { // (re-)check availability state of both var t1 = context.PerformRead(new GetDriverState() { DriverId = AvailableDriver.DriverId }); var t2 = context.PerformRead(new GetRiderState() { RiderId = AvailableRider.RiderId }); var t3 = context.NewGuid(); var driverAvailability = (await t1).Availability; var riderAvailability = (await t2).Availability; var rideId = await t3; if (riderAvailability == null && driverAvailability != null) { return(Response.DriverRemainsUnmatched); } else if (driverAvailability == null && riderAvailability != null) { return(Response.RiderRemainsUnmatched); } else if (driverAvailability == null && riderAvailability == null) { return(Response.Ok); } else { await context.PerformEvent(new RideMatchedEvent() { DriverId = AvailableDriver.DriverId, DriverLocation = AvailableDriver.CurrentAvailability.Value, RiderId = AvailableRider.RiderId, RiderLocation = AvailableRider.CurrentAvailability.Value, RideId = rideId }); return(Response.Ok); } }