How to use LinkTransition method of Microsoft.Coyote.Actors.Coverage.ActorRuntimeLogGraphBuilder class

Best Coyote code snippet using Microsoft.Coyote.Actors.Coverage.ActorRuntimeLogGraphBuilder.LinkTransition

ActorRuntimeLogGraphBuilder.cs

Source:ActorRuntimeLogGraphBuilder.cs Github

copy

Full Screen

...218 }219 /// <inheritdoc/>220 public void OnExecuteAction(ActorId id, string handlingStateName, string currentStateName, string actionName)221 {222 this.LinkTransition(typeof(DoActionEvent), id, handlingStateName, currentStateName, null);223 }224 /// <inheritdoc/>225 public void OnGotoState(ActorId id, string currentStateName, string newStateName)226 {227 this.LinkTransition(typeof(GotoStateEvent), id, currentStateName, currentStateName, newStateName);228 }229 /// <inheritdoc/>230 public void OnPushState(ActorId id, string currentStateName, string newStateName)231 {232 this.LinkTransition(typeof(PushStateEvent), id, currentStateName, currentStateName, newStateName);233 }234 /// <inheritdoc/>235 public void OnPopState(ActorId id, string currentStateName, string restoredStateName)236 {237 if (!string.IsNullOrEmpty(currentStateName))238 {239 this.LinkTransition(typeof(PopStateEvent), id, currentStateName,240 currentStateName, restoredStateName);241 }242 }243 /// <inheritdoc/>244 public void OnHalt(ActorId id, int inboxSize)245 {246 lock (this.Inbox)247 {248 this.HaltedStates.TryGetValue(id, out string stateName);249 var target = this.GetOrCreateChild(id?.Name, id?.Type, "Halt", "Halt");250 // Transition to the Halt state.251 if (!string.IsNullOrEmpty(stateName))252 {253 var source = this.GetOrCreateChild(id?.Name, id?.Type, stateName);254 this.GetOrCreateEventLink(source, target, new EventInfo() { Event = typeof(HaltEvent).FullName });255 }256 }257 }258 private int? GetLinkIndex(GraphNode source, GraphNode target, string id)259 {260 if (this.MergeEventLinks)261 {262 return null;263 }264 return this.Graph.GetUniqueLinkIndex(source, target, id);265 }266 /// <inheritdoc/>267 public void OnDefaultEventHandler(ActorId id, string stateName)268 {269 lock (this.Inbox)270 {271 string resolvedId = this.GetResolveActorId(id?.Name, id?.Type);272 string eventName = typeof(DefaultEvent).FullName;273 this.AddEvent(id.Name, id.Type, id.Name, id.Type, stateName, eventName);274 this.Dequeued[id] = this.PopEvent(resolvedId, eventName);275 }276 }277 /// <inheritdoc/>278 public void OnHandleRaisedEvent(ActorId id, string stateName, Event e)279 {280 lock (this.Inbox)281 {282 // We used the inbox to store raised event, but it should be the first one handled since283 // raised events are highest priority.284 string resolvedId = this.GetResolveActorId(id?.Name, id?.Type);285 lock (this.Inbox)286 {287 if (this.Inbox.TryGetValue(resolvedId, out List<EventInfo> inbox))288 {289 string eventName = e.GetType().FullName;290 for (int i = inbox.Count - 1; i >= 0; i--)291 {292 EventInfo info = inbox[i];293 if (info.Event == eventName)294 {295 this.Dequeued[id] = info;296 break;297 }298 }299 }300 }301 }302 }303 /// <inheritdoc/>304 public void OnPopStateUnhandledEvent(ActorId actorId, string currentStateName, Event e)305 {306 lock (this.Inbox)307 {308 if (e is HaltEvent)309 {310 this.HaltedStates[actorId] = currentStateName;311 }312 }313 }314 /// <inheritdoc/>315 public void OnExceptionThrown(ActorId id, string stateName, string actionName, Exception ex)316 {317 }318 /// <inheritdoc/>319 public void OnExceptionHandled(ActorId id, string stateName, string actionName, Exception ex)320 {321 }322 /// <inheritdoc/>323 public void OnCreateTimer(TimerInfo info)324 {325 // TODO: figure out how to graph timers when we have no "timer id" at this point...326 }327 /// <inheritdoc/>328 public void OnStopTimer(TimerInfo info)329 {330 }331 /// <inheritdoc/>332 public void OnCreateMonitor(string monitorType)333 {334 lock (this.Inbox)335 {336 GraphNode node = this.Graph.GetOrCreateNode(monitorType, monitorType);337 node.Category = MonitorCategory;338 }339 }340 /// <inheritdoc/>341 public void OnMonitorExecuteAction(string monitorType, string stateName, string actionName)342 {343 // Monitors process actions immediately, so this state transition is a result of the only event in the inbox.344 lock (this.Inbox)345 {346 if (this.Inbox.TryGetValue(monitorType, out List<EventInfo> inbox) && inbox.Count > 0)347 {348 var e = inbox[inbox.Count - 1];349 inbox.RemoveAt(inbox.Count - 1);350 // Draw the link connecting the Sender state to this state!351 var source = this.GetOrCreateChild(e.Name, e.Type, e.State);352 var target = this.GetOrCreateChild(monitorType, monitorType, stateName);353 this.GetOrCreateEventLink(source, target, e);354 }355 }356 }357 /// <inheritdoc/>358 public void OnMonitorProcessEvent(string monitorType, string stateName, string senderName, string senderType,359 string senderStateName, Event e)360 {361 lock (this.Inbox)362 {363 string eventName = e.GetType().FullName;364 // Now add a fake event for internal monitor state transition that might now happen as a result of this event,365 // storing the monitor's current state in this event.366 var info = this.AddEvent(monitorType, monitorType, monitorType, monitorType, stateName, eventName);367 // Draw the link connecting the Sender state to this state!368 var source = this.GetOrCreateChild(senderName, senderType, senderStateName);369 var target = this.GetOrCreateChild(monitorType, monitorType, stateName);370 this.GetOrCreateEventLink(source, target, info);371 }372 }373 /// <inheritdoc/>374 public void OnMonitorRaiseEvent(string monitorType, string stateName, Event e)375 {376 // Raising event to self.377 string eventName = e.GetType().FullName;378 this.AddEvent(monitorType, monitorType, monitorType, monitorType, stateName, eventName);379 }380 /// <inheritdoc/>381 public void OnMonitorStateTransition(string monitorType, string stateName, bool isEntry, bool? isInHotState)382 {383 if (isEntry)384 {385 lock (this.Inbox)386 {387 // Monitors process events immediately (and does not call OnDequeue), so this state transition is a result of388 // the fake event we created in OnMonitorProcessEvent.389 if (this.Inbox.TryGetValue(monitorType, out List<EventInfo> inbox) && inbox.Count > 0)390 {391 var info = inbox[inbox.Count - 1];392 inbox.RemoveAt(inbox.Count - 1);393 // draw the link connecting the current state to this new state!394 var source = this.GetOrCreateChild(monitorType, monitorType, info.State);395 var shortStateName = this.GetLabel(monitorType, monitorType, stateName);396 string suffix = string.Empty;397 if (isInHotState.HasValue)398 {399 suffix = (isInHotState is true) ? "[hot]" : "[cold]";400 shortStateName += suffix;401 }402 string label = shortStateName;403 var target = this.GetOrCreateChild(monitorType, monitorType, shortStateName, label);404 // In case this node was already created, we may need to override the label here now that405 // we know this is a hot state. This is because, unfortunately, other OnMonitor* methods406 // do not provide the isInHotState parameter.407 target.Label = label;408 this.GetOrCreateEventLink(source, target, info);409 }410 }411 }412 }413 /// <inheritdoc/>414 public void OnMonitorError(string monitorType, string stateName, bool? isInHotState)415 {416 var source = this.GetOrCreateChild(monitorType, monitorType, stateName);417 source.Category = "Error";418 }419 /// <inheritdoc/>420 public void OnRandom(object result, string callerName, string callerType)421 {422 }423 /// <inheritdoc/>424 public void OnAssertionFailure(string error)425 {426 }427 /// <inheritdoc/>428 public void OnStrategyDescription(string strategyName, string description)429 {430 }431 /// <inheritdoc/>432 public void OnCompleted()433 {434 }435 /// <summary>436 /// Return current graph and reset for next iteration.437 /// </summary>438 /// <param name="reset">Set to true will reset the graph for the next iteration.</param>439 /// <returns>The graph.</returns>440 public Graph SnapshotGraph(bool reset)441 {442 Graph result = this.CurrentGraph;443 if (reset)444 {445 // start fresh.446 this.CurrentGraph = null;447 }448 return result;449 }450 private string GetResolveActorId(string name, string type)451 {452 if (type is null)453 {454 // The sender id can be null if an event is fired from non-actor code.455 return ExternalCodeName;456 }457 if (this.CollapseMachineInstances)458 {459 return type;460 }461 return name;462 }463 private EventInfo AddEvent(string targetName, string targetType, string senderName, string senderType,464 string senderStateName, string eventName)465 {466 string targetId = this.GetResolveActorId(targetName, targetType);467 EventInfo info = null;468 lock (this.Inbox)469 {470 if (!this.Inbox.TryGetValue(targetId, out List<EventInfo> inbox))471 {472 inbox = new List<EventInfo>();473 this.Inbox[targetId] = inbox;474 }475 info = new EventInfo()476 {477 Name = senderName ?? ExternalCodeName,478 Type = senderType ?? ExternalCodeName,479 State = senderStateName,480 Event = eventName481 };482 inbox.Add(info);483 }484 return info;485 }486 private void LinkTransition(Type transitionType, ActorId id, string handlingStateName,487 string currentStateName, string newStateName)488 {489 string name = id.Name;490 string type = id.Type;491 lock (this.Inbox)492 {493 if (this.Dequeued.TryGetValue(id, out EventInfo info))494 {495 // Event was dequeued, but now we know what state is handling this event, so connect the dots...496 if (info.Type != type || info.Name != name || info.State != currentStateName)497 {498 var source = this.GetOrCreateChild(info.Name, info.Type, info.State);499 var target = this.GetOrCreateChild(name, type, currentStateName);500 info.HandlingState = handlingStateName;...

Full Screen

Full Screen

LinkTransition

Using AI Code Generation

copy

Full Screen

1ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();2graphBuilder.LinkTransition(3, 4, "e1");3ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();4graphBuilder.LinkTransition(3, 4, "e1");5ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();6graphBuilder.LinkTransition(3, 4, "e1");7ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();8graphBuilder.LinkTransition(3, 4, "e1");9ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();10graphBuilder.LinkTransition(3, 4, "e1");11ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();12graphBuilder.LinkTransition(3, 4, "e1");13ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();14graphBuilder.LinkTransition(3, 4, "e1");15ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();16graphBuilder.LinkTransition(3, 4, "e1");17ActorRuntimeLogGraphBuilder graphBuilder = new ActorRuntimeLogGraphBuilder();18graphBuilder.LinkTransition(3, 4, "e1");

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