Пример #1
0
        // ok - as expected
        public virtual void CheckInvalidBlock(ExtendedBlock b)
        {
            SimulatedFSDataset fsdataset = GetSimulatedFSDataset();

            NUnit.Framework.Assert.IsFalse(fsdataset.IsValidBlock(b));
            try
            {
                fsdataset.GetLength(b);
                NUnit.Framework.Assert.IsTrue("Expected an IO exception", false);
            }
            catch (IOException)
            {
            }
            // ok - as expected
            try
            {
                fsdataset.GetBlockInputStream(b);
                NUnit.Framework.Assert.IsTrue("Expected an IO exception", false);
            }
            catch (IOException)
            {
            }
            // ok - as expected
            try
            {
                fsdataset.FinalizeBlock(b);
                NUnit.Framework.Assert.IsTrue("Expected an IO exception", false);
            }
            catch (IOException)
            {
            }
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        internal virtual int AddSomeBlocks(SimulatedFSDataset fsdataset, int startingBlockId
                                           )
        {
            int bytesAdded = 0;

            for (int i = startingBlockId; i < startingBlockId + Numblocks; ++i)
            {
                ExtendedBlock b = new ExtendedBlock(bpid, i, 0, 0);
                // we pass expected len as zero, - fsdataset should use the sizeof actual
                // data written
                ReplicaInPipelineInterface bInfo = fsdataset.CreateRbw(StorageType.Default, b, false
                                                                       ).GetReplica();
                ReplicaOutputStreams @out = bInfo.CreateStreams(true, DataChecksum.NewDataChecksum
                                                                    (DataChecksum.Type.Crc32, 512));
                try
                {
                    OutputStream dataOut = @out.GetDataOut();
                    NUnit.Framework.Assert.AreEqual(0, fsdataset.GetLength(b));
                    for (int j = 1; j <= BlockIdToLen(i); ++j)
                    {
                        dataOut.Write(j);
                        NUnit.Framework.Assert.AreEqual(j, bInfo.GetBytesOnDisk());
                        // correct length even as we write
                        bytesAdded++;
                    }
                }
                finally
                {
                    @out.Close();
                }
                b.SetNumBytes(BlockIdToLen(i));
                fsdataset.FinalizeBlock(b);
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(i), fsdataset.GetLength(b));
            }
            return(bytesAdded);
        }