public void FactorLessThanZeroTest() { var initDic = new Dictionary <byte, int[]> { { (byte)FeedbackName.PeerCount, new[] { 0, 104, 0, 1, 209, 104, 2, 314, 209, 3, 419, 314, 4, 524, 419, 5, 629, 524, 6, 734, 629, 7, 838, 734, 8, 943, 838, 9, int.MaxValue, 943 } } }; var prediction = new LoadPrediction(10, initDic); var loadStatsCollector = new LoadStatsCollector(0.8f); Dictionary <byte, int[]> updatedLevels; loadStatsCollector.UpdatePrediction(204, FeedbackLevel.Lowest, out updatedLevels); if (updatedLevels != null && updatedLevels.Count > 0) { prediction.UpdatePredictionLevels(updatedLevels); updatedLevels.Clear(); } Assert.That(prediction.Output == FeedbackLevel.Lowest); prediction.SetPeerCount(185); Assert.That(prediction.Output == FeedbackLevel.Level1); prediction.SetPeerCount(183); Assert.That(prediction.Output == FeedbackLevel.Lowest); prediction.SetPeerCount(300); Assert.That(prediction.Output == FeedbackLevel.Level2); loadStatsCollector.UpdatePrediction(199, FeedbackLevel.Level2, out updatedLevels); if (updatedLevels != null && updatedLevels.Count > 0) { prediction.UpdatePredictionLevels(updatedLevels); updatedLevels.Clear(); } prediction.SetPeerCount(200); Assert.That(prediction.Output == FeedbackLevel.Level1); prediction.SetPeerCount(202); Assert.That(prediction.Output == FeedbackLevel.Level2); }
//[Test] //public void ReloadingPredictionDataTest() //{ // var configFile = Path.Combine(Environment.CurrentDirectory, "Prediction.config"); // try // { // File.Copy(configFile, configFile + ".bak", true); // var collector = new LoadStatsCollector(Environment.CurrentDirectory, "Prediction.config"); // var thresholds = collector.GetControllersThresholds(); // TestBody(collector, new LoadPrediction((int)FeedbackLevel.LEVELS_COUNT, thresholds));// some updates to values should happen // collector.SaveToFile(); // var prediction = new LoadPrediction(Environment.CurrentDirectory, "Prediction.config"); // prediction.SetPeerCount(199); // Assert.That(prediction.Output == FeedbackLevel.Level1); // prediction.SetPeerCount(200); // Assert.That(prediction.Output == FeedbackLevel.Level2); // prediction.SetPeerCount(150); // Assert.That(prediction.Output == FeedbackLevel.Level1); // prediction.SetPeerCount(50); // Assert.That(prediction.Output, Is.EqualTo(FeedbackLevel.Lowest)); // } // finally // { // File.Copy(configFile + ".bak", configFile, true); // File.Delete(configFile + ".bak"); // } //} private static void TestBody(LoadStatsCollector loadStatsCollector, LoadPrediction predictor) { Assert.That(predictor.Output == FeedbackLevel.Lowest); predictor.SetPeerCount(100); Assert.That(predictor.Output == FeedbackLevel.Lowest); Dictionary <byte, int[]> updatedLevels; loadStatsCollector.UpdatePrediction(100, FeedbackLevel.Lowest, out updatedLevels); if (updatedLevels != null && updatedLevels.Count > 0) { predictor.UpdatePredictionLevels(updatedLevels); updatedLevels.Clear(); } Assert.That(predictor.Output == FeedbackLevel.Lowest); predictor.SetPeerCount(200); Assert.That(predictor.Output == FeedbackLevel.Level1); loadStatsCollector.UpdatePrediction(200, FeedbackLevel.Lowest, out updatedLevels); if (updatedLevels != null && updatedLevels.Count > 0) { predictor.UpdatePredictionLevels(updatedLevels); updatedLevels.Clear(); } Assert.That(predictor.Output == FeedbackLevel.Lowest); loadStatsCollector.UpdatePrediction(200, FeedbackLevel.Level2, out updatedLevels); if (updatedLevels != null && updatedLevels.Count > 0) { predictor.UpdatePredictionLevels(updatedLevels); updatedLevels.Clear(); } Assert.That(predictor.Output, Is.EqualTo(FeedbackLevel.Level2)); predictor.SetPeerCount(198); Assert.That(predictor.Output, Is.EqualTo(FeedbackLevel.Level1)); }