コード例 #1
0
 public void available_sending_count_some_connected_some_still_connecting()
 {
     var choke = new SendingChoke();
     4.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     25.Times(x => choke.StartSend());
     choke.AvailableSendingCount.ShouldEqual(1);
 }
コード例 #2
0
        public void available_sending_count_some_connected_some_still_connecting()
        {
            var choke = new SendingChoke();

            4.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            25.Times(x => choke.StartSend());
            choke.AvailableSendingCount.ShouldEqual(1);
        }
コード例 #3
0
        public void choke_returns_false_if_max_sending_isnt_exceeded_but_max_connecting_is()
        {
            var choke = new SendingChoke();

            2.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            31.Times(x => choke.StartSend());
            choke.ShouldBeginSend().ShouldBeFalse();
        }
コード例 #4
0
        public void choke_returns_true_if_several_connecting_but_not_connected_yet_up_to_maximum_connecting_count()
        {
            var choke = new SendingChoke();

            4.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            30.Times(x =>
            {
                choke.StartSend();
            });
            choke.ShouldBeginSend().ShouldBeTrue();
        }
コード例 #5
0
        public void available_sending_count_with_max_connecting()
        {
            var choke = new SendingChoke();

            30.Times(x => choke.StartSend());
            choke.AvailableSendingCount.ShouldEqual(0);
        }
コード例 #6
0
        public void Send()
        {
            var allEndpoints = new ThreadSafeSet <Endpoint>();

            while (_continueSending)
            {
                if (!_choke.ShouldBeginSend())
                {
                    continue;
                }

                var endpoints = gatherEndpoints(allEndpoints.All()).ToArray();
                if (!endpoints.Any())
                {
                    _choke.NoMessagesToSend();
                    continue;
                }
                allEndpoints.Add(endpoints);

                endpoints.Each(endpoint =>
                {
                    var messages = gatherMessagesToSend(endpoint);
                    if (!messages.Any())
                    {
                        allEndpoints.Remove(endpoint);
                        return;
                    }

                    _choke.StartSend();

                    sendMessages(endpoint, messages)
                    .ContinueWith(x => allEndpoints.Remove(endpoint));
                });
            }
        }
コード例 #7
0
        public void available_sending_count_with_connecting_endpoints()
        {
            var choke = new SendingChoke();

            5.Times(x => choke.StartSend());
            choke.AvailableSendingCount.ShouldEqual(5);
        }
コード例 #8
0
 public void can_alter_max_connecting_count()
 {
     var choke = new SendingChoke();
     choke.AlterConnectingCountMaximumTo(10);
     11.Times(x => choke.StartSend());
     choke.ShouldBeginSend().ShouldBeFalse();
 }
コード例 #9
0
 public void can_alter_max_sending_count()
 {
     var choke = new SendingChoke();
     choke.AlterSendingCountMaximumTo(10);
     5.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     choke.ShouldBeginSend().ShouldBeTrue();
     5.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     choke.ShouldBeginSend().ShouldBeFalse();
 }
コード例 #10
0
        public void can_alter_max_connecting_count()
        {
            var choke = new SendingChoke();

            choke.AlterConnectingCountMaximumTo(10);
            11.Times(x => choke.StartSend());
            choke.ShouldBeginSend().ShouldBeFalse();
        }
コード例 #11
0
        public void can_alter_max_sending_count()
        {
            var choke = new SendingChoke();

            choke.AlterSendingCountMaximumTo(10);
            5.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            choke.ShouldBeginSend().ShouldBeTrue();
            5.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            choke.ShouldBeginSend().ShouldBeFalse();
        }
コード例 #12
0
 public void available_sending_count_with_all_connected()
 {
     var choke = new SendingChoke();
     5.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     choke.AvailableSendingCount.ShouldEqual(0);
 }
コード例 #13
0
        public void choke_returns_false_if_at_max_sending_count()
        {
            var choke = new SendingChoke();

            5.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            choke.ShouldBeginSend().ShouldBeFalse();
        }
コード例 #14
0
        public void available_sending_count_with_all_connected()
        {
            var choke = new SendingChoke();

            5.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            choke.AvailableSendingCount.ShouldEqual(0);
        }
コード例 #15
0
 public void choke_returns_true_if_several_connecting_but_not_connected_yet_up_to_maximum_connecting_count()
 {
     var choke = new SendingChoke();
     4.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     30.Times(x =>
     {
         choke.StartSend();
     });
     choke.ShouldBeginSend().ShouldBeTrue();
 }
コード例 #16
0
 public void choke_returns_false_if_max_sending_isnt_exceeded_but_max_connecting_is()
 {
     var choke = new SendingChoke();
     2.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     31.Times(x => choke.StartSend());
     choke.ShouldBeginSend().ShouldBeFalse();
 }
コード例 #17
0
 public void choke_returns_false_if_at_max_sending_count()
 {
     var choke = new SendingChoke();
     5.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     choke.ShouldBeginSend().ShouldBeFalse();
 }
コード例 #18
0
 public void available_sending_count_with_max_connecting()
 {
     var choke = new SendingChoke();
     30.Times(x => choke.StartSend());
     choke.AvailableSendingCount.ShouldEqual(0);
 }
コード例 #19
0
 public void available_sending_count_with_connecting_endpoints()
 {
     var choke = new SendingChoke();
     5.Times(x => choke.StartSend());
     choke.AvailableSendingCount.ShouldEqual(5);
 }