public void CanReadMultipleWrittenDataFromSameStream()
        {
            const int iterations = 10;

            for (int i = 0; i < iterations; ++i)
            {
                using (var writer = new PersistedDataWriter(stream, dimensions, this.streamManager))
                {
                    writer.WriteData(AnyCounterName, AnyStart, AnyEnd, (uint)data.Count, AnySources, data);
                }
            }

            stream.Position = 0;
            using (var reader = new PersistedDataReader(stream, this.streamManager))
            {
                for (int i = 0; i < iterations; ++i)
                {
                    Assert.IsTrue(reader.ReadDataHeader());
                    Assert.AreEqual(reader.Header.Name, "/Foo");
                    Assert.AreEqual((uint)data.Count, reader.Header.DataCount);
                    reader.ReadData <InternalHitCount>(
                        (key, value) => Assert.AreEqual(AnyDataValue, value.HitCount));
                }
            }
        }
        public void ReadingTruncatedDataThrowsPersistedDataException()
        {
            using (var writer = new PersistedDataWriter(stream, dimensions, this.streamManager))
            {
                writer.WriteData(AnyCounterName, AnyStart, AnyEnd, (uint)data.Count, AnySources, data);
            }

            for (int i = (int)stream.Length / 2; i >= 0; --i)
            {
                var buffer = new byte[i];
                Buffer.BlockCopy(stream.GetBuffer(), 0, buffer, 0, i);
                using (var truncatedStream = new MemoryStream(buffer, false))
                    using (var reader = new PersistedDataReader(truncatedStream, this.streamManager))
                    {
                        try
                        {
                            // If we can't read the header it's fine.
                            if (reader.ReadDataHeader())
                            {
                                reader.ReadData <InternalHitCount>((key, value) => { });
                                Assert.Fail();
                            }
                        }
                        catch (PersistedDataException) {}
                    }
            }
        }
        public void CanReadWrittenData()
        {
            using (var writer = new PersistedDataWriter(stream, dimensions, this.streamManager))
            {
                writer.WriteData(AnyCounterName, AnyStart, AnyEnd, (uint)data.Count, AnySources, data);
            }

            stream.Position = 0;
            using (var reader = new PersistedDataReader(stream, this.streamManager))
            {
                Assert.IsTrue(reader.ReadDataHeader());
                Assert.AreEqual("/Foo", reader.Header.Name);
                Assert.AreEqual((uint)data.Count, reader.Header.DataCount);
                reader.ReadData <InternalHitCount>(
                    (key, value) => Assert.AreEqual(AnyDataValue, value.HitCount));
            }
        }
Ejemplo n.º 4
0
        private void ValidateStreamContents(Stream input)
        {
            var reader = new PersistedDataReader(input, this.memoryStreamManager);

            Assert.IsTrue(reader.ReadDataHeader());
            Assert.AreEqual((uint)3, reader.Header.DataCount);
            Assert.AreEqual(AnyCounter, reader.Header.Name);
            Assert.AreEqual(this.GetStartTime().ToUniversalTime(), reader.StartTime);
            Assert.AreEqual(this.GetEndTime().ToUniversalTime(), reader.EndTime);

            reader.ReadData <InternalHitCount>(
                (key, data) =>
            {
                bool allDimensionsProvided;
                if (
                    key.Matches(this.dimensionSet.CreateKey(new DimensionSpecification {
                    { AnyDimension, "a" }
                },
                                                            out allDimensionsProvided)))
                {
                    Assert.AreEqual((ulong)1, data.HitCount);
                }
                else if (
                    key.Matches(this.dimensionSet.CreateKey(
                                    new DimensionSpecification {
                    { AnyDimension, "b" }
                }, out allDimensionsProvided)))
                {
                    Assert.AreEqual((ulong)2, data.HitCount);
                }
                else if (
                    key.Matches(
                        this.dimensionSet.CreateKey(new DimensionSpecification {
                    { AnyDimension, "c" }
                },
                                                    out allDimensionsProvided)))
                {
                    Assert.AreEqual((ulong)1, data.HitCount);
                }
                else
                {
                    Assert.Fail("Unexpected data found!");
                }
            });
        }
