private static async Task DoLeakyBucketWait(AlgorithmCheckResult checkResult) { // Simulation leaky bucket algorithm queuing mechanism var wait = checkResult.RuleCheckResults.Max(d => d.Wait); if (wait > 0) { await Task.Delay((int)wait).ConfigureAwait(false); } }
public void TestInitialize() { List <RuleCheckResult> results = new List <RuleCheckResult>(); var checks = GetRuleCheckResults(); foreach (var c in checks) { results.Add(c); } result = new AlgorithmCheckResult(results); _countValue1 = 0; _countValue2 = 0; }
private async Task DoOnAfterUntriggeredDoNext(HttpContext context, AlgorithmCheckResult checkResult) { if (_interceptor != null) { if (_interceptor.OnAfterUntriggeredDoNextAsync != null) { await _interceptor.OnAfterUntriggeredDoNextAsync(context, checkResult).ConfigureAwait(false); } else if (_interceptor.OnAfterUntriggeredDoNext != null) { _interceptor.OnAfterUntriggeredDoNext(context, checkResult); } } }
private async Task <string> BuildHttpContent(HttpContext context, AlgorithmCheckResult checkResult) { string content = null; if (_error.BuildHttpContentAsync != null) { content = await _error.BuildHttpContentAsync(context, checkResult).ConfigureAwait(false); } else if (_error.BuildHttpContent != null) { content = _error.BuildHttpContent(context, checkResult); } return(content); }
/// <summary> /// Вывод результата проверки корректности опеределения алгоритма /// <seealso cref="AlgorithmCheckResult"/> /// </summary> /// <param name="algorithmPath">Путь к разархивированной папке определения алгоритма</param> private static void CheckAlgorithm(string algorithmPath) { if (algorithmPath == null) { throw new ArgumentNullException(nameof(algorithmPath)); } var valid = false; try { ValidateAlgorithm(algorithmPath); valid = true; } catch (Exception) { } var check = new AlgorithmCheckResult { ValidAlgorithm = valid }; Console.WriteLine(JsonConvert.SerializeObject(check)); }
public async Task TestAsync(string storageType) { var processor = GetAlgorithm(storageType, TimeSpan.FromSeconds(6), TimeSpan.FromSeconds(1), lockSeconds: 0); for (int i = 1; i <= 15; i++) { int j = 3; if (i == 7 || i == 10) { j = 6; } AlgorithmCheckResult checkResult = null; for (int k = 0; k < j; k++) { checkResult = await processor.CheckAsync(new SimulationRequest() { RequestId = Guid.NewGuid().ToString(), RequestResource = "home", Parameters = new Dictionary <string, string>() { { "from", "sample" }, } }); Debug.WriteLine(DateTimeOffset.Now.ToString("HH:mm:ss.fff")); } Debug.WriteLine("for " + i + "," + checkResult.RuleCheckResults.First().Count); if (i == 7 || i == 10) { Assert.AreEqual(true, checkResult.IsLimit); } else { Assert.AreEqual(false, checkResult.IsLimit); } await Task.Delay(1000); } }
private async Task <Dictionary <string, StringValues> > BuildHttpHeaders(HttpContext context, AlgorithmCheckResult checkResult) { Dictionary <string, StringValues> headers = null; if (_error.BuildHttpHeadersAsync != null) { headers = await _error.BuildHttpHeadersAsync(context, checkResult).ConfigureAwait(false); } else if (_error.BuildHttpHeaders != null) { headers = _error.BuildHttpHeaders(context, checkResult); } return(headers); }