Exemplo n.º 1
0
        public void SyncWorkQueueCancelling()
        {
            WithSync(() => {
                var wq = new WorkQueueInfo(new RabbitHostInfo("localhost"), "fooQueue", false);
                using (var p = new WorkQueueProducer(wq))
                {
                    var isConnected       = false;
                    p.IsConnectedChanged += x => isConnected = x;
                    Waiter.Wait(() => isConnected);
                    RabbitTestHelper.PurgeQueue("fooQueue");

                    SyncWorkQueueConsumer c = null;
                    var task = Task.Factory.StartNew(() => {
                        WithSync(() => {
                            using (c = new SyncWorkQueueConsumer(wq))
                            {
                                var msg = c.Receive();
                                msg.ShouldBeOfType <ReceiveWasCancelled>();
                                throw new Exception("cancelled");
                            }
                        });
                    });

                    Thread.Sleep(500);
                    c.Cancel();
                    new Action(() => task.Wait()).ShouldThrow <Exception>(x => x.InnerException.Message.ShouldEqual("cancelled"));
                }
            });
        }
Exemplo n.º 2
0
        public void SyncWorkQueue()
        {
            WithSync(() => {
                var wq = new WorkQueueInfo(new RabbitHostInfo("localhost"), "fooQueue", false);
                using (var p = new WorkQueueProducer(wq))
                {
                    var task = Task.Factory.StartNew(() => {
                        WithSync(() => {
                            using (var c = new SyncWorkQueueConsumer(wq))
                            {
                                Lists.Repeat(1000, _ => {
                                    var msg = c.Receive();
                                    c.Ack(msg);
                                });
                            }
                        });
                    });

                    Lists.Repeat(1000, _ => p.Send(new TestMessage()));

                    task.Wait(2000).ShouldBeTrue();
                }
            });
        }