Exemple #1
0
        public void Run(IServiceBus bus, int iterations, Func <Guid, TRequest> generateRequest)
        {
            using (bus.Subscribe(this).Disposable())
            {
                ThreadUtil.Sleep(2.Seconds());

                for (int i = 0; i < iterations; i++)
                {
                    var commandInstance = new CommandInstance();
                    lock (_commands)
                        _commands.Add(commandInstance.Id, commandInstance);

                    var command = generateRequest(commandInstance.Id);

                    ThreadUtil.Sleep(5.Milliseconds());

                    bus.Publish(command, x =>
                    {
                        x.SendResponseTo(bus.Endpoint);

                        x.IfNoSubscribers <FirstCommand>(message => { throw new InvalidOperationException("No subscriptions were found (timing error?)"); });
                    });
                }

                while (_received.WaitOne(5.Seconds(), true))
                {
                }
            }

            DisplayResults();
        }
        public void Run(IServiceBus bus, IEndpoint sendTo, IEnumerable <IServiceBus> instances, int iterations,
                        Func <Guid, TRequest> generateRequest)
        {
            using (bus.SubscribeInstance(this).Disposable())
            {
                instances.Each(x => x.ShouldHaveRemoteSubscriptionFor <TResponse>());

                for (int i = 0; i < iterations; i++)
                {
                    var commandInstance = new CommandInstance();
                    lock (_commands)
                        _commands.Add(commandInstance.Id, commandInstance);

                    TRequest command = generateRequest(commandInstance.Id);

                    ThreadUtil.Sleep(5.Milliseconds());

                    sendTo.Send(command, x => { x.SendResponseTo(bus.Endpoint); });
                }

                _received.WaitOne(20.Seconds(), true);
                while (_received.WaitOne(8.Seconds(), true))
                {
                }
            }

            DisplayResults();
        }