コード例 #1
0
        public void when_sending_message_with_session_then_session_receiver_gets_both_messages_fast()
        {
            var sender = Settings.CreateTopicClient(Topic);
            var signal = new AutoResetEvent(false);
            var body1 = Guid.NewGuid().ToString();
            var body2 = Guid.NewGuid().ToString();
            var stopWatch = new Stopwatch();

            var receiver = new SessionSubscriptionReceiver(Settings, Topic, Subscription);

            sender.Send(new BrokeredMessage(body1) {SessionId = "foo"});
            sender.Send(new BrokeredMessage(body2) {SessionId = "bar"});

            var received = new ConcurrentBag<string>();

            receiver.Start(
                m => {
                    received.Add(m.GetBody<string>());
                    signal.Set();
                    return MessageReleaseAction.CompleteMessage;
                });

            signal.WaitOne();
            stopWatch.Start();
            signal.WaitOne();
            stopWatch.Stop();

            receiver.Stop();

            Assert.Contains(body1, received);
            Assert.Contains(body2, received);
            Assert.InRange(stopWatch.Elapsed, TimeSpan.Zero, TimeSpan.FromSeconds(2));
        }
コード例 #2
0
        public void when_sending_message_with_session_then_session_receiver_gets_it()
        {
            var sender = Settings.CreateTopicClient(Topic);
            var signal = new ManualResetEventSlim();
            var body = Guid.NewGuid().ToString();

            var receiver = new SessionSubscriptionReceiver(Settings, Topic, Subscription);

            sender.Send(new BrokeredMessage(Guid.NewGuid().ToString()));
            sender.Send(new BrokeredMessage(body) {SessionId = "foo"});

            var received = "";

            receiver.Start(
                m => {
                    received = m.GetBody<string>();
                    signal.Set();
                    return MessageReleaseAction.CompleteMessage;
                });

            signal.Wait();

            receiver.Stop();

            Assert.Equal(body, received);
        }
コード例 #3
0
        public void when_starting_twice_then_ignores_second_request()
        {
            var receiver = new SessionSubscriptionReceiver(Settings, Topic, Subscription);

            receiver.Start(m => MessageReleaseAction.CompleteMessage);
            receiver.Start(m => MessageReleaseAction.CompleteMessage);

            receiver.Stop();
        }
コード例 #4
0
        public void when_sending_message_to_different_sessions_then_processes_concurrently()
        {
            var sender           = this.Settings.CreateTopicClient(this.Topic);
            var message1received = new ManualResetEvent(false);
            var message2received = new ManualResetEvent(false);
            var body1            = Guid.NewGuid().ToString();
            var body2            = Guid.NewGuid().ToString();

            var receiver  = new SessionSubscriptionReceiver(this.Settings, this.Topic, this.Subscription);
            var stopWatch = new Stopwatch();

            receiver.Start(
                m =>
            {
                var msg = m.GetBody <string>();
                if (msg == body1)
                {
                    message1received.Set();
                    // do not continue until we verify that the 2nd message is received, hence implying parallelism
                    message2received.WaitOne();
                }
                else
                {
                    message2received.Set();
                }

                return(MessageReleaseAction.CompleteMessage);
            });

            sender.Send(new BrokeredMessage(body1)
            {
                SessionId = "foo"
            });
            stopWatch.Start();
            Assert.True(message1received.WaitOne(10000));

            sender.Send(new BrokeredMessage(body2)
            {
                SessionId = "bar"
            });
            Assert.True(message2received.WaitOne(10000));
            stopWatch.Stop();

            receiver.Stop();

            Assert.InRange(stopWatch.Elapsed, TimeSpan.Zero, TimeSpan.FromSeconds(10));
        }
コード例 #5
0
        public void when_disposing_not_started_then_no_op()
        {
            var receiver = new SessionSubscriptionReceiver(Settings, Topic, Subscription);

            receiver.Dispose();
        }
コード例 #6
0
        public void when_stopping_without_starting_then_ignores_request()
        {
            var receiver = new SessionSubscriptionReceiver(Settings, Topic, Subscription);

            receiver.Stop();
        }