Пример #1
0
        public virtual void TestStorageUsage()
        {
            SimulatedFSDataset fsdataset = GetSimulatedFSDataset();

            NUnit.Framework.Assert.AreEqual(fsdataset.GetDfsUsed(), 0);
            NUnit.Framework.Assert.AreEqual(fsdataset.GetRemaining(), fsdataset.GetCapacity()
                                            );
            int bytesAdded = AddSomeBlocks(fsdataset);

            NUnit.Framework.Assert.AreEqual(bytesAdded, fsdataset.GetDfsUsed());
            NUnit.Framework.Assert.AreEqual(fsdataset.GetCapacity() - bytesAdded, fsdataset.GetRemaining
                                                ());
        }
Пример #2
0
        public virtual void TestInjectionEmpty()
        {
            SimulatedFSDataset fsdataset   = GetSimulatedFSDataset();
            BlockListAsLongs   blockReport = fsdataset.GetBlockReport(bpid);

            NUnit.Framework.Assert.AreEqual(0, blockReport.GetNumberOfBlocks());
            int bytesAdded = AddSomeBlocks(fsdataset);

            blockReport = fsdataset.GetBlockReport(bpid);
            NUnit.Framework.Assert.AreEqual(Numblocks, blockReport.GetNumberOfBlocks());
            foreach (Block b in blockReport)
            {
                NUnit.Framework.Assert.IsNotNull(b);
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(b.GetBlockId()), b.GetNumBytes());
            }
            // Inject blocks into an empty fsdataset
            //  - injecting the blocks we got above.
            SimulatedFSDataset sfsdataset = GetSimulatedFSDataset();

            sfsdataset.InjectBlocks(bpid, blockReport);
            blockReport = sfsdataset.GetBlockReport(bpid);
            NUnit.Framework.Assert.AreEqual(Numblocks, blockReport.GetNumberOfBlocks());
            foreach (Block b_1 in blockReport)
            {
                NUnit.Framework.Assert.IsNotNull(b_1);
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(b_1.GetBlockId()), b_1.GetNumBytes()
                                                );
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(b_1.GetBlockId()), sfsdataset.GetLength
                                                    (new ExtendedBlock(bpid, b_1)));
            }
            NUnit.Framework.Assert.AreEqual(bytesAdded, sfsdataset.GetDfsUsed());
            NUnit.Framework.Assert.AreEqual(sfsdataset.GetCapacity() - bytesAdded, sfsdataset
                                            .GetRemaining());
        }
Пример #3
0
        public virtual void TestInjectionNonEmpty()
        {
            SimulatedFSDataset fsdataset   = GetSimulatedFSDataset();
            BlockListAsLongs   blockReport = fsdataset.GetBlockReport(bpid);

            NUnit.Framework.Assert.AreEqual(0, blockReport.GetNumberOfBlocks());
            int bytesAdded = AddSomeBlocks(fsdataset);

            blockReport = fsdataset.GetBlockReport(bpid);
            NUnit.Framework.Assert.AreEqual(Numblocks, blockReport.GetNumberOfBlocks());
            foreach (Block b in blockReport)
            {
                NUnit.Framework.Assert.IsNotNull(b);
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(b.GetBlockId()), b.GetNumBytes());
            }
            fsdataset = null;
            // Inject blocks into an non-empty fsdataset
            //  - injecting the blocks we got above.
            SimulatedFSDataset sfsdataset = GetSimulatedFSDataset();

            // Add come blocks whose block ids do not conflict with
            // the ones we are going to inject.
            bytesAdded += AddSomeBlocks(sfsdataset, Numblocks + 1);
            sfsdataset.GetBlockReport(bpid);
            NUnit.Framework.Assert.AreEqual(Numblocks, blockReport.GetNumberOfBlocks());
            sfsdataset.GetBlockReport(bpid);
            NUnit.Framework.Assert.AreEqual(Numblocks, blockReport.GetNumberOfBlocks());
            sfsdataset.InjectBlocks(bpid, blockReport);
            blockReport = sfsdataset.GetBlockReport(bpid);
            NUnit.Framework.Assert.AreEqual(Numblocks * 2, blockReport.GetNumberOfBlocks());
            foreach (Block b_1 in blockReport)
            {
                NUnit.Framework.Assert.IsNotNull(b_1);
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(b_1.GetBlockId()), b_1.GetNumBytes()
                                                );
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(b_1.GetBlockId()), sfsdataset.GetLength
                                                    (new ExtendedBlock(bpid, b_1)));
            }
            NUnit.Framework.Assert.AreEqual(bytesAdded, sfsdataset.GetDfsUsed());
            NUnit.Framework.Assert.AreEqual(sfsdataset.GetCapacity() - bytesAdded, sfsdataset
                                            .GetRemaining());
            // Now test that the dataset cannot be created if it does not have sufficient cap
            conf.SetLong(SimulatedFSDataset.ConfigPropertyCapacity, 10);
            try
            {
                sfsdataset = GetSimulatedFSDataset();
                sfsdataset.AddBlockPool(bpid, conf);
                sfsdataset.InjectBlocks(bpid, blockReport);
                NUnit.Framework.Assert.IsTrue("Expected an IO exception", false);
            }
            catch (IOException)
            {
            }
        }
Пример #4
0
        public virtual void TestInvalidate()
        {
            SimulatedFSDataset fsdataset = GetSimulatedFSDataset();
            int bytesAdded = AddSomeBlocks(fsdataset);

            Block[] deleteBlocks = new Block[2];
            deleteBlocks[0] = new Block(1, 0, 0);
            deleteBlocks[1] = new Block(2, 0, 0);
            fsdataset.Invalidate(bpid, deleteBlocks);
            CheckInvalidBlock(new ExtendedBlock(bpid, deleteBlocks[0]));
            CheckInvalidBlock(new ExtendedBlock(bpid, deleteBlocks[1]));
            long sizeDeleted = BlockIdToLen(1) + BlockIdToLen(2);

            NUnit.Framework.Assert.AreEqual(bytesAdded - sizeDeleted, fsdataset.GetDfsUsed());
            NUnit.Framework.Assert.AreEqual(fsdataset.GetCapacity() - bytesAdded + sizeDeleted
                                            , fsdataset.GetRemaining());
            // Now make sure the rest of the blocks are valid
            for (int i = 3; i <= Numblocks; ++i)
            {
                Block b = new Block(i, 0, 0);
                NUnit.Framework.Assert.IsTrue(fsdataset.IsValidBlock(new ExtendedBlock(bpid, b)));
            }
        }