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);
        }
Example #2
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);
        }