public void ShouldThrowExceptionWhenServiceTypeRequestedDoesntExist() { // arrange StatsCheckerFactory factory = new StatsCheckerFactory(); ClientSetting setting = new ClientSetting { AssemblyName = "Rbi.Property.HealthMonitoring.Tests", FullQualifiedServiceName = "Rbi.Property.HealthMonitoring.Tests.StatsCheckers.DummyType" }; // act Assert.Throws<Exception>(() => factory.CreateStatsCheckerInstance(setting)); }
public void ShouldCreateBasicHttpCheckerWhenItsTypeIsRequested() { // arrange StatsCheckerFactory factory = new StatsCheckerFactory(); ClientSetting setting = new ClientSetting { AssemblyName = "Rbi.Property.HealthMonitoring", FullQualifiedServiceName = "Rbi.Property.HealthMonitoring.StatsCheckers.BasicHttpStatsChecker" }; // act IChecker actual = factory.CreateStatsCheckerInstance(setting); Assert.IsInstanceOf(typeof(BasicHttpStatsChecker), actual); }
static void Main(string[] args) { string pathToConfig = args.Length > 0 ? args[0] : Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "healthMonitoring.config"); // Load settings IFileManager fileManager = new FileManager(); ISettingLoader loader = new SettingLoader(fileManager); HealthMonitoringSetting setting = loader.Parse(pathToConfig); IStatsCheckerFactory statsCheckerFactory = new StatsCheckerFactory(); IOutputChannelFactory outputChannelFactory = new OutputChannelFactory(); IStatsTemplate template = new BasicStatsTemplate(); ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>(); Parallel.For(0, setting.Clients.Length, (i, loopState) => { try { Controller controller = new Controller(setting.Clients[i], statsCheckerFactory, outputChannelFactory, template); controller.Start(); } catch(Exception ex) { exceptions.Enqueue(ex); } }); // Throw the exceptions here after the loop completes. if (exceptions.Count > 0) throw new AggregateException(exceptions); Thread.Sleep(Timeout.Infinite); }