示例#1
0
        public void TestReadChannelsData()
        {
            const int channelCount = 10;

            for (int i = 1; i <= channelCount; ++i)
            {
                var hint = log.AddChannel();
                log.WriteChannelData(hint, 0, new TestChannel {
                    id = i, NonSerialized = "bbb"
                });
            }
            var channels = logReader.ReadChannelsData(1, channelCount);

            Assert.Equal(channelCount, channels.Count);
            for (int i = 1; i <= channelCount; ++i)
            {
                var channel = channels[i - 1] as TestChannel;
                Assert.NotNull(channel);
                Assert.Equal(i, channel.id);
                Assert.True(string.IsNullOrEmpty(channel.NonSerialized));
            }
            channels = logReader.ReadChannelsData(3, 1);
            Assert.Equal(1, channels.Count);
            var channel2 = channels[0] as TestChannel;

            Assert.NotNull(channel2);
            Assert.Equal(3, channel2.id);
            channels = logReader.ReadChannelsData(3, 0);
            Assert.Equal(0, channels.Count);
        }
示例#2
0
        public void TestAddChannel()
        {
            log.AddChannel();
            log.AddChannel();
            log.Close();
            FileStream   stream    = new FileStream(filename, FileMode.Open, FileAccess.Read);
            BinaryReader binReader = new BinaryReader(stream);

            stream.Position = sizeof(long);
            // 2 channels
            Assert.Equal(2, binReader.ReadInt64());
            // skip next channel table pointer
            stream.Position += sizeof(long);
            long channelPos = binReader.ReadInt64();

            // check the first channel
            Assert.True(channelPos > 0);
            Assert.True(stream.Length > channelPos + sizeof(long));
            // move to event count
            stream.Position = channelPos + sizeof(long);
            Assert.Equal(0, binReader.ReadInt64());
            // move to the second channel pointer
            stream.Position = 4 * sizeof(long);
            channelPos      = binReader.ReadInt64();
            // check the second channel
            Assert.True(channelPos > 0);
            Assert.True(stream.Length > channelPos + sizeof(long));
            // move to event count
            stream.Position = channelPos + sizeof(long);
            Assert.Equal(0, binReader.ReadInt64());
            binReader.Close();
        }
示例#3
0
        public void TestSerializationToMultipleFileLogs()
        {
            var log1    = new FileLog(Path.GetTempFileName());
            var log2    = new FileLog(Path.GetTempFileName());
            var builder = new LoggedFileBuilder(log1);

            builder.Append(new ByteArray(new byte[] { 0, 1, 2, 3, 4, 5 }));
            var file        = builder.Close();
            var channelHint = log2.AddChannel();

            log2.LogEvent(channelHint, new Event(1, EventType.RequestReceived, new Netool.Network.DataEventArgs {
                Data = file, State = null
            }, DateTime.Now));
            log2.LogEvent(channelHint, new Event(2, EventType.RequestReceived, new Netool.Network.DataEventArgs {
                Data = file, State = null
            }, DateTime.Now));
            using (var reader = log2.CreateReader())
            {
                var e1 = reader.ReadEvent(channelHint, 1);
                var e2 = reader.ReadEvent(channelHint, 2);
                Assert.Equal(file.Length, e1.Data.Data.Length);
                Assert.Equal(3, e1.Data.Data.ReadByte(3));
                // check that it isn't copied repeatedly
                Assert.True(((IEquatable <LoggedFile>)e1.Data.Data).Equals((LoggedFile)e2.Data.Data));
            }

            log1.DeleteFile();
            log2.DeleteFile();
        }
示例#4
0
        public void TestSerialization()
        {
            var filename  = Path.GetTempFileName();
            var log       = new FileLog(filename);
            var innerData = new ByteArray(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            var lazy      = new LazyLoggedFile(innerData);
            var channel   = log.AddChannel();

            log.LogEvent(channel, new Event(1, EventType.RequestReceived, new Netool.Network.DataEventArgs {
                Data = lazy, State = null
            }, DateTime.Now));
            var reader = log.CreateReader();
            var e      = reader.ReadEvent(channel, 1);

            for (byte i = 0; i < 10; ++i)
            {
                Assert.Equal(i, e.Data.Data.ReadByte(i));
            }
            log.Close();
            reader.Close();
            File.Delete(filename);
        }