public void FailedHostIncreasesOnePointPerMinute() { _strategy = new TimeTravelTestScoreMirrorSelector(defaultHostPool); FailMultiplier(httpHost, 2); var host1 = _strategy.GetHost(); Thread.Sleep(4000); var host2 = _strategy.GetHost(); host1.Should().Be(rsyncHost, "because it should have higher score"); host2.Should().Be(httpHost, "because it should have same score again"); }
void RegisterDownloaderFactories() { // TODO: this is a replacement for the simple factory classes we have, they can be removed later? _container.RegisterSingleton <Func <IMirrorSelector, ExportLifetimeContext <IMultiMirrorFileDownloader> > >( x => new ExportLifetimeContext <IMultiMirrorFileDownloader>( new MultiMirrorFileDownloader(_container.GetInstance <IFileDownloader>(), x), TaskExt.NullAction)); _container.RegisterSingleton <Func <IReadOnlyCollection <Uri>, ExportLifetimeContext <IMirrorSelector> > >( x => { var hostChecker = _container.GetInstance <Func <ExportLifetimeContext <IHostChecker> > >().Invoke(); var selector = new ScoreMirrorSelector(hostChecker.Value, x); return(new ExportLifetimeContext <IMirrorSelector>(selector, () => { selector.Dispose(); hostChecker.Dispose(); })); }); _container .RegisterSingleton <Func <int, IReadOnlyCollection <Uri>, ExportLifetimeContext <IMirrorSelector> > >( (limit, x) => { var hostChecker = _container.GetInstance <Func <ExportLifetimeContext <IHostChecker> > >().Invoke(); var selector = new ScoreMirrorSelector(limit, hostChecker.Value, x); return(new ExportLifetimeContext <IMirrorSelector>(selector, () => { selector.Dispose(); hostChecker.Dispose(); })); }); _container.RegisterSingleton <Func <ExportLifetimeContext <IHostChecker> > >(() => { var hostCheckerType = _container.GetInstance <Func <HostCheckerType> >(); var hostChecker = hostCheckerType() == HostCheckerType.WithPing ? _container.GetInstance <IHostCheckerWithPing>() : _container.GetInstance <IHostChecker>(); return(new ExportLifetimeContext <IHostChecker>(hostChecker, TaskExt.NullAction)); }); _container.RegisterSingleton <Func <ExportLifetimeContext <IWebClient> > >(() => { var wc = _container.GetInstance <Func <IWebClient> >(); var webClient = wc(); return(new ExportLifetimeContext <IWebClient>(webClient, webClient.Dispose)); }); }
public void ThrowsOnNullHostList() { Action act = () => _strategy = new ScoreMirrorSelector(GetHostChecker(), null); act.ShouldThrow <ArgumentNullException>(); }
public void Setup() { _strategy = new ScoreMirrorSelector(GetHostChecker(), defaultHostPool); }
public void ThrowsOnCreateWithEmptyHostList() { Action act = () => _strategy = new ScoreMirrorSelector(GetHostChecker(), new Uri[0]); act.ShouldThrow <EmptyHostList>(); }