Esempio n. 1
0
        public void InfiniteFileInMemory()
        {
            using (var infFile = new InfiniteFileWriter(nameof(this.InfiniteFileInMemory), 128, 0))
            {
                using (var infFile2 = new InfiniteFileReader(nameof(this.InfiniteFileInMemory)))
                {
                    byte[] bytes = new byte[100];
                    byte   val   = 100;
                    int    pos   = 10;
                    for (int i = 0; i < 4; i++)
                    {
                        bytes[pos] = val;
                        infFile.ReserveBlock(bytes.Length);
                        infFile.WriteToBlock(bytes);
                        infFile.CommitBlock();

                        infFile2.MoveNext();
                        infFile2.ReadBlock(ref bytes);
                        Assert.AreEqual(0, bytes[0]);
                        Assert.AreEqual(val, bytes[pos]);

                        val++;
                    }
                }
            }
        }
Esempio n. 2
0
        public void InfiniteFileTruncation()
        {
            const int extentSize = 10 * 1024;

            using (var infFile = new InfiniteFileWriter(this.path, nameof(this.InfiniteFileTest), extentSize))
            {
                // write less data than would fill an extent
                byte[] bytes = new byte[1024];
                infFile.ReserveBlock(bytes.Length);
                infFile.WriteToBlock(bytes);
                infFile.CommitBlock();
            }

            // get the full pathname of the first (and only) extent file
            string extentPath = Path.Combine(this.path, string.Format("{0}_{1:000000}.psi", nameof(this.InfiniteFileTest), 0));

            // verify that the extent file has been truncated (to the nearest 4096 byte block)
            Assert.AreEqual(4096, new FileInfo(extentPath).Length);
        }
Esempio n. 3
0
        public void InfiniteFileTest()
        {
            const int extentSize        = 10 * 1024;
            const int messagesPerExtent = 3;
            const int messageSize       = (int)(extentSize * 0.9) / messagesPerExtent; // not a multiple of 4k and not a divisor of initial file size, to force truncation
            const int extentCount       = 5;
            const int iterations        = messagesPerExtent * extentCount;

            using (var infFile = new InfiniteFileWriter(this.path, nameof(this.InfiniteFileTest), extentSize))
            {
                byte[] bytes = new byte[messageSize];
                byte   val   = 100;
                for (int i = 0; i < iterations; i++)
                {
                    bytes[messageSize - 1] = val;
                    val++;
                    infFile.ReserveBlock(bytes.Length);
                    infFile.WriteToBlock(bytes);
                    infFile.CommitBlock();
                }
            }

            using (var infFile = new InfiniteFileReader(this.path, nameof(this.InfiniteFileTest)))
            {
                byte[] bytes = new byte[messageSize];
                byte   val   = 100;
                for (int i = 0; i < iterations; i++)
                {
                    infFile.MoveNext();
                    infFile.ReadBlock(ref bytes);
                    Assert.AreEqual(0, bytes[0]);
                    Assert.AreEqual(val, bytes[messageSize - 1]);
                    val++;
                }
            }
        }