Пример #1
0
 /// <exception cref="System.IO.IOException"/>
 public TestFileDescriptorPair()
 {
     fis = new FileInputStream[2];
     for (int i = 0; i < 2; i++)
     {
         string           name = dir.GetDir() + "/file" + i;
         FileOutputStream fos  = new FileOutputStream(name);
         if (i == 0)
         {
             // write 'data' file
             fos.Write(1);
         }
         else
         {
             // write 'metadata' file
             BlockMetadataHeader header = new BlockMetadataHeader((short)1, DataChecksum.NewDataChecksum
                                                                      (DataChecksum.Type.Null, 4));
             DataOutputStream dos = new DataOutputStream(fos);
             BlockMetadataHeader.WriteHeader(dos, header);
             dos.Close();
         }
         fos.Close();
         fis[i] = new FileInputStream(name);
     }
 }
Пример #2
0
        public static void SetupCluster()
        {
            if (DomainSocket.GetLoadingFailureReason() != null)
            {
                return;
            }
            sockDir = new TemporarySocketDirectory();
            HdfsConfiguration conf = new HdfsConfiguration();

            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), "TestParallelShortCircuitReadUnCached._PORT.sock"
                                                                        ).GetAbsolutePath());
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            // Enabling data transfer encryption should have no effect when using
            // short-circuit local reads.  This is a regression test for HDFS-5353.
            conf.SetBoolean(DFSConfigKeys.DfsEncryptDataTransferKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsBlockAccessTokenEnableKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
            conf.SetBoolean(DFSConfigKeys.DfsClientDomainSocketDataTraffic, true);
            // We want to test reading from stale sockets.
            conf.SetInt(DFSConfigKeys.DfsDatanodeSocketReuseKeepaliveKey, 1);
            conf.SetLong(DFSConfigKeys.DfsClientSocketCacheExpiryMsecKey, 5 * 60 * 1000);
            conf.SetInt(DFSConfigKeys.DfsClientSocketCacheCapacityKey, 32);
            // Avoid using the FileInputStreamCache.
            conf.SetInt(DFSConfigKeys.DfsClientReadShortcircuitStreamsCacheSizeKey, 0);
            DomainSocket.DisableBindPathValidation();
            DFSInputStream.tcpReadsDisabledForTesting = true;
            SetupCluster(1, conf);
        }
Пример #3
0
        /// <summary>
        /// If ramDiskStorageLimit is &gt;=0, then RAM_DISK capacity is artificially
        /// capped.
        /// </summary>
        /// <remarks>
        /// If ramDiskStorageLimit is &gt;=0, then RAM_DISK capacity is artificially
        /// capped. If ramDiskStorageLimit &lt; 0 then it is ignored.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        protected internal void StartUpCluster(bool hasTransientStorage, int ramDiskReplicaCapacity
                                               , bool useSCR, bool useLegacyBlockReaderLocal)
        {
            Configuration conf = new Configuration();

            conf.SetLong(DfsBlockSizeKey, BlockSize);
            conf.SetInt(DfsNamenodeLazyPersistFileScrubIntervalSec, LazyWriteFileScrubberIntervalSec
                        );
            conf.SetLong(DfsHeartbeatIntervalKey, HeartbeatIntervalSec);
            conf.SetInt(DfsNamenodeHeartbeatRecheckIntervalKey, HeartbeatRecheckIntervalMsec);
            conf.SetInt(DfsDatanodeLazyWriterIntervalSec, LazyWriterIntervalSec);
            conf.SetInt(DfsDatanodeRamDiskLowWatermarkBytes, EvictionLowWatermark * BlockSize
                        );
            if (useSCR)
            {
                conf.SetBoolean(DfsClientReadShortcircuitKey, true);
                // Do not share a client context across tests.
                conf.Set(DfsClientContext, UUID.RandomUUID().ToString());
                if (useLegacyBlockReaderLocal)
                {
                    conf.SetBoolean(DfsClientUseLegacyBlockreaderlocal, true);
                    conf.Set(DfsBlockLocalPathAccessUserKey, UserGroupInformation.GetCurrentUser().GetShortUserName
                                 ());
                }
                else
                {
                    sockDir = new TemporarySocketDirectory();
                    conf.Set(DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), this.GetType().Name
                                                                  + "._PORT.sock").GetAbsolutePath());
                }
            }
            long[] capacities = null;
            if (hasTransientStorage && ramDiskReplicaCapacity >= 0)
            {
                // Convert replica count to byte count, add some delta for .meta and
                // VERSION files.
                long ramDiskStorageLimit = ((long)ramDiskReplicaCapacity * BlockSize) + (BlockSize
                                                                                         - 1);
                capacities = new long[] { ramDiskStorageLimit, -1 };
            }
            cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(ReplFactor).StorageCapacities
                          (capacities).StorageTypes(hasTransientStorage ? new StorageType[] { StorageType.
                                                                                              RamDisk, StorageType.Default } : null).Build();
            fs     = cluster.GetFileSystem();
            client = fs.GetClient();
            try
            {
                jmx = InitJMX();
            }
            catch (Exception e)
            {
                NUnit.Framework.Assert.Fail("Failed initialize JMX for testing: " + e);
            }
            Log.Info("Cluster startup complete");
        }
