コード例 #1
0
            public void ReturnsNoMessagesWhenLastMessageIdIsEqualToLastMessage()
            {
                // id = 27
                // 24, 25, 27
                //         ^

                var trace = new TraceManager();
                var bus = new InProcessMessageBus(trace, false);
                bus.Send("testclient", "foo", "1").Wait();
                bus.Send("testclient", "foo", "2").Wait();

                // REVIEW: Will block
                //var result = bus.GetMessagesSince(new[] { "foo" }, 2).Result.ToList();
                //Assert.Equal(0, result.Count);
            }
コード例 #2
0
            public void ReturnsAllMessagesWhenLastMessageIdIsLessThanAllMessages()
            {
                //    id = 27
                // _, 28, 29, 32
                // ^

                var trace = new TraceManager();
                var bus = new InProcessMessageBus(trace, false);
                bus.Send("testclient", "bar", "1").Wait();
                bus.Send("testclient", "bar", "2").Wait();
                bus.Send("testclient", "foo", "3").Wait();
                bus.Send("testclient", "foo", "4").Wait();

                var result = bus.GetMessages(new[] { "foo" }, "1", CancellationToken.None).Result;
                Assert.Equal(2, result.Messages.Count);
            }
コード例 #3
0
            public void ReturnsNoMessagesWhenLastMessageIdIsGreaterThanAllMessages()
            {
                // id = 27
                // 14, 18, 25, 26
                //             ^

                var trace = new TraceManager();
                var bus = new InProcessMessageBus(trace, false);
                bus.Send("foo", "1").Wait();
                bus.Send("foo", "2").Wait();
                bus.Send("bar", "3").Wait();
                bus.Send("bar", "4").Wait();

                // REVIEW: Will block
                // var result = bus.GetMessagesSince(new[] { "foo" }, 3).Result.ToList();
                // Assert.Equal(0, result.Count);
            }
コード例 #4
0
            public void ReturnsMessagesGreaterThanLastMessageIdWhenLastMessageIdNotInStore()
            {
                // id = 27
                // 24, 25, 28, 30, 45
                //     ^

                var trace = new TraceManager();
                var bus = new InProcessMessageBus(trace, false);
                bus.Send("testclient", "bar", "1").Wait();
                bus.Send("testclient", "foo", "2").Wait();
                bus.Send("testclient", "bar", "3").Wait();
                bus.Send("testclient", "foo", "4").Wait();
                bus.Send("testclient", "bar", "5").Wait();
                bus.Send("testclient", "foo", "6").Wait();

                var result = bus.GetMessages(new[] { "foo" }, "3", CancellationToken.None).Result;
                Assert.Equal(2, result.Messages.Count);
            }
コード例 #5
0
ファイル: Program.cs プロジェクト: jbagavathi/SignalR
        private static void StartSendLoop(InProcessMessageBus bus, string payload)
        {
            while (_exception == null)
            {
                long old = _rate;
                var interval = TimeSpan.FromMilliseconds((1000.0 / _rate) * _senders);
                //var interval = TimeSpan.FromMilliseconds(1000.0 / _rate);
                while (Interlocked.Read(ref _rate) == old && _exception == null)
                {
                    try
                    {
                        var sw = Stopwatch.StartNew();
                        bus.Send("a", payload).ContinueWith(task =>
                        {
                            Interlocked.Exchange(ref _exception, task.Exception);
                        },
                        TaskContinuationOptions.OnlyOnFaulted);
                        sw.Stop();
                        Interlocked.Exchange(ref _lastSendTimeTicks, sw.ElapsedTicks);

                        Interlocked.Increment(ref _sent);
                        Interlocked.Increment(ref _avgLastSendsCount);

                        //Thread.Sleep(interval);
                    }
                    catch (Exception ex)
                    {
                        Interlocked.Exchange(ref _exception, ex);
                    }
                }
            }
        }