Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a method overload to Raven Health check to allow additional R…
…aven Options like array of Urls, certificate etc. - Marked the existing Raven Health check method as `Obsolete`
- Loading branch information
vijayankit
committed
Apr 3, 2019
1 parent
de377b3
commit ee3adfc
Showing
7 changed files
with
289 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace HealthChecks.RavenDB | ||
{ | ||
public class RavenDBOptions | ||
{ | ||
public string[] Urls { get; set; } | ||
|
||
public X509Certificate2 Certificate { get; set; } | ||
|
||
public string Database { get; set; } | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
test/FunctionalTests/HealthChecks.RavenDB/RavenDBWithOptionsHealthCheckTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using FluentAssertions; | ||
using FunctionalTests.Base; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace FunctionalTests.HealthChecks.RavenDB | ||
{ | ||
[Collection("execution")] | ||
public class ravendb_with_options_healthcheck_should | ||
{ | ||
private readonly ExecutionFixture _fixture; | ||
private readonly string[] _urls = new[] {"http://live-test.ravendb.net:80"}; | ||
|
||
public ravendb_with_options_healthcheck_should(ExecutionFixture fixture) | ||
{ | ||
_fixture = fixture ?? throw new ArgumentNullException(nameof(fixture)); | ||
} | ||
|
||
[SkipOnAppVeyor] | ||
public async Task be_healthy_if_ravendb_is_available() | ||
{ | ||
|
||
var webHostBuilder = new WebHostBuilder() | ||
.UseStartup<DefaultStartup>() | ||
.ConfigureServices(services => | ||
{ | ||
services | ||
.AddHealthChecks() | ||
.AddRavenDB(_ => { _.Urls = _urls; }, tags: new string[] {"ravendb"}); | ||
}) | ||
.Configure(app => | ||
{ | ||
app.UseHealthChecks("/health", new HealthCheckOptions() | ||
{ | ||
Predicate = r => r.Tags.Contains("ravendb") | ||
}); | ||
}); | ||
|
||
var server = new TestServer(webHostBuilder); | ||
|
||
var response = await server.CreateRequest($"/health") | ||
.GetAsync(); | ||
|
||
response.StatusCode | ||
.Should().Be(HttpStatusCode.OK); | ||
} | ||
|
||
[SkipOnAppVeyor] | ||
public async Task be_healthy_if_ravendb_is_available_and_contains_specific_database() | ||
{ | ||
var webHostBuilder = new WebHostBuilder() | ||
.UseStartup<DefaultStartup>() | ||
.ConfigureServices(services => | ||
{ | ||
services | ||
.AddHealthChecks() | ||
.AddRavenDB(_ => | ||
{ | ||
_.Urls = _urls; | ||
_.Database = "Demo"; | ||
}, tags: new string[] {"ravendb"}); | ||
}) | ||
.Configure(app => | ||
{ | ||
app.UseHealthChecks("/health", new HealthCheckOptions() | ||
{ | ||
Predicate = r => r.Tags.Contains("ravendb") | ||
}); | ||
}); | ||
|
||
var server = new TestServer(webHostBuilder); | ||
|
||
var response = await server.CreateRequest($"/health") | ||
.GetAsync(); | ||
|
||
response.StatusCode | ||
.Should().Be(HttpStatusCode.OK); | ||
} | ||
|
||
[Fact] | ||
public async Task be_unhealthy_if_ravendb_is_not_available() | ||
{ | ||
var connectionString = "http://localhost:9999"; | ||
|
||
var webHostBuilder = new WebHostBuilder() | ||
.UseStartup<DefaultStartup>() | ||
.ConfigureServices(services => | ||
{ | ||
services | ||
.AddHealthChecks() | ||
.AddRavenDB(_ => { _.Urls = new string[] {connectionString}; }, tags: new string[] {"ravendb"}); | ||
}) | ||
.Configure(app => | ||
{ | ||
app.UseHealthChecks("/health", new HealthCheckOptions() | ||
{ | ||
Predicate = r => r.Tags.Contains("ravendb") | ||
}); | ||
}); | ||
|
||
var server = new TestServer(webHostBuilder); | ||
|
||
var response = await server.CreateRequest($"/health") | ||
.GetAsync(); | ||
|
||
response.StatusCode | ||
.Should().Be(HttpStatusCode.ServiceUnavailable); | ||
} | ||
|
||
[Fact] | ||
public async Task be_unhealthy_if_ravendb_is_available_but_database_doesnot_exist() | ||
{ | ||
var webHostBuilder = new WebHostBuilder() | ||
.UseStartup<DefaultStartup>() | ||
.ConfigureServices(services => | ||
{ | ||
services | ||
.AddHealthChecks() | ||
.AddRavenDB(_ => | ||
{ | ||
_.Urls = _urls; | ||
_.Database = "ThisDatabaseReallyDoesnExist"; | ||
}, tags: new string[] {"ravendb"}); | ||
}) | ||
.Configure(app => | ||
{ | ||
app.UseHealthChecks("/health", new HealthCheckOptions() | ||
{ | ||
Predicate = r => r.Tags.Contains("ravendb") | ||
}); | ||
}); | ||
|
||
var server = new TestServer(webHostBuilder); | ||
|
||
var response = await server.CreateRequest($"/health") | ||
.GetAsync(); | ||
|
||
response.StatusCode | ||
.Should().Be(HttpStatusCode.ServiceUnavailable); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
test/UnitTests/DependencyInjection/RavenDB/RavenWithOptionsUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using FluentAssertions; | ||
using HealthChecks.RavenDB; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Options; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace UnitTests.DependencyInjection.RavenDB | ||
{ | ||
public class ravendb_with_options_registration_should | ||
{ | ||
[Fact] | ||
public void add_health_check_when_properly_configured() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddHealthChecks() | ||
.AddRavenDB(_ => { _.Urls = new[] {"http://localhost:8080", "http://localhost:8081"}; }); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
var options = serviceProvider.GetService<IOptions<HealthCheckServiceOptions>>(); | ||
|
||
var registration = options.Value.Registrations.First(); | ||
var check = registration.Factory(serviceProvider); | ||
|
||
registration.Name.Should().Be("ravendb"); | ||
check.GetType().Should().Be(typeof(RavenDBHealthCheck)); | ||
} | ||
|
||
[Fact] | ||
public void add_named_health_check_when_properly_configured() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddHealthChecks() | ||
.AddRavenDB(_ => { _.Urls = new[] {"http://localhost:8080", "http://localhost:8081"}; }, | ||
name: "my-ravendb"); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
var options = serviceProvider.GetService<IOptions<HealthCheckServiceOptions>>(); | ||
|
||
var registration = options.Value.Registrations.First(); | ||
var check = registration.Factory(serviceProvider); | ||
|
||
registration.Name.Should().Be("my-ravendb"); | ||
check.GetType().Should().Be(typeof(RavenDBHealthCheck)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters