Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-45451: [C#] Integration with Grpc.Net.ClientFactory #45458

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions csharp/src/Apache.Arrow.Flight/Client/FlightClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public FlightClient(ChannelBase grpcChannel)
_client = new FlightService.FlightServiceClient(grpcChannel);
}

public FlightClient(CallInvoker callInvoker)
{
_client = new FlightService.FlightServiceClient(callInvoker);
}

public AsyncServerStreamingCall<FlightInfo> ListFlights(FlightCriteria criteria = null, Metadata headers = null)
{
return ListFlights(criteria, headers, null, CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.67.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
Expand Down
24 changes: 24 additions & 0 deletions csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -546,7 +547,30 @@ public async Task EnsureCallRaisesRequestCancelled()
var handshakeStreamingCall = _flightClient.Handshake(null, null, cts.Token);
exception = await Assert.ThrowsAsync<RpcException>(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<FlightClient>(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<FlightClient>();

// 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);
}
}
}
Loading