Remove Ocelot specific Middleware to make Ocelot more compatible with kestrel middleware and get ready for YARP

This commit is contained in:
Tom Pallister
2020-05-23 15:48:51 +01:00
committed by GitHub
parent 99a15d8668
commit fe3e8bd23a
214 changed files with 9574 additions and 9919 deletions

View File

@ -19,11 +19,11 @@ namespace Ocelot.UnitTests.LoadBalancer
private LeastConnection _leastConnection;
private List<Service> _services;
private Random _random;
private DownstreamContext _context;
private HttpContext _httpContext;
public LeastConnectionTests()
{
_context = new DownstreamContext(new DefaultHttpContext());
_httpContext = new DefaultHttpContext();
_random = new Random();
}
@ -64,9 +64,9 @@ namespace Ocelot.UnitTests.LoadBalancer
_leastConnection = new LeastConnection(() => Task.FromResult(availableServices), serviceName);
var hostAndPortOne = _leastConnection.Lease(_context).Result;
var hostAndPortOne = _leastConnection.Lease(_httpContext).Result;
hostAndPortOne.Data.DownstreamHost.ShouldBe("127.0.0.1");
var hostAndPortTwo = _leastConnection.Lease(_context).Result;
var hostAndPortTwo = _leastConnection.Lease(_httpContext).Result;
hostAndPortTwo.Data.DownstreamHost.ShouldBe("127.0.0.2");
_leastConnection.Release(hostAndPortOne.Data);
_leastConnection.Release(hostAndPortTwo.Data);
@ -76,9 +76,9 @@ namespace Ocelot.UnitTests.LoadBalancer
new Service(serviceName, new ServiceHostAndPort("127.0.0.1", 80), string.Empty, string.Empty, new string[0]),
};
hostAndPortOne = _leastConnection.Lease(_context).Result;
hostAndPortOne = _leastConnection.Lease(_httpContext).Result;
hostAndPortOne.Data.DownstreamHost.ShouldBe("127.0.0.1");
hostAndPortTwo = _leastConnection.Lease(_context).Result;
hostAndPortTwo = _leastConnection.Lease(_httpContext).Result;
hostAndPortTwo.Data.DownstreamHost.ShouldBe("127.0.0.1");
_leastConnection.Release(hostAndPortOne.Data);
_leastConnection.Release(hostAndPortTwo.Data);
@ -89,9 +89,9 @@ namespace Ocelot.UnitTests.LoadBalancer
new Service(serviceName, new ServiceHostAndPort("127.0.0.2", 80), string.Empty, string.Empty, new string[0]),
};
hostAndPortOne = _leastConnection.Lease(_context).Result;
hostAndPortOne = _leastConnection.Lease(_httpContext).Result;
hostAndPortOne.Data.DownstreamHost.ShouldBe("127.0.0.1");
hostAndPortTwo = _leastConnection.Lease(_context).Result;
hostAndPortTwo = _leastConnection.Lease( _httpContext).Result;
hostAndPortTwo.Data.DownstreamHost.ShouldBe("127.0.0.2");
_leastConnection.Release(hostAndPortOne.Data);
_leastConnection.Release(hostAndPortTwo.Data);
@ -99,7 +99,7 @@ namespace Ocelot.UnitTests.LoadBalancer
private async Task LeaseDelayAndRelease()
{
var hostAndPort = await _leastConnection.Lease(_context);
var hostAndPort = await _leastConnection.Lease(_httpContext);
await Task.Delay(_random.Next(1, 100));
_leastConnection.Release(hostAndPort.Data);
}
@ -138,15 +138,15 @@ namespace Ocelot.UnitTests.LoadBalancer
_services = availableServices;
_leastConnection = new LeastConnection(() => Task.FromResult(_services), serviceName);
var response = _leastConnection.Lease(_context).Result;
var response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[0].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[1].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[2].HostAndPort.DownstreamHost);
}
@ -165,19 +165,19 @@ namespace Ocelot.UnitTests.LoadBalancer
_services = availableServices;
_leastConnection = new LeastConnection(() => Task.FromResult(_services), serviceName);
var response = _leastConnection.Lease(_context).Result;
var response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[0].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[1].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[0].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[1].HostAndPort.DownstreamHost);
}
@ -196,26 +196,26 @@ namespace Ocelot.UnitTests.LoadBalancer
_services = availableServices;
_leastConnection = new LeastConnection(() => Task.FromResult(_services), serviceName);
var response = _leastConnection.Lease(_context).Result;
var response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[0].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[1].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[0].HostAndPort.DownstreamHost);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[1].HostAndPort.DownstreamHost);
//release this so 2 should have 1 connection and we should get 2 back as our next host and port
_leastConnection.Release(availableServices[1].HostAndPort);
response = _leastConnection.Lease(_context).Result;
response = _leastConnection.Lease(_httpContext).Result;
response.Data.DownstreamHost.ShouldBe(availableServices[1].HostAndPort.DownstreamHost);
}
@ -276,7 +276,7 @@ namespace Ocelot.UnitTests.LoadBalancer
private void WhenIGetTheNextHostAndPort()
{
_result = _leastConnection.Lease(_context).Result;
_result = _leastConnection.Lease(_httpContext).Result;
}
private void ThenTheNextHostAndPortIsReturned()