Inheritance: ISetupSystemTables
            public void ShouldBeAbleToUse()
            {
                var connection = new Mock<IDbConnection>();
                var connectionInstance = connection.Object;

                var settings = BuildSettings();

                var monitorConfigs = new ConcurrentDictionary<string, MonitorConfig>();
                monitorConfigs.TryAdd("Test1", new MonitorConfig { Name = "Test1", ComparisonCalculator = new ProcessingInstructionAverage(), ReduceLevels = new List<ReduceLevel> { new ReduceLevel { Resolution = 1000 }, new ReduceLevel { Resolution = 60000 } } });
                monitorConfigs.TryAdd("Test2", new MonitorConfig { Name = "Test2", ComparisonCalculator = new ProcessingInstructionAverage(), ReduceLevels = new List<ReduceLevel> { new ReduceLevel { Resolution = 1000 }, new ReduceLevel { Resolution = 60000 } } });
                monitorConfigs.TryAdd("Test3", new MonitorConfig { Name = "Test3", ComparisonCalculator = new ProcessingInstructionAverage(), ReduceLevels = new List<ReduceLevel> { new ReduceLevel { Resolution = 1000 }, new ReduceLevel { Resolution = 60000 } } });
                monitorConfigs.TryAdd("Test4", new MonitorConfig { Name = "Test4", ComparisonCalculator = new ProcessingInstructionAverage(), ReduceLevels = new List<ReduceLevel> { new ReduceLevel { Resolution = 1000 }, new ReduceLevel { Resolution = 60000 } } });

                var cache = new Mock<IDataCache>();
                cache.SetupGet(x => x.MonitorConfigs).Returns(monitorConfigs).Verifiable();

                IEnumerable<string> needCreatingTable = null;
                IEnumerable<string> needCreatingTableComparison = null;
                Dictionary<string, Tuple<string, long>> tablesConfigResolution = null;

                var existingTables = new List<string> { "Test1SecondlyData", "Test1MinutelyData", "Test2SecondlyData", "Test2MinutelyData", "Test1SecondlyComparison", "Test1MinutelyComparison", "Test2SecondlyComparison", "Test2MinutelyComparison" };
                var storageCommands = new Mock<IStorageCommandsSetup>();
                storageCommands.Setup(x => x.SelectListAllExistingTables(connectionInstance)).Returns(existingTables);
                storageCommands.Setup(x => x.BuildTables(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>(), It.IsAny<Dictionary<string, Tuple<string, long>>>(), connectionInstance))
                    .Callback((IEnumerable<string> nCT, IEnumerable<string> nCTC, Dictionary<string, Tuple<string, long>> tCR, IDbConnection c) => { needCreatingTable = nCT; needCreatingTableComparison = nCTC; tablesConfigResolution = tCR; }).Verifiable();

                var setupSystemTables = new SetupSystemTables(cache.Object, storageCommands.Object, settings.Object);
                setupSystemTables.ValidateAndCreateDataTables(connectionInstance);

                Assert.Equal(4, needCreatingTable.Count());
                Assert.True(needCreatingTable.Contains("Test3SecondlyData"));
                Assert.True(needCreatingTable.Contains("Test3MinutelyData"));
                Assert.True(needCreatingTable.Contains("Test4SecondlyData"));
                Assert.Equal(4, needCreatingTableComparison.Count());
                Assert.True(needCreatingTableComparison.Contains("Test3SecondlyComparison"));
                Assert.True(needCreatingTableComparison.Contains("Test3MinutelyComparison"));
                Assert.True(needCreatingTableComparison.Contains("Test4SecondlyComparison"));
                Assert.Equal(8, tablesConfigResolution.Count());
                Assert.True(tablesConfigResolution.ContainsKey("Test3SecondlyData"));
                Assert.True(tablesConfigResolution.ContainsKey("Test3MinutelyData"));
                Assert.True(tablesConfigResolution.ContainsKey("Test4SecondlyData"));

                cache.VerifyAll();
                storageCommands.VerifyAll();
            }
Example #2
0
        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();
        }