protected override void EstablishContext() { base.EstablishContext(); _future = new FutureMessage <PingMessage>(); LocalBus.SubscribeHandler <PingMessage>(message => _future.Set(message)); _ping = new PingMessage(); LocalBus.Publish(_ping); }
public void A_message_is_published() { _receivedB = new Future <B>(); LocalBus.SubscribeHandler <B>(message => _receivedB.Complete(message)); LocalBus.Publish(new A { StringA = "ValueA", StringB = "ValueB", }); }
public void Should_continue_with_the_source_itinerary() { var trackingNumber = Guid.NewGuid(); var completed = new TaskCompletionSource <RoutingSlipCompleted>(); var reviseActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(); var testActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext reviseActivity = GetActivityContext <ReviseWithNoChangeItineraryActivity>(); LocalBus.SubscribeHandler <RoutingSlipCompleted>(msg => { if (msg.TrackingNumber == trackingNumber) { completed.SetResult(msg); } }); LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(msg => { if (msg.TrackingNumber == trackingNumber) { if (msg.ActivityName.Equals(testActivity.Name)) { testActivityCompleted.SetResult(msg); } if (msg.ActivityName.Equals(reviseActivity.Name)) { reviseActivityCompleted.SetResult(msg); } } }); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>()); var builder = new RoutingSlipBuilder(trackingNumber); builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new { Value = "Time to remove any remaining items!", }); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", }); LocalBus.Execute(builder.Build()); Assert.IsTrue(completed.Task.Wait(TestTimeout), "RoutingSlip did not complete"); Assert.IsTrue(reviseActivityCompleted.Task.Wait(TestTimeout), "Revise Activity did not complete"); Assert.IsTrue(testActivityCompleted.Task.Wait(TestTimeout), "TestActivity did not complete"); }
public void The_method_should_be_called_for_each_destination_endpoint() { LocalBus.SubscribeHandler <PingMessage>(x => { }); var ping = new PingMessage(); var consumers = new List <Uri>(); LocalBus.Publish(ping, x => { x.ForEachSubscriber(address => consumers.Add(address.Uri)); }); Assert.AreEqual(1, consumers.Count); Assert.AreEqual(LocalBus.Endpoint.Address.Uri, consumers[0]); }
public void Should_immediately_complete_an_empty_list() { var handled = new ManualResetEvent(false); LocalBus.SubscribeHandler <RoutingSlipCompleted>(message => { handled.Set(); }); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); LocalBus.Execute(builder.Build()); Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); }
public void The_method_should_not_carry_over_to_the_next_call_context() { var ping = new PingMessage(); var consumers = new List <Uri>(); LocalBus.Publish(ping, x => { x.ForEachSubscriber(address => consumers.Add(address.Uri)); }); LocalBus.SubscribeHandler <PingMessage>(x => { }); LocalBus.Publish(ping); Assert.AreEqual(0, consumers.Count); }
public void Should_receive_using_the_first_consumer() { const string name = "Joe"; var complete = new ManualResetEvent(false); LocalBus.SubscribeHandler <SimpleMessageClass>(x => complete.Set()); LocalBus.Publish(new SimpleMessageClass(name)); complete.WaitOne(8.Seconds()); GetSimpleConsumer() .Last.Name.ShouldEqual(name); }
public void The_message_should_be_delivered_to_a_remote_subscriber() { var updated = new Future <UpdateMessage>(); LocalBus.SubscribeHandler <UpdateMessage>(updated.Complete); RemoteBus.HasSubscription <UpdateMessage>().Count().ShouldBeGreaterThan(0); var um = new UpdateMessage(); RemoteBus.Publish(um); updated.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update not received"); }
public void The_source_address_should_pass() { var received = new FutureMessage <PingMessage>(); LocalBus.SubscribeHandler <PingMessage>(message => { Assert.AreEqual(LocalBus.Endpoint.Address.Uri, LocalBus.Context().SourceAddress); received.Set(message); }); LocalBus.Publish(new PingMessage()); Assert.IsTrue(received.IsAvailable(5.Seconds()), "No message was received"); }
public void Subscring_to_an_endpoint_should_accept_and_dispatch_messages() { FutureMessage <PingMessage> fm = new FutureMessage <PingMessage>(); bool workDid = false; LocalBus.SubscribeHandler <PingMessage>( (msg) => { workDid = true; fm.Set(msg); }, delegate { return(true); }); RemoteBus.ShouldHaveSubscriptionFor <PingMessage>(); RemoteBus.Publish(_message); fm.IsAvailable(1.Seconds()); Assert.That(workDid, Is.True, "Lazy Test!"); }
public void The_timeout_should_be_added_to_the_storage() { var _timedOut = new ManualResetEvent(false); LocalBus.SubscribeHandler <TimeoutExpired>(x => _timedOut.Set()); LocalBus.Publish(new ScheduleTimeout(_correlationId, 1.Seconds())); Stopwatch watch = Stopwatch.StartNew(); Assert.IsTrue(_timedOut.WaitOne(TimeSpan.FromSeconds(10), true)); watch.Stop(); Debug.WriteLine(string.Format("Timeout took {0}ms", watch.ElapsedMilliseconds)); }
protected override void EstablishContext() { base.EstablishContext(); _repository = SetupSagaRepository <AutoStateMachineSaga>(); // this just shows that you can easily respond to the message LocalBus.SubscribeHandler <SendUserVerificationEmail>( x => LocalBus.Publish(new UserVerificationEmailSent(x.CorrelationId, x.Email))); _transactionId = NewIds.NewId.NextGuid(); _username = "******"; _password = "******"; _email = "*****@*****.**"; _displayName = "Joe Blow"; }
public void Setup() { _faulted = new TaskCompletionSource <RoutingSlipFaulted>(TestCancellationToken); _firstActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken); _firstActivityCompensated = new TaskCompletionSource <RoutingSlipActivityCompensated>(TestCancellationToken); LocalBus.SubscribeHandler <RoutingSlipFaulted>(x => _faulted.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x => { if (x.ActivityName.Equals("Test")) { _firstActivityCompleted.SetResult(x); } }); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompensated>(x => { if (x.ActivityName.Equals("Test")) { _firstActivityCompensated.SetResult(x); } }); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompensated>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", }); testActivity = GetActivityContext <SecondTestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); testActivity = GetActivityContext <FaultyActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
public void Should_work_for_activity_arguments() { _intValue = 27; _stringValue = "Hello, World."; _decimalValue = 123.45m; var completed = new TaskCompletionSource <RoutingSlipCompleted>(); var faulted = new TaskCompletionSource <RoutingSlipFaulted>(); LocalBus.SubscribeHandler <RoutingSlipCompleted>(message => completed.TrySetResult(message)); LocalBus.SubscribeHandler <RoutingSlipFaulted>(message => faulted.TrySetResult(message)); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext <ObjectGraphTestActivity>(); ActivityTestContext testActivity2 = GetActivityContext <TestActivity>(); var dictionary = new Dictionary <string, object> { { "Outer", new OuterObjectImpl(_intValue, _stringValue, _decimalValue) }, { "Names", new[] { "Albert", "Chris" } }, }; builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, dictionary); builder.AddActivity(testActivity2.Name, testActivity2.ExecuteUri); LocalBus.Execute(builder.Build()); Assert.AreNotEqual(WaitHandle.WaitTimeout, Task.WaitAny(new Task[] { completed.Task, faulted.Task }, Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); if (faulted.Task.Status == TaskStatus.RanToCompletion) { Assert.Fail("Failed due to exception {0}", faulted.Task.Result.ActivityExceptions.Any() ? faulted.Task.Result.ActivityExceptions.First() .ExceptionInfo.Message : "Unknown"); } Assert.AreEqual(TaskStatus.RanToCompletion, completed.Task.Status, "Did not complete"); }
public void The_correlation_id_should_pass() { Guid id = Guid.NewGuid(); var received = new FutureMessage <PingMessage>(); LocalBus.SubscribeHandler <PingMessage>(message => { Assert.AreEqual(id.ToString(), LocalBus.Context().CorrelationId); received.Set(message); }); LocalBus.Publish(new PingMessage(), context => context.SetCorrelationId(id.ToString())); Assert.IsTrue(received.IsAvailable(5.Seconds()), "No message was received"); }
public void A_random_header_should_pass() { Guid id = Guid.NewGuid(); var received = new FutureMessage <PingMessage>(); LocalBus.SubscribeHandler <PingMessage>(message => { Assert.AreEqual(id.ToString(), LocalBus.Context().Headers["RequestId"]); received.Set(message); }); LocalBus.Publish(new PingMessage(), context => context.SetHeader("RequestId", id.ToString())); Assert.IsTrue(received.IsAvailable(5.Seconds()), "No message was received"); }
public void The_method_should_be_called_for_each_destination_endpoint_when_there_are_multiple() { RemoteBus.SubscribeHandler <PingMessage>(x => { }); LocalBus.ShouldHaveSubscriptionFor <PingMessage>(); LocalBus.SubscribeHandler <PingMessage>(x => { }); var ping = new PingMessage(); var consumers = new List <Uri>(); LocalBus.Publish(ping, x => { x.ForEachSubscriber(address => consumers.Add(address.Uri)); }); Assert.AreEqual(2, consumers.Count); Assert.IsTrue(consumers.Contains(LocalBus.Endpoint.Address.Uri)); Assert.IsTrue(consumers.Contains(RemoteBus.Endpoint.Address.Uri)); }
public void Should_capture_a_thrown_exception() { var handled = new ManualResetEvent(false); LocalBus.SubscribeHandler <RoutingSlipFaulted>(message => handled.Set()); Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>()); ActivityTestContext faultActivity = GetActivityContext <NastyFaultyActivity>(); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri); LocalBus.Execute(builder.Build()); Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); }
public void Should_execute() { var received = new TaskCompletionSource<MagicMade>(TestCancellationToken); LocalBus.SubscribeHandler<MagicMade>(x => received.SetResult(x)); Assert.IsTrue(WaitForSubscription<MagicMade>()); Uri commandUri = GetActivityContext<MakeMagicHappen>().ExecuteUri; var command = new MakeMagicHappenCommand("Hello, World."); DispatchMessageHandle<MakeMagicHappenCommand> handle = DispatchEndpoint.DispatchMessage(command, commandUri); Assert.IsTrue(_accepted.Task.Wait(TestTimeout)); DispatchAccepted accepted = _accepted.Task.Result; Assert.AreEqual(handle.DispatchId, accepted.DispatchId); Assert.IsTrue(received.Task.Wait(TestTimeout)); }
public void Can_collect_iworkeravaiable_messages() { int workerAvaiableCountRecieved = 0; var messageRecieved = new ManualResetEvent(false); UnsubscribeAction unsubscribe = LocalBus.SubscribeHandler <IWorkerAvailable>(message => { Interlocked.Increment(ref workerAvaiableCountRecieved); messageRecieved.Set(); }); Instances.ToList().ForEach(x => { x.Value.DataBus.ControlBus.Endpoint.Send(new PingWorker()); }); messageRecieved.WaitOne(3.Seconds()); unsubscribe(); workerAvaiableCountRecieved.ShouldBeGreaterThan(0); }
public void Multiple_Local_Services_Should_Be_Available() { var updated = new Future <UpdateMessage>(); var deleted = new Future <DeleteMessage>(); LocalBus.SubscribeHandler <UpdateMessage>(updated.Complete); LocalBus.SubscribeHandler <DeleteMessage>(deleted.Complete); var dm = new DeleteMessage(); LocalBus.Publish(dm); var um = new UpdateMessage(); LocalBus.Publish(um); updated.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update not received"); deleted.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Delete not received"); }
public void The_timeout_should_be_added_to_the_storage() { var timedOut = new FutureMessage <TimeoutExpired>(); LocalBus.SubscribeHandler <TimeoutExpired>(timedOut.Set); LocalBus.HasSubscription <TimeoutExpired>(8.Seconds()).Any() .ShouldBeTrue("No subscription"); LocalBus.Publish(new ScheduleTimeout(_correlationId, 2.Seconds())); Stopwatch watch = Stopwatch.StartNew(); timedOut.IsAvailable(8.Seconds()).ShouldBeTrue("Did not get timeout message"); watch.Stop(); Debug.WriteLine(string.Format("Timeout took {0}ms", watch.ElapsedMilliseconds)); }
public void Ensure_workers_will_respond_to_ping_request() { int workerAvaiableCountRecieved = 0; var messageRecieved = new ManualResetEvent(false); UnsubscribeAction unsubscribe = LocalBus.SubscribeHandler <WorkerAvailable <FirstCommand> >(message => { Interlocked.Increment(ref workerAvaiableCountRecieved); messageRecieved.Set(); }); Instances.ToList().ForEach(x => { x.Value.DataBus.ControlBus.Endpoint.Send(new PingWorker()); }); messageRecieved.WaitOne(3.Seconds()); unsubscribe(); workerAvaiableCountRecieved.ShouldBeGreaterThan(0); }
public void Should_deliver_the_message_to_an_both_interested_consumers() { var first = new Future <FirstMessageContract>(); var second = new Future <SecondMessageContract>(); // These can't be on the same bus, because we only send a message to an endpoint once // maybe we can do something here by changing the outbound context to keep track of tmessage/endpoint uri RemoteBus.SubscribeHandler <FirstMessageContract>(first.Complete); LocalBus.SubscribeHandler <SecondMessageContract>(second.Complete); LocalBus.ShouldHaveSubscriptionFor <FirstMessageContract>(); var message = new SomeMessageContract("Joe", 27); LocalBus.Publish(message); first.WaitUntilCompleted(1.Seconds()).ShouldBeTrue(); second.WaitUntilCompleted(1.Seconds()).ShouldBeTrue(); }
public void Should_publish_the_completed_event() { var handled = new ManualResetEvent(false); LocalBus.SubscribeHandler <RoutingSlipCompleted>(message => { handled.Set(); }); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", }); LocalBus.Execute(builder.Build()); Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); }
protected override void EstablishContext() { base.EstablishContext(); _ping = new PingMessage(); _faultFuture = new FutureMessage <Fault <PingMessage, Guid> >(); _future = new FutureMessage <PingMessage, Guid>(_ping.CorrelationId); LocalBus.SubscribeHandler <PingMessage>(message => { _future.Set(message); throw new NotSupportedException("I am a naughty consumer! I go boom!"); }); LocalBus.SubscribeHandler <Fault <PingMessage, Guid> >(message => _faultFuture.Set(message)); LocalBus.Publish(_ping); _future.WaitUntilAvailable(1.Seconds()); }
protected override void EstablishContext() { base.EstablishContext(); _faultFuture = new FutureMessage <Fault <PingMessage, Guid> >(); LocalBus.SubscribeHandler <PingMessage>(message => { throw new NotSupportedException("I am a naughty consumer! I go boom!"); }); LocalBus.SubscribeHandler <Fault <PingMessage, Guid> >(message => { if (_faultFuture.IsAvailable(TimeSpan.Zero)) { return; } _faultFuture.Set(message); }); LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>(); LocalBus.ShouldHaveRemoteSubscriptionFor <Fault <PingMessage, Guid> >(); _ping = new PingMessage(); LocalBus.Publish(_ping); }
public void Should_receive_using_the_first_consumer() { const string name = "Joe"; var complete = new ManualResetEvent(false); LocalBus.SubscribeHandler <SimpleMessageClass>(x => complete.Set()); LocalBus.Publish(new SimpleMessageClass(name)); complete.WaitOne(8.Seconds()); SimpleConsumer lastConsumer = SimpleConsumer.LastConsumer; lastConsumer.ShouldNotBeNull(); lastConsumer.Last.Name .ShouldEqual(name); lastConsumer.Dependency.WasDisposed .ShouldBeTrue("Dependency was not disposed"); lastConsumer.Dependency.SomethingDone .ShouldBeTrue("Dependency was disposed before consumer executed"); }
public void Should_ignore_a_response_that_was_not_for_us() { var pongReceived = new FutureMessage <PongMessage>(); var pingReceived = new FutureMessage <PingMessage>(); var badResponse = new FutureMessage <PongMessage>(); LocalBus.SubscribeHandler <PongMessage>(pongReceived.Set); RemoteBus.SubscribeContextHandler <PingMessage>(x => { RemoteBus.ShouldHaveRemoteSubscriptionFor <PongMessage>(); pingReceived.Set(x.Message); RemoteBus.Publish(new PongMessage { TransactionId = x.Message.TransactionId }); }); LocalBus.ShouldHaveSubscriptionFor <PingMessage>(); var ping = new PingMessage(); TimeSpan timeout = 8.Seconds(); Assert.Throws <RequestTimeoutException>(() => { RemoteBus.Endpoint.SendRequest(ping, LocalBus, x => { x.Handle <PongMessage>(badResponse.Set); x.SetTimeout(timeout); }); }); pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received"); pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received"); badResponse.IsAvailable(2.Seconds()).ShouldBeFalse("Should not have received a response"); }
public void The_message_should_be_delivered_to_a_remote_subscriber_with_a_reply() { var updated = new Future <UpdateMessage>(); var updateAccepted = new Future <UpdateAcceptedMessage>(); RemoteBus.SubscribeContextHandler <UpdateMessage>(context => { updated.Complete(context.Message); context.Respond(new UpdateAcceptedMessage()); }); LocalBus.HasSubscription <UpdateMessage>().Count().ShouldBeGreaterThan(0); LocalBus.SubscribeHandler <UpdateAcceptedMessage>(updateAccepted.Complete); RemoteBus.HasSubscription <UpdateAcceptedMessage>().Count().ShouldBeGreaterThan(0); var um = new UpdateMessage(); LocalBus.Publish(um); updated.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update not received"); updateAccepted.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update accepted not received"); }