Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from ThreeMammals/feature/rename-providers-so-c…
Browse files Browse the repository at this point in the history
…an-reflect-in-ocelot

#580 renamed classes so can reflect on them in ocelot
  • Loading branch information
TomPallister authored Aug 29, 2018
2 parents bed7cc7 + 1c9f8b5 commit c0c3bd7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
using ServiceDiscovery.Providers;
using Values;

public class ConsulServiceDiscoveryProvider : IServiceDiscoveryProvider

public class Consul : IServiceDiscoveryProvider
{
private readonly ConsulRegistryConfiguration _config;
private readonly IOcelotLogger _logger;
private readonly IConsulClient _consul;
private const string VersionPrefix = "version-";

public ConsulServiceDiscoveryProvider(ConsulRegistryConfiguration config, IOcelotLoggerFactory factory, IConsulClientFactory clientFactory)
public Consul(ConsulRegistryConfiguration config, IOcelotLoggerFactory factory, IConsulClientFactory clientFactory)
{
_logger = factory.CreateLogger<ConsulServiceDiscoveryProvider>();
_logger = factory.CreateLogger<Consul>();
_config = config;
_consul = clientFactory.Get(_config);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ocelot.Provider.Consul/ConsulProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public static class ConsulProviderFactory

var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Host, config.Port, name, config.Token);

var consulServiceDiscoveryProvider = new ConsulServiceDiscoveryProvider(consulRegistryConfiguration, factory, consulFactory);
var consulServiceDiscoveryProvider = new Consul(consulRegistryConfiguration, factory, consulFactory);

if (config.Type?.ToLower() == "pollconsul")
{
return new PollingConsulServiceDiscoveryProvider(config.PollingInterval, factory, consulServiceDiscoveryProvider);
return new PollConsul(config.PollingInterval, factory, consulServiceDiscoveryProvider);
}

return consulServiceDiscoveryProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
using ServiceDiscovery.Providers;
using Values;

public class PollingConsulServiceDiscoveryProvider : IServiceDiscoveryProvider
public class PollConsul : IServiceDiscoveryProvider
{
private readonly IOcelotLogger _logger;
private readonly IServiceDiscoveryProvider _consulServiceDiscoveryProvider;
private readonly Timer _timer;
private bool _polling;
private List<Service> _services;

public PollingConsulServiceDiscoveryProvider(int pollingInterval, IOcelotLoggerFactory factory, IServiceDiscoveryProvider consulServiceDiscoveryProvider)
public PollConsul(int pollingInterval, IOcelotLoggerFactory factory, IServiceDiscoveryProvider consulServiceDiscoveryProvider)
{
_logger = factory.CreateLogger<PollingConsulServiceDiscoveryProvider>();
_logger = factory.CreateLogger<PollConsul>();
_consulServiceDiscoveryProvider = consulServiceDiscoveryProvider;
_services = new List<Service>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ConsulServiceDiscoveryProviderTests : IDisposable
{
private IWebHost _fakeConsulBuilder;
private readonly List<ServiceEntry> _serviceEntries;
private ConsulServiceDiscoveryProvider _provider;
private Consul _provider;
private readonly string _serviceName;
private readonly int _port;
private readonly string _consulHost;
Expand All @@ -40,10 +40,10 @@ public ConsulServiceDiscoveryProviderTests()
_factory = new Mock<IOcelotLoggerFactory>();
_clientFactory = new ConsulClientFactory();
_logger = new Mock<IOcelotLogger>();
_factory.Setup(x => x.CreateLogger<ConsulServiceDiscoveryProvider>()).Returns(_logger.Object);
_factory.Setup(x => x.CreateLogger<PollingConsulServiceDiscoveryProvider>()).Returns(_logger.Object);
_factory.Setup(x => x.CreateLogger<Consul>()).Returns(_logger.Object);
_factory.Setup(x => x.CreateLogger<PollConsul>()).Returns(_logger.Object);
var config = new ConsulRegistryConfiguration(_consulHost, _port, _serviceName, null);
_provider = new ConsulServiceDiscoveryProvider(config, _factory.Object, _clientFactory);
_provider = new Consul(config, _factory.Object, _clientFactory);
}

[Fact]
Expand Down Expand Up @@ -73,7 +73,7 @@ public void should_use_token()
{
var token = "test token";
var config = new ConsulRegistryConfiguration(_consulHost, _port, _serviceName, token);
_provider = new ConsulServiceDiscoveryProvider(config, _factory.Object, _clientFactory);
_provider = new Consul(config, _factory.Object, _clientFactory);

var serviceEntryOne = new ServiceEntry()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class PollingConsulServiceDiscoveryProviderTests
{
private readonly int _delay;
private PollingConsulServiceDiscoveryProvider _provider;
private PollConsul _provider;
private readonly List<Service> _services;
private readonly Mock<IOcelotLoggerFactory> _factory;
private readonly Mock<IOcelotLogger> _logger;
Expand All @@ -27,7 +27,7 @@ public PollingConsulServiceDiscoveryProviderTests()
_delay = 1;
_factory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_factory.Setup(x => x.CreateLogger<PollingConsulServiceDiscoveryProvider>()).Returns(_logger.Object);
_factory.Setup(x => x.CreateLogger<PollConsul>()).Returns(_logger.Object);
_consulServiceDiscoveryProvider = new Mock<IServiceDiscoveryProvider>();
}

Expand Down Expand Up @@ -55,7 +55,7 @@ private void ThenTheCountIs(int count)

private void WhenIGetTheServices(int expected)
{
_provider = new PollingConsulServiceDiscoveryProvider(_delay, _factory.Object, _consulServiceDiscoveryProvider.Object);
_provider = new PollConsul(_delay, _factory.Object, _consulServiceDiscoveryProvider.Object);

var result = Wait.WaitFor(3000).Until(() => {
try
Expand Down
8 changes: 4 additions & 4 deletions test/Ocelot.Provider.Consul.UnitTests/ProviderFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public ProviderFactoryTests()
var services = new ServiceCollection();
var loggerFactory = new Mock<IOcelotLoggerFactory>();
var logger = new Mock<IOcelotLogger>();
loggerFactory.Setup(x => x.CreateLogger<ConsulServiceDiscoveryProvider>()).Returns(logger.Object);
loggerFactory.Setup(x => x.CreateLogger<PollingConsulServiceDiscoveryProvider>()).Returns(logger.Object);
loggerFactory.Setup(x => x.CreateLogger<Consul>()).Returns(logger.Object);
loggerFactory.Setup(x => x.CreateLogger<PollConsul>()).Returns(logger.Object);
var consulFactory = new Mock<IConsulClientFactory>();
services.AddSingleton<IConsulClientFactory>(consulFactory.Object);
services.AddSingleton<IOcelotLoggerFactory>(loggerFactory.Object);
Expand All @@ -29,15 +29,15 @@ public ProviderFactoryTests()
public void should_return_ConsulServiceDiscoveryProvider()
{
var provider = ConsulProviderFactory.Get(_provider, new ServiceProviderConfiguration("", "", 1, "", "", 1), "");
provider.ShouldBeOfType<ConsulServiceDiscoveryProvider>();
provider.ShouldBeOfType<Consul>();
}

[Fact]
public void should_return_PollingConsulServiceDiscoveryProvider()
{
var stopsPollerFromPolling = 10000;
var provider = ConsulProviderFactory.Get(_provider, new ServiceProviderConfiguration("pollconsul", "", 1, "", "", stopsPollerFromPolling), "");
provider.ShouldBeOfType<PollingConsulServiceDiscoveryProvider>();
provider.ShouldBeOfType<PollConsul>();
}
}
}

0 comments on commit c0c3bd7

Please sign in to comment.