forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlightTests.cs
More file actions
576 lines (441 loc) · 24.8 KB
/
FlightTests.cs
File metadata and controls
576 lines (441 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Apache.Arrow.Flight.Client;
using Apache.Arrow.Flight.TestWeb;
using Apache.Arrow.Tests;
using Google.Protobuf;
using Grpc.Core;
using Grpc.Core.Utils;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Apache.Arrow.Flight.Tests
{
public class FlightTests : IDisposable
{
readonly TestWebFactory _testWebFactory;
readonly FlightClient _flightClient;
readonly FlightStore _flightStore;
public FlightTests()
{
_flightStore = new FlightStore();
_testWebFactory = new TestWebFactory(_flightStore);
_flightClient = new FlightClient(_testWebFactory.GetChannel());
}
public void Dispose()
{
_testWebFactory.Dispose();
}
private RecordBatch CreateTestBatch(int startValue, int length)
{
var batchBuilder = new RecordBatch.Builder();
Int32Array.Builder builder = new Int32Array.Builder();
for (int i = 0; i < length; i++)
{
builder.Append(startValue + i);
}
batchBuilder.Append("test", true, builder.Build());
return batchBuilder.Build();
}
private Schema GetStoreSchema(FlightDescriptor flightDescriptor)
{
Assert.Contains(flightDescriptor, (IReadOnlyDictionary<FlightDescriptor, FlightHolder>)_flightStore.Flights);
var flightHolder = _flightStore.Flights[flightDescriptor];
return flightHolder.GetFlightInfo().Schema;
}
private IEnumerable<RecordBatchWithMetadata> GetStoreBatch(FlightDescriptor flightDescriptor)
{
Assert.Contains(flightDescriptor, (IReadOnlyDictionary<FlightDescriptor, FlightHolder>)_flightStore.Flights);
var flightHolder = _flightStore.Flights[flightDescriptor];
return flightHolder.GetRecordBatches();
}
private FlightInfo GivenStoreBatches(FlightDescriptor flightDescriptor, params RecordBatchWithMetadata[] batches)
{
var initialBatch = batches.FirstOrDefault();
var flightHolder = new FlightHolder(flightDescriptor, initialBatch?.RecordBatch.Schema, _testWebFactory.GetAddress());
foreach (var batch in batches)
{
flightHolder.AddBatch(batch);
}
_flightStore.Flights[flightDescriptor] = flightHolder;
return flightHolder.GetFlightInfo();
}
[Fact]
public async Task TestPutSingleRecordBatch()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch = CreateTestBatch(0, 100);
var putStream = await _flightClient.StartPut(flightDescriptor, expectedBatch.Schema);
await putStream.RequestStream.WriteAsync(expectedBatch);
await putStream.RequestStream.CompleteAsync();
var putResults = await putStream.ResponseStream.ToListAsync();
Assert.Single(putResults);
var actualBatches = GetStoreBatch(flightDescriptor);
Assert.Single(actualBatches);
ArrowReaderVerifier.CompareBatches(expectedBatch, actualBatches.First().RecordBatch);
}
[Fact]
public async Task TestPutTwoRecordBatches()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch1 = CreateTestBatch(0, 100);
var expectedBatch2 = CreateTestBatch(0, 100);
var putStream = await _flightClient.StartPut(flightDescriptor, expectedBatch1.Schema);
await putStream.RequestStream.WriteAsync(expectedBatch1);
await putStream.RequestStream.WriteAsync(expectedBatch2);
await putStream.RequestStream.CompleteAsync();
var putResults = await putStream.ResponseStream.ToListAsync();
Assert.Equal(2, putResults.Count);
var actualBatches = GetStoreBatch(flightDescriptor).ToList();
Assert.Equal(2, actualBatches.Count);
ArrowReaderVerifier.CompareBatches(expectedBatch1, actualBatches[0].RecordBatch);
ArrowReaderVerifier.CompareBatches(expectedBatch2, actualBatches[1].RecordBatch);
}
[Fact]
public async Task TestPutZeroRecordBatches()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var schema = CreateTestBatch(0, 1).Schema;
var putStream = await _flightClient.StartPut(flightDescriptor, schema);
await putStream.RequestStream.CompleteAsync();
var putResults = await putStream.ResponseStream.ToListAsync();
Assert.Empty(putResults);
var actualSchema = GetStoreSchema(flightDescriptor);
SchemaComparer.Compare(schema, actualSchema);
}
[Fact]
public async Task TestGetRecordBatchWithDelayedSchema()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch = CreateTestBatch(0, 100);
//Add flight info only to the in memory store without schema or batch
GivenStoreBatches(flightDescriptor);
//Get the flight info for the ticket and verify the schema is null
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
Assert.Single(flightInfo.Endpoints);
Assert.Null(flightInfo.Schema);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
//Update the store with the batch and schema
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch));
var getStream = _flightClient.GetStream(endpoint.Ticket);
var resultList = await getStream.ResponseStream.ToListAsync();
Assert.Single(resultList);
ArrowReaderVerifier.CompareBatches(expectedBatch, resultList[0]);
}
[Fact]
public async Task TestGetSingleRecordBatch()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch = CreateTestBatch(0, 100);
//Add batch to the in memory store
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch));
//Get the flight info for the ticket
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
Assert.Single(flightInfo.Endpoints);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
var getStream = _flightClient.GetStream(endpoint.Ticket);
var resultList = await getStream.ResponseStream.ToListAsync();
Assert.Single(resultList);
ArrowReaderVerifier.CompareBatches(expectedBatch, resultList[0]);
}
[Fact]
public async Task TestGetTwoRecordBatch()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch1 = CreateTestBatch(0, 100);
var expectedBatch2 = CreateTestBatch(100, 100);
//Add batch to the in memory store
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch1), new RecordBatchWithMetadata(expectedBatch2));
//Get the flight info for the ticket
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
Assert.Single(flightInfo.Endpoints);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
var getStream = _flightClient.GetStream(endpoint.Ticket);
var resultList = await getStream.ResponseStream.ToListAsync();
Assert.Equal(2, resultList.Count);
ArrowReaderVerifier.CompareBatches(expectedBatch1, resultList[0]);
ArrowReaderVerifier.CompareBatches(expectedBatch2, resultList[1]);
}
[Fact]
public async Task TestGetFlightMetadata()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch1 = CreateTestBatch(0, 100);
var expectedMetadata = ByteString.CopyFromUtf8("test metadata");
var expectedMetadataList = new List<ByteString>() { expectedMetadata };
//Add batch to the in memory store
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch1, expectedMetadata));
//Get the flight info for the ticket
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
Assert.Single(flightInfo.Endpoints);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
var getStream = _flightClient.GetStream(endpoint.Ticket);
List<ByteString> actualMetadata = new List<ByteString>();
while (await getStream.ResponseStream.MoveNext(default))
{
actualMetadata.AddRange(getStream.ResponseStream.ApplicationMetadata);
}
Assert.Equal(expectedMetadataList, actualMetadata);
}
[Fact]
public async Task TestPutWithMetadata()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch = CreateTestBatch(0, 100);
var expectedMetadata = ByteString.CopyFromUtf8("test metadata");
var putStream = await _flightClient.StartPut(flightDescriptor, expectedBatch.Schema);
await putStream.RequestStream.WriteAsync(expectedBatch, expectedMetadata);
await putStream.RequestStream.CompleteAsync();
var putResults = await putStream.ResponseStream.ToListAsync();
Assert.Single(putResults);
var actualBatches = GetStoreBatch(flightDescriptor);
Assert.Single(actualBatches);
ArrowReaderVerifier.CompareBatches(expectedBatch, actualBatches.First().RecordBatch);
Assert.Equal(expectedMetadata, actualBatches.First().Metadata);
}
[Fact]
public async Task TestGetSchema()
{
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);
}
[Fact]
public async Task TestDoAction()
{
var expectedResult = new List<FlightResult>()
{
new FlightResult("test data")
};
var resultStream = _flightClient.DoAction(new FlightAction("test"));
var actualResult = await resultStream.ResponseStream.ToListAsync();
Assert.Equal(expectedResult, actualResult);
}
[Fact]
public async Task TestListActions()
{
var expected = new List<FlightActionType>()
{
new FlightActionType("get", "get a flight"),
new FlightActionType("put", "add a flight"),
new FlightActionType("delete", "delete a flight"),
new FlightActionType("test", "test action")
};
var actual = await _flightClient.ListActions().ResponseStream.ToListAsync();
Assert.Equal(expected, actual);
}
[Fact]
public async Task TestListFlights()
{
var flightDescriptor1 = FlightDescriptor.CreatePathDescriptor("test1");
var flightDescriptor2 = FlightDescriptor.CreatePathDescriptor("test2");
var expectedBatch = CreateTestBatch(0, 100);
List<FlightInfo> expectedFlightInfo = new List<FlightInfo>();
expectedFlightInfo.Add(GivenStoreBatches(flightDescriptor1, new RecordBatchWithMetadata(expectedBatch)));
expectedFlightInfo.Add(GivenStoreBatches(flightDescriptor2, new RecordBatchWithMetadata(expectedBatch)));
var listFlightStream = _flightClient.ListFlights();
var actualFlights = await listFlightStream.ResponseStream.ToListAsync();
for (int i = 0; i < expectedFlightInfo.Count; i++)
{
FlightInfoComparer.Compare(expectedFlightInfo[i], actualFlights[i]);
}
}
[Fact]
public async Task TestHandshake()
{
var duplexStreamingCall = _flightClient.Handshake();
await duplexStreamingCall.RequestStream.WriteAsync(new FlightHandshakeRequest(ByteString.Empty));
await duplexStreamingCall.RequestStream.CompleteAsync();
var results = await duplexStreamingCall.ResponseStream.ToListAsync();
Assert.Single(results);
Assert.Equal("Done", results.First().Payload.ToStringUtf8());
}
[Fact]
public async Task TestSingleExchange()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("single_exchange");
var duplexStreamingCall = _flightClient.DoExchange(flightDescriptor);
var expectedBatch = CreateTestBatch(0, 100);
await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch);
await duplexStreamingCall.RequestStream.CompleteAsync();
var results = await duplexStreamingCall.ResponseStream.ToListAsync();
Assert.Single(results);
ArrowReaderVerifier.CompareBatches(expectedBatch, results.FirstOrDefault());
}
[Fact]
public async Task TestMultipleExchange()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("multiple_exchange");
var duplexStreamingCall = _flightClient.DoExchange(flightDescriptor);
var expectedBatch1 = CreateTestBatch(0, 100);
var expectedBatch2 = CreateTestBatch(100, 100);
await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch1);
await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch2);
await duplexStreamingCall.RequestStream.CompleteAsync();
var results = await duplexStreamingCall.ResponseStream.ToListAsync();
ArrowReaderVerifier.CompareBatches(expectedBatch1, results[0]);
ArrowReaderVerifier.CompareBatches(expectedBatch2, results[1]);
}
[Fact]
public async Task TestExchangeWithMetadata()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("metadata_exchange");
var duplexStreamingCall = _flightClient.DoExchange(flightDescriptor);
var expectedBatch = CreateTestBatch(0, 100);
var expectedMetadata = ByteString.CopyFromUtf8("test metadata");
await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch, expectedMetadata);
await duplexStreamingCall.RequestStream.CompleteAsync();
List<ByteString> actualMetadata = new List<ByteString>();
List<RecordBatch> actualBatch = new List<RecordBatch>();
while (await duplexStreamingCall.ResponseStream.MoveNext(default))
{
actualBatch.Add(duplexStreamingCall.ResponseStream.Current);
actualMetadata.AddRange(duplexStreamingCall.ResponseStream.ApplicationMetadata);
}
ArrowReaderVerifier.CompareBatches(expectedBatch, actualBatch.FirstOrDefault());
Assert.Equal(expectedMetadata, actualMetadata.FirstOrDefault());
}
[Fact]
public async Task TestHandshakeWithSpecificMessage()
{
var duplexStreamingCall = _flightClient.Handshake();
await duplexStreamingCall.RequestStream.WriteAsync(new FlightHandshakeRequest(ByteString.CopyFromUtf8("Hello")));
await duplexStreamingCall.RequestStream.CompleteAsync();
var results = await duplexStreamingCall.ResponseStream.ToListAsync();
Assert.Single(results);
Assert.Equal("Hello handshake", results.First().Payload.ToStringUtf8());
}
[Fact]
public async Task TestGetBatchesWithAsyncEnumerable()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("test");
var expectedBatch1 = CreateTestBatch(0, 100);
var expectedBatch2 = CreateTestBatch(100, 100);
//Add batch to the in memory store
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(expectedBatch1), new RecordBatchWithMetadata(expectedBatch2));
//Get the flight info for the ticket
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
Assert.Single(flightInfo.Endpoints);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
var getStream = _flightClient.GetStream(endpoint.Ticket);
List<RecordBatch> resultList = new List<RecordBatch>();
await foreach (var recordBatch in getStream.ResponseStream)
{
resultList.Add(recordBatch);
}
Assert.Equal(2, resultList.Count);
ArrowReaderVerifier.CompareBatches(expectedBatch1, resultList[0]);
ArrowReaderVerifier.CompareBatches(expectedBatch2, resultList[1]);
}
[Fact]
public async Task EnsureTheSerializedBatchContainsTheProperTotalRecordsAndTotalBytesProperties()
{
var flightDescriptor1 = FlightDescriptor.CreatePathDescriptor("test1");
var expectedBatch = CreateTestBatch(0, 100);
var expectedTotalBytes = expectedBatch.Arrays.Sum(arr => arr.Data.Buffers.Sum(b => b.Length));
List<FlightInfo> expectedFlightInfo = new List<FlightInfo>();
expectedFlightInfo.Add(GivenStoreBatches(flightDescriptor1, new RecordBatchWithMetadata(expectedBatch)));
var listFlightStream = _flightClient.ListFlights();
var actualFlights = await listFlightStream.ResponseStream.ToListAsync();
var result = actualFlights.First();
Assert.Equal(expectedBatch.Length, result.TotalRecords);
Assert.Equal(expectedTotalBytes, result.TotalBytes);
}
[Fact]
public async Task EnsureCallRaisesDeadlineExceeded()
{
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("raise_deadline");
var deadline = DateTime.UtcNow;
var batch = CreateTestBatch(0, 100);
RpcException exception = null;
var asyncServerStreamingCallFlights = _flightClient.ListFlights(null, null, deadline);
Assert.Equal(StatusCode.DeadlineExceeded, asyncServerStreamingCallFlights.GetStatus().StatusCode);
var asyncServerStreamingCallActions = _flightClient.ListActions(null, deadline);
Assert.Equal(StatusCode.DeadlineExceeded, asyncServerStreamingCallFlights.GetStatus().StatusCode);
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(batch));
exception = await Assert.ThrowsAsync<RpcException>(async () => await _flightClient.GetInfo(flightDescriptor, null, deadline));
Assert.Equal(StatusCode.DeadlineExceeded, exception.StatusCode);
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
var getStream = _flightClient.GetStream(endpoint.Ticket, null, deadline);
Assert.Equal(StatusCode.DeadlineExceeded, getStream.GetStatus().StatusCode);
var duplexStreamingCall = _flightClient.DoExchange(flightDescriptor, null, deadline);
exception = await Assert.ThrowsAsync<RpcException>(async () => await duplexStreamingCall.RequestStream.WriteAsync(batch));
Assert.Equal(StatusCode.DeadlineExceeded, exception.StatusCode);
exception = await Assert.ThrowsAsync<RpcException>(async () => await _flightClient.StartPut(flightDescriptor, batch.Schema, null, deadline));
Assert.Equal(StatusCode.DeadlineExceeded, exception.StatusCode);
exception = await Assert.ThrowsAsync<RpcException>(async () => await _flightClient.GetSchema(flightDescriptor, null, deadline));
Assert.Equal(StatusCode.DeadlineExceeded, exception.StatusCode);
var handshakeStreamingCall = _flightClient.Handshake(null, deadline);
exception = await Assert.ThrowsAsync<RpcException>(async () => await handshakeStreamingCall.RequestStream.WriteAsync(new FlightHandshakeRequest(ByteString.Empty)));
Assert.Equal(StatusCode.DeadlineExceeded, exception.StatusCode);
}
[Fact]
public async Task EnsureCallRaisesRequestCancelled()
{
var cts = new CancellationTokenSource();
cts.CancelAfter(1);
var batch = CreateTestBatch(0, 100);
var metadata = new Metadata();
var flightDescriptor = FlightDescriptor.CreatePathDescriptor("raise_cancelled");
await Task.Delay(5);
RpcException exception = null;
var asyncServerStreamingCallFlights = _flightClient.ListFlights(null, null, null, cts.Token);
Assert.Equal(StatusCode.Cancelled, asyncServerStreamingCallFlights.GetStatus().StatusCode);
var asyncServerStreamingCallActions = _flightClient.ListActions(null, null, cts.Token);
Assert.Equal(StatusCode.Cancelled, asyncServerStreamingCallFlights.GetStatus().StatusCode);
GivenStoreBatches(flightDescriptor, new RecordBatchWithMetadata(batch));
exception = await Assert.ThrowsAsync<RpcException>(async () => await _flightClient.GetInfo(flightDescriptor, null, null, cts.Token));
Assert.Equal(StatusCode.Cancelled, exception.StatusCode);
var flightInfo = await _flightClient.GetInfo(flightDescriptor);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
var getStream = _flightClient.GetStream(endpoint.Ticket, null, null, cts.Token);
Assert.Equal(StatusCode.Cancelled, getStream.GetStatus().StatusCode);
var duplexStreamingCall = _flightClient.DoExchange(flightDescriptor, null, null, cts.Token);
exception = await Assert.ThrowsAsync<RpcException>(async () => await duplexStreamingCall.RequestStream.WriteAsync(batch));
Assert.Equal(StatusCode.Cancelled, exception.StatusCode);
exception = await Assert.ThrowsAsync<RpcException>(async () => await _flightClient.StartPut(flightDescriptor, batch.Schema, null, null, cts.Token));
Assert.Equal(StatusCode.Cancelled, exception.StatusCode);
exception = await Assert.ThrowsAsync<RpcException>(async () => await _flightClient.GetSchema(flightDescriptor, null, null, cts.Token));
Assert.Equal(StatusCode.Cancelled, exception.StatusCode);
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);
}
}
}