public void only_cache_up_to_the_setting_limit() { var settings = new DiagnosticsSettings { MaxRequests = 10 }; var cache = new RequestHistoryCache(settings); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.RecentReports().Count().ShouldEqual(9); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.Store(new RequestLog()); cache.RecentReports().Count().ShouldEqual(settings.MaxRequests); }
public void only_keeps_50_records() { var history = new RequestHistoryCache(); for (int i = 0; i < 60; i++) { history.AddReport(new DebugReport()); } history.RecentReports().ShouldHaveCount(50); }
public void keep_the_newest_reports() { var history = new RequestHistoryCache(); for (int i = 0; i < 50; i++) { history.AddReport(new DebugReport()); } var report1 = new DebugReport(); var report2 = new DebugReport(); var report3 = new DebugReport(); history.AddReport(report1); history.AddReport(report2); history.AddReport(report3); history.RecentReports().Take(3).ShouldHaveTheSameElementsAs(report3, report2, report1); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, SameNodeCache sameNodeList, RequestHistoryCache requestHistoryList) { // Enable Request.Body read several times from middleware and controllers // app.Use(async(context, next) => { context.Request.EnableBuffering(); await next(); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // API Authentication // app.ConfigureApiAuthenticationHandler(); // Same Node handler // Always define it before any other middleware that needs the selected "NodeHost". // var roundRobin = new RoundRobin(nodes); app.ConfigureSameNodeHandler(sameNodeList, roundRobin); // Tracks requests in temporary memory // app.ConfigureRequestHistoryTracker(requestHistoryList); // Proxy of WebSocket connections // app.UseWebSockets(); app.UseWhen( context => context.WebSockets.IsWebSocketRequest, appInner => { appInner.UseWebSocketProxy( context => { return(new Uri("ws://" + context.Items["NodeHost"] + ":9944/")); }, options => options.AddXForwardedHeaders()); }); // Proxy of HTTP connections // app.UseWhen( context => !context.WebSockets.IsWebSocketRequest, appInner => appInner.RunProxy(async contextInner => { var response = await contextInner .ForwardTo("http://" + contextInner.Items["NodeHost"] + ":9933/") .CopyXForwardedHeaders() .AddXForwardedHeaders() .Send(); if (!response.IsSuccessStatusCode) { Console.WriteLine("### Exception: " + response.StatusCode.ToString()); } return(response); })); }