public void can_alter_max_connecting_count()
 {
     var choke = new SendingChoke();
     choke.AlterConnectingCountMaximumTo(10);
     11.Times(x => choke.StartSend());
     choke.ShouldBeginSend().ShouldBeFalse();
 }
示例#2
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));
                });
            }
        }
 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();
 }
        public void can_alter_max_connecting_count()
        {
            var choke = new SendingChoke();

            choke.AlterConnectingCountMaximumTo(10);
            11.Times(x => choke.StartSend());
            choke.ShouldBeginSend().ShouldBeFalse();
        }
        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();
        }
        public void choke_returns_false_if_at_max_sending_count()
        {
            var choke = new SendingChoke();

            5.Times(x =>
            {
                choke.StartSend();
                choke.SuccessfullyConnected();
            });
            choke.ShouldBeginSend().ShouldBeFalse();
        }
        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();
        }
        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();
        }
 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();
 }
 public void choke_returns_false_if_at_max_sending_count()
 {
     var choke = new SendingChoke();
     5.Times(x =>
     {
         choke.StartSend();
         choke.SuccessfullyConnected();
     });
     choke.ShouldBeginSend().ShouldBeFalse();
 }
 public void choke_should_send_returns_true_if_havent_sent_anything()
 {
     var choke = new SendingChoke();
     choke.ShouldBeginSend().ShouldBeTrue();
 }
 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();
 }
        public void choke_should_send_returns_true_if_havent_sent_anything()
        {
            var choke = new SendingChoke();

            choke.ShouldBeginSend().ShouldBeTrue();
        }