CurtHagenlocher commented on code in PR #426: URL: https://github.com/apache/arrow-dotnet/pull/426#discussion_r3855042294
########## test/Apache.Arrow.Tests/StreamExtensionsTests.cs: ########## @@ -0,0 +1,98 @@ +// 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.IO; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Apache.Arrow.Tests +{ + public class StreamExtensionsTests + { + /// <summary> + /// A stream whose Read/ReadAsync overrides throw if ever invoked, standing in for a + /// socket-backed stream (e.g. NetworkStream) whose zero-length ReadAsync/Read does not + /// complete immediately the way MemoryStream's does — it blocks as though waiting for the + /// peer to send more data. Used to prove ReadFullBufferAsync/ReadFullBuffer never call + /// into the underlying stream for a zero-length request. + /// </summary> + private sealed class ThrowsIfReadStream : Stream + { + public override bool CanRead => true; + public override bool CanSeek => false; + public override bool CanWrite => false; + public override long Length => throw new NotSupportedException(); + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } + + public override int Read(byte[] buffer, int offset, int count) => + throw new InvalidOperationException("Read should not be called for a zero-length buffer."); + + public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => + throw new InvalidOperationException("ReadAsync should not be called for a zero-length buffer."); + + public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) => Review Comment: This will need an `#if` to exclude it from netstandard20 builds -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
