internal static void RunTest(IActorRuntime runtime, LogEvent config) { var actor = runtime.CreateActor(typeof(X3), config); runtime.SendEvent(actor, new E1()); // deferred runtime.SendEvent(actor, new E2()); // push state Active, and allow handling of deferred event. }
public static void RunTest(IActorRuntime runtime, LogEvent initEvent) { var actor = runtime.CreateActor(typeof(M8), initEvent); runtime.SendEvent(actor, new E1()); // should be handled by Init state, and trigger push to Ready runtime.SendEvent(actor, new E1()); // should pop Active and go back to Init where it will be handled. }
public static void RunTest(IActorRuntime r, LogEvent config) { var actor = r.CreateActor(typeof(W), config); r.SendEvent(actor, new E1()); r.SendEvent(actor, new E2()); }
internal static void RunTest(IActorRuntime runtime) { var a = runtime.CreateActor(typeof(M5a)); runtime.SendEvent(a, new E2()); // Push(S1) runtime.SendEvent(a, new E1()); // Execute foo without popping runtime.SendEvent(a, new E3()); // Can handle it because A is still in S1 }
public static void RunTest(IActorRuntime r, LogEvent config) { var a = r.CreateActor(typeof(Aa), config); r.SendEvent(a, new E2()); r.SendEvent(a, UnitEvent.Instance); r.SendEvent(a, new E1()); }
internal static void RunTest(IActorRuntime runtime, LogEvent config) { var actor = runtime.CreateActor(typeof(X3), config); runtime.SendEvent(actor, new E1()); // ignored (and therefore dropped) runtime.SendEvent(actor, new E2()); // push state Active. runtime.SendEvent(actor, new E1()); // Catch by wildcard (overriding inherited IgnoreEvents) }
internal static void RunTest(IActorRuntime runtime, LogEvent config) { var actor = runtime.CreateActor(typeof(X2), config); runtime.SendEvent(actor, new E1()); // handle E1 & push active runtime.SendEvent(actor, new E1()); // catch E1, by wildcard runtime.SendEvent(actor, new E2()); // handle E2, specific handler wins }
public static void RunTest(IActorRuntime runtime, LogEvent initEvent) { var actor = runtime.CreateActor(typeof(M7), initEvent); runtime.SendEvent(actor, new E1()); // should be handled by Init state, and trigger push to Ready runtime.SendEvent(actor, new E1()); // should be handled by Ready with OnEventPushState to Active runtime.SendEvent(actor, new E2()); // Now OnEventGotoState(E2) should not be inherited so this should pop us back to the Init state. runtime.SendEvent(actor, new E3()); // just to prove we are no longer in the Active state, this should raise an unhandled event error. }
public async Task IncrementCount() { var request = new RequestEvent <int, int>(IncrementAmount); AddActor = runtime.CreateActor(typeof(AddActor), request); var response = await request.Completed.Task; CurrentCount = CurrentCount + response; runtime.SendEvent(AddActor, HaltEvent.Instance); }
private async Task RunClient(IActorRuntime runtime, ActorId clusterManager, string subscriptionName) { CancellationTokenSource cancelSource = new CancellationTokenSource(); StartRaftServers(this.ConnectionString, this.TopicName, this.ClusterSize); var receiver = new AzureMessageReceiver(runtime, this.ConnectionString, this.TopicName, this.LocalId, subscriptionName); var nowait = receiver.RunAsync(cancelSource.Token); receiver.ResponseReceived += (s, e) => { this.completed.SetResult(e); }; // Now send the requested number of ClientRequestEvents to the cluster, and wait for each response. for (int i = 0; i < this.NumRequests; i++) { string command = $"request-{i}"; Console.WriteLine($"<Client> sending {command}."); this.completed = new TaskCompletionSource <ClientResponseEvent>(); runtime.SendEvent(clusterManager, new ClientRequestEvent(command)); var response = await this.completed.Task; Console.WriteLine($"<Client> received response for {response.Command} from {response.Server}."); } }
public static void Execute(IActorRuntime runtime) { runtime.OnFailure += OnRuntimeFailure; runtime.RegisterMonitor <LivenessMonitor>(); runtime.RegisterMonitor <DoorSafetyMonitor>(); ActorId driver = runtime.CreateActor(typeof(FailoverDriver), new ConfigEvent(RunForever)); runtime.SendEvent(driver, new FailoverDriver.StartTestEvent()); }
public static async Task Execute(IActorRuntime runtime) { var request = new RequestEvent <string, string>("Hi Mom!"); ActorId id = runtime.CreateActor(typeof(ExampleHttpServer), request); var response = await request.Completed.Task; runtime.SendEvent(id, HaltEvent.Instance); }
public static async Task Execute(IActorRuntime runtime) { int CurrentCount = 0; int incrementAmount = 3; var request = new RequestEvent <int, int>(incrementAmount); var AddActor = runtime.CreateActor(typeof(AddActor), request); var response = await request.Completed.Task; CurrentCount = CurrentCount + response; runtime.SendEvent(AddActor, HaltEvent.Instance); }
internal static void RunTest(IActorRuntime runtime, LogEvent config) { var actor = runtime.CreateActor(typeof(X), config); runtime.SendEvent(actor, new E1()); // handle runtime.SendEvent(actor, new E3()); // catch runtime.SendEvent(actor, new E2()); // catch & push to ready runtime.SendEvent(actor, new E3()); // handled by Ready (overriding wildcard) runtime.SendEvent(actor, new E4()); // catch, wildcard still in effect runtime.SendEvent(actor, new E3()); // catch, wildcard still in effect }
public static void Send(IActorRuntime runtime, ActorId target) { runtime.SendEvent(target, new E(2)); }
/// <summary> /// During testing, Coyote injects a special version of the <see cref="IActorRuntime"/> /// that takes control of the test execution and systematically exercises interleavings /// and other sources of nondeterminism to find bugs in the specified scenario. /// </summary> public void RunTest(IActorRuntime runtime, int numServers, int numRequests) { // Register a safety monitor for checking the specification that // only one leader can be elected at any given term. runtime.RegisterMonitor <SafetyMonitor>(); // Create the actor id for a client that will be sending requests to the Raft service. var client = runtime.CreateActorIdFromName(typeof(MockClient), "Client"); // Create the actor for a cluster manager. var cluster = this.CreateClusterManager(runtime); var serverProxies = new List <ActorId>(); for (int serverId = 0; serverId < numServers; serverId++) { // Create an actor id that will uniquely identify the server state machine // and act as a proxy for communicating with that state machine. serverProxies.Add(runtime.CreateActorIdFromName(typeof(Server), $"Server-{serverId}")); } runtime.SendEvent(cluster, new RegisterClientEvent() { ClientId = client }); // Create the mock server hosts for wrapping and handling communication between // all server state machines that execute in-memory during this test. var serverHosts = new List <IServerManager>(); foreach (var serverProxy in serverProxies) { // pass the remote server id's to the ClusterManager. runtime.SendEvent(cluster, new RegisterServerEvent() { ServerId = serverProxy }); // Pass the actor id of each remote server to the host. serverHosts.Add(this.CreateServerHost(runtime, serverProxy, serverProxies.Where( id => id != serverProxy), client, cluster)); } // Create the server actors foreach (var serverHost in serverHosts) { serverHost.Initialize(); } // Start executing each server. It is important to do this only after all state machines // have been initialized, since each one will try to asynchronously communicate with the // others, and thus they have to be already bound to their corresponding actor ids (else // the events cannot be delivered, and the runtime will catch it as an error). foreach (var serverHost in serverHosts) { serverHost.Start(); } // Create the client actor instance, so the runtime starts executing it. runtime.CreateActor(client, typeof(MockClient), new MockClient.SetupEvent(cluster, numRequests, TimeSpan.FromSeconds(1))); }