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); }
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 available_sending_count_with_max_connecting() { var choke = new SendingChoke(); 30.Times(x => choke.StartSend()); choke.AvailableSendingCount.ShouldEqual(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 available_sending_count_with_connecting_endpoints() { var choke = new SendingChoke(); 5.Times(x => choke.StartSend()); choke.AvailableSendingCount.ShouldEqual(5); }
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 available_sending_count_with_all_connected() { var choke = new SendingChoke(); 5.Times(x => { choke.StartSend(); choke.SuccessfullyConnected(); }); choke.AvailableSendingCount.ShouldEqual(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(); }