diff --git a/.gitignore b/.gitignore index d0021ff..1696146 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ protos *.sln.DotSettings.user output +.vs diff --git a/src/Qdrant.Client/QdrantClient.cs b/src/Qdrant.Client/QdrantClient.cs index 862ac33..c729f57 100644 --- a/src/Qdrant.Client/QdrantClient.cs +++ b/src/Qdrant.Client/QdrantClient.cs @@ -1,5 +1,6 @@ using System.Runtime.InteropServices; using Google.Protobuf.Collections; +using Grpc.Core; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Qdrant.Client.Grpc; @@ -93,7 +94,6 @@ private QdrantClient( _collectionsClient = grpcClient.Collections; _pointsClient = grpcClient.Points; _snapshotsClient = grpcClient.Snapshots; - _grpcTimeout = grpcTimeout; _logger = loggerFactory?.CreateLogger("Qdrant.Client") ?? NullLogger.Instance; } @@ -4288,6 +4288,21 @@ public async Task DeleteShardKeyAsync( #endregion Cluster management + /// + /// Asynchronously checks the health of the Qdrant service. + /// + /// The token to monitor for cancellation requests. The default value is . + /// + /// A task that represents the asynchronous operation. The task result contains + /// a indicating the health status of the Qdrant service. + /// + /// occurs when server is unavailable + public async Task HealthAsync(CancellationToken cancellationToken = default) => + await _grpcClient.Qdrant.HealthCheckAsync( + new HealthCheckRequest(), + deadline: _grpcTimeout == default ? null : DateTime.UtcNow.Add(_grpcTimeout), + cancellationToken: cancellationToken).ConfigureAwait(false); + private static void Populate(RepeatedField repeatedField, ReadOnlyMemory memory) { if (MemoryMarshal.TryGetArray(memory, out var segment) && diff --git a/tests/Qdrant.Client.Tests/HealthCheckTests.cs b/tests/Qdrant.Client.Tests/HealthCheckTests.cs new file mode 100644 index 0000000..fd40af9 --- /dev/null +++ b/tests/Qdrant.Client.Tests/HealthCheckTests.cs @@ -0,0 +1,31 @@ +using FluentAssertions; +using Grpc.Core; +using Xunit; + +namespace Qdrant.Client +{ + public class HealthCheckTests : IClassFixture + { + private readonly QdrantClient _client; + + public HealthCheckTests(QdrantFixture qdrantFixture) => _client = qdrantFixture.CreateClient(); + + [Fact] + public async Task Server_Should_Be_Healthy() + { + var response = await _client.HealthAsync(); + + response.Title.Should().NotBeNullOrEmpty(); + response.Version.Should().NotBeNullOrEmpty(); + } + [Fact] + public async Task Server_Should_Be_UnHealthy() + { + var client = new QdrantClient("localhost", 9999); + ; + + await Assert.ThrowsAsync(async () => await client.HealthAsync()); + } + + } +}