public void ShouldBeAbleToUse() { var connection = new Mock<IDbConnection>(); var connectionInstance = connection.Object; var monitorConfigs = new ConcurrentDictionary<string, MonitorConfig>(); var cache = new Mock<IDataCache>(); cache.SetupGet(x => x.MonitorConfigs).Returns(monitorConfigs).Verifiable(); var reduceLevelData = new List<ReduceLevel> { new ReduceLevel { MonitorConfigName = "Test1", Resolution = 60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test1", Resolution = 5*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test1", Resolution = 60*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test1", Resolution = 24*60*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test2", Resolution = 60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test2", Resolution = 5*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test2", Resolution = 60*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test2", Resolution = 24*60*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test3", Resolution = 60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test3", Resolution = 5*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test3", Resolution = 60*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test3", Resolution = 24*60*60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test4", Resolution = 60*1000, HistoryLength = 7*24*60*60*1000 }, new ReduceLevel { MonitorConfigName = "Test4", Resolution = 5*60*1000, HistoryLength = 7*24*60*60*1000 } }; var monitorConfigData = new List<MonitorConfig> { new MonitorConfig { Name = "Test1" }, new MonitorConfig { Name = "Test2" }, new MonitorConfig { Name = "Test3" }, new MonitorConfig { Name = "Test4" } }; var storageCommands = new Mock<IStorageCommandsSetup>(); storageCommands.Setup(x => x.SelectListAllReduceLevels(connectionInstance)).Returns(reduceLevelData); storageCommands.Setup(x => x.SelectListAllMonitorConfigs(connectionInstance)).Returns(monitorConfigData); var reduceMethodProvider = new Mock<IReduceMethodProvider>(); reduceMethodProvider.Setup(x => x.Retrieve(It.IsAny<string>())).Returns(new Mock<IReduceMethod<double>>().Object); var settings = BuildSettings(); settings.SetupGet(x => x.Debug).Returns(true); settings.SetupGet(x => x.ReduceMethodProvider).Returns(reduceMethodProvider.Object); var setupSystem = new SetupSystemData(cache.Object, storageCommands.Object, settings.Object); setupSystem.LoadAndValidateData(connectionInstance); Assert.Equal(4, monitorConfigs.Count); Assert.True(monitorConfigs.ContainsKey("Test1")); Assert.Equal(4, monitorConfigs["Test1"].ReduceLevels.Count); Assert.Equal("Test1", monitorConfigs["Test1"].Name); Assert.True(monitorConfigs.ContainsKey("Test2")); Assert.Equal(4, monitorConfigs["Test2"].ReduceLevels.Count); Assert.Equal("Test2", monitorConfigs["Test2"].Name); Assert.True(monitorConfigs.ContainsKey("Test3")); Assert.Equal(4, monitorConfigs["Test3"].ReduceLevels.Count); Assert.Equal("Test3", monitorConfigs["Test3"].Name); Assert.True(monitorConfigs.ContainsKey("Test4")); Assert.Equal(2, monitorConfigs["Test4"].ReduceLevels.Count); Assert.Equal("Test4", monitorConfigs["Test4"].Name); cache.VerifyAll(); storageCommands.VerifyAll(); }
public void Initialize(SettingsExtensionOptions settingsExtensionOptions) { //Need to setup the logger first LoggerProvider = settingsExtensionOptions.LoggerProvider ?? new SystemLoggerProvider(this); var storageFactory = settingsExtensionOptions.StorageFactory; if (settingsExtensionOptions.StorageFactory == null) { var storageFactoryProvider = new StorageFactoryProvider(); storageFactory = storageFactoryProvider.CreateProvider(); } var storageCommands = settingsExtensionOptions.StorageCommands ?? new StorageCommands(storageFactory, this); var storageCommandsSetup = settingsExtensionOptions.StorageCommandsSetup ?? new StorageCommandsSetup(); var cache = new DataCache(); var flusherUpdate = new RecordFlushUpdate(cache, storageCommands); var reduceStatus = new RecordReduceStatus(new RecordReduceStatusSourceProviderFile(this)); var reduceAggregate = new RecordReduceAggregate(); var compare = new RecordCompare(storageCommands, this); var setupSystemTables = new SetupSystemTables(cache, storageCommandsSetup, this); var setupSystemData = new SetupSystemData(cache, storageCommandsSetup, this); var setupSystem = new SetupSystem(setupSystemTables, setupSystemData, storageFactory); var defineDefaults = new SetupMonitorConfig(storageCommands, setupSystemTables, cache, storageFactory, this); ConfigSeed = new ConfigSeed(cache, this); Recorder = new Recorder(cache, this); RecordFlush = new RecordFlush(defineDefaults, cache, storageCommands, flusherUpdate, storageFactory, this); RecordReduce = new RecordReduce(reduceStatus, reduceAggregate, cache, compare, storageCommands, storageFactory, this); ReduceMethodProvider = new ReduceMethodProvider(); ReduceMethodProvider.Register(new ReduceMethodAccumulate()); ReduceMethodProvider.Register(new ReduceMethodAverage()); ProcessingInstructionProvider = new ProcessingInstructionProvider(); ProcessingInstructionProvider.Register(new ProcessingInstructionAccumulate(storageCommands)); ProcessingInstructionProvider.Register(new ProcessingInstructionAverage()); //Run system setup setupSystem.Initialize(); }