Пример #4
0
        public static Configuration CreateShortCircuitConf(string testName, TemporarySocketDirectory
                                                           sockDir)
        {
            Configuration conf = new Configuration();

            conf.Set(DFSConfigKeys.DfsClientContext, testName);
            conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, 4096);
            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), testName
                                                                        + "._PORT").GetAbsolutePath());
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
            conf.SetBoolean(DFSConfigKeys.DfsClientDomainSocketDataTraffic, false);
            return(conf);
        }
        private static Configuration GetDefaultConf()
        {
            HdfsConfiguration conf = new HdfsConfiguration();

            conf.SetLong(DFSConfigKeys.DfsNamenodePathBasedCacheRefreshIntervalMs, 50);
            conf.SetLong(DFSConfigKeys.DfsCachereportIntervalMsecKey, 250);
            conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, BlockSize);
            conf.SetLong(DFSConfigKeys.DfsDatanodeMaxLockedMemoryKey, TestFsDatasetCache.CacheCapacity
                         );
            conf.SetLong(DFSConfigKeys.DfsHeartbeatIntervalKey, 1);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), "sock"
                                                                        ).GetAbsolutePath());
            return(conf);
        }
Пример #6
0
        /// <summary>
        /// Test that file data can be read by reading the block file
        /// directly from the local store.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void DoTestShortCircuitReadImpl(bool ignoreChecksum, int size, int
                                                       readOffset, string shortCircuitUser, string readingUser, bool legacyShortCircuitFails
                                                       )
        {
            Configuration conf = new Configuration();

            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, ignoreChecksum
                            );
            // Set a random client context name so that we don't share a cache with
            // other invocations of this function.
            conf.Set(DFSConfigKeys.DfsClientContext, UUID.RandomUUID().ToString());
            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), "TestShortCircuitLocalRead._PORT.sock"
                                                                        ).GetAbsolutePath());
            if (shortCircuitUser != null)
            {
                conf.Set(DFSConfigKeys.DfsBlockLocalPathAccessUserKey, shortCircuitUser);
                conf.SetBoolean(DFSConfigKeys.DfsClientUseLegacyBlockreaderlocal, true);
            }
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Format(
                true).Build();
            FileSystem fs = cluster.GetFileSystem();

            try
            {
                // check that / exists
                Path path = new Path("/");
                NUnit.Framework.Assert.IsTrue("/ should be a directory", fs.GetFileStatus(path).IsDirectory
                                                  () == true);
                byte[]             fileData = AppendTestUtil.RandomBytes(seed, size);
                Path               file1    = fs.MakeQualified(new Path("filelocal.dat"));
                FSDataOutputStream stm      = CreateFile(fs, file1, 1);
                stm.Write(fileData);
                stm.Close();
                URI uri = cluster.GetURI();
                CheckFileContent(uri, file1, fileData, readOffset, readingUser, conf, legacyShortCircuitFails
                                 );
                CheckFileContentDirect(uri, file1, fileData, readOffset, readingUser, conf, legacyShortCircuitFails
                                       );
            }
            finally
            {
                fs.Close();
                cluster.Shutdown();
            }
        }
