/// <summary> /// Called when the metric command is changed by "delta" units at time "time" /// via user "user" /// </summary> /// <param name="time">the time of the event</param> /// <param name="command">the metric that is updated, e.g., the operation name</param> /// <param name="user">the user that updated the metric</param> /// <param name="delta">the amount of change in the metric, e.g., +1</param> public virtual void RecordMetric(long time, string command, string user, long delta ) { RollingWindow window = GetRollingWindow(command, user); window.IncAt(time, delta); }
public virtual void TestReorderedAccess() { RollingWindow window = new RollingWindow(WindowLen, BucketCnt); long time = 2 * WindowLen + BucketLen * 3 / 2; window.IncAt(time, 5); time++; NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect the recent update" , 5, window.GetSum(time)); long reorderedTime = time - 2 * BucketLen; window.IncAt(reorderedTime, 6); NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect the reordered update" , 11, window.GetSum(time)); time = reorderedTime + WindowLen; NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect rolling effect" , 5, window.GetSum(time)); }
public virtual void TestBasics() { RollingWindow window = new RollingWindow(WindowLen, BucketCnt); long time = 1; NUnit.Framework.Assert.AreEqual("The initial sum of rolling window must be 0", 0, window.GetSum(time)); time = WindowLen + BucketLen * 3 / 2; NUnit.Framework.Assert.AreEqual("The initial sum of rolling window must be 0", 0, window.GetSum(time)); window.IncAt(time, 5); NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect the recent update" , 5, window.GetSum(time)); time += BucketLen; window.IncAt(time, 6); NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect the recent update" , 11, window.GetSum(time)); time += WindowLen - BucketLen; NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect rolling effect" , 6, window.GetSum(time)); time += BucketLen; NUnit.Framework.Assert.AreEqual("The sum of rolling window does not reflect rolling effect" , 0, window.GetSum(time)); }