コード例 #1
0
        public void SendTimeoutRequestAndWaitForTimeout()
        {
            var handler = new TimeoutCommandHandler();

            var bus = CreateBusFactory()
                      .WithHandlers(typeof(TimeoutCommandHandler))
                      .ConfigureContainer(x => x.ForSingletonOf <TimeoutCommandHandler>().Use(handler))
                      .CreateAndStartBus();

            bus.Subscribe(Subscription.Matching <TimeoutCommand>(x => x.ServiceName == bus.PeerId.ToString()));

            var state = new State {
                Value = 42
            };
            var requestTimeoutCommand = Timeout.BuildRequest("Testing", DateTime.Now.AddSeconds(15), state, bus.PeerId.ToString());

            bus.Send(requestTimeoutCommand);

            var stopwatch = Stopwatch.StartNew();

            if (handler.Signal.WaitOne(100.Seconds()))
            {
                Console.WriteLine("Yay for the orange game!");
                Console.WriteLine("Elapsed: {0}", stopwatch.Elapsed);
            }

            bus.Stop();
        }
コード例 #2
0
        public void SendSeveralTimeoutRequestAndCheckForResponseUnicity()
        {
            var handler = new AccumulatingTimeoutCommandHandler();

            var bus = CreateBusFactory()
                      .WithHandlers(typeof(AccumulatingTimeoutCommandHandler))
                      .ConfigureContainer(x => x.ForSingletonOf <AccumulatingTimeoutCommandHandler>().Use(handler))
                      .CreateAndStartBus();

            bus.Subscribe(Subscription.Matching <TimeoutCommand>(x => x.ServiceName == bus.PeerId.ToString()));

            const int messageCount = 100;

            for (var i = 0; i < messageCount; i++)
            {
                var state = new State {
                    Value = i
                };
                var requestTimeoutCommand = Timeout.BuildRequest(Guid.NewGuid().ToString(), DateTime.Now.AddSeconds(1), state, bus.PeerId.ToString());
                bus.Send(requestTimeoutCommand);
            }

            Thread.Sleep(2.Seconds());

            handler.Commands.Count.ShouldEqual(messageCount);

            bus.Stop();
        }