Example #1
0
        // Wait until the test times out.
        /// <exception cref="System.Exception"/>
        public virtual void TestRBWFileCreationError()
        {
            short replication = 1;

            StartCluster(BlockSize, replication, -1);
            FsVolumeImpl fsVolumeImpl = (FsVolumeImpl)cluster.GetDataNodes()[0].GetFSDataset(
                ).GetVolumes()[0];
            string methodName = GenericTestUtils.GetMethodName();
            Path   file       = new Path("/" + methodName + ".01.dat");
            // Mock BlockPoolSlice so that RBW file creation gives IOExcception
            BlockPoolSlice blockPoolSlice = Org.Mockito.Mockito.Mock <BlockPoolSlice>();

            Org.Mockito.Mockito.When(blockPoolSlice.CreateRbwFile((Block)Org.Mockito.Mockito.
                                                                  Any())).ThenThrow(new IOException("Synthetic IO Exception Throgh MOCK"));
            FieldInfo field = Sharpen.Runtime.GetDeclaredField(typeof(FsVolumeImpl), "bpSlices"
                                                               );
            IDictionary <string, BlockPoolSlice> bpSlices = (IDictionary <string, BlockPoolSlice
                                                                          >)field.GetValue(fsVolumeImpl);

            bpSlices[fsVolumeImpl.GetBlockPoolList()[0]] = blockPoolSlice;
            try
            {
                // Write 1 byte to the file
                FSDataOutputStream os = fs.Create(file, replication);
                os.Write(new byte[1]);
                os.Hsync();
                os.Close();
                NUnit.Framework.Assert.Fail("Expecting IOException file creation failure");
            }
            catch (IOException)
            {
            }
            // Exception can be ignored (expected)
            // Ensure RBW space reserved is released
            NUnit.Framework.Assert.IsTrue("Expected ZERO but got " + fsVolumeImpl.GetReservedForRbw
                                              (), fsVolumeImpl.GetReservedForRbw() == 0);
        }