mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 11:38:15 +08:00
Feature/automatic routes with sd (#351)
* #340 started looking at supporting automatic routing when using service discovery * #340 getting old routing tests to pass * #340 renamed stuff to provider rather than finder, as its not longer finding anything * #340 working towards supporting dynamic routing * #340 loads of refactoring to make configuration work with dynamic routing * #340 refactor consul config code so the registry class owns it * #340 default to consul to maintain backwards compat * #340 added docs, finished this branches todos
This commit is contained in:
@ -38,14 +38,21 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_add_specifics()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandler",
|
||||
"FakeDelegatingHandlerTwo"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -67,7 +74,14 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_order_specifics_and_globals()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
@ -75,7 +89,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
"FakeDelegatingHandler",
|
||||
"FakeDelegatingHandlerFour"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -97,14 +111,21 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_order_specifics()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandlerTwo",
|
||||
"FakeDelegatingHandler"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -126,13 +147,20 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_order_and_only_add_specifics_in_config()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandler",
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -153,9 +181,16 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_dont_add_specifics()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -175,14 +210,18 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_apply_re_route_specific()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandler",
|
||||
"FakeDelegatingHandlerTwo"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -197,8 +236,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_all_from_all_routes_provider_and_qos()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheQosProviderHouseReturns(new OkResponse<IQoSProvider>(It.IsAny<PollyQoSProvider>())))
|
||||
@ -213,8 +259,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_provider_with_no_delegates()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(false)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheServiceProviderReturnsNothing())
|
||||
@ -226,8 +276,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_provider_with_qos_delegate()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheQosProviderHouseReturns(new OkResponse<IQoSProvider>(It.IsAny<PollyQoSProvider>())))
|
||||
@ -241,8 +298,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_error()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheQosProviderHouseReturns(new ErrorResponse<IQoSProvider>(It.IsAny<Error>())))
|
||||
|
@ -46,10 +46,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_build_http_client()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -63,10 +66,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_log_if_ignoring_ssl_errors()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.WithDangerousAcceptAnyServerCertificateValidator(true)
|
||||
.Build();
|
||||
@ -82,10 +88,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_delegating_handlers_in_order()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -110,10 +119,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_re_use_cookies_from_container()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, true, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -142,10 +154,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
HttpMethod method = new HttpMethod(verb);
|
||||
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
|
@ -47,10 +47,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_request_correctly()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -70,10 +73,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_request_unable_to_complete_request()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -92,10 +98,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void http_client_request_times_out()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().WithTimeoutValue(1).Build())
|
||||
.Build();
|
||||
|
||||
|
@ -31,9 +31,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_no_qos_provider()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithUpstreamHttpMethod(new List<string> { "get" })
|
||||
.WithIsQos(false)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenAReRoute(reRoute))
|
||||
@ -53,7 +56,6 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string> { "get" })
|
||||
.WithIsQos(true)
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
|
@ -25,8 +25,14 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
[Fact]
|
||||
public void should_store_qos_provider_on_first_request()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.Then(x => x.ThenItIsAdded())
|
||||
@ -36,7 +42,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_not_store_qos_provider_on_first_request()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.When(x => x.WhenWeGetTheQoSProvider(reRoute))
|
||||
@ -47,8 +59,21 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_store_qos_providers_by_key()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
var reRouteTwo = new DownstreamReRouteBuilder().WithQosKey("testTwo").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var qosOptionsTwo = new QoSOptionsBuilder()
|
||||
.WithKey("testTwo")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptionsTwo)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.And(x => x.GivenThereIsAQoSProvider(reRouteTwo, new FakePollyQoSProvider()))
|
||||
@ -62,7 +87,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_error_if_no_qos_provider_with_key()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
this.When(x => x.WhenWeGetTheQoSProvider(reRoute))
|
||||
.Then(x => x.ThenAnErrorIsReturned())
|
||||
@ -72,9 +102,24 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_get_new_qos_provider_if_reroute_qos_provider_has_changed()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
var useQoSOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithKey("test")
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder().WithQosKey("test").WithIsQos(true).Build();
|
||||
var dontUseQoSOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(dontUseQoSOptions)
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(useQoSOptions)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.When(x => x.WhenWeGetTheQoSProvider(reRoute))
|
||||
|
Reference in New Issue
Block a user