Ejemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        private void DoPread(FSDataInputStream stm, long position, byte[] buffer, int offset
                             , int length)
        {
            int            nread     = 0;
            long           totalRead = 0;
            DFSInputStream dfstm     = null;

            if (stm.GetWrappedStream() is DFSInputStream)
            {
                dfstm     = (DFSInputStream)(stm.GetWrappedStream());
                totalRead = dfstm.GetReadStatistics().GetTotalBytesRead();
            }
            while (nread < length)
            {
                int nbytes = stm.Read(position + nread, buffer, offset + nread, length - nread);
                NUnit.Framework.Assert.IsTrue("Error in pread", nbytes > 0);
                nread += nbytes;
            }
            if (dfstm != null)
            {
                if (isHedgedRead)
                {
                    NUnit.Framework.Assert.IsTrue("Expected read statistic to be incremented", length
                                                  <= dfstm.GetReadStatistics().GetTotalBytesRead() - totalRead);
                }
                else
                {
                    NUnit.Framework.Assert.AreEqual("Expected read statistic to be incremented", length
                                                    , dfstm.GetReadStatistics().GetTotalBytesRead() - totalRead);
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void TestReadClosedStream()
        {
            Path testFile         = new Path("/testfile+2");
            FSDataOutputStream os = hdfs.Create(testFile, true);

            os.WriteBytes("0123456789");
            os.Close();
            // ByteRangeInputStream delays opens until reads. Make sure it doesn't
            // open a closed stream that has never been opened
            FSDataInputStream @in = hftpFs.Open(testFile);

            @in.Close();
            CheckClosedStream(@in);
            CheckClosedStream(@in.GetWrappedStream());
            // force the stream to connect and then close it
            @in = hftpFs.Open(testFile);
            int ch = @in.Read();

            NUnit.Framework.Assert.AreEqual('0', ch);
            @in.Close();
            CheckClosedStream(@in);
            CheckClosedStream(@in.GetWrappedStream());
            // make sure seeking doesn't automagically reopen the stream
            @in.Seek(4);
            CheckClosedStream(@in);
            CheckClosedStream(@in.GetWrappedStream());
        }
Ejemplo n.º 3
0
        /// <exception cref="System.IO.IOException"/>
        public static void Check(FileSystem fs, Path p, long length)
        {
            int i = -1;

            try
            {
                FileStatus        status = fs.GetFileStatus(p);
                FSDataInputStream @in    = fs.Open(p);
                if (@in.GetWrappedStream() is DFSInputStream)
                {
                    long len = ((DFSInputStream)@in.GetWrappedStream()).GetFileLength();
                    NUnit.Framework.Assert.AreEqual(length, len);
                }
                else
                {
                    NUnit.Framework.Assert.AreEqual(length, status.GetLen());
                }
                for (i++; i < length; i++)
                {
                    NUnit.Framework.Assert.AreEqual(unchecked ((byte)i), unchecked ((byte)@in.Read()));
                }
                i = -(int)length;
                NUnit.Framework.Assert.AreEqual(-1, @in.Read());
                //EOF
                @in.Close();
            }
            catch (IOException ioe)
            {
                throw new IOException("p=" + p + ", length=" + length + ", i=" + i, ioe);
            }
        }