Skip to content

Commit

Permalink
removed tasks we dont need
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPallister committed Apr 13, 2020
1 parent ccb5b84 commit 2843cdb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
{
using Ocelot.Configuration;
using Ocelot.Responses;
using System.Threading.Tasks;

public interface ILoadBalancerFactory
{
Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config);
Response<ILoadBalancer> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config);
}
}
3 changes: 1 addition & 2 deletions src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerHouse.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Ocelot.Configuration;
using Ocelot.Responses;
using System.Threading.Tasks;

namespace Ocelot.LoadBalancer.LoadBalancers
{
public interface ILoadBalancerHouse
{
Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config);
Response<ILoadBalancer> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config);
}
}
4 changes: 2 additions & 2 deletions src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public LoadBalancerFactory(IServiceDiscoveryProviderFactory serviceProviderFacto
_loadBalancerCreators = loadBalancerCreators;
}

public Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config)
public Response<ILoadBalancer> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config)
{
var serviceProviderFactoryResponse = _serviceProviderFactory.Get(config, reRoute);

Expand All @@ -36,7 +36,7 @@ public Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, ServiceProvi
response = new OkResponse<ILoadBalancer>(createdLoadBalancer);
}

return Task.FromResult(response);
return response;
}
}
}
9 changes: 4 additions & 5 deletions src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerHouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Ocelot.LoadBalancer.LoadBalancers
{
Expand All @@ -18,7 +17,7 @@ public LoadBalancerHouse(ILoadBalancerFactory factory)
_loadBalancers = new ConcurrentDictionary<string, ILoadBalancer>();
}

public async Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config)
public Response<ILoadBalancer> Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config)
{
try
{
Expand All @@ -30,7 +29,7 @@ public async Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, Servic

if (reRoute.LoadBalancerOptions.Type != loadBalancer.GetType().Name)
{
result = await _factory.Get(reRoute, config);
result = _factory.Get(reRoute, config);
if (result.IsError)
{
return new ErrorResponse<ILoadBalancer>(result.Errors);
Expand All @@ -43,7 +42,7 @@ public async Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, Servic
return new OkResponse<ILoadBalancer>(loadBalancer);
}

result = await _factory.Get(reRoute, config);
result = _factory.Get(reRoute, config);

if (result.IsError)
{
Expand All @@ -58,7 +57,7 @@ public async Task<Response<ILoadBalancer>> Get(DownstreamReRoute reRoute, Servic
{
return new ErrorResponse<ILoadBalancer>(new List<Ocelot.Errors.Error>()
{
new UnableToFindLoadBalancerError($"unabe to find load balancer for {reRoute.LoadBalancerKey} exception is {ex}")
new UnableToFindLoadBalancerError($"unabe to find load balancer for {reRoute.LoadBalancerKey} exception is {ex}"),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LoadBalancingMiddleware(OcelotRequestDelegate next,

public async Task Invoke(DownstreamContext context)
{
var loadBalancer = await _loadBalancerHouse.Get(context.DownstreamReRoute, context.Configuration.ServiceProviderConfiguration);
var loadBalancer = _loadBalancerHouse.Get(context.DownstreamReRoute, context.Configuration.ServiceProviderConfiguration);
if (loadBalancer.IsError)
{
Logger.LogDebug("there was an error retriving the loadbalancer, setting pipeline error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void GivenAReRoute(DownstreamReRoute reRoute)

private void WhenIGetTheLoadBalancer()
{
_result = _factory.Get(_reRoute, _serviceProviderConfig).Result;
_result = _factory.Get(_reRoute, _serviceProviderConfig);
}

private void ThenTheLoadBalancerIsReturned<T>()
Expand Down
10 changes: 5 additions & 5 deletions test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void should_get_new_load_balancer_if_reroute_load_balancer_has_changed()
private void WhenIGetTheReRouteWithTheSameKeyButDifferentLoadBalancer(DownstreamReRoute reRoute)
{
_reRoute = reRoute;
_factory.Setup(x => x.Get(_reRoute, _serviceProviderConfig)).ReturnsAsync(new OkResponse<ILoadBalancer>(new LeastConnection(null, null)));
_getResult = _loadBalancerHouse.Get(_reRoute, _serviceProviderConfig).Result;
_factory.Setup(x => x.Get(_reRoute, _serviceProviderConfig)).Returns(new OkResponse<ILoadBalancer>(new LeastConnection(null, null)));
_getResult = _loadBalancerHouse.Get(_reRoute, _serviceProviderConfig);
}

private void ThenAnErrorIsReturned()
Expand All @@ -138,13 +138,13 @@ private void GivenThereIsALoadBalancer(DownstreamReRoute reRoute, ILoadBalancer
{
_reRoute = reRoute;
_loadBalancer = loadBalancer;
_factory.Setup(x => x.Get(_reRoute, _serviceProviderConfig)).ReturnsAsync(new OkResponse<ILoadBalancer>(loadBalancer));
_getResult = _loadBalancerHouse.Get(reRoute, _serviceProviderConfig).Result;
_factory.Setup(x => x.Get(_reRoute, _serviceProviderConfig)).Returns(new OkResponse<ILoadBalancer>(loadBalancer));
_getResult = _loadBalancerHouse.Get(reRoute, _serviceProviderConfig);
}

private void WhenWeGetTheLoadBalancer(DownstreamReRoute reRoute)
{
_getResult = _loadBalancerHouse.Get(reRoute, _serviceProviderConfig).Result;
_getResult = _loadBalancerHouse.Get(reRoute, _serviceProviderConfig);
}

private void ThenItIsReturned()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void GivenTheLoadBalancerHouseReturns()
{
_loadBalancerHouse
.Setup(x => x.Get(It.IsAny<DownstreamReRoute>(), It.IsAny<ServiceProviderConfiguration>()))
.ReturnsAsync(new OkResponse<ILoadBalancer>(_loadBalancer.Object));
.Returns(new OkResponse<ILoadBalancer>(_loadBalancer.Object));
}

private void GivenTheLoadBalancerHouseReturnsAnError()
Expand All @@ -194,7 +194,7 @@ private void GivenTheLoadBalancerHouseReturnsAnError()

_loadBalancerHouse
.Setup(x => x.Get(It.IsAny<DownstreamReRoute>(), It.IsAny<ServiceProviderConfiguration>()))
.ReturnsAsync(_getLoadBalancerHouseError);
.Returns(_getLoadBalancerHouseError);
}

private void ThenAnErrorStatingLoadBalancerCouldNotBeFoundIsSetOnPipeline()
Expand Down

0 comments on commit 2843cdb

Please sign in to comment.