public void PerformanceCounterPersistence_Load_ResourceCounters_NonExistLoadDefault()
        {
            var _file    = new Mock <IFile>();
            var register = new Mock <IWarewolfPerformanceCounterRegister>();

            PerformanceCounterPersistence obj = new PerformanceCounterPersistence(_file.Object);

            IList <IResourcePerformanceCounter> counters = new List <IResourcePerformanceCounter>();

            counters.Add(new TestResourceCounter());
            var serialiser = new Dev2JsonSerializer();
            var fileName   = Path.GetTempFileName();

            _file.Setup(a => a.Exists(fileName)).Returns(false);


            File.WriteAllText(fileName, serialiser.Serialize(counters));

            var persisted = obj.LoadOrCreateResourceCounters(fileName);

            Assert.AreEqual(0, obj.DefaultResourceCounters.Count);
            Assert.AreEqual(persisted.Count, 0);

            File.Delete(fileName);
        }
        public void PerformanceCounterPersistence_SaveEmpty_ExpectCountersSaved()
        {
            PerformanceCounterPersistence obj = new PerformanceCounterPersistence(new FileWrapper());

            IList <IPerformanceCounter> counters = new List <IPerformanceCounter>();
            var fileName = Path.GetTempFileName();

            obj.Save(counters, fileName);
            var saved = File.ReadAllText(fileName);
            Dev2JsonSerializer serialiser = new Dev2JsonSerializer();
            var persisted = serialiser.Deserialize <IList <IPerformanceCounter> >(saved);

            Assert.IsNotNull(persisted);

            File.Delete(fileName);
        }
        public void PerformanceCounterPersistence_Save_ExpectCountersSaved()
        {
            var obj = new PerformanceCounterPersistence(new FileWrapper());
            IList <IPerformanceCounter> counters = new List <IPerformanceCounter>();

            counters.Add(new TestCounter());
            var fileName = Path.GetTempFileName();

            obj.Save(counters, fileName);
            var saved      = File.ReadAllText(fileName);
            var serialiser = new Dev2JsonSerializer();
            var persisted  = serialiser.Deserialize <IList <IPerformanceCounter> >(saved);

            Assert.AreEqual(persisted.Count, 1);

            File.Delete(fileName);
        }
        public void PerformanceCounterPersistence_Load_ExpectCountersRecreatedForNoFile()
        {
            var _file    = new Mock <IFile>();
            var register = new Mock <IWarewolfPerformanceCounterRegister>();

            PerformanceCounterPersistence obj = new PerformanceCounterPersistence(_file.Object);

            IList <IPerformanceCounter> counters = new List <IPerformanceCounter>();

            counters.Add(new TestCounter());
            register.Setup(a => a.DefaultCounters).Returns(counters);
            var fileName = Path.GetTempFileName();

            _file.Setup(a => a.Exists(fileName)).Returns(false);
            obj.Save(counters, fileName);
            var persisted = obj.LoadOrCreate(fileName);

            Assert.AreEqual(persisted.Count, 6);

            File.Delete(fileName);
        }
Exemplo n.º 5
0
        static void LoadPerformanceCounters()
        {
            try
            {
                var perf     = new PerformanceCounterPersistence(new FileWrapper());
                var register = new WarewolfPerformanceCounterRegister(perf.LoadOrCreate(), perf.LoadOrCreateResourcesCounters(perf.DefaultResourceCounters));
                var locater  = new WarewolfPerformanceCounterManager(register.Counters, register.ResourceCounters, register, perf);
                locater.CreateCounter(Guid.Parse("a64fc548-3045-407d-8603-2a7337d874a6"), WarewolfPerfCounterType.ExecutionErrors, "workflow1");
                locater.CreateCounter(Guid.Parse("a64fc548-3045-407d-8603-2a7337d874a6"), WarewolfPerfCounterType.AverageExecutionTime, "workflow1");
                locater.CreateCounter(Guid.Parse("a64fc548-3045-407d-8603-2a7337d874a6"), WarewolfPerfCounterType.ConcurrentRequests, "workflow1");
                locater.CreateCounter(Guid.Parse("a64fc548-3045-407d-8603-2a7337d874a6"), WarewolfPerfCounterType.RequestsPerSecond, "workflow1");


                CustomContainer.Register <IWarewolfPerformanceCounterLocater>(locater);
                CustomContainer.Register <IPerformanceCounterRepository>(locater);
            }
            catch (Exception err)
            {
                // ignored
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
            }
        }
        public void PerformanceCounterPersistence_Load_ExpectCountersLoadedForExistingFile()
        {
            var _file = new Mock <IFile>();
            var obj   = new PerformanceCounterPersistence(_file.Object);

            IList <IPerformanceCounter> counters = new List <IPerformanceCounter>();

            counters.Add(new TestCounter());
            var fileName = Path.GetTempFileName();

            _file.Setup(a => a.Exists(fileName)).Returns(true);
            obj.Save(counters, fileName);

            var serialiser = new Dev2JsonSerializer();

            File.WriteAllText(fileName, serialiser.Serialize(counters));
            _file.Setup(a => a.ReadAllText(fileName)).Returns(File.ReadAllText(fileName));
            var persisted = obj.LoadOrCreate(fileName);

            Assert.AreEqual(persisted.Count, 1);

            File.Delete(fileName);
        }
        public void CtorTest()
        {
            PerformanceCounterPersistence obj = new PerformanceCounterPersistence(new Mock <IFile>().Object);

            Assert.IsNotNull(obj);
        }