示例#1
0
 /// <summary>Constructs a split with host and cached-blocks information</summary>
 /// <param name="file">the file name</param>
 /// <param name="start">the position of the first byte in the file to process</param>
 /// <param name="length">the number of bytes in the file to process</param>
 /// <param name="hosts">the list of hosts containing the block</param>
 /// <param name="inMemoryHosts">the list of hosts containing the block in memory</param>
 public FileSplit(Path file, long start, long length, string[] hosts, string[] inMemoryHosts
                  )
     : this(file, start, length, hosts)
 {
     hostInfos = new SplitLocationInfo[hosts.Length];
     for (int i = 0; i < hosts.Length; i++)
     {
         // because N will be tiny, scanning is probably faster than a HashSet
         bool inMemory = false;
         foreach (string inMemoryHost in inMemoryHosts)
         {
             if (inMemoryHost.Equals(hosts[i]))
             {
                 inMemory = true;
                 break;
             }
         }
         hostInfos[i] = new SplitLocationInfo(hosts[i], inMemory);
     }
 }
        public virtual void TestSplitLocationInfo()
        {
            Configuration conf = GetConfiguration();

            conf.Set(FileInputFormat.InputDir, "test:///a1/a2");
            Job                job             = Job.GetInstance(conf);
            TextInputFormat    fileInputFormat = new TextInputFormat();
            IList <InputSplit> splits          = fileInputFormat.GetSplits(job);

            string[] locations = splits[0].GetLocations();
            NUnit.Framework.Assert.AreEqual(2, locations.Length);
            SplitLocationInfo[] locationInfo = splits[0].GetLocationInfo();
            NUnit.Framework.Assert.AreEqual(2, locationInfo.Length);
            SplitLocationInfo localhostInfo = locations[0].Equals("localhost") ? locationInfo
                                              [0] : locationInfo[1];
            SplitLocationInfo otherhostInfo = locations[0].Equals("otherhost") ? locationInfo
                                              [0] : locationInfo[1];

            NUnit.Framework.Assert.IsTrue(localhostInfo.IsOnDisk());
            NUnit.Framework.Assert.IsTrue(localhostInfo.IsInMemory());
            NUnit.Framework.Assert.IsTrue(otherhostInfo.IsOnDisk());
            NUnit.Framework.Assert.IsFalse(otherhostInfo.IsInMemory());
        }