public void Sending_a_bid_request_should_get_a_response() { var response = new FutureChannel <Response <Status> >(); UntypedChannel responseChannel = new ChannelAdapter(); responseChannel.Connect(x => x.AddChannel(response)); Auction.Request(new Ask(Id), responseChannel); response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.Body.AuctionId.ShouldEqual(Id); // ThreadUtil.Sleep(2.Seconds()); // go ahead and buy something var purchased = new FutureChannel <Response <Purchased> >(); responseChannel.Connect(x => x.AddChannel(purchased)); Auction.Request(new Buy { Quantity = 15, Token = response.Value.Body.Token }, responseChannel); purchased.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for purchase"); purchased.Value.Body.Quantity.ShouldEqual(15); purchased.Value.Body.Price.ShouldEqual(response.Value.Body.CurrentBid); }
public void Should_properly_handle_the_response() { var response = new FutureChannel<Purchased>(); decimal price = 0.0m; AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(30.Seconds()) .Receive<Response<Status>>(m => status => { price = status.Body.CurrentBid; Auction.Request(new Buy(status.Body.Token, 1), inbox) .Within(30.Seconds()) .Receive<Response<Purchased>>(pm => pmsg => response.Complete(pmsg.Body)) .Otherwise(() => { }); }) .Receive<Response<Ended>>(m => ended => { }); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.AuctionId.ShouldEqual(Id); response.Value.Quantity.ShouldEqual(1); response.Value.Price.ShouldEqual(price); }
public Subject() { FutureA = new Future <Message <A> >(); FutureB = new Future <Message <B> >(); FutureC = new Future <Message <C> >(); FutureD = new FutureChannel <Message <D> >(); }
public void EstablishContext() { _serviceStarted = new FutureChannel <ServiceRunning>(); _service = new TestService(); _hostChannel = new TestChannel(); _coordinator = new Model.ServiceCoordinator(); var b = new LocalServiceBuilder <TestService>(null, _serviceName, (d, name, coordinator) => _service, x => x.Start(), x => x.Stop(), x => { }, x => { }); _controllerFactory = new ServiceControllerFactory(); _factory = _controllerFactory.CreateFactory(inbox => b.Build(inbox, _coordinator)); _instance = _factory.GetActor(); _hostChannel.Connect(x => { x.AddChannel(_instance); x.AddChannel(_serviceStarted); }); _coordinator.Send(new CreateService(_serviceName)); _coordinator.Send(new StartService(_serviceName)); _serviceStarted.WaitUntilCompleted(5.Seconds()); }
public void Sending_a_bid_request_should_get_a_response() { var response = new FutureChannel<Response<Status>>(); UntypedChannel responseChannel = new ChannelAdapter(); responseChannel.Connect(x => x.AddChannel(response)); Auction.Request(new Ask(Id), responseChannel); response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.Body.AuctionId.ShouldEqual(Id); // ThreadUtil.Sleep(2.Seconds()); // go ahead and buy something var purchased = new FutureChannel<Response<Purchased>>(); responseChannel.Connect(x => x.AddChannel(purchased)); Auction.Request(new Buy { Quantity = 15, Token = response.Value.Body.Token }, responseChannel); purchased.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for purchase"); purchased.Value.Body.Quantity.ShouldEqual(15); purchased.Value.Body.Price.ShouldEqual(response.Value.Body.CurrentBid); }
public Subject() { FutureA = new Future<Message<A>>(); FutureB = new Future<Message<B>>(); FutureC = new Future<Message<C>>(); FutureD = new FutureChannel<Message<D>>(); }
public void Should_properly_handle_the_response() { var response = new FutureChannel <Purchased>(); decimal price = 0.0m; AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(30.Seconds()) .Receive <Response <Status> >(m => status => { price = status.Body.CurrentBid; Auction.Request(new Buy(status.Body.Token, 1), inbox) .Within(30.Seconds()) .Receive <Response <Purchased> >(pm => pmsg => response.Complete(pmsg.Body)) .Otherwise(() => { }); }) .Receive <Response <Ended> >(m => ended => { }); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.AuctionId.ShouldEqual(Id); response.Value.Quantity.ShouldEqual(1); response.Value.Price.ShouldEqual(price); }
public void Should_stop() { var stopped = new FutureChannel <ServiceStopped>(); _hostChannel.Connect(x => x.AddChannel(stopped)); _hostChannel.Send(new StopService(_serviceName)); stopped.WaitUntilCompleted(5.Seconds()).ShouldBeTrue(); _serviceController.CurrentState.ShouldEqual(_controllerFactory.Workflow.GetState(x => x.Stopped)); _service.Stopped.IsCompleted.ShouldBeTrue(); }
public void Should_not_receive_a_response_to_a_stupid_message() { var response = new FutureChannel <bool>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(new Guid()), inbox) .Within(1.Seconds()) .Receive <Response <Status> >(m => status => {}) .Otherwise(() => response.Complete(true)); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for otherwise to be called"); }
public void Should_filter_out_unwanted_messages() { var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()}; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel<UserUpdate>(); var filter = new FilterChannel<UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now); Channel<UserUpdate> channel = new BroadcastChannel<UserUpdate>(new[] {filter}); channel.Send(update); Assert.IsFalse(future.WaitUntilCompleted(1.Seconds())); }
public void Should_work_through_a_channel_network() { var received = new FutureChannel <Request <Simple> >(); UntypedChannel channel = new ChannelAdapter(); channel.Connect(x => x.AddChannel(received)); var simpleImpl = new SimpleImpl(); channel.Send(new RequestImpl <SimpleImpl>(null, simpleImpl)); received.IsCompleted.ShouldBeTrue(); received.Value.ShouldNotBeNull(); received.Value.Body.ShouldEqual(simpleImpl); }
public void Should_receive_the_expected_value() { var response = new FutureChannel<Status>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(30.Seconds()) .Receive<Response<Status>>(m => status => response.Complete(status.Body)) .Receive<Response<Ended>>(m => ended => { }); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.AuctionId.ShouldEqual(Id); }
public void Should_receive_the_expected_value() { var response = new FutureChannel <Status>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(30.Seconds()) .Receive <Response <Status> >(m => status => response.Complete(status.Body)) .Receive <Response <Ended> >(m => ended => {}); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.AuctionId.ShouldEqual(Id); }
public void Should_receive_the_alternate_ending_if_it_is_such() { Auction.Send(new End()); var response = new FutureChannel <Ended>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(30.Seconds()) .Receive <Response <Status> >(m => status => {}) .Receive <Response <Ended> >(m => ended => response.Complete(ended.Body)); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.AuctionId.ShouldEqual(Id); }
public void Should_filter_out_unwanted_messages() { var update = new UserUpdate { LastActivity = DateTime.Now - 5.Minutes() }; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel <UserUpdate>(); var filter = new FilterChannel <UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now); Channel <UserUpdate> channel = new BroadcastChannel <UserUpdate>(new[] { filter }); channel.Send(update); Assert.IsFalse(future.WaitUntilCompleted(1.Seconds())); }
public void Should_receive_the_alternate_ending_if_it_is_such() { Auction.Send(new End()); var response = new FutureChannel<Ended>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(30.Seconds()) .Receive<Response<Status>>(m => status => {}) .Receive<Response<Ended>>(m => ended => response.Complete(ended.Body)); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.AuctionId.ShouldEqual(Id); }
public void Should_schedule_events() { var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()}; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel<UserUpdate>(); Channel<UserUpdate> channel = new BroadcastChannel<UserUpdate>(new Channel<UserUpdate>[] {future}); var scheduler = new TimerScheduler(fiber); scheduler.Schedule(1000, fiber, () => channel.Send(update)); Thread.Sleep(500); Assert.IsFalse(future.WaitUntilCompleted(0.Seconds())); Assert.IsTrue(future.WaitUntilCompleted(1.Seconds())); }
public void Sending_a_request_to_one_channel() { _server.Connect(x => { x.AddConsumerOf<Request<MyRequest>>() .UsingConsumer(request => { request.Respond(new MyResponse()); }); }); var response = new FutureChannel<Response<MyResponse>>(); _client.Connect(x => x.AddChannel(response)); _server.Request(new MyRequest(), _client); response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.BodyType.ShouldEqual(typeof(MyResponse).ToMessageUrn()); }
public void Should_not_call_the_other_receive_handlers() { var statusResponse = new FutureChannel <Status>(); var endedResponse = new FutureChannel <Ended>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(10.Seconds()) .Receive <Response <Status> >(m => status => { statusResponse.Complete(status.Body); Auction.Send(new End()); Auction.Request(new Ask(Id), inbox); }) .Receive <Response <Ended> >(m => ended => endedResponse.Complete(ended.Body)); }); statusResponse.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); endedResponse.WaitUntilCompleted(2.Seconds()).ShouldBeFalse("The receiver for Ended should not have been called."); }
public void Sending_a_request_to_one_channel() { _server.Connect(x => { x.AddConsumerOf <Request <MyRequest> >() .UsingConsumer(request => { request.Respond(new MyResponse()); }); }); var response = new FutureChannel <Response <MyResponse> >(); _client.Connect(x => x.AddChannel(response)); _server.Request(new MyRequest(), _client); response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.BodyType.ShouldEqual(typeof(MyResponse).ToMessageUrn()); }
public void Should_schedule_events() { var update = new UserUpdate { LastActivity = DateTime.Now - 5.Minutes() }; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel <UserUpdate>(); Channel <UserUpdate> channel = new BroadcastChannel <UserUpdate>(new Channel <UserUpdate>[] { future }); var scheduler = new TimerScheduler(fiber); scheduler.Schedule(1000, fiber, () => channel.Send(update)); Thread.Sleep(500); Assert.IsFalse(future.WaitUntilCompleted(0.Seconds())); Assert.IsTrue(future.WaitUntilCompleted(1.Seconds())); }
public void Should_not_receive_a_response_to_a_stupid_message() { var response = new FutureChannel<bool>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(new Guid()), inbox) .Within(1.Seconds()) .Receive<Response<Status>>(m => status => { }) .Otherwise(() => response.Complete(true)); }); response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for otherwise to be called"); }
public void Should_work_through_a_channel_network() { var received = new FutureChannel<Request<Simple>>(); UntypedChannel channel = new ChannelAdapter(); channel.Connect(x => x.AddChannel(received)); var simpleImpl = new SimpleImpl(); channel.Send(new RequestImpl<SimpleImpl>(null, simpleImpl)); received.IsCompleted.ShouldBeTrue(); received.Value.ShouldNotBeNull(); received.Value.Body.ShouldEqual(simpleImpl); }
public void Should_not_call_the_other_receive_handlers() { var statusResponse = new FutureChannel<Status>(); var endedResponse = new FutureChannel<Ended>(); AnonymousActor.New(inbox => { Auction.Request(new Ask(Id), inbox) .Within(10.Seconds()) .Receive<Response<Status>>(m => status => { statusResponse.Complete(status.Body); Auction.Send(new End()); Auction.Request(new Ask(Id), inbox); }) .Receive<Response<Ended>>(m => ended => endedResponse.Complete(ended.Body)); }); statusResponse.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response"); endedResponse.WaitUntilCompleted(2.Seconds()).ShouldBeFalse("The receiver for Ended should not have been called."); }