public void MultilineLoggingInSingleLogEntryWithTlvFormat() { var logs = new List <byte[]>(); var offsets = new List <int>(); var counts = new List <int>(); var stream = new TestFileStream((log, offset, count) => { logs.Add(log); offsets.Add(offset); counts.Add(count); }); TextWriter writer = FileDescriptorLogFactory.InitializeWriter(stream); // assert that initializing the stream does not result in UTF-8 preamble log entry Assert.Equal(0, counts.Count); Assert.Equal(0, offsets.Count); Assert.Equal(0, logs.Count); const string logMessage = "hello world\nsomething else on a new line."; int logMessageLength = logMessage.Length; writer.Write(logMessage); Assert.Equal(2, offsets.Count); int headerLogEntryOffset = offsets[0]; int consoleLogEntryOffset = offsets[1]; Assert.Equal(0, headerLogEntryOffset); Assert.Equal(0, consoleLogEntryOffset); Assert.Equal(2, counts.Count); int headerLogEntrySize = counts[0]; int consoleLogEntrySize = counts[1]; Assert.Equal(HeaderLength, headerLogEntrySize); Assert.Equal(logMessageLength, consoleLogEntrySize); Assert.Equal(2, logs.Count); byte[] headerLogEntry = logs[0]; byte[] consoleLogEntry = logs[1]; Assert.Equal(HeaderLength, headerLogEntry.Length); Assert.Equal(logMessageLength, consoleLogEntry.Length); byte[] expectedLengthBytes = { 0x00, 0x00, 0x00, 0x29 }; AssertHeaderBytes(headerLogEntry, expectedLengthBytes); Assert.Equal(logMessage, Encoding.UTF8.GetString(consoleLogEntry)); }
public void MaxSizeProducesOneLogFrame() { var logs = new List <byte[]>(); var offsets = new List <int>(); var counts = new List <int>(); var stream = new TestFileStream((log, offset, count) => { logs.Add(log); offsets.Add(offset); counts.Add(count); }); TextWriter writer = FileDescriptorLogFactory.InitializeWriter(stream); // assert that initializing the stream does not result in UTF-8 preamble log entry Assert.Equal(0, counts.Count); Assert.Equal(0, offsets.Count); Assert.Equal(0, logs.Count); string logMessage = new string('a', LogEntryMaxLength - 1) + "b"; writer.Write(logMessage); Assert.Equal(2, offsets.Count); int headerLogEntryOffset = offsets[0]; int consoleLogEntryOffset = offsets[1]; Assert.Equal(0, headerLogEntryOffset); Assert.Equal(0, consoleLogEntryOffset); Assert.Equal(2, counts.Count); int headerLogEntrySize = counts[0]; int consoleLogEntrySize = counts[1]; Assert.Equal(HeaderLength, headerLogEntrySize); Assert.Equal(LogEntryMaxLength, consoleLogEntrySize); Assert.Equal(2, logs.Count); byte[] headerLogEntry = logs[0]; byte[] consoleLogEntry = logs[1]; Assert.Equal(HeaderLength, headerLogEntry.Length); Assert.Equal(LogEntryMaxLength, consoleLogEntry.Length); byte[] expectedLengthBytes = { 0x00, 0x03, 0xFF, 0xE6 }; AssertHeaderBytes(headerLogEntry, expectedLengthBytes); Assert.Equal(logMessage, Encoding.UTF8.GetString(consoleLogEntry)); }