示例#1
0
        public void LargeDataFrameShouldMatch()
        {
            // Create a large message to force chunking.
            var originalData    = Data(1024 * 1024);
            int originalPadding = 100;
            var endOfStream     = true;

            writer.WriteDataAsync(this.ctx.Object, STREAM_ID, originalData.Slice(), originalPadding,
                                  endOfStream, this.ctx.Object.NewPromise());
            this.ReadFrames();

            // Verify that at least one frame was sent with eos=false and exactly one with eos=true.
            this.listener.Verify(
                x => x.OnDataRead(
                    It.Is <IChannelHandlerContext>(c => c == this.ctx.Object),
                    It.Is <int>(id => id == STREAM_ID),
                    It.IsAny <IByteBuffer>(),
                    It.IsAny <int>(),
                    It.Is <bool>(v => v == false)),
                Times.AtLeastOnce());
            this.listener.Verify(
                x => x.OnDataRead(
                    It.Is <IChannelHandlerContext>(c => c == this.ctx.Object),
                    It.Is <int>(id => id == STREAM_ID),
                    It.IsAny <IByteBuffer>(),
                    It.IsAny <int>(),
                    It.Is <bool>(v => v == true)));

            // Capture the read data and padding.
            var dataCaptor    = new ArgumentCaptor <IByteBuffer>();
            var paddingCaptor = new ArgumentCaptor <int>();

            this.listener.Verify(
                x => x.OnDataRead(
                    It.Is <IChannelHandlerContext>(c => c == this.ctx.Object),
                    It.Is <int>(id => id == STREAM_ID),
                    It.Is <IByteBuffer>(d => dataCaptor.Capture(d)),
                    It.Is <int>(v => paddingCaptor.Capture(v)),
                    It.IsAny <bool>()),
                Times.AtLeastOnce());

            // Make sure the data matches the original.
            foreach (var chunk in dataCaptor.GetAllValues())
            {
                var originalChunk = originalData.ReadSlice(chunk.ReadableBytes);
                Assert.Equal(originalChunk, chunk);
            }
            Assert.False(originalData.IsReadable());

            // Make sure the padding matches the original.
            int totalReadPadding = 0;

            foreach (int framePadding in paddingCaptor.GetAllValues())
            {
                totalReadPadding += framePadding;
            }
            Assert.Equal(originalPadding, totalReadPadding);
        }
 public virtual Task WriteDataAsync(IChannelHandlerContext ctx, int streamId, IByteBuffer data, int padding, bool endOfStream, IPromise promise)
 {
     return(_innerWriter.WriteDataAsync(ctx, streamId, data, padding, endOfStream, promise));
 }
示例#3
0
 public Task WriteDataAsync(IChannelHandlerContext ctx, int streamId, IByteBuffer data, int padding, bool endOfStream, IPromise promise)
 {
     _logger.LogData(Direction.Outbound, ctx, streamId, data, padding, endOfStream);
     return(_writer.WriteDataAsync(ctx, streamId, data, padding, endOfStream, promise));
 }
示例#4
0
 public Task WriteDataAsync(ArraySegment <byte> data, CancellationToken cancellationToken)
 {
     return(_frameWriter.WriteDataAsync(_streamId, data, cancellationToken));
 }
示例#5
0
 public Task WriteDataAsync(ReadOnlySpan <byte> data, CancellationToken cancellationToken)
 {
     return(_frameWriter.WriteDataAsync(_streamId, data, cancellationToken));
 }