|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
4 | 4 | using System.Collections.Generic; |
5 | | -using System.Diagnostics; |
6 | | -using System.Globalization; |
7 | 5 | using System.IO; |
8 | 6 | using System.Linq; |
9 | 7 | using System.Text.Json.Serialization.Metadata; |
@@ -335,47 +333,6 @@ await Assert.ThrowsAsync<TaskCanceledException>(async () => |
335 | 333 | }); |
336 | 334 | } |
337 | 335 |
|
338 | | - [Theory] |
339 | | - [InlineData(5, 1024)] |
340 | | - [InlineData(5, 1024 * 1024)] |
341 | | - public static async Task DeserializeAsyncEnumerable_SlowStreamWithLargeStrings(int totalStrings, int stringLength) |
342 | | - { |
343 | | - var options = new JsonSerializerOptions |
344 | | - { |
345 | | - Converters = { new StringLengthConverter() } |
346 | | - }; |
347 | | - |
348 | | - using var stream = new SlowStream(GenerateJsonCharacters()); |
349 | | - string expectedElement = stringLength.ToString(CultureInfo.InvariantCulture); |
350 | | - IAsyncEnumerable<string?> asyncEnumerable = JsonSerializer.DeserializeAsyncEnumerable<string>(stream, options); |
351 | | - |
352 | | - await foreach (string? value in asyncEnumerable) |
353 | | - { |
354 | | - Assert.Equal(expectedElement, value); |
355 | | - } |
356 | | - |
357 | | - IEnumerable<byte> GenerateJsonCharacters() |
358 | | - { |
359 | | - // ["xxx...x","xxx...x",...,"xxx...x"] |
360 | | - yield return (byte)'['; |
361 | | - for (int i = 0; i < totalStrings; i++) |
362 | | - { |
363 | | - yield return (byte)'"'; |
364 | | - for (int j = 0; j < stringLength; j++) |
365 | | - { |
366 | | - yield return (byte)'x'; |
367 | | - } |
368 | | - yield return (byte)'"'; |
369 | | - |
370 | | - if (i < totalStrings - 1) |
371 | | - { |
372 | | - yield return (byte)','; |
373 | | - } |
374 | | - } |
375 | | - yield return (byte)']'; |
376 | | - } |
377 | | - } |
378 | | - |
379 | 336 | public static IEnumerable<object[]> GetAsyncEnumerableSources() |
380 | 337 | { |
381 | 338 | yield return WrapArgs(Enumerable.Empty<int>(), 1, DeserializeAsyncEnumerableOverload.JsonSerializerOptions); |
@@ -424,48 +381,5 @@ private static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> sourc |
424 | 381 | } |
425 | 382 | return list; |
426 | 383 | } |
427 | | - |
428 | | - private sealed class SlowStream(IEnumerable<byte> byteSource) : Stream, IDisposable |
429 | | - { |
430 | | - private readonly IEnumerator<byte> _enumerator = byteSource.GetEnumerator(); |
431 | | - private long _position; |
432 | | - |
433 | | - public override bool CanRead => true; |
434 | | - public override int Read(byte[] buffer, int offset, int count) |
435 | | - { |
436 | | - Debug.Assert(buffer != null); |
437 | | - Debug.Assert(offset >= 0 && count <= buffer.Length - offset); |
438 | | - |
439 | | - if (count == 0 || !_enumerator.MoveNext()) |
440 | | - { |
441 | | - return 0; |
442 | | - } |
443 | | - |
444 | | - _position++; |
445 | | - buffer[offset] = _enumerator.Current; |
446 | | - return 1; |
447 | | - } |
448 | | - |
449 | | - public override bool CanSeek => false; |
450 | | - public override bool CanWrite => false; |
451 | | - public override long Position { get => _position; set => throw new NotSupportedException(); } |
452 | | - public override long Length => throw new NotSupportedException(); |
453 | | - public override void Flush() => throw new NotSupportedException(); |
454 | | - public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); |
455 | | - public override void SetLength(long value) => throw new NotSupportedException(); |
456 | | - public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); |
457 | | - void IDisposable.Dispose() => _enumerator.Dispose(); |
458 | | - } |
459 | | - |
460 | | - private sealed class StringLengthConverter : JsonConverter<string> |
461 | | - { |
462 | | - public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
463 | | - { |
464 | | - Debug.Assert(!reader.ValueIsEscaped && !reader.HasValueSequence); |
465 | | - return reader.ValueSpan.Length.ToString(CultureInfo.InvariantCulture); |
466 | | - } |
467 | | - |
468 | | - public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) => throw new NotImplementedException(); |
469 | | - } |
470 | 384 | } |
471 | 385 | } |
0 commit comments