public void DecodeFromSlowStream() { var original = Tools.FindFile($".corpus/reymont"); var encoded = Path.GetTempFileName(); try { ReferenceLZ4.Encode("-1 -BD -B4", original, encoded); var origStream = File.OpenRead(encoded); // We need this to work even if the stream gives us only a single byte at a time var slowStream = new FakeNetworkStream(origStream); using (var input = LZ4Stream.Decode(slowStream, Mem.M1)) { var buffer = new byte[0x80000]; Assert.Equal(5000, input.Read(buffer, 0, 5000)); Assert.Equal(0x10000 - 5000, input.Read(buffer, 0, 0x10000)); } } finally { File.Delete(encoded); } }
public void WriteToStream_rethrows_socket_errors_if_not_aborted() { var ns = new FakeNetworkStream().WithInnerException(new SocketException(10050)); _sut.SetStringContent("Hello Stephen, this is Clem Fandango. Can you hear me Stephen?"); Assert.ThrowsException <IOException>(() => _sut.WriteToStream(ns)); }
public void WriteToStream_rethrows_non_socket_errors() { var ns = new FakeNetworkStream(); _sut.SetStringContent("Hello Stephen, this is Clem Fandango. Can you hear me Stephen?"); Assert.ThrowsException <IOException>(() => _sut.WriteToStream(ns)); }
public void WriteToStream_logs_WARN_if_socket_aborted() { var expectedLogItems = new[] { new LogItem("Event", "WriteToStream failed. Socket aborted"), new LogItem("Exception", Path.DirectorySeparatorChar == '/'?"Software caused connection abort":"An established connection was aborted by the software in your host machine"), new LogItem("StackTrace", default(string)) }; var ns = new FakeNetworkStream().WithInnerException(new SocketException(10053)); _sut.SetStringContent("Hello Stephen, this is Clem Fandango. Can you hear me Stephen?"); try { _sut.WriteToStream(ns); } catch (Exception e) { Assert.Fail("WriteToStream should not re-throw SocketExceptions when the error code is SocketError.ConnectionAborted", e.Message); } _mockLogger.Verify(x => x.Warn("HttpResponse.WriteToStream", It.Is <LogItem[]>(i => CheckLogItems(i, expectedLogItems))), Times.Once); }