/// <summary> /// Initializes any custom actor logs. /// </summary> private void InitializeCustomActorLogging(IActorRuntime runtime) { if (this.Configuration.IsTraceVisualizationEnabled) { // Registers an activity coverage graph builder. runtime.RegisterLog(new ActorRuntimeLogGraphBuilder(false, false)); } if (this.Configuration.IsActivityCoverageReported) { // Registers an activity coverage graph builder that collapses instances. runtime.RegisterLog(new ActorRuntimeLogGraphBuilder(false, true)); // Need this additional logger to get the event coverage report correct runtime.RegisterLog(new ActorRuntimeLogEventCoverage()); } if (this.Configuration.IsXmlLogEnabled) { this.XmlLog = new StringBuilder(); runtime.RegisterLog(new ActorRuntimeLogXmlFormatter(XmlWriter.Create(this.XmlLog, new XmlWriterSettings() { Indent = true, IndentChars = " ", OmitXmlDeclaration = true }))); } }
public async Task TestGraphLoggerCollapsed() { CustomLogger logger = new CustomLogger(); Configuration config = Configuration.Create().WithVerbosityEnabled(); var graphBuilder = new ActorRuntimeLogGraphBuilder(false); graphBuilder.CollapseMachineInstances = true; var tcs = TaskCompletionSource.Create <bool>(); IActorRuntime runtime = CreateTestRuntime(config, tcs, logger); runtime.RegisterLog(graphBuilder); ActorId serverId = runtime.CreateActor(typeof(Server)); runtime.CreateActor(typeof(Client), new ClientSetupEvent(serverId)); runtime.CreateActor(typeof(Client), new ClientSetupEvent(serverId)); runtime.CreateActor(typeof(Client), new ClientSetupEvent(serverId)); await WaitAsync(tcs.Task, 5000000); await Task.Delay(1000); string actual = graphBuilder.Graph.ToString(); Assert.Contains("<Node Id='Microsoft.Coyote.Production.Tests.Actors.CustomActorRuntimeLogTests+Client.Client' Label='Client'/>", actual); Assert.Contains("<Node Id='Microsoft.Coyote.Production.Tests.Actors.CustomActorRuntimeLogTests+Server.Complete' Label='Complete'/>", actual); logger.Dispose(); }
public async Task TestCustomActorRuntimeLogFormatter() { Configuration config = Configuration.Create().WithVerbosityEnabled(); var tcs = TaskCompletionSource.Create <bool>(); IActorRuntime runtime = CreateTestRuntime(config, tcs); runtime.RegisterMonitor <S>(); runtime.SetLogger(null); var logger = new CustomActorRuntimeLog(); runtime.RegisterLog(logger); runtime.CreateActor(typeof(M)); await WaitAsync(tcs.Task, 5000); await Task.Delay(200); string expected = @"CreateActor CreateStateMachine StateTransition StateTransition StateTransition "; string actual = RemoveNonDeterministicValuesFromReport(logger.ToString()); Assert.Equal(expected, actual); }
public async Task TestCustomActorRuntimeLogFormatter() { Configuration config = Configuration.Create().WithVerbosityEnabled(); config.IsMonitoringEnabledInInProduction = true; IActorRuntime runtime = RuntimeFactory.Create(config); runtime.RegisterMonitor <S>(); runtime.SetLogger(null); var logger = new CustomActorRuntimeLog(); runtime.RegisterLog(logger); var tcs = new TaskCompletionSource <bool>(); runtime.CreateActor(typeof(M), new SetupEvent(tcs)); await WaitAsync(tcs.Task); await Task.Delay(200); string expected = @"CreateActor StateTransition CreateActor StateTransition StateTransition StateTransition "; string actual = RemoveNonDeterministicValuesFromReport(logger.ToString()); Assert.Equal(expected, actual); }
public static void Execute(IActorRuntime runtime) { runtime.RegisterLog(new PLogFormatter()); PModule.runtime = runtime; PHelper.InitializeInterfaces(); PHelper.InitializeEnums(); InitializeLinkMap(); InitializeInterfaceDefMap(); InitializeMonitorMap(runtime); InitializeMonitorObserves(); runtime.CreateActor(typeof(_GodMachine), new _GodMachine.Config(typeof(Main))); }
public async Task TestGraphLogger() { CustomLogger logger = new CustomLogger(); Configuration config = Configuration.Create().WithVerbosityEnabled(); var graphBuilder = new ActorRuntimeLogGraphBuilder(false); var tcs = TaskCompletionSource.Create <bool>(); IActorRuntime runtime = CreateTestRuntime(config, tcs, logger); runtime.RegisterLog(graphBuilder); runtime.CreateActor(typeof(M)); await WaitAsync(tcs.Task); await Task.Delay(200); string expected = @"<DirectedGraph xmlns='http://schemas.microsoft.com/vs/2009/dgml'> <Nodes> <Node Id='M()' Category='Actor' Group='Expanded'/> <Node Id='M().M()' Label='M()'/> <Node Id='N()' Category='StateMachine' Group='Expanded'/> <Node Id='N().Act' Label='Act'/> <Node Id='N().Init' Label='Init'/> <Node Id='TestMonitor' Group='Expanded'/> <Node Id='TestMonitor.Init' Label='Init'/> <Node Id='TestMonitor.OnCompleted' Label='OnCompleted'/> </Nodes> <Links> <Link Source='M().M()' Target='N().Init' Label='E' Index='' EventId='E' HandledBy='Init'/> <Link Source='M().M()' Target='TestMonitor.Init' Label='CompletedEvent' Index='' EventId='CompletedEvent'/> <Link Source='M()' Target='M().M()' Category='Contains'/> <Link Source='N().Act' Target='M().M()' Label='E' Index='' EventId='E'/> <Link Source='N().Init' Target='N().Act' Label='E' Index='' EventId='E' HandledBy='Init'/> <Link Source='N()' Target='N().Act' Category='Contains'/> <Link Source='N()' Target='N().Init' Category='Contains'/> <Link Source='TestMonitor.Init' Target='TestMonitor.OnCompleted' Label='CompletedEvent' Index='' EventId='CompletedEvent'/> <Link Source='TestMonitor' Target='TestMonitor.Init' Category='Contains'/> <Link Source='TestMonitor' Target='TestMonitor.OnCompleted' Category='Contains'/> </Links> </DirectedGraph> "; string actual = RemoveNonDeterministicValuesFromReport(graphBuilder.Graph.ToString()); Assert.Equal(expected, actual); logger.Dispose(); }
/// <summary> /// Take care of handling the <see cref="Configuration"/> settings for <see cref="Configuration.CustomActorRuntimeLogType"/>, /// <see cref="Configuration.IsDgmlGraphEnabled"/>, and <see cref="Configuration.ReportActivityCoverage"/> by setting up the /// LogWriters on the given <see cref="IActorRuntime"/> object. /// </summary> private void InitializeCustomActorLogging(IActorRuntime runtime) { if (!string.IsNullOrEmpty(this.Configuration.CustomActorRuntimeLogType)) { var log = this.Activate <IActorRuntimeLog>(this.Configuration.CustomActorRuntimeLogType); if (log != null) { runtime.RegisterLog(log); } } if (this.Configuration.IsDgmlGraphEnabled || this.Configuration.ReportActivityCoverage) { // Registers an activity coverage graph builder. runtime.RegisterLog(new ActorRuntimeLogGraphBuilder(false) { CollapseMachineInstances = this.Configuration.ReportActivityCoverage }); } if (this.Configuration.ReportActivityCoverage) { // Need this additional logger to get the event coverage report correct runtime.RegisterLog(new ActorRuntimeLogEventCoverage()); } if (this.Configuration.IsXmlLogEnabled) { this.XmlLog = new StringBuilder(); runtime.RegisterLog(new ActorRuntimeLogXmlFormatter(XmlWriter.Create(this.XmlLog, new XmlWriterSettings() { Indent = true, IndentChars = " ", OmitXmlDeclaration = true }))); } }
internal async Task RunAsync() { try { // We use the Topic/Subscription pattern which is a pub/sub model where each Server will send // messages to this Topic, and every other server has a Subscription to receive those messages. // If the Message has a "To" field then the server ignores the message as it was not meant for them. // Otherwise the Message is considered a "broadcast" to all servers and each server will handle it. // The client also has a subcription on the same topic and is how it broadcasts requests and receives // the final response from the elected Leader. var managementClient = new ManagementClient(this.ConnectionString); if (!await managementClient.TopicExistsAsync(this.TopicName)) { await managementClient.CreateTopicAsync(this.TopicName); } // then we need a subscription, whether we are client or server and the subscription name will be // the same as our local actorid. string subscriptionName = (this.ServerId < 0) ? "Client" : $"Server-{this.ServerId}"; if (!await managementClient.SubscriptionExistsAsync(this.TopicName, subscriptionName)) { await managementClient.CreateSubscriptionAsync( new SubscriptionDescription(this.TopicName, subscriptionName)); } Console.WriteLine("Running " + subscriptionName); IActorRuntime runtime = RuntimeFactory.Create(Configuration.Create().WithVerbosityEnabled()); if (this.GraphIt) { var graphBuilder = new ActorRuntimeLogGraphBuilder(false); runtime.RegisterLog(graphBuilder); _ = Task.Run(() => { PeriodicSaves(graphBuilder, subscriptionName); }); } // We create a new Coyote actor runtime instance, and pass an optional configuration // that increases the verbosity level to see the Coyote runtime log. runtime.OnFailure += RuntimeOnFailure; var topicClient = new TopicClient(this.ConnectionString, this.TopicName); // cluster manager needs the topic client in order to be able to broadcast messages using Azure Service Bus var clusterManager = runtime.CreateActor(typeof(AzureClusterManager), new AzureClusterManager.RegisterMessageBusEvent() { TopicClient = topicClient }); if (this.ServerId < 0) { await this.RunClient(runtime, clusterManager, subscriptionName); } else { await this.RunServer(runtime, clusterManager, subscriptionName); } } catch (Exception ex) { Console.WriteLine($"{DateTime.Now} :: ex: {ex.ToString()}"); } }