示例#1
0
            public void ShouldExitIfHasNoValues()
            {
                var dataUpdate = new RecordFlushUpdate(null, null);
                var result = dataUpdate.UpdateExisting("", new Dictionary<long, MonitorRecord<double>>(), null);

                Assert.True(result);
            }
示例#2
0
            public void ShouldThrowExceptionIfInfoNotFoundInCache()
            {
                var dictionary = new ConcurrentDictionary<string, MonitorInfo>();

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

                var data = new Dictionary<long, MonitorRecord<double>> { { 1000, null } };
                var dataUpdate = new RecordFlushUpdate(cache.Object, null);
                Assert.Throws<DataException>(() => dataUpdate.UpdateExisting("Test", data, null));

                cache.VerifyAll();
            }
示例#3
0
            public void ShouldUpdateExistingData()
            {
                var connection = new Mock<IDbConnection>();
                var connectionInstance = connection.Object;

                IEnumerable<MonitorRecord<double>> updateList = null;

                var storeData = new List<MonitorRecord<double>>
                                    {
                                        new MonitorRecord<double>(new DateTime(2010, 6, 6, 10, 30, 0), 1),
                                        new MonitorRecord<double>(new DateTime(2010, 6, 6, 10, 30, 1), 1)
                                    };

                var store = new Mock<IStorageCommands>();
                store.Setup(x => x.SelectListForUpdateExisting("TestSecondlyData", new DateTime(2010, 6, 6, 10, 30, 0, 100), connectionInstance, null)).Returns(storeData).Verifiable();
                store.Setup(x => x.Update("TestSecondlyData", It.IsAny<IEnumerable<MonitorRecord<double>>>(), connectionInstance, null)).Callback((string tableName, IEnumerable<MonitorRecord<double>> values, IDbConnection conn, IDbTransaction transaction) => { updateList = values; }).Verifiable();

                var reduceLevel = new ReduceLevel { AggregationClass = new ReduceMethodAccumulate(), Resolution = 1000 };
                var monitorInfo = new MonitorInfo { FirstReduceLevel = reduceLevel };

                var dictionary = new ConcurrentDictionary<string, MonitorInfo>();
                dictionary.TryAdd("Test", monitorInfo);

                var cache = new Mock<IDataCache>();
                cache.SetupGet(x => x.Empty).Returns(new MonitorRecord<double>()).Verifiable();
                cache.SetupGet(x => x.MonitorInfo).Returns(dictionary).Verifiable();

                var data = new Dictionary<long, MonitorRecord<double>>
                               {
                                   { 1000, new MonitorRecord<double>(new DateTime(2010, 6, 6, 10, 30, 0, 100), 3) },
                                   { 1001, new MonitorRecord<double>(new DateTime(2010, 6, 6, 10, 30, 0, 200), 5) },
                                   { 1002, new MonitorRecord<double>(new DateTime(2010, 6, 6, 10, 30, 0, 400), 1) },
                                   { 1003, new MonitorRecord<double>(new DateTime(2010, 6, 6, 10, 30, 1, 300), 2) }
                               };
                var dataUpdate = new RecordFlushUpdate(cache.Object, store.Object);
                var result = dataUpdate.UpdateExisting("Test", data, connectionInstance);

                Assert.True(result);

                //I'm really not sure about these assertions as given the test data the output isn't what I would expect
                Assert.Equal(2, updateList.Count());
                var first = updateList.First();
                Assert.Equal(4, first.Value);
                Assert.Equal(2, first.Number);
                var last = updateList.Last();
                Assert.Equal(3, last.Value);
                Assert.Equal(2, last.Number);

                cache.VerifyAll();
                store.VerifyAll();
            }
示例#4
0
文件: Settings.cs 项目: Zocdoc/ZocMon
        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();
        }