From 902eba0ddc983a41d620f2464b6d0250249dab57 Mon Sep 17 00:00:00 2001 From: Robert Cao Date: Thu, 6 Feb 2025 11:42:47 -0600 Subject: [PATCH 1/2] . --- csharp/src/Apache.Arrow.Flight/Client/FlightClient.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/csharp/src/Apache.Arrow.Flight/Client/FlightClient.cs b/csharp/src/Apache.Arrow.Flight/Client/FlightClient.cs index 10660f40b4c3e..c11b7e532dfbb 100644 --- a/csharp/src/Apache.Arrow.Flight/Client/FlightClient.cs +++ b/csharp/src/Apache.Arrow.Flight/Client/FlightClient.cs @@ -33,6 +33,11 @@ public FlightClient(ChannelBase grpcChannel) _client = new FlightService.FlightServiceClient(grpcChannel); } + public FlightClient(CallInvoker callInvoker) + { + _client = new FlightService.FlightServiceClient(callInvoker); + } + public AsyncServerStreamingCall ListFlights(FlightCriteria criteria = null, Metadata headers = null) { return ListFlights(criteria, headers, null, CancellationToken.None); From 6bbfeb7bb3726bf7884d6f990aae3d57c34851e2 Mon Sep 17 00:00:00 2001 From: Robert Cao Date: Thu, 6 Feb 2025 19:33:12 -0600 Subject: [PATCH 2/2] add support for integraion with Grpc.Net.ClientFactory --- .../Apache.Arrow.Flight.Tests.csproj | 1 + .../Apache.Arrow.Flight.Tests/FlightTests.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj b/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj index eca1f70760cfe..296da1046311c 100644 --- a/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj +++ b/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj @@ -6,6 +6,7 @@ + diff --git a/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs b/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs index 241b3c006a003..acdd824590446 100644 --- a/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs +++ b/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs @@ -24,6 +24,7 @@ using Google.Protobuf; using Grpc.Core; using Grpc.Core.Utils; +using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Apache.Arrow.Flight.Tests @@ -546,7 +547,30 @@ public async Task EnsureCallRaisesRequestCancelled() var handshakeStreamingCall = _flightClient.Handshake(null, null, cts.Token); exception = await Assert.ThrowsAsync(async () => await handshakeStreamingCall.RequestStream.WriteAsync(new FlightHandshakeRequest(ByteString.Empty))); Assert.Equal(StatusCode.Cancelled, exception.StatusCode); + } + + [Fact] + public async Task TestIntegrationWithGrpcNetClientFactory() + { + IServiceCollection services = new ServiceCollection(); + services.AddGrpcClient(grpc => grpc.Address = new Uri(_testWebFactory.GetAddress())); + + IServiceProvider provider = services.BuildServiceProvider(); + + // Test that an instance of the FlightClient can be resolved whilst using the Grpc.Net.ClientFactory library. + FlightClient flightClient = provider.GetRequiredService(); + + // Test that the resolved client is functional. + var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test"); + var expectedBatch = CreateTestBatch(0, 100); + var expectedSchema = expectedBatch.Schema; + + GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch)); + + var actualSchema = await flightClient.GetSchema(flightDescriptor); + + SchemaComparer.Compare(expectedSchema, actualSchema); } } }