How to use CreateActorIdFromName method of Microsoft.Coyote.Actors.ActorExecutionContext class

Best Coyote code snippet using Microsoft.Coyote.Actors.ActorExecutionContext.CreateActorIdFromName

ActorExecutionContext.cs

Source:ActorExecutionContext.cs Github

copy

Full Screen

...118 }119 /// <inheritdoc/>120 public ActorId CreateActorId(Type type, string name = null) => new ActorId(type, this.GetNextOperationId(), name, this);121 /// <inheritdoc/>122 public virtual ActorId CreateActorIdFromName(Type type, string name) => new ActorId(type, 0, name, this, true);123 /// <inheritdoc/>124 public virtual ActorId CreateActor(Type type, Event initialEvent = null, EventGroup eventGroup = null) =>125 this.CreateActor(null, type, null, initialEvent, null, eventGroup);126 /// <inheritdoc/>127 public virtual ActorId CreateActor(Type type, string name, Event initialEvent = null, EventGroup eventGroup = null) =>128 this.CreateActor(null, type, name, initialEvent, null, eventGroup);129 /// <inheritdoc/>130 public virtual ActorId CreateActor(ActorId id, Type type, Event initialEvent = null, EventGroup eventGroup = null) =>131 this.CreateActor(id, type, null, initialEvent, null, eventGroup);132 /// <inheritdoc/>133 public virtual Task<ActorId> CreateActorAndExecuteAsync(Type type, Event initialEvent = null, EventGroup eventGroup = null) =>134 this.CreateActorAndExecuteAsync(null, type, null, initialEvent, null, eventGroup);135 /// <inheritdoc/>136 public virtual Task<ActorId> CreateActorAndExecuteAsync(Type type, string name, Event initialEvent = null, EventGroup eventGroup = null) =>137 this.CreateActorAndExecuteAsync(null, type, name, initialEvent, null, eventGroup);138 /// <inheritdoc/>139 public virtual Task<ActorId> CreateActorAndExecuteAsync(ActorId id, Type type, Event initialEvent = null, EventGroup eventGroup = null) =>140 this.CreateActorAndExecuteAsync(id, type, null, initialEvent, null, eventGroup);141 /// <summary>142 /// Creates a new <see cref="Actor"/> of the specified <see cref="Type"/>.143 /// </summary>144 internal virtual ActorId CreateActor(ActorId id, Type type, string name, Event initialEvent, Actor creator, EventGroup eventGroup)145 {146 Actor actor = this.CreateActor(id, type, name, creator, eventGroup);147 if (actor is StateMachine)148 {149 this.LogWriter.LogCreateStateMachine(actor.Id, creator?.Id.Name, creator?.Id.Type);150 }151 else152 {153 this.LogWriter.LogCreateActor(actor.Id, creator?.Id.Name, creator?.Id.Type);154 }155 this.RunActorEventHandler(actor, initialEvent, true);156 return actor.Id;157 }158 /// <summary>159 /// Creates a new <see cref="Actor"/> of the specified <see cref="Type"/>. The method160 /// returns only when the actor is initialized and the <see cref="Event"/> (if any)161 /// is handled.162 /// </summary>163 internal virtual async Task<ActorId> CreateActorAndExecuteAsync(ActorId id, Type type, string name, Event initialEvent,164 Actor creator, EventGroup eventGroup)165 {166 Actor actor = this.CreateActor(id, type, name, creator, eventGroup);167 if (actor is StateMachine)168 {169 this.LogWriter.LogCreateStateMachine(actor.Id, creator?.Id.Name, creator?.Id.Type);170 }171 else172 {173 this.LogWriter.LogCreateActor(actor.Id, creator?.Id.Name, creator?.Id.Type);174 }175 await this.RunActorEventHandlerAsync(actor, initialEvent, true);176 return actor.Id;177 }178 /// <summary>179 /// Creates a new <see cref="Actor"/> of the specified <see cref="Type"/>.180 /// </summary>181 internal virtual Actor CreateActor(ActorId id, Type type, string name, Actor creator, EventGroup eventGroup)182 {183 if (!type.IsSubclassOf(typeof(Actor)))184 {185 this.Assert(false, "Type '{0}' is not an actor.", type.FullName);186 }187 if (id is null)188 {189 id = this.CreateActorId(type, name);190 }191 else if (id.Runtime != null && id.Runtime != this)192 {193 this.Assert(false, "Unbound actor id '{0}' was created by another runtime.", id.Value);194 }195 else if (id.Type != type.FullName)196 {197 this.Assert(false, "Cannot bind actor id '{0}' of type '{1}' to an actor of type '{2}'.",198 id.Value, id.Type, type.FullName);199 }200 else201 {202 id.Bind(this);203 }204 // If no event group is provided then inherit the current group from the creator.205 if (eventGroup is null && creator != null)206 {207 eventGroup = creator.EventGroup;208 }209 Actor actor = ActorFactory.Create(type);210 IEventQueue eventQueue = new EventQueue(actor);211 actor.Configure(this, id, null, eventQueue, eventGroup);212 actor.SetupEventHandlers();213 if (!this.ActorMap.TryAdd(id, actor))214 {215 this.Assert(false, $"An actor with id '{id.Value}' was already created by another runtime instance.");216 }217 return actor;218 }219 /// <inheritdoc/>220 public virtual void SendEvent(ActorId targetId, Event initialEvent, EventGroup eventGroup = default, SendOptions options = null) =>221 this.SendEvent(targetId, initialEvent, null, eventGroup, options);222 /// <inheritdoc/>223 public virtual Task<bool> SendEventAndExecuteAsync(ActorId targetId, Event initialEvent,224 EventGroup eventGroup = null, SendOptions options = null) =>225 this.SendEventAndExecuteAsync(targetId, initialEvent, null, eventGroup, options);226 /// <summary>227 /// Sends an asynchronous <see cref="Event"/> to an actor.228 /// </summary>229 internal virtual void SendEvent(ActorId targetId, Event e, Actor sender, EventGroup eventGroup, SendOptions options)230 {231 EnqueueStatus enqueueStatus = this.EnqueueEvent(targetId, e, sender, eventGroup, out Actor target);232 if (enqueueStatus is EnqueueStatus.EventHandlerNotRunning)233 {234 this.RunActorEventHandler(target, null, false);235 }236 }237 /// <summary>238 /// Sends an asynchronous <see cref="Event"/> to an actor. Returns immediately if the target was239 /// already running. Otherwise blocks until the target handles the event and reaches quiescense.240 /// </summary>241 internal virtual async Task<bool> SendEventAndExecuteAsync(ActorId targetId, Event e, Actor sender,242 EventGroup eventGroup, SendOptions options)243 {244 EnqueueStatus enqueueStatus = this.EnqueueEvent(targetId, e, sender, eventGroup, out Actor target);245 if (enqueueStatus is EnqueueStatus.EventHandlerNotRunning)246 {247 await this.RunActorEventHandlerAsync(target, null, false);248 return true;249 }250 return enqueueStatus is EnqueueStatus.Dropped;251 }252 /// <summary>253 /// Enqueues an event to the actor with the specified id.254 /// </summary>255 private EnqueueStatus EnqueueEvent(ActorId targetId, Event e, Actor sender, EventGroup eventGroup, out Actor target)256 {257 if (e is null)258 {259 string message = sender != null ?260 string.Format("{0} is sending a null event.", sender.Id.ToString()) :261 "Cannot send a null event.";262 this.Assert(false, message);263 }264 if (targetId is null)265 {266 string message = (sender != null) ?267 string.Format("{0} is sending event {1} to a null actor.", sender.Id.ToString(), e.ToString())268 : string.Format("Cannot send event {0} to a null actor.", e.ToString());269 this.Assert(false, message);270 }271 target = this.GetActorWithId<Actor>(targetId);272 // If no group is provided we default to passing along the group from the sender.273 if (eventGroup is null && sender != null)274 {275 eventGroup = sender.EventGroup;276 }277 Guid opId = eventGroup is null ? Guid.Empty : eventGroup.Id;278 if (target is null || target.IsHalted)279 {280 this.LogWriter.LogSendEvent(targetId, sender?.Id.Name, sender?.Id.Type,281 (sender as StateMachine)?.CurrentStateName ?? default, e, opId, isTargetHalted: true);282 this.HandleDroppedEvent(e, targetId);283 return EnqueueStatus.Dropped;284 }285 this.LogWriter.LogSendEvent(targetId, sender?.Id.Name, sender?.Id.Type,286 (sender as StateMachine)?.CurrentStateName ?? default, e, opId, isTargetHalted: false);287 EnqueueStatus enqueueStatus = target.Enqueue(e, eventGroup, null);288 if (enqueueStatus == EnqueueStatus.Dropped)289 {290 this.HandleDroppedEvent(e, targetId);291 }292 return enqueueStatus;293 }294 /// <summary>295 /// Runs a new asynchronous actor event handler.296 /// This is a fire and forget invocation.297 /// </summary>298 private void RunActorEventHandler(Actor actor, Event initialEvent, bool isFresh)299 {300 Task.Run(async () =>301 {302 try303 {304 if (isFresh)305 {306 await actor.InitializeAsync(initialEvent);307 }308 await actor.RunEventHandlerAsync();309 }310 catch (Exception ex)311 {312 this.Scheduler.IsProgramExecuting = false;313 this.RaiseOnFailureEvent(ex);314 }315 finally316 {317 if (actor.IsHalted)318 {319 this.ActorMap.TryRemove(actor.Id, out Actor _);320 }321 }322 });323 }324 /// <summary>325 /// Runs a new asynchronous actor event handler.326 /// </summary>327 private async Task RunActorEventHandlerAsync(Actor actor, Event initialEvent, bool isFresh)328 {329 try330 {331 if (isFresh)332 {333 await actor.InitializeAsync(initialEvent);334 }335 await actor.RunEventHandlerAsync();336 }337 catch (Exception ex)338 {339 this.Scheduler.IsProgramExecuting = false;340 this.RaiseOnFailureEvent(ex);341 return;342 }343 }344 /// <summary>345 /// Creates a new timer that sends a <see cref="TimerElapsedEvent"/> to its owner actor.346 /// </summary>347 internal virtual IActorTimer CreateActorTimer(TimerInfo info, Actor owner) => new ActorTimer(info, owner);348 /// <inheritdoc/>349 public virtual EventGroup GetCurrentEventGroup(ActorId currentActorId)350 {351 Actor actor = this.GetActorWithId<Actor>(currentActorId);352 return actor?.CurrentEventGroup;353 }354 /// <summary>355 /// Gets the actor of type <typeparamref name="TActor"/> with the specified id,356 /// or null if no such actor exists.357 /// </summary>358 internal TActor GetActorWithId<TActor>(ActorId id)359 where TActor : Actor =>360 id != null && this.ActorMap.TryGetValue(id, out Actor value) &&361 value is TActor actor ? actor : null;362 /// <summary>363 /// Returns the next available unique operation id.364 /// </summary>365 /// <returns>Value representing the next available unique operation id.</returns>366 internal ulong GetNextOperationId() => this.Runtime.GetNextOperationId();367 /// <inheritdoc/>368 public bool RandomBoolean() => this.GetNondeterministicBooleanChoice(2, null, null);369 /// <inheritdoc/>370 public bool RandomBoolean(int maxValue) => this.GetNondeterministicBooleanChoice(maxValue, null, null);371 /// <summary>372 /// Returns a controlled nondeterministic boolean choice.373 /// </summary>374 internal virtual bool GetNondeterministicBooleanChoice(int maxValue, string callerName, string callerType)375 {376 bool result = false;377 if (this.ValueGenerator.Next(maxValue) is 0)378 {379 result = true;380 }381 this.LogWriter.LogRandom(result, callerName, callerType);382 return result;383 }384 /// <inheritdoc/>385 public int RandomInteger(int maxValue) => this.GetNondeterministicIntegerChoice(maxValue, null, null);386 /// <summary>387 /// Returns a controlled nondeterministic integer choice.388 /// </summary>389 internal virtual int GetNondeterministicIntegerChoice(int maxValue, string callerName, string callerType)390 {391 var result = this.ValueGenerator.Next(maxValue);392 this.LogWriter.LogRandom(result, callerName, callerType);393 return result;394 }395 /// <summary>396 /// Logs that the specified actor invoked an action.397 /// </summary>398 internal virtual void LogInvokedAction(Actor actor, MethodInfo action, string handlingStateName, string currentStateName)399 {400 if (this.Configuration.IsVerbose)401 {402 this.LogWriter.LogExecuteAction(actor.Id, handlingStateName, currentStateName, action.Name);403 }404 }405 /// <summary>406 /// Logs that the specified actor enqueued an <see cref="Event"/>.407 /// </summary>408 internal virtual void LogEnqueuedEvent(Actor actor, Event e, EventGroup eventGroup, EventInfo eventInfo)409 {410 if (this.Configuration.IsVerbose)411 {412 this.LogWriter.LogEnqueueEvent(actor.Id, e);413 }414 }415 /// <summary>416 /// Logs that the specified actor dequeued an <see cref="Event"/>.417 /// </summary>418 internal virtual void LogDequeuedEvent(Actor actor, Event e, EventInfo eventInfo, bool isFreshDequeue)419 {420 if (this.Configuration.IsVerbose)421 {422 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;423 this.LogWriter.LogDequeueEvent(actor.Id, stateName, e);424 }425 }426 /// <summary>427 /// Logs that the specified actor dequeued the default <see cref="Event"/>.428 /// </summary>429 [MethodImpl(MethodImplOptions.AggressiveInlining)]430 internal virtual void LogDefaultEventDequeued(Actor actor)431 {432 }433 /// <summary>434 /// Notifies that the inbox of the specified actor is about to be435 /// checked to see if the default event handler should fire.436 /// </summary>437 [MethodImpl(MethodImplOptions.AggressiveInlining)]438 internal virtual void LogDefaultEventHandlerCheck(Actor actor)439 {440 }441 /// <summary>442 /// Logs that the specified actor raised an <see cref="Event"/>.443 /// </summary>444 internal virtual void LogRaisedEvent(Actor actor, Event e, EventGroup eventGroup, EventInfo eventInfo)445 {446 if (this.Configuration.IsVerbose)447 {448 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;449 this.LogWriter.LogRaiseEvent(actor.Id, stateName, e);450 }451 }452 /// <summary>453 /// Logs that the specified actor is handling a raised <see cref="Event"/>.454 /// </summary>455 [MethodImpl(MethodImplOptions.AggressiveInlining)]456 internal virtual void LogHandleRaisedEvent(Actor actor, Event e)457 {458 }459 /// <summary>460 /// Logs that the specified actor called <see cref="Actor.ReceiveEventAsync(Type[])"/>461 /// or one of its overloaded methods.462 /// </summary>463 [MethodImpl(MethodImplOptions.AggressiveInlining)]464 internal virtual void LogReceiveCalled(Actor actor)465 {466 }467 /// <summary>468 /// Logs that the specified actor enqueued an event that it was waiting to receive.469 /// </summary>470 internal virtual void LogReceivedEvent(Actor actor, Event e, EventInfo eventInfo)471 {472 if (this.Configuration.IsVerbose)473 {474 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;475 this.LogWriter.LogReceiveEvent(actor.Id, stateName, e, wasBlocked: true);476 }477 }478 /// <summary>479 /// Logs that the specified actor received an event without waiting because the event480 /// was already in the inbox when the actor invoked the receive statement.481 /// </summary>482 internal virtual void LogReceivedEventWithoutWaiting(Actor actor, Event e, EventInfo eventInfo)483 {484 if (this.Configuration.IsVerbose)485 {486 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;487 this.LogWriter.LogReceiveEvent(actor.Id, stateName, e, wasBlocked: false);488 }489 }490 /// <summary>491 /// Logs that the specified actor is waiting to receive an event of one of the specified types.492 /// </summary>493 internal virtual void LogWaitEvent(Actor actor, IEnumerable<Type> eventTypes)494 {495 if (this.Configuration.IsVerbose)496 {497 string stateName = actor is StateMachine stateMachine ? stateMachine.CurrentStateName : default;498 var eventWaitTypesArray = eventTypes.ToArray();499 if (eventWaitTypesArray.Length is 1)500 {501 this.LogWriter.LogWaitEvent(actor.Id, stateName, eventWaitTypesArray[0]);502 }503 else504 {505 this.LogWriter.LogWaitEvent(actor.Id, stateName, eventWaitTypesArray);506 }507 }508 }509 /// <summary>510 /// Logs that the specified state machine entered a state.511 /// </summary>512 internal virtual void LogEnteredState(StateMachine stateMachine)513 {514 if (this.Configuration.IsVerbose)515 {516 this.LogWriter.LogStateTransition(stateMachine.Id, stateMachine.CurrentStateName, isEntry: true);517 }518 }519 /// <summary>520 /// Logs that the specified state machine exited a state.521 /// </summary>522 internal virtual void LogExitedState(StateMachine stateMachine)523 {524 if (this.Configuration.IsVerbose)525 {526 this.LogWriter.LogStateTransition(stateMachine.Id, stateMachine.CurrentStateName, isEntry: false);527 }528 }529 /// <summary>530 /// Logs that the specified state machine invoked pop.531 /// </summary>532 [MethodImpl(MethodImplOptions.AggressiveInlining)]533 internal virtual void LogPopState(StateMachine stateMachine)534 {535 }536 /// <summary>537 /// Logs that the specified state machine invoked an action.538 /// </summary>539 internal virtual void LogInvokedOnEntryAction(StateMachine stateMachine, MethodInfo action)540 {541 if (this.Configuration.IsVerbose)542 {543 this.LogWriter.LogExecuteAction(stateMachine.Id, stateMachine.CurrentStateName,544 stateMachine.CurrentStateName, action.Name);545 }546 }547 /// <summary>548 /// Logs that the specified state machine invoked an action.549 /// </summary>550 internal virtual void LogInvokedOnExitAction(StateMachine stateMachine, MethodInfo action)551 {552 if (this.Configuration.IsVerbose)553 {554 this.LogWriter.LogExecuteAction(stateMachine.Id, stateMachine.CurrentStateName,555 stateMachine.CurrentStateName, action.Name);556 }557 }558 /// <summary>559 /// Builds the coverage graph information, if any. This information is only available560 /// when <see cref="Configuration.ReportActivityCoverage"/> is enabled.561 /// </summary>562 internal CoverageInfo BuildCoverageInfo()563 {564 var result = this.CoverageInfo;565 if (result != null)566 {567 var builder = this.LogWriter.GetLogsOfType<ActorRuntimeLogGraphBuilder>().FirstOrDefault();568 if (builder != null)569 {570 result.CoverageGraph = builder.SnapshotGraph(this.Configuration.IsDgmlBugGraph);571 }572 var eventCoverage = this.LogWriter.GetLogsOfType<ActorRuntimeLogEventCoverage>().FirstOrDefault();573 if (eventCoverage != null)574 {575 result.EventInfo = eventCoverage.EventCoverage;576 }577 }578 return result;579 }580 /// <summary>581 /// Returns the current hashed state of the actors.582 /// </summary>583 /// <remarks>584 /// The hash is updated in each execution step.585 /// </remarks>586 internal virtual int GetHashedActorState() => 0;587 /// <summary>588 /// Returns the program counter of the specified actor.589 /// </summary>590 [MethodImpl(MethodImplOptions.AggressiveInlining)]591 internal virtual int GetActorProgramCounter(ActorId actorId) => 0;592 /// <inheritdoc/>593 public void RegisterMonitor<T>()594 where T : Monitor =>595 this.TryCreateMonitor(typeof(T));596 /// <inheritdoc/>597 public void Monitor<T>(Event e)598 where T : Monitor599 {600 // If the event is null then report an error and exit.601 this.Assert(e != null, "Cannot monitor a null event.");602 this.InvokeMonitor(typeof(T), e, null, null, null);603 }604 /// <summary>605 /// Tries to create a new <see cref="Specifications.Monitor"/> of the specified <see cref="Type"/>.606 /// </summary>607 protected bool TryCreateMonitor(Type type) => this.SpecificationEngine.TryCreateMonitor(608 type, this.CoverageInfo, this.LogWriter);609 /// <summary>610 /// Invokes the specified <see cref="Specifications.Monitor"/> with the specified <see cref="Event"/>.611 /// </summary>612 internal void InvokeMonitor(Type type, Event e, string senderName, string senderType, string senderStateName) =>613 this.SpecificationEngine.InvokeMonitor(type, e, senderName, senderType, senderStateName);614 /// <inheritdoc/>615 [MethodImpl(MethodImplOptions.AggressiveInlining)]616 public void Assert(bool predicate) => this.SpecificationEngine.Assert(predicate);617 /// <inheritdoc/>618 [MethodImpl(MethodImplOptions.AggressiveInlining)]619 public void Assert(bool predicate, string s, object arg0) => this.SpecificationEngine.Assert(predicate, s, arg0);620 /// <inheritdoc/>621 [MethodImpl(MethodImplOptions.AggressiveInlining)]622 public void Assert(bool predicate, string s, object arg0, object arg1) => this.SpecificationEngine.Assert(predicate, s, arg0, arg1);623 /// <inheritdoc/>624 [MethodImpl(MethodImplOptions.AggressiveInlining)]625 public void Assert(bool predicate, string s, object arg0, object arg1, object arg2) =>626 this.SpecificationEngine.Assert(predicate, s, arg0, arg1, arg2);627 /// <inheritdoc/>628 [MethodImpl(MethodImplOptions.AggressiveInlining)]629 public void Assert(bool predicate, string s, params object[] args) => this.SpecificationEngine.Assert(predicate, s, args);630 /// <summary>631 /// Asserts that the actor calling an actor method is also the actor that is currently executing.632 /// </summary>633 [MethodImpl(MethodImplOptions.AggressiveInlining)]634 internal virtual void AssertExpectedCallerActor(Actor caller, string calledAPI)635 {636 }637 /// <summary>638 /// Raises the <see cref="OnFailure"/> event with the specified <see cref="Exception"/>.639 /// </summary>640 internal void RaiseOnFailureEvent(Exception exception) => this.Runtime.RaiseOnFailureEvent(exception);641 /// <summary>642 /// Handle the specified dropped <see cref="Event"/>.643 /// </summary>644 internal void HandleDroppedEvent(Event e, ActorId id) => this.OnEventDropped?.Invoke(e, id);645 /// <summary>646 /// Throws an <see cref="AssertionFailureException"/> exception containing the specified exception.647 /// </summary>648#if !DEBUG649 [DebuggerHidden]650#endif651 internal void WrapAndThrowException(Exception exception, string s, params object[] args) =>652 this.SpecificationEngine.WrapAndThrowException(exception, s, args);653 /// <inheritdoc/>654 [Obsolete("Please set the Logger property directory instead of calling this method.")]655 public TextWriter SetLogger(TextWriter logger)656 {657 var result = this.LogWriter.SetLogger(new TextWriterLogger(logger));658 if (result != null)659 {660 return result.TextWriter;661 }662 return null;663 }664 /// <inheritdoc/>665 public void RegisterLog(IActorRuntimeLog log) => this.LogWriter.RegisterLog(log);666 /// <inheritdoc/>667 public void RemoveLog(IActorRuntimeLog log) => this.LogWriter.RemoveLog(log);668 /// <inheritdoc/>669 public void Stop() => this.Scheduler.ForceStop();670 /// <summary>671 /// Disposes runtime resources.672 /// </summary>673 protected virtual void Dispose(bool disposing)674 {675 if (disposing)676 {677 this.ActorMap.Clear();678 }679 }680 /// <inheritdoc/>681 public void Dispose()682 {683 this.Dispose(true);684 GC.SuppressFinalize(this);685 }686 /// <summary>687 /// The mocked execution context of an actor program.688 /// </summary>689 internal sealed class Mock : ActorExecutionContext690 {691 /// <summary>692 /// Map that stores all unique names and their corresponding actor ids.693 /// </summary>694 private readonly ConcurrentDictionary<string, ActorId> NameValueToActorId;695 /// <summary>696 /// Map of program counters used for state-caching to distinguish697 /// scheduling from non-deterministic choices.698 /// </summary>699 private readonly ConcurrentDictionary<ActorId, int> ProgramCounterMap;700 /// <summary>701 /// If true, the actor execution is controlled, else false.702 /// </summary>703 internal override bool IsExecutionControlled => true;704 /// <summary>705 /// Initializes a new instance of the <see cref="Mock"/> class.706 /// </summary>707 internal Mock(Configuration configuration, CoyoteRuntime runtime, OperationScheduler scheduler,708 SpecificationEngine specificationEngine, IRandomValueGenerator valueGenerator, LogWriter logWriter)709 : base(configuration, runtime, scheduler, specificationEngine, valueGenerator, logWriter)710 {711 this.NameValueToActorId = new ConcurrentDictionary<string, ActorId>();712 this.ProgramCounterMap = new ConcurrentDictionary<ActorId, int>();713 }714 /// <inheritdoc/>715 public override ActorId CreateActorIdFromName(Type type, string name)716 {717 // It is important that all actor ids use the monotonically incrementing718 // value as the id during testing, and not the unique name.719 return this.NameValueToActorId.GetOrAdd(name, key => this.CreateActorId(type, key));720 }721 /// <inheritdoc/>722 public override ActorId CreateActor(Type type, Event initialEvent = null, EventGroup eventGroup = null) =>723 this.CreateActor(null, type, null, initialEvent, eventGroup);724 /// <inheritdoc/>725 public override ActorId CreateActor(Type type, string name, Event initialEvent = null, EventGroup eventGroup = null) =>726 this.CreateActor(null, type, name, initialEvent, eventGroup);727 /// <inheritdoc/>728 public override ActorId CreateActor(ActorId id, Type type, Event initialEvent = null, EventGroup eventGroup = null)729 {...

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Runtime;6using Microsoft.Coyote.Specifications;7using Microsoft.Coyote.Tasks;8using Microsoft.Coyote.TestingServices;9using Microsoft.Coyote.TestingServices.Runtime;10using Microsoft.Coyote.TestingServices.SchedulingStrategies;11using Microsoft.Coyote.TestingServices.SchedulingStrategies.DPOR;12using Microsoft.Coyote.TestingServices.Tracing.Schedule;13using Microsoft.Coyote.Tests.Common;14using Microsoft.Coyote.Tests.Common.Actors;15using Microsoft.Coyote.Tests.Common.Runtime;16using Microsoft.Coyote.Tests.Common.Tasks;17using Microsoft.Coyote.Tests.Common.TestingServices;18using Microsoft.Coyote.Tests.Common.TestingServices.SchedulingStrategies;19using Microsoft.Coyote.Tests.Common.TestingServices.Tracing.Schedule;20using Microsoft.Coyote.Tests.Common.Utilities;21using Microsoft.Coyote.Tests.Common.Utilities.Storage;22using Microsoft.Coyote.Tests.Common.Utilities.Storage.Logging;23using Microsoft.Coyote.Tests.Common.Utilities.Storage.Stores;24using Microsoft.Coyote.Tests.Common.Utilities.Storage.Stores.InMemory;25using Microsoft.Coyote.Tests.Common.Utilities.Storage.Traces;26{27 {28 public static void Main(string[] args)29 {30 var config = Configuration.Create();31 config.MaxSchedulingSteps = 1000;32 config.MaxFairSchedulingSteps = 1000;33 config.MaxStepsFromEntryToExit = 1000;34 config.MaxStepsFromCreateActorToExit = 1000;

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.SystematicTesting;6using Microsoft.Coyote.TestingServices;7using Microsoft.Coyote.TestingServices.Runtime;8using Microsoft.Coyote.TestingServices.SchedulingStrategies;9using Microsoft.Coyote.TestingServices.Tracing.Schedule;10using Microsoft.Coyote.Tests.Common;11using Microsoft.Coyote.Tests.Common.Actors;12using Microsoft.Coyote.Tests.Common.Events;13using Microsoft.Coyote.Tests.Common.TestingServices;14using Microsoft.Coyote.Tests.Common.TestingServices.Coverage;15using Microsoft.Coyote.Tests.Common.TestingServices.SchedulingStrategies;16using Microsoft.Coyote.Tests.Common.TestingServices.Tracing.Schedule;17using Microsoft.Coyote.Tests.Common.Utilities;18using Microsoft.Coyote.Tests.Common.Utilities.Storage;19using Microsoft.Coyote.Tests.SystematicTesting;20using Microsoft.Coyote.Tests.SystematicTesting.Actors;21using Microsoft.Coyote.Tests.SystematicTesting.Actors.BugFinding;22using Microsoft.Coyote.Tests.SystematicTesting.Actors.Coverage;23using Microsoft.Coyote.Tests.SystematicTesting.Actors.FaultInjection;24using Microsoft.Coyote.Tests.SystematicTesting.Actors.TestingServices;25using Microsoft.Coyote.Tests.SystematicTesting.Actors.TestingServices.Coverage;26using Microsoft.Coyote.Tests.SystematicTesting.Actors.TestingServices.SchedulingStrategies;27using Microsoft.Coyote.Tests.SystematicTesting.Actors.TestingServices.Tracing.Schedule;28using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities;29using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.Storage;30using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.TestingServices;31using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.TestingServices.Coverage;32using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.TestingServices.SchedulingStrategies;33using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.TestingServices.Tracing.Schedule;34using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.Tracing.Schedule;35using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.Tracing.Schedule.TestingServices;36using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.Tracing.Schedule.TestingServices.SchedulingStrategies;37using Microsoft.Coyote.Tests.SystematicTesting.Actors.Utilities.Tracing.Schedule.TestingServices.Tracing.Schedule;

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using System;3using System.Threading.Tasks;4{5 {6 static void Main(string[] args)7 {8 Console.WriteLine("Hello World!");9 var runtime = RuntimeFactory.Create();10 runtime.CreateActor(typeof(Actor1), null, "Actor1");11 var actorId = runtime.CreateActorIdFromName("Actor1");12 Console.WriteLine("Actor Id is {0}", actorId);13 Console.ReadKey();14 }15 }16 {17 protected override Task OnInitializeAsync(Event initialEvent)18 {19 Console.WriteLine("Actor1 is initialized");20 return base.OnInitializeAsync(initialEvent);21 }22 }23}24Actor Id is ActorId(Actor1)

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Actors.Timers;6{7 {8 private static async Task Main(string[] args)9 {10 var runtime = RuntimeFactory.Create();11 await runtime.CreateActor(typeof(Actor1));12 await runtime.CreateActor(typeof(Actor2));13 await runtime.CreateActor(typeof(Actor3));14 await runtime.CreateActor(typeof(Actor4));15 await runtime.CreateActor(typeof(Actor5));16 await runtime.CreateActor(typeof(Actor6));17 await runtime.CreateActor(typeof(Actor7));18 await runtime.CreateActor(typeof(Actor8));19 await runtime.CreateActor(typeof(Actor9));20 await runtime.CreateActor(typeof(Actor10));21 await runtime.CreateActor(typeof(Actor11));22 await runtime.CreateActor(typeof(Actor12));23 await runtime.CreateActor(typeof(Actor13));24 await runtime.CreateActor(typeof(Actor14));25 await runtime.CreateActor(typeof(Actor15));26 await runtime.CreateActor(typeof(Actor16));27 await runtime.CreateActor(typeof(Actor17));28 await runtime.CreateActor(typeof(Actor18));29 await runtime.CreateActor(typeof(Actor19));30 await runtime.CreateActor(typeof(Actor20));31 await runtime.CreateActor(typeof(Actor21));32 await runtime.CreateActor(typeof(Actor22));33 await runtime.CreateActor(typeof(Actor23));34 await runtime.CreateActor(typeof(Actor24));35 await runtime.CreateActor(typeof(Actor25));36 await runtime.CreateActor(typeof(Actor26));37 await runtime.CreateActor(typeof(Actor27));38 await runtime.CreateActor(typeof(Actor28));39 await runtime.CreateActor(typeof(Actor29));40 await runtime.CreateActor(typeof(Actor30));41 await runtime.CreateActor(typeof(Actor31));42 await runtime.CreateActor(typeof(Actor32));43 await runtime.CreateActor(typeof(Actor33));44 await runtime.CreateActor(typeof(Actor34));45 await runtime.CreateActor(typeof(Actor35));46 await runtime.CreateActor(typeof(Actor36));47 await runtime.CreateActor(typeof(Actor37));48 await runtime.CreateActor(typeof(Actor38));49 await runtime.CreateActor(typeof(Actor39));50 await runtime.CreateActor(typeof(Actor40));51 await runtime.CreateActor(typeof(Actor41));52 await runtime.CreateActor(typeof(Actor42));53 await runtime.CreateActor(typeof(Actor43));

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote.Actors;4using Microsoft.Coyote.Specifications;5using Microsoft.Coyote.SystematicTesting;6using Microsoft.Coyote.Tasks;7{8 {9 private static async Task Main()10 {11 var configuration = Configuration.Create();12 configuration.SchedulingIterations = 100;13 configuration.MaxSchedulingSteps = 1000;14 configuration.TestingIterations = 10;15 configuration.Verbose = 1;16 var testingEngine = TestingEngineFactory.Create(configuration, new CreateActorIdFromNameTest());17 testingEngine.Run();18 }19 }20 {21 protected override async Task ExecuteAsync(SystematicTestingContext context)22 {23 var actor = context.CreateActor(typeof(MyActor));24 var actorId = context.CreateActorIdFromName("MyActor");25 context.Assert(actorId == actor, "Actor Ids are not the same.");26 }27 }28 {29 protected override Task OnInitializeAsync(Event initialEvent)30 {31 this.RegisterStateHandler(typeof(Default), this.DefaultHandler);32 return Task.CompletedTask;33 }34 private Task DefaultHandler(Event e)35 {36 return Task.CompletedTask;37 }38 }39}40using System;41using System.Threading.Tasks;42using Microsoft.Coyote.Actors;43using Microsoft.Coyote.Specifications;44using Microsoft.Coyote.SystematicTesting;45using Microsoft.Coyote.Tasks;46{47 {48 private static async Task Main()49 {50 var configuration = Configuration.Create();51 configuration.SchedulingIterations = 100;52 configuration.MaxSchedulingSteps = 1000;53 configuration.TestingIterations = 10;54 configuration.Verbose = 1;55 var testingEngine = TestingEngineFactory.Create(configuration, new CreateActorIdFromNameTest());56 testingEngine.Run();57 }58 }59 {60 protected override async Task ExecuteAsync(SystematicTestingContext context)61 {62 var actor = context.CreateActor(typeof(MyActor));63 var actorId = context.CreateActorIdFromName("MyActor");

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1{2 using Microsoft.Coyote;3 using Microsoft.Coyote.Actors;4 using Microsoft.Coyote.Actors.Timers;5 using Microsoft.Coyote.Runtime;6 using Microsoft.Coyote.Specifications;7 using System;8 using System.Collections.Generic;9 using System.Threading.Tasks;10 {11 static void Main(string[] args)12 {13 ActorId id = ActorExecutionContext.CreateActorIdFromName("MyActor");14 Console.WriteLine(id);15 }16 }17}18ActorId(1,MyActor)

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using System;3using System.Threading.Tasks;4{5 {6 static void Main(string[] args)7 {8 ActorId actorId = ActorExecutionContext.CreateActorIdFromName("actor1");9 Console.WriteLine("ActorId: " + actorId);10 Console.ReadLine();11 }12 }13}14ActorExecutionContext.CreateActorIdFromName() method

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Specifications;6using Microsoft.Coyote.Tasks;7{8 {9 public static void Main(string[] args)10 {11 var runtime = RuntimeFactory.Create();12 runtime.CreateActor(typeof(Actor1));13 runtime.CreateActor(typeof(Actor2));14 runtime.CreateActor(typeof(Actor3));15 runtime.CreateActor(typeof(Actor4));16 runtime.CreateActor(typeof(Actor5));17 runtime.CreateActor(typeof(Actor6));18 runtime.CreateActor(typeof(Actor7));19 runtime.CreateActor(typeof(Actor8));20 runtime.CreateActor(typeof(Actor9));21 runtime.CreateActor(typeof(Actor10));22 runtime.CreateActor(typeof(Actor11));23 runtime.CreateActor(typeof(Actor12));24 runtime.CreateActor(typeof(Actor13));25 runtime.CreateActor(typeof(Actor14));26 runtime.CreateActor(typeof(Actor15));27 runtime.CreateActor(typeof(Actor16));28 runtime.CreateActor(typeof(Actor17));29 runtime.CreateActor(typeof(Actor18));30 runtime.CreateActor(typeof(Actor19));31 runtime.CreateActor(typeof(Actor20));32 runtime.CreateActor(typeof(Actor21));33 runtime.CreateActor(typeof(Actor22));34 runtime.CreateActor(typeof(Actor23));35 runtime.CreateActor(typeof(Actor24));36 runtime.CreateActor(typeof(Actor25));37 runtime.CreateActor(typeof(Actor26));38 runtime.CreateActor(typeof(Actor27));39 runtime.CreateActor(typeof(Actor28));40 runtime.CreateActor(typeof(Actor29));41 runtime.CreateActor(typeof(Actor30));42 runtime.CreateActor(typeof(Actor31));43 runtime.CreateActor(typeof(Actor32));44 runtime.CreateActor(typeof(Actor33));45 runtime.CreateActor(typeof(Actor34));46 runtime.CreateActor(typeof(Actor35));47 runtime.CreateActor(typeof(Actor36));48 runtime.CreateActor(typeof(Actor37));49 runtime.CreateActor(typeof(Actor38));50 runtime.CreateActor(typeof(Actor39));51 runtime.CreateActor(typeof(Actor40));52 runtime.CreateActor(typeof(Actor41));53 runtime.CreateActor(typeof(Actor42));54 runtime.CreateActor(typeof(Actor43));55 runtime.CreateActor(typeof(Actor44));56 runtime.CreateActor(typeof(Actor45));57 runtime.CreateActor(typeof(Actor46));

Full Screen

Full Screen

CreateActorIdFromName

Using AI Code Generation

copy

Full Screen

1using System;2using Microsoft.Coyote.Actors;3using Microsoft.Coyote.Specifications;4using Microsoft.Coyote.SystematicTesting;5using Microsoft.Coyote.Tasks;6{7 {8 static void Main(string[] args)9 {10 var configuration = Configuration.Create();11 configuration.MaxSchedulingSteps = 100000;12 configuration.MaxFairSchedulingSteps = 100000;13 configuration.EnableDataRaceDetection = true;14 configuration.EnableDeadlockDetection = true;15 configuration.EnableIntegerOverflowChecks = true;16 configuration.EnableActorGarbageCollection = true;17 configuration.EnableActorCycleDetection = true;18 configuration.EnableActorStatePrinting = true;19 configuration.EnableActorTaskInterleavings = true;20 configuration.EnableActorTaskInterleavings = true;21 configuration.EnableOperationInterleavings = true;22 configuration.EnableOperationInterleavings = true;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful