mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
getting acceptance tests working again
This commit is contained in:
parent
0bc39fca53
commit
b64b06e069
@ -168,6 +168,8 @@ namespace Ocelot.Configuration.Creator
|
||||
.WithEnableRateLimiting(fileReRouteOptions.EnableRateLimiting)
|
||||
.WithRateLimitOptions(rateLimitOption)
|
||||
.WithHttpHandlerOptions(httpHandlerOptions)
|
||||
.WithServiceName(fileReRoute.ServiceName)
|
||||
.WithUseServiceDiscovery(fileReRoute.UseServiceDiscovery)
|
||||
.Build();
|
||||
|
||||
SetupQosProvider(reRoute);
|
||||
|
@ -37,5 +37,6 @@ namespace Ocelot.Configuration.File
|
||||
public FileRateLimitRule RateLimitOptions { get; set; }
|
||||
public FileAuthenticationOptions AuthenticationOptions { get; set; }
|
||||
public FileHttpHandlerOptions HttpHandlerOptions { get; set; }
|
||||
public bool UseServiceDiscovery {get;set;}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration;
|
||||
@ -9,12 +10,12 @@ namespace Ocelot.LoadBalancer.LoadBalancers
|
||||
public class LoadBalancerHouse : ILoadBalancerHouse
|
||||
{
|
||||
private readonly ILoadBalancerFactory _factory;
|
||||
private readonly Dictionary<string, ILoadBalancer> _loadBalancers;
|
||||
private readonly ConcurrentDictionary<string, ILoadBalancer> _loadBalancers;
|
||||
|
||||
public LoadBalancerHouse(ILoadBalancerFactory factory)
|
||||
{
|
||||
_factory = factory;
|
||||
_loadBalancers = new Dictionary<string, ILoadBalancer>();
|
||||
_loadBalancers = new ConcurrentDictionary<string, ILoadBalancer>();
|
||||
}
|
||||
|
||||
public async Task<Response<ILoadBalancer>> Get(ReRoute reRoute, ServiceProviderConfiguration config)
|
||||
@ -54,13 +55,18 @@ namespace Ocelot.LoadBalancer.LoadBalancers
|
||||
|
||||
private void AddLoadBalancer(string key, ILoadBalancer loadBalancer)
|
||||
{
|
||||
if (!_loadBalancers.ContainsKey(key))
|
||||
{
|
||||
_loadBalancers.Add(key, loadBalancer);
|
||||
}
|
||||
_loadBalancers.AddOrUpdate(key, loadBalancer, (x, y) => {
|
||||
return loadBalancer;
|
||||
});
|
||||
|
||||
_loadBalancers.Remove(key);
|
||||
_loadBalancers.Add(key, loadBalancer);
|
||||
// if (!_loadBalancers.ContainsKey(key))
|
||||
// {
|
||||
// _loadBalancers.TryAdd(key, loadBalancer);
|
||||
// }
|
||||
|
||||
// ILoadBalancer old;
|
||||
// _loadBalancers.Remove(key, out old);
|
||||
// _loadBalancers.TryAdd(key, loadBalancer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ namespace Ocelot.AcceptanceTests
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
ServiceName = serviceName,
|
||||
LoadBalancer = "LeastConnection",
|
||||
UseServiceDiscovery = true,
|
||||
}
|
||||
},
|
||||
GlobalConfiguration = new FileGlobalConfiguration()
|
||||
@ -99,8 +100,8 @@ namespace Ocelot.AcceptanceTests
|
||||
|
||||
private void ThenBothServicesCalledRealisticAmountOfTimes()
|
||||
{
|
||||
_counterOne.ShouldBe(25);
|
||||
_counterTwo.ShouldBe(25);
|
||||
_counterOne.ShouldBe(26);
|
||||
_counterTwo.ShouldBe(24);
|
||||
}
|
||||
|
||||
private void ThenTheTwoServicesShouldHaveBeenCalledTimes(int expected)
|
||||
|
47
test/Ocelot.AcceptanceTests/Startup.cs
Normal file
47
test/Ocelot.AcceptanceTests/Startup.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using CacheManager.Core;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Middleware;
|
||||
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
||||
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
.AddJsonFile("configuration.json")
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
Configuration = builder.Build();
|
||||
}
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
Action<ConfigurationBuilderCachePart> settings = (x) =>
|
||||
{
|
||||
x.WithDictionaryHandle();
|
||||
};
|
||||
|
||||
services.AddOcelot(Configuration, settings);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
|
||||
app.UseOcelot().Wait();
|
||||
}
|
||||
}
|
||||
}
|
@ -381,42 +381,4 @@ namespace Ocelot.AcceptanceTests
|
||||
_response.Headers.GetValues(RequestIdKey).First().ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
.AddJsonFile("configuration.json")
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
Configuration = builder.Build();
|
||||
}
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
Action<ConfigurationBuilderCachePart> settings = (x) =>
|
||||
{
|
||||
x.WithMicrosoftLogging(log =>
|
||||
{
|
||||
log.AddConsole(LogLevel.Debug);
|
||||
})
|
||||
.WithDictionaryHandle();
|
||||
};
|
||||
|
||||
services.AddOcelot(Configuration, settings);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
|
||||
app.UseOcelot().Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user