Ejemplo n.º 5
0
        public void CanReadWrittenData()
        {
            using (var writer = new PersistedDataWriter(stream, dimensions, this.streamManager))
            {
                writer.WriteData(AnyCounterName, AnyStart, AnyEnd, (uint)data.Count, AnySources, data);
            }

            stream.Position = 0;
            using (var reader = new PersistedDataReader(stream, this.streamManager))
            {
                Assert.IsTrue(reader.ReadDataHeader());
                Assert.AreEqual("/Foo", reader.Header.Name);
                Assert.AreEqual((uint)data.Count, reader.Header.DataCount);
                reader.ReadData<InternalHitCount>(
                    (key, value) => Assert.AreEqual(AnyDataValue, value.HitCount));
            }
        }
Ejemplo n.º 6
0
        public void CanReadMultipleWrittenDataFromSameStream()
        {
            const int iterations = 10;
            for (int i = 0; i < iterations; ++i)
            {
                using (var writer = new PersistedDataWriter(stream, dimensions, this.streamManager))
                {
                    writer.WriteData(AnyCounterName, AnyStart, AnyEnd, (uint)data.Count, AnySources, data);
                }
            }

            stream.Position = 0;
            using (var reader = new PersistedDataReader(stream, this.streamManager))
            {
                for (int i = 0; i < iterations; ++i)
                {
                    Assert.IsTrue(reader.ReadDataHeader());
                    Assert.AreEqual(reader.Header.Name, "/Foo");
                    Assert.AreEqual((uint)data.Count, reader.Header.DataCount);
                    reader.ReadData<InternalHitCount>(
                         (key, value) => Assert.AreEqual(AnyDataValue, value.HitCount));
                }
            }
        }
Ejemplo n.º 7
0
        public void ReadingTruncatedDataThrowsPersistedDataException()
        {
            using (var writer = new PersistedDataWriter(stream, dimensions, this.streamManager))
            {
                writer.WriteData(AnyCounterName, AnyStart, AnyEnd, (uint)data.Count, AnySources, data);
            }

            for (int i = (int)stream.Length / 2; i >= 0; --i)
            {
                var buffer = new byte[i];
                Buffer.BlockCopy(stream.GetBuffer(), 0, buffer, 0, i);
                using (var truncatedStream = new MemoryStream(buffer, false))
                using (var reader = new PersistedDataReader(truncatedStream, this.streamManager))
                {
                    try
                    {
                        // If we can't read the header it's fine.
                        if (reader.ReadDataHeader())
                        {
                            reader.ReadData<InternalHitCount>((key, value) => { });
                            Assert.Fail();
                        }
                    }
                    catch (PersistedDataException) {} 
                }
            }
        }
Ejemplo n.º 8
0
        private void ValidateStreamContents(Stream input)
        {
            var reader = new PersistedDataReader(input, this.memoryStreamManager);
            Assert.IsTrue(reader.ReadDataHeader());
            Assert.AreEqual((uint)3, reader.Header.DataCount);
            Assert.AreEqual(AnyCounter, reader.Header.Name);
            Assert.AreEqual(this.GetStartTime().ToUniversalTime(), reader.StartTime);
            Assert.AreEqual(this.GetEndTime().ToUniversalTime(), reader.EndTime);

            reader.ReadData<InternalHitCount>(
                (key, data) =>
                {
                    bool allDimensionsProvided;
                    if (
                        key.Matches(this.dimensionSet.CreateKey(new DimensionSpecification {{AnyDimension, "a"}},
                            out allDimensionsProvided)))
                    {
                        Assert.AreEqual((ulong)1, data.HitCount);
                    }
                    else if (
                        key.Matches(this.dimensionSet.CreateKey(
                            new DimensionSpecification {{AnyDimension, "b"}}, out allDimensionsProvided)))
                    {
                        Assert.AreEqual((ulong)2, data.HitCount);
                    }
                    else if (
                        key.Matches(
                            this.dimensionSet.CreateKey(new DimensionSpecification {{AnyDimension, "c"}},
                                out allDimensionsProvided)))
                    {
                        Assert.AreEqual((ulong)1, data.HitCount);
                    }
                    else
                    {
                        Assert.Fail("Unexpected data found!");
                    }
                });
        }