Exemplo n.º 1
0
        // os2.close() will fail as no block was allocated.
        /// <summary>
        /// Ensure that reserved space is released when the client goes away
        /// unexpectedly.
        /// </summary>
        /// <remarks>
        /// Ensure that reserved space is released when the client goes away
        /// unexpectedly.
        /// The verification is done for each replica in the write pipeline.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Sharpen.TimeoutException"/>
        public virtual void TestSpaceReleasedOnUnexpectedEof()
        {
            short replication = 3;

            StartCluster(BlockSize, replication, -1);
            string methodName = GenericTestUtils.GetMethodName();
            Path   file       = new Path("/" + methodName + ".01.dat");
            // Write 1 byte to the file and kill the writer.
            FSDataOutputStream os = fs.Create(file, replication);

            os.Write(new byte[1]);
            os.Hsync();
            DFSTestUtil.AbortStream((DFSOutputStream)os.GetWrappedStream());
            // Ensure all space reserved for the replica was released on each
            // DataNode.
            foreach (DataNode dn in cluster.GetDataNodes())
            {
                FsVolumeImpl volume = (FsVolumeImpl)dn.GetFSDataset().GetVolumes()[0];
                GenericTestUtils.WaitFor(new _Supplier_276(volume), 500, int.MaxValue);
            }
        }
        /// <exception cref="System.IO.IOException"/>
        private void DoWriteAndAbort(DistributedFileSystem fs, Path path)
        {
            fs.Mkdirs(path);
            fs.AllowSnapshot(path);
            DFSTestUtil.CreateFile(fs, new Path("/test/test1"), 100, (short)2, 100024L);
            DFSTestUtil.CreateFile(fs, new Path("/test/test2"), 100, (short)2, 100024L);
            Path file = new Path("/test/test/test2");
            FSDataOutputStream @out = fs.Create(file);

            for (int i = 0; i < 2; i++)
            {
                long count = 0;
                while (count < 1048576)
                {
                    @out.WriteBytes("hell");
                    count += 4;
                }
            }
            ((DFSOutputStream)@out.GetWrappedStream()).Hsync(EnumSet.Of(HdfsDataOutputStream.SyncFlag
                                                                        .UpdateLength));
            DFSTestUtil.AbortStream((DFSOutputStream)@out.GetWrappedStream());
            Path file2 = new Path("/test/test/test3");
            FSDataOutputStream out2 = fs.Create(file2);

            for (int i_1 = 0; i_1 < 2; i_1++)
            {
                long count = 0;
                while (count < 1048576)
                {
                    out2.WriteBytes("hell");
                    count += 4;
                }
            }
            ((DFSOutputStream)out2.GetWrappedStream()).Hsync(EnumSet.Of(HdfsDataOutputStream.SyncFlag
                                                                        .UpdateLength));
            DFSTestUtil.AbortStream((DFSOutputStream)out2.GetWrappedStream());
            fs.CreateSnapshot(path, "s1");
        }