mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 06:48:16 +08:00
Refactor CircuitBreaker Pattern
Add Qos Config in ReRoute And Refactor CircuitBreakingDelegatingHandler
This commit is contained in:
@ -25,6 +25,7 @@ namespace Ocelot.UnitTests.Request
|
||||
private readonly IRequestCreator _requestCreator;
|
||||
private Response<Ocelot.Request.Request> _result;
|
||||
private Ocelot.RequestId.RequestId _requestId;
|
||||
private Ocelot.Values.QoS _qos;
|
||||
|
||||
public RequestBuilderTests()
|
||||
{
|
||||
@ -37,6 +38,7 @@ namespace Ocelot.UnitTests.Request
|
||||
{
|
||||
this.Given(x => x.GivenIHaveHttpMethod("GET"))
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x=> x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectDownstreamUrlIsUsed("http://www.bbc.co.uk/"))
|
||||
.BDDfy();
|
||||
@ -47,6 +49,8 @@ namespace Ocelot.UnitTests.Request
|
||||
{
|
||||
this.Given(x => x.GivenIHaveHttpMethod("POST"))
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectHttpMethodIsUsed(HttpMethod.Post))
|
||||
.BDDfy();
|
||||
@ -59,7 +63,9 @@ namespace Ocelot.UnitTests.Request
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x => x.GivenIHaveTheHttpContent(new StringContent("Hi from Tom")))
|
||||
.And(x => x.GivenTheContentTypeIs("application/json"))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectContentIsUsed(new StringContent("Hi from Tom")))
|
||||
.BDDfy();
|
||||
}
|
||||
@ -71,6 +77,8 @@ namespace Ocelot.UnitTests.Request
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x => x.GivenIHaveTheHttpContent(new StringContent("Hi from Tom")))
|
||||
.And(x => x.GivenTheContentTypeIs("application/json"))
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectContentHeadersAreUsed(new HeaderDictionary
|
||||
{
|
||||
@ -88,6 +96,8 @@ namespace Ocelot.UnitTests.Request
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x => x.GivenIHaveTheHttpContent(new StringContent("Hi from Tom")))
|
||||
.And(x => x.GivenTheContentTypeIs("application/json; charset=utf-8"))
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectContentHeadersAreUsed(new HeaderDictionary
|
||||
{
|
||||
@ -107,6 +117,8 @@ namespace Ocelot.UnitTests.Request
|
||||
{
|
||||
{"ChopSticks", "Bubbles" }
|
||||
}))
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectHeadersAreUsed(new HeaderDictionary
|
||||
{
|
||||
@ -124,7 +136,8 @@ namespace Ocelot.UnitTests.Request
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x => x.GivenTheHttpHeadersAre(new HeaderDictionary()))
|
||||
.And(x => x.GivenTheRequestIdIs(new Ocelot.RequestId.RequestId("RequestId", requestId)))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectHeadersAreUsed(new HeaderDictionary
|
||||
{
|
||||
{"RequestId", requestId }
|
||||
@ -142,7 +155,8 @@ namespace Ocelot.UnitTests.Request
|
||||
{"RequestId", "534534gv54gv45g" }
|
||||
}))
|
||||
.And(x => x.GivenTheRequestIdIs(new Ocelot.RequestId.RequestId("RequestId", Guid.NewGuid().ToString())))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheCorrectHeadersAreUsed(new HeaderDictionary
|
||||
{
|
||||
{"RequestId", "534534gv54gv45g" }
|
||||
@ -161,7 +175,8 @@ namespace Ocelot.UnitTests.Request
|
||||
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
|
||||
.And(x => x.GivenTheHttpHeadersAre(new HeaderDictionary()))
|
||||
.And(x => x.GivenTheRequestIdIs(new Ocelot.RequestId.RequestId(requestIdKey, requestIdValue)))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.GivenTheQos(new Values.QoS(3, 8, 5000, Polly.Timeout.TimeoutStrategy.Pessimistic)))
|
||||
.When(x => x.WhenICreateARequest())
|
||||
.And(x => x.ThenTheRequestIdIsNotInTheHeaders())
|
||||
.BDDfy();
|
||||
}
|
||||
@ -171,6 +186,11 @@ namespace Ocelot.UnitTests.Request
|
||||
_requestId = requestId;
|
||||
}
|
||||
|
||||
private void GivenTheQos(Ocelot.Values.QoS qos)
|
||||
{
|
||||
_qos = qos;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_use_cookies()
|
||||
{
|
||||
@ -281,7 +301,7 @@ namespace Ocelot.UnitTests.Request
|
||||
private void WhenICreateARequest()
|
||||
{
|
||||
_result = _requestCreator.Build(_httpMethod, _downstreamUrl, _content?.ReadAsStreamAsync().Result, _headers,
|
||||
_cookies, _query, _contentType, _requestId).Result;
|
||||
_cookies, _query, _contentType, _requestId, _qos).Result;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user