mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 18:22:49 +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)
|
.WithEnableRateLimiting(fileReRouteOptions.EnableRateLimiting)
|
||||||
.WithRateLimitOptions(rateLimitOption)
|
.WithRateLimitOptions(rateLimitOption)
|
||||||
.WithHttpHandlerOptions(httpHandlerOptions)
|
.WithHttpHandlerOptions(httpHandlerOptions)
|
||||||
|
.WithServiceName(fileReRoute.ServiceName)
|
||||||
|
.WithUseServiceDiscovery(fileReRoute.UseServiceDiscovery)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
SetupQosProvider(reRoute);
|
SetupQosProvider(reRoute);
|
||||||
|
@ -37,5 +37,6 @@ namespace Ocelot.Configuration.File
|
|||||||
public FileRateLimitRule RateLimitOptions { get; set; }
|
public FileRateLimitRule RateLimitOptions { get; set; }
|
||||||
public FileAuthenticationOptions AuthenticationOptions { get; set; }
|
public FileAuthenticationOptions AuthenticationOptions { get; set; }
|
||||||
public FileHttpHandlerOptions HttpHandlerOptions { get; set; }
|
public FileHttpHandlerOptions HttpHandlerOptions { get; set; }
|
||||||
|
public bool UseServiceDiscovery {get;set;}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ocelot.Configuration;
|
using Ocelot.Configuration;
|
||||||
@ -9,12 +10,12 @@ namespace Ocelot.LoadBalancer.LoadBalancers
|
|||||||
public class LoadBalancerHouse : ILoadBalancerHouse
|
public class LoadBalancerHouse : ILoadBalancerHouse
|
||||||
{
|
{
|
||||||
private readonly ILoadBalancerFactory _factory;
|
private readonly ILoadBalancerFactory _factory;
|
||||||
private readonly Dictionary<string, ILoadBalancer> _loadBalancers;
|
private readonly ConcurrentDictionary<string, ILoadBalancer> _loadBalancers;
|
||||||
|
|
||||||
public LoadBalancerHouse(ILoadBalancerFactory factory)
|
public LoadBalancerHouse(ILoadBalancerFactory factory)
|
||||||
{
|
{
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
_loadBalancers = new Dictionary<string, ILoadBalancer>();
|
_loadBalancers = new ConcurrentDictionary<string, ILoadBalancer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Response<ILoadBalancer>> Get(ReRoute reRoute, ServiceProviderConfiguration config)
|
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)
|
private void AddLoadBalancer(string key, ILoadBalancer loadBalancer)
|
||||||
{
|
{
|
||||||
if (!_loadBalancers.ContainsKey(key))
|
_loadBalancers.AddOrUpdate(key, loadBalancer, (x, y) => {
|
||||||
{
|
return loadBalancer;
|
||||||
_loadBalancers.Add(key, loadBalancer);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
_loadBalancers.Remove(key);
|
// if (!_loadBalancers.ContainsKey(key))
|
||||||
_loadBalancers.Add(key, loadBalancer);
|
// {
|
||||||
|
// _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" },
|
UpstreamHttpMethod = new List<string> { "Get" },
|
||||||
ServiceName = serviceName,
|
ServiceName = serviceName,
|
||||||
LoadBalancer = "LeastConnection",
|
LoadBalancer = "LeastConnection",
|
||||||
|
UseServiceDiscovery = true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GlobalConfiguration = new FileGlobalConfiguration()
|
GlobalConfiguration = new FileGlobalConfiguration()
|
||||||
@ -99,8 +100,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void ThenBothServicesCalledRealisticAmountOfTimes()
|
private void ThenBothServicesCalledRealisticAmountOfTimes()
|
||||||
{
|
{
|
||||||
_counterOne.ShouldBe(25);
|
_counterOne.ShouldBe(26);
|
||||||
_counterTwo.ShouldBe(25);
|
_counterTwo.ShouldBe(24);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThenTheTwoServicesShouldHaveBeenCalledTimes(int expected)
|
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);
|
_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