public void Should_execute_services_in_parallel()
        {
            _target = new MultiPollerService(new Func<IService>[] {
                () => new TestService("S1", _log),
                () => new TestService("S2", _log)
            }, TimeSpan.Zero);

            _target.Start();
            Thread.Sleep(45 * TestSlowness);
            _target.Stop();

            _log.ToArray().Should().Have.SameSequenceAs(new[] {
                "S1: create",
                "S2: create",
                "S1: work",
                "S2: work",
                "S1: work",
                "S2: work",
                "S1: work",
                "S2: work",
                "S1: work",
                "S2: work",
                "S1: work",
                "S2: work"
            });
        }
Beispiel #2
0
        public static void Main()
        {
            BasicConfigurator.Configure();

            var multiService = new MultiPollerService(new Func<IService>[] {
                () => new Service("svc1"),
                () => new Service("svc2"),
                () => new Service("svc3")
            }, TimeSpan.FromSeconds(5));

            HostFactory.Run(hcfg => {
                hcfg.UseLog4Net();
                hcfg.Service<MultiPollerService>(scfg => {
                    scfg.ConstructUsing(() => multiService);
                    scfg.WhenStarted(svc => svc.Start());
                    scfg.WhenStopped(svc => svc.Stop());
                });
            });
        }
        public void Failing_service_should_not_interfere_with_other_services()
        {
            _target = new MultiPollerService(new Func<IService>[] {
                () => new TestService("S1", _log),
                () => new TestService("S2", _log) { ExceptionFreq = 1 },
            }, TimeSpan.Zero);

            _target.Start();
            Thread.Sleep(45 * TestSlowness);
            _target.Stop();

            _log.Where(x=>x.StartsWith("S1")).Should().Have.SameSequenceAs(new[] {
                "S1: create",
                "S1: work",
                "S1: work",
                "S1: work",
                "S1: work",
                "S1: work"
            });
        }
 public void TearDown()
 {
     if (_target != null)
     {
         _target.Dispose();
         _target = null;
     }
 }
        public void Should_reinit_after_exception()
        {
            _target = new MultiPollerService(new Func<IService>[] {
                () => new TestService("S1", _log) { ExceptionFreq = 2 }
            }, TimeSpan.Zero);

            _target.Start();
            Thread.Sleep(45 * TestSlowness);
            _target.Stop();

            _log.ToArray().Should().Have.SameSequenceAs(new[] {
                "S1: create",
                "S1: work",
                "S1: exception",
                "S1: create",
                "S1: work",
                "S1: exception",
                "S1: create",
                "S1: work"
            });
        }