public override void AddCron(string group, string name, Instrumentation.Cron cron
                              )
 {
     InstrumentationService.Timer timer = GetToAdd <InstrumentationService.Timer>(group
                                                                                  , name, timerLock, timers);
     timer.AddCron((InstrumentationService.Cron)cron);
 }
Exemple #2
0
        public virtual void Timer()
        {
            InstrumentationService.Timer timer = new InstrumentationService.Timer(2);
            InstrumentationService.Cron  cron  = new InstrumentationService.Cron();
            long ownStart;
            long ownEnd;
            long totalStart;
            long totalEnd;
            long ownDelta;
            long totalDelta;
            long avgTotal;
            long avgOwn;

            cron.Start();
            ownStart   = Time.Now();
            totalStart = ownStart;
            ownDelta   = 0;
            Sleep(100);
            cron.Stop();
            ownEnd    = Time.Now();
            ownDelta += ownEnd - ownStart;
            Sleep(100);
            cron.Start();
            ownStart = Time.Now();
            Sleep(100);
            cron.Stop();
            ownEnd     = Time.Now();
            ownDelta  += ownEnd - ownStart;
            totalEnd   = ownEnd;
            totalDelta = totalEnd - totalStart;
            avgTotal   = totalDelta;
            avgOwn     = ownDelta;
            timer.AddCron(cron);
            long[] values = timer.GetValues();
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.LastTotal], totalDelta
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.LastOwn], ownDelta
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.AvgTotal], avgTotal
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.AvgOwn], avgOwn
                                            , 20);
            cron = new InstrumentationService.Cron();
            cron.Start();
            ownStart   = Time.Now();
            totalStart = ownStart;
            ownDelta   = 0;
            Sleep(200);
            cron.Stop();
            ownEnd    = Time.Now();
            ownDelta += ownEnd - ownStart;
            Sleep(200);
            cron.Start();
            ownStart = Time.Now();
            Sleep(200);
            cron.Stop();
            ownEnd     = Time.Now();
            ownDelta  += ownEnd - ownStart;
            totalEnd   = ownEnd;
            totalDelta = totalEnd - totalStart;
            avgTotal   = (avgTotal * 1 + totalDelta) / 2;
            avgOwn     = (avgOwn * 1 + ownDelta) / 2;
            timer.AddCron(cron);
            values = timer.GetValues();
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.LastTotal], totalDelta
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.LastOwn], ownDelta
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.AvgTotal], avgTotal
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.AvgOwn], avgOwn
                                            , 20);
            avgTotal = totalDelta;
            avgOwn   = ownDelta;
            cron     = new InstrumentationService.Cron();
            cron.Start();
            ownStart   = Time.Now();
            totalStart = ownStart;
            ownDelta   = 0;
            Sleep(300);
            cron.Stop();
            ownEnd    = Time.Now();
            ownDelta += ownEnd - ownStart;
            Sleep(300);
            cron.Start();
            ownStart = Time.Now();
            Sleep(300);
            cron.Stop();
            ownEnd     = Time.Now();
            ownDelta  += ownEnd - ownStart;
            totalEnd   = ownEnd;
            totalDelta = totalEnd - totalStart;
            avgTotal   = (avgTotal * 1 + totalDelta) / 2;
            avgOwn     = (avgOwn * 1 + ownDelta) / 2;
            cron.Stop();
            timer.AddCron(cron);
            values = timer.GetValues();
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.LastTotal], totalDelta
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.LastOwn], ownDelta
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.AvgTotal], avgTotal
                                            , 20);
            NUnit.Framework.Assert.AreEqual(values[InstrumentationService.Timer.AvgOwn], avgOwn
                                            , 20);
            JSONObject json = (JSONObject) new JSONParser().Parse(timer.ToJSONString());

            NUnit.Framework.Assert.AreEqual(json.Count, 4);
            NUnit.Framework.Assert.AreEqual(json["lastTotal"], values[InstrumentationService.Timer
                                                                      .LastTotal]);
            NUnit.Framework.Assert.AreEqual(json["lastOwn"], values[InstrumentationService.Timer
                                                                    .LastOwn]);
            NUnit.Framework.Assert.AreEqual(json["avgTotal"], values[InstrumentationService.Timer
                                                                     .AvgTotal]);
            NUnit.Framework.Assert.AreEqual(json["avgOwn"], values[InstrumentationService.Timer
                                                                   .AvgOwn]);
            StringWriter writer = new StringWriter();

            timer.WriteJSONString(writer);
            writer.Close();
            json = (JSONObject) new JSONParser().Parse(writer.ToString());
            NUnit.Framework.Assert.AreEqual(json.Count, 4);
            NUnit.Framework.Assert.AreEqual(json["lastTotal"], values[InstrumentationService.Timer
                                                                      .LastTotal]);
            NUnit.Framework.Assert.AreEqual(json["lastOwn"], values[InstrumentationService.Timer
                                                                    .LastOwn]);
            NUnit.Framework.Assert.AreEqual(json["avgTotal"], values[InstrumentationService.Timer
                                                                     .AvgTotal]);
            NUnit.Framework.Assert.AreEqual(json["avgOwn"], values[InstrumentationService.Timer
                                                                   .AvgOwn]);
        }