コード例 #1
0
        public void Quota()
        {
            // Arrange
            PermutationSetup permutation = new PermutationSetup();

            permutation.Add(blockpool_3KB);

            permutation.Add(case_ms);
            permutation.Add(case_decor_ms);
            permutation.Add(case_vfs_ms);
            permutation.Add(case_vfs_2ms);


            // Act & Assert
            foreach (Scenario scenario in permutation.Scenarios)
            {
                using (Run run = scenario.Run().Initialize())
                {
                    IFileSystemDisposable fs   = run.Parameters["Class"] as IFileSystemDisposable;
                    IBlockPool            pool = run.Parameters["BlockPool"] as IBlockPool;
                    fs.CreateDirectory("dir/");

                    using (var s = fs.Open("dir/file", FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                    {
                        Assert.AreEqual(0L, pool.BytesAllocated);

                        s.Write(new byte[1024]);
                        Assert.AreEqual(1024L, pool.BytesAllocated);
                        Assert.AreEqual(2048L, pool.BytesAvailable);
                        Assert.AreEqual(1024L, s.Length);

                        s.Write(new byte[1024]);
                        Assert.AreEqual(2048L, pool.BytesAllocated);
                        Assert.AreEqual(1024L, pool.BytesAvailable);
                        Assert.AreEqual(2048L, s.Length);

                        s.Write(new byte[1024]);
                        Assert.AreEqual(3072L, s.Length);
                        Assert.AreEqual(3072L, pool.BytesAllocated);
                        Assert.AreEqual(0L, pool.BytesAvailable);

                        try
                        {
                            s.Write(new byte[1024]);
                            Assert.Fail();
                        }
                        catch (FileSystemExceptionOutOfDiskSpace)
                        {
                        }
                        Assert.AreEqual(3072, s.Length);

                        try
                        {
                            s.WriteByte(3);
                            Assert.Fail();
                        }
                        catch (FileSystemExceptionOutOfDiskSpace)
                        {
                        }
                        Assert.AreEqual(3072, s.Length);

                        s.SetLength(3071);
                        Assert.AreEqual(3071, s.Length);

                        s.WriteByte(3);
                        Assert.AreEqual(3072, s.Length);

                        s.SetLength(0L);
                        Assert.AreEqual(0, s.Length);
                        Assert.AreEqual(0L, pool.BytesAllocated);
                        Assert.AreEqual(3072L, pool.BytesAvailable);

                        s.Write(new byte[1024]);
                        s.Write(new byte[1024]);
                        s.Write(new byte[1024]);
                        Assert.AreEqual(3072L, s.Length);
                        Assert.AreEqual(3072L, pool.BytesAllocated);
                        Assert.AreEqual(0L, pool.BytesAvailable);
                    }

                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    fs.Delete("dir/", true);
                    Assert.AreEqual(0L, pool.BytesAllocated);
                    Assert.AreEqual(3072L, pool.BytesAvailable);


                    fs.CreateFile("newfile", new byte[3072]);
                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    Stream ss = fs.Open("newfile", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                    fs.Delete("newfile");
                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    ss.Dispose();
                    Assert.AreEqual(0L, pool.BytesAllocated);
                    Assert.AreEqual(3072L, pool.BytesAvailable);

                    fs.CreateFile("newfile", new byte[3072]);
                    Assert.AreEqual(3072L, pool.BytesAllocated);
                    Assert.AreEqual(0L, pool.BytesAvailable);
                    fs.Dispose();
                    Assert.AreEqual(0L, pool.BytesAllocated);
                    Assert.AreEqual(3072L, pool.BytesAvailable);
                }
            }
        }