public void ReceiveWhile_Filter_should_not_consume_last_message_that_didnt_match() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell(4711); ReceiveWhile <object>(_ => _ is string?_: null); ExpectMsg(4711); }
protected override SupervisorStrategy SupervisorStrategy() { return(new OneForOneStrategy(exception => { TestActor.Tell(exception); return Directive.Resume; })); }
public void WithinSample() { TestActor.Tell(42, ActorRefs.NoSender); Within(0.Milliseconds(), 1.Seconds(), () => { Assert.Equal(42, ExpectMsg <int>()); }); }
public void ExpectMsgAllOf_should_receive_correct_messages() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell("3"); TestActor.Tell("4"); ExpectMsgAllOf("3", "1", "4", "2").ShouldOnlyContainInOrder("1", "2", "3", "4"); }
public void ExpectMsgAllOf_should_fail_when_receiving_unexpected() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell("Totally unexpected"); TestActor.Tell("3"); Intercept(() => ExpectMsgAllOf("3", "1", "2")); }
public void ImplicitSender_should_not_change_when_creating_TestActors() { var testActor2 = CreateTestActor("test2"); TestActor.Tell("message"); ReceiveOne(); LastSender.ShouldBe(TestActor); }
public void FishForMessage_should_return_matched_message() { TestActor.Tell(1); TestActor.Tell(2); TestActor.Tell(10); TestActor.Tell(20); FishForMessage <int>(i => i >= 10).ShouldBe(10); }
public void IgnoreMessages_should_ignore_messages() { IgnoreMessages(o => o is int && (int)o == 1); TestActor.Tell(1); TestActor.Tell("1"); String.Equals((string)ReceiveOne(), "1").ShouldBeTrue(); HasMessages.ShouldBeFalse(); }
public void ImplicitSender_should_not_change_when_creating_Testprobes() { //Verifies that bug #459 has been fixed var testProbe = CreateTestProbe(); TestActor.Tell("message"); ReceiveOne(); LastSender.ShouldBe(TestActor); }
public void ReceiveN_should_receive_correct_number_of_messages() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell("3"); TestActor.Tell("4"); ReceiveN(3).ShouldOnlyContainInOrder("1", "2", "3"); ReceiveN(1).ShouldOnlyContainInOrder("4"); }
public void ReceiveWhile_Predicate_should_break_when_type_is_wrong_and_we_dont_ignore_those_and_return_correct_messages() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell("3"); TestActor.Tell(4); TestActor.Tell("5"); ReceiveWhile <string>(s => s.Length == 1, shouldIgnoreOtherMessageTypes: false).ShouldOnlyContainInOrder("1", "2", "3"); }
public void ReceiveWhile_Predicate_should_continue_when_type_is_other_but_we_ignore_other_types_and_return_correct_messages() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell("3"); TestActor.Tell(4); TestActor.Tell("5"); ReceiveWhile <string>(s => s.Length == 1, shouldIgnoreOtherMessageTypes: true).ShouldOnlyContainInOrder("1", "2", "3", "5"); }
/// <summary> /// On my test code I want to pass the mock statemanager all the time. /// </summary> /// <param name="actorStateManager">Mock StateManager.</param> /// <returns>TestActor.</returns> private TestActor CreateTestDemoActor(IActorStateManager actorStateManager) { var actorTypeInformation = ActorTypeInformation.Get(typeof(TestActor)); var loggerFactory = new LoggerFactory(); var host = new ActorHost(actorTypeInformation, ActorId.CreateRandom(), loggerFactory); var testActor = new TestActor(host, actorStateManager); return(testActor); }
/// <summary> /// On my test code I want to pass the mock statemanager all the time. /// </summary> /// <param name="actorStateManager">Mock StateManager.</param> /// <returns>TestActor.</returns> private TestActor CreateTestDemoActor(IActorStateManager actorStateManager) { var actorTypeInformation = ActorTypeInformation.Get(typeof(TestActor)); var loggerFactory = new LoggerFactory(); var host = new ActorHost(actorTypeInformation, ActorId.CreateRandom(), JsonSerializerDefaults.Web, loggerFactory, ActorProxy.DefaultProxyFactory, new DaprHttpInteractor()); var testActor = new TestActor(host, actorStateManager); return(testActor); }
public void ReceiveWhile_Filter_should_break_on_function_returning_null_and_return_correct_messages() { TestActor.Tell("1"); TestActor.Tell(2); TestActor.Tell("3"); TestActor.Tell(99999.0); TestActor.Tell(4); ReceiveWhile <string>(_ => _ is double?null: _.ToString()).ShouldOnlyContainInOrder("1", "2", "3"); }
public void ReceiveWhile_Predicate_should_break_when_predicate_returns_false_and_return_correct_messages() { TestActor.Tell("1"); TestActor.Tell("2"); TestActor.Tell("3"); TestActor.Tell("-----------"); TestActor.Tell("4"); ReceiveWhile <string>(s => s.Length == 1).ShouldOnlyContainInOrder("1", "2", "3"); }
private Props SupervisorProps(IActorRef probeRef) { var options = Backoff.OnFailure(TestActor.Props(probeRef), "someChildName", 200.Milliseconds(), 10.Seconds(), 0.0, -1) .WithSupervisorStrategy(new OneForOneStrategy(4, TimeSpan.FromSeconds(30), ex => ex is StoppingException ? Directive.Stop : SupervisorStrategy.DefaultStrategy.Decider.Decide(ex))); return(BackoffSupervisor.Props(options)); }
public void MergeHub_must_respect_the_buffer_size() { this.AssertAllStagesStopped(() => { var downstream = this.CreateManualSubscriberProbe <int>(); var sink = Sink.FromSubscriber(downstream).RunWith(MergeHub.Source <int>(3), Materializer); Source.From(Enumerable.Range(1, 10)).Select(i => { TestActor.Tell(i); return(i); }).RunWith(sink, Materializer); var sub = downstream.ExpectSubscription(); sub.Request(1); // Demand starts from 3 ExpectMsg(1); ExpectMsg(2); ExpectMsg(3); ExpectNoMsg(TimeSpan.FromMilliseconds(100)); // One element consumed (it was requested), demand 0 remains at producer downstream.ExpectNext(1); // Requesting next element, results in next element to be consumed. sub.Request(1); downstream.ExpectNext(2); // Two elements have been consumed, so threshold of 2 is reached, additional 2 demand is dispatched. // There is 2 demand at the producer now ExpectMsg(4); ExpectMsg(5); ExpectNoMsg(TimeSpan.FromMilliseconds(100)); // Two additional elements have been sent: // - 3, 4, 5 are pending // - demand is 0 at the producer // - next demand batch is after two elements have been consumed again // Requesting next gives the next element // Demand is not yet refreshed for the producer as there is one more element until threshold is met sub.Request(1); downstream.ExpectNext(3); ExpectNoMsg(TimeSpan.FromMilliseconds(100)); sub.Request(1); downstream.ExpectNext(4); ExpectMsg(6); ExpectMsg(7); sub.Cancel(); }, Materializer); }
public void Calls_fallback_when_handler_not_found() { var actor = new TestActor {Prototype = ActorPrototype.Define(typeof(TestActor))}; var unknownMessage = new UnknownMessage(); object bouncedMessage = null; Assert.DoesNotThrow(() => actor.Dispatch(unknownMessage, message => bouncedMessage = message)); Assert.That(bouncedMessage, Is.SameAs(unknownMessage)); }
public ActorFilter2Should() { var components = new IComponent[] { new TestComponent1(), new TestComponent2() }; _actor = new TestActor(1, components); _actorContext = new Mock <IActorContext>(); _actorFilter = new ActorFilter <TestComponent1, TestComponent2>(_actorContext.Object); InjectComponentsArray(components); }
public async Task DeleteAsync_NotDisposable() { var activator = new DefaultActorActivator(); var host = ActorHost.CreateForTest <TestActor>(); var actor = new TestActor(host); var state = new ActorActivatorState(actor); await activator.DeleteAsync(state); // does not throw }
public void IgnoreMessages_should_ignore_messages_T() { IgnoreMessages <IgnoredMessage>(); TestActor.Tell("1"); TestActor.Tell(new IgnoredMessage(), TestActor); TestActor.Tell("2"); ReceiveN(2).ShouldOnlyContainInOrder("1", "2"); HasMessages.ShouldBeFalse(); }
public async Task DeleteAsync_NotDisposable() { var activator = new DefaultActorActivator(); var host = new ActorHost(ActorTypeInformation.Get(typeof(TestActor)), ActorId.CreateRandom(), JsonSerializerDefaults.Web, NullLoggerFactory.Instance, ActorProxy.DefaultProxyFactory); var actor = new TestActor(host); var state = new ActorActivatorState(actor); await activator.DeleteAsync(state); // does not throw }
public SingleActorShould() { _actor = new TestActor(1); _actorContext = new Mock <IActorContext>(); _actorContext .Setup(context => context.GetEnumerator()) .Returns(EmptyEnumerator <Actor> .Instance); _single = new SingleActor <TestActor>(_actorContext.Object); }
public void ImplicitSender_should_have_testActor_as_sender() { var echoActor = Sys.ActorOf(c => c.ReceiveAny((m, ctx) => TestActor.Tell(ctx.Sender))); echoActor.Tell("message"); ExpectMsg <IActorRef>(actorRef => Equals(actorRef, TestActor)); //Test that it works after we know that context has been changed echoActor.Tell("message"); ExpectMsg <IActorRef>(actorRef => Equals(actorRef, TestActor)); }
public ActorContextShould() { _actorContext = new ActorContext(); _actor = new TestActor(1); Fixture.Inject(new IComponent[] { new TestComponent1(), new TestComponent2() }); }
public void A_wireTap_must_call_the_procedure_for_each_element() { this.AssertAllStagesStopped(() => { Source.From(Enumerable.Range(1, 100)) .WireTap(i => TestActor.Tell(i)) .RunWith(Sink.Ignore <int>(), Materializer).Wait(); Enumerable.Range(1, 100).Select(i => ExpectMsg(i)); }, Materializer); }
public void ScheduleRepeatedly_in_milliseconds_Tests(int initialDelay, int interval) { // Prepare, set up actions to be fired IActionScheduler testScheduler = new DedicatedThreadScheduler(Sys); testScheduler.ScheduleRepeatedly(initialDelay, interval, () => TestActor.Tell("Test")); //Just check that we receives more than one message ExpectMsg("Test"); ExpectMsg("Test"); ExpectMsg("Test"); }
public void IgnoreMessages_should_ignore_messages_T_with_Func() { IgnoreMessages <IgnoredMessage>(m => String.IsNullOrWhiteSpace(m.IgnoreMe)); var msg = new IgnoredMessage("not ignored!"); TestActor.Tell("1"); TestActor.Tell(msg, TestActor); TestActor.Tell("2"); ReceiveN(3).ShouldOnlyContainInOrder("1", msg, "2"); HasMessages.ShouldBeFalse(); }
public MongoDbEventsByTagSpec(ITestOutputHelper output, DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture, Counter.GetAndIncrement()), "MongoDbCurrentEventsByTagSpec", output) { _output = output; output.WriteLine(databaseFixture.ConnectionString + Counter.Current); ReadJournal = Sys.ReadJournalFor <MongoDbReadJournal>(MongoDbReadJournal.Identifier); var x = Sys.ActorOf(TestActor.Props("x")); x.Tell("warm-up"); ExpectMsg("warm-up-done", TimeSpan.FromSeconds(10)); }
public void When_ScheduleOnce_using_canceled_Cancelable_Then_their_actions_should_not_be_invoked() { // Prepare, set up actions to be fired IActionScheduler scheduler = new DedicatedThreadScheduler(Sys); var canceled = Cancelable.CreateCanceled(); scheduler.ScheduleOnce(0, () => TestActor.Tell("Test"), canceled); //Validate that no messages were sent ExpectNoMsg(100); }
public void TestActorInjectsPropsFromDI() { DI.MapSingleton<TestClassToInject> (); TestActor actor = new TestActor (); Assert.NotNull (actor.TestVar); }
public void TestActorInjectsFieldsFromDI() { DI.MapSingleton<TestPM> (); TestActor actor = new TestActor (); Assert.NotNull (actor.PM); }
public override void When() { Node.Open(); Actor = new TestActor(); Thread.Sleep(30); }
public override void Given() { Node = ConduitNode.Create() .WithServiceBus(new FakeServiceBus()); Actor = new TestActor(); }
public override void Given() { Node = new ConduitNode(); Actor = new TestActor(); }
public void TestActorInjectsFieldsFromDI() { DI.MapSingleton<TestPM> (); var actor = new TestActor (); actor.PM.ShouldNotBeNull (); }
public override void Given() { Node1 = new ConduitNode(); Node2 = new ConduitNode(); Actor1 = new TestActor(Node1); Actor2 = new TestActor(Node2); }
public override void Given() { FakeServiceBus bus = new FakeServiceBus(); Node = new ConduitNode(bus); Actor = new TestActor(); }
public void TestActorInjectsPropsFromDI() { DI.MapSingleton<TestClassToInject> (); var actor = new TestActor (); actor.TestVar.ShouldNotBeNull (); }