Пример #7
0
        public static void SetupCluster()
        {
            if (DomainSocket.GetLoadingFailureReason() != null)
            {
                return;
            }
            DFSInputStream.tcpReadsDisabledForTesting = true;
            sockDir = new TemporarySocketDirectory();
            HdfsConfiguration conf = new HdfsConfiguration();

            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), "TestParallelLocalRead.%d.sock"
                                                                        ).GetAbsolutePath());
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
            DomainSocket.DisableBindPathValidation();
            SetupCluster(1, conf);
        }
Пример #8
0
        private static Configuration CreateShortCircuitConf(string testName, TemporarySocketDirectory
                                                            sockDir)
        {
            Configuration conf = new Configuration();

            conf.Set(DFSConfigKeys.DfsClientContext, testName);
            conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, 4096);
            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), testName
                                                                        ).GetAbsolutePath());
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
            conf.SetBoolean(DFSConfigKeys.DfsClientDomainSocketDataTraffic, false);
            DFSInputStream.tcpReadsDisabledForTesting = true;
            DomainSocket.DisableBindPathValidation();
            Assume.AssumeThat(DomainSocket.GetLoadingFailureReason(), CoreMatchers.EqualTo(null
                                                                                           ));
            return(conf);
        }
        public static HdfsConfiguration InitZeroCopyTest()
        {
            Assume.AssumeTrue(NativeIO.IsAvailable());
            Assume.AssumeTrue(SystemUtils.IsOsUnix);
            HdfsConfiguration conf = new HdfsConfiguration();

            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, BlockSize);
            conf.SetInt(DFSConfigKeys.DfsClientMmapCacheSize, 3);
            conf.SetLong(DFSConfigKeys.DfsClientMmapCacheTimeoutMs, 100);
            conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), "TestRequestMmapAccess._PORT.sock"
                                                                        ).GetAbsolutePath());
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, true);
            conf.SetLong(DFSConfigKeys.DfsHeartbeatIntervalKey, 1);
            conf.SetLong(DFSConfigKeys.DfsCachereportIntervalMsecKey, 1000);
            conf.SetLong(DFSConfigKeys.DfsNamenodePathBasedCacheRefreshIntervalMs, 1000);
            return(conf);
        }
Пример #10
0
        public virtual void TestCreateAndDestroySpanReceiver()
        {
            Configuration conf = new Configuration();

            conf = new Configuration();
            conf.Set(DFSConfigKeys.DfsServerHtracePrefix + SpanReceiverHost.SpanReceiversConfSuffix
                     , string.Empty);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(3).Build();

            cluster.WaitActive();
            TemporarySocketDirectory tempDir = new TemporarySocketDirectory();
            string tracePath = new FilePath(tempDir.GetDir(), "tracefile").GetAbsolutePath();

            try
            {
                TraceAdmin trace = new TraceAdmin();
                trace.SetConf(conf);
                NUnit.Framework.Assert.AreEqual("ret:0, [no span receivers found]" + Newline, RunTraceCommand
                                                    (trace, "-list", "-host", GetHostPortForNN(cluster)));
                NUnit.Framework.Assert.AreEqual("ret:0, Added trace span receiver 1 with " + "configuration local-file-span-receiver.path = "
                                                + tracePath + Newline, RunTraceCommand(trace, "-add", "-host", GetHostPortForNN
                                                                                           (cluster), "-class", "org.apache.htrace.impl.LocalFileSpanReceiver", "-Clocal-file-span-receiver.path="
                                                                                       + tracePath));
                string list = RunTraceCommand(trace, "-list", "-host", GetHostPortForNN(cluster));
                NUnit.Framework.Assert.IsTrue(list.StartsWith("ret:0"));
                NUnit.Framework.Assert.IsTrue(list.Contains("1   org.apache.htrace.impl.LocalFileSpanReceiver"
                                                            ));
                NUnit.Framework.Assert.AreEqual("ret:0, Removed trace span receiver 1" + Newline,
                                                RunTraceCommand(trace, "-remove", "1", "-host", GetHostPortForNN(cluster)));
                NUnit.Framework.Assert.AreEqual("ret:0, [no span receivers found]" + Newline, RunTraceCommand
                                                    (trace, "-list", "-host", GetHostPortForNN(cluster)));
                NUnit.Framework.Assert.AreEqual("ret:0, Added trace span receiver 2 with " + "configuration local-file-span-receiver.path = "
                                                + tracePath + Newline, RunTraceCommand(trace, "-add", "-host", GetHostPortForNN
                                                                                           (cluster), "-class", "LocalFileSpanReceiver", "-Clocal-file-span-receiver.path="
                                                                                       + tracePath));
                NUnit.Framework.Assert.AreEqual("ret:0, Removed trace span receiver 2" + Newline,
                                                RunTraceCommand(trace, "-remove", "2", "-host", GetHostPortForNN(cluster)));
            }
            finally
            {
                cluster.Shutdown();
                tempDir.Close();
            }
        }
Пример #11
0
        /// <summary>
        /// If ramDiskStorageLimit is &gt;=0, then RAM_DISK capacity is artificially
        /// capped.
        /// </summary>
        /// <remarks>
        /// If ramDiskStorageLimit is &gt;=0, then RAM_DISK capacity is artificially
        /// capped. If ramDiskStorageLimit &lt; 0 then it is ignored.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        protected internal void StartUpCluster(int numDataNodes, StorageType[] storageTypes
                                               , long ramDiskStorageLimit, bool useSCR)
        {
            Configuration conf = new Configuration();

            conf.SetLong(DfsBlockSizeKey, BlockSize);
            conf.SetInt(DfsNamenodeLazyPersistFileScrubIntervalSec, LazyWriteFileScrubberIntervalSec
                        );
            conf.SetLong(DfsHeartbeatIntervalKey, HeartbeatIntervalSec);
            conf.SetInt(DfsNamenodeHeartbeatRecheckIntervalKey, HeartbeatRecheckIntervalMsec);
            conf.SetInt(DfsDatanodeLazyWriterIntervalSec, LazyWriterIntervalSec);
            if (useSCR)
            {
                conf.SetBoolean(DfsClientReadShortcircuitKey, useSCR);
                conf.Set(DfsClientContext, UUID.RandomUUID().ToString());
                sockDir = new TemporarySocketDirectory();
                conf.Set(DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), this.GetType().Name
                                                              + "._PORT.sock").GetAbsolutePath());
                conf.Set(DfsBlockLocalPathAccessUserKey, UserGroupInformation.GetCurrentUser().GetShortUserName
                             ());
            }
            cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(numDataNodes).StorageTypes
                          (storageTypes != null ? storageTypes : new StorageType[] { StorageType.Default,
                                                                                     StorageType.Default }).Build();
            fs     = cluster.GetFileSystem();
            client = fs.GetClient();
            // Artificially cap the storage capacity of the RAM_DISK volume.
            if (ramDiskStorageLimit >= 0)
            {
                IList <FsVolumeSpi> volumes = cluster.GetDataNodes()[0].GetFSDataset().GetVolumes(
                    );
                foreach (FsVolumeSpi volume in volumes)
                {
                    if (volume.GetStorageType() == StorageType.RamDisk)
                    {
                        ((FsVolumeImpl)volume).SetCapacityForTesting(ramDiskStorageLimit);
                    }
                }
            }
            Log.Info("Cluster startup complete");
        }
Пример #12
0
        /// <exception cref="System.IO.IOException"/>
        private static HdfsConfiguration GetConfiguration(TemporarySocketDirectory socketDir
                                                          )
        {
            HdfsConfiguration conf = new HdfsConfiguration();

            if (socketDir == null)
            {
                conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, string.Empty);
            }
            else
            {
                conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(socketDir.GetDir(), "TestBlockReaderLocalLegacy.%d.sock"
                                                                            ).GetAbsolutePath());
            }
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientUseLegacyBlockreaderlocal, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
            conf.Set(DFSConfigKeys.DfsBlockLocalPathAccessUserKey, UserGroupInformation.GetCurrentUser
                         ().GetShortUserName());
            conf.SetBoolean(DFSConfigKeys.DfsClientDomainSocketDataTraffic, false);
            // Set short retry timeouts so this test runs faster
            conf.SetInt(DFSConfigKeys.DfsClientRetryWindowBase, 10);
            return(conf);
        }
Пример #13
0
        /// <exception cref="System.Exception"/>
        private void TestStatistics(bool isShortCircuit)
        {
            Assume.AssumeTrue(DomainSocket.GetLoadingFailureReason() == null);
            HdfsConfiguration        conf    = new HdfsConfiguration();
            TemporarySocketDirectory sockDir = null;

            if (isShortCircuit)
            {
                DFSInputStream.tcpReadsDisabledForTesting = true;
                sockDir = new TemporarySocketDirectory();
                conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), "TestStatisticsForLocalRead.%d.sock"
                                                                            ).GetAbsolutePath());
                conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
                DomainSocket.DisableBindPathValidation();
            }
            else
            {
                conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, false);
            }
            MiniDFSCluster    cluster    = null;
            Path              TestPath   = new Path("/a");
            long              RandomSeed = 4567L;
            FSDataInputStream fsIn       = null;

            byte[]     original = new byte[TestBlockReaderLocal.BlockReaderLocalTest.TestLength];
            FileSystem fs       = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
                cluster.WaitActive();
                fs = cluster.GetFileSystem();
                DFSTestUtil.CreateFile(fs, TestPath, TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                       , (short)1, RandomSeed);
                try
                {
                    DFSTestUtil.WaitReplication(fs, TestPath, (short)1);
                }
                catch (Exception e)
                {
                    NUnit.Framework.Assert.Fail("unexpected InterruptedException during " + "waitReplication: "
                                                + e);
                }
                catch (TimeoutException e)
                {
                    NUnit.Framework.Assert.Fail("unexpected TimeoutException during " + "waitReplication: "
                                                + e);
                }
                fsIn = fs.Open(TestPath);
                IOUtils.ReadFully(fsIn, original, 0, TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                  );
                HdfsDataInputStream dfsIn = (HdfsDataInputStream)fsIn;
                NUnit.Framework.Assert.AreEqual(TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                                , dfsIn.GetReadStatistics().GetTotalBytesRead());
                NUnit.Framework.Assert.AreEqual(TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                                , dfsIn.GetReadStatistics().GetTotalLocalBytesRead());
                if (isShortCircuit)
                {
                    NUnit.Framework.Assert.AreEqual(TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                                    , dfsIn.GetReadStatistics().GetTotalShortCircuitBytesRead());
                }
                else
                {
                    NUnit.Framework.Assert.AreEqual(0, dfsIn.GetReadStatistics().GetTotalShortCircuitBytesRead
                                                        ());
                }
                fsIn.Close();
                fsIn = null;
            }
            finally
            {
                DFSInputStream.tcpReadsDisabledForTesting = false;
                if (fsIn != null)
                {
                    fsIn.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
                if (sockDir != null)
                {
                    sockDir.Close();
                }
            }
        }
Пример #14
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void RunBlockReaderLocalTest(TestBlockReaderLocal.BlockReaderLocalTest
                                                    test, bool checksum, long readahead)
        {
            Assume.AssumeThat(DomainSocket.GetLoadingFailureReason(), CoreMatchers.EqualTo(null
                                                                                           ));
            MiniDFSCluster    cluster = null;
            HdfsConfiguration conf    = new HdfsConfiguration();

            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, !checksum
                            );
            conf.SetLong(DFSConfigKeys.DfsBytesPerChecksumKey, TestBlockReaderLocal.BlockReaderLocalTest
                         .BytesPerChecksum);
            conf.Set(DFSConfigKeys.DfsChecksumTypeKey, "CRC32C");
            conf.SetLong(DFSConfigKeys.DfsClientCacheReadahead, readahead);
            test.SetConfiguration(conf);
            FileInputStream   dataIn           = null;
            FileInputStream   metaIn           = null;
            Path              TestPath         = new Path("/a");
            long              RandomSeed       = 4567L;
            BlockReaderLocal  blockReaderLocal = null;
            FSDataInputStream fsIn             = null;

            byte[]           original = new byte[TestBlockReaderLocal.BlockReaderLocalTest.TestLength];
            FileSystem       fs       = null;
            ShortCircuitShm  shm      = null;
            RandomAccessFile raf      = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
                cluster.WaitActive();
                fs = cluster.GetFileSystem();
                DFSTestUtil.CreateFile(fs, TestPath, TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                       , (short)1, RandomSeed);
                try
                {
                    DFSTestUtil.WaitReplication(fs, TestPath, (short)1);
                }
                catch (Exception e)
                {
                    NUnit.Framework.Assert.Fail("unexpected InterruptedException during " + "waitReplication: "
                                                + e);
                }
                catch (TimeoutException e)
                {
                    NUnit.Framework.Assert.Fail("unexpected TimeoutException during " + "waitReplication: "
                                                + e);
                }
                fsIn = fs.Open(TestPath);
                IOUtils.ReadFully(fsIn, original, 0, TestBlockReaderLocal.BlockReaderLocalTest.TestLength
                                  );
                fsIn.Close();
                fsIn = null;
                ExtendedBlock     block             = DFSTestUtil.GetFirstBlock(fs, TestPath);
                FilePath          dataFile          = cluster.GetBlockFile(0, block);
                FilePath          metaFile          = cluster.GetBlockMetadataFile(0, block);
                ShortCircuitCache shortCircuitCache = ClientContext.GetFromConf(conf).GetShortCircuitCache
                                                          ();
                cluster.Shutdown();
                cluster = null;
                test.Setup(dataFile, checksum);
                FileInputStream[] streams = new FileInputStream[] { new FileInputStream(dataFile)
                                                                    , new FileInputStream(metaFile) };
                dataIn = streams[0];
                metaIn = streams[1];
                ExtendedBlockId key = new ExtendedBlockId(block.GetBlockId(), block.GetBlockPoolId
                                                              ());
                raf = new RandomAccessFile(new FilePath(sockDir.GetDir().GetAbsolutePath(), UUID.
                                                        RandomUUID().ToString()), "rw");
                raf.SetLength(8192);
                FileInputStream shmStream = new FileInputStream(raf.GetFD());
                shm = new ShortCircuitShm(ShortCircuitShm.ShmId.CreateRandom(), shmStream);
                ShortCircuitReplica replica = new ShortCircuitReplica(key, dataIn, metaIn, shortCircuitCache
                                                                      , Time.Now(), shm.AllocAndRegisterSlot(ExtendedBlockId.FromExtendedBlock(block))
                                                                      );
                blockReaderLocal = new BlockReaderLocal.Builder(new DFSClient.Conf(conf)).SetFilename
                                       (TestPath.GetName()).SetBlock(block).SetShortCircuitReplica(replica).SetCachingStrategy
                                       (new CachingStrategy(false, readahead)).SetVerifyChecksum(checksum).Build();
                dataIn = null;
                metaIn = null;
                test.DoTest(blockReaderLocal, original);
                // BlockReaderLocal should not alter the file position.
                NUnit.Framework.Assert.AreEqual(0, streams[0].GetChannel().Position());
                NUnit.Framework.Assert.AreEqual(0, streams[1].GetChannel().Position());
            }
            finally
            {
                if (fsIn != null)
                {
                    fsIn.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
                if (dataIn != null)
                {
                    dataIn.Close();
                }
                if (metaIn != null)
                {
                    metaIn.Close();
                }
                if (blockReaderLocal != null)
                {
                    blockReaderLocal.Close();
                }
                if (shm != null)
                {
                    shm.Free();
                }
                if (raf != null)
                {
                    raf.Close();
                }
            }
        }