/// <summary>
        /// Trivial test case that verifies basic functionality of
        /// <see cref="JobIdHistoryFileInfoMap"/>
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestWithSingleElement()
        {
            HistoryFileManager.JobIdHistoryFileInfoMap mapWithSize = new HistoryFileManager.JobIdHistoryFileInfoMap
                                                                         ();
            JobId jobId = MRBuilderUtils.NewJobId(1, 1, 1);

            HistoryFileManager.HistoryFileInfo fileInfo1 = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo
                                                                                     >();
            Org.Mockito.Mockito.When(fileInfo1.GetJobId()).ThenReturn(jobId);
            // add it twice
            NUnit.Framework.Assert.AreEqual("Incorrect return on putIfAbsent()", null, mapWithSize
                                            .PutIfAbsent(jobId, fileInfo1));
            NUnit.Framework.Assert.AreEqual("Incorrect return on putIfAbsent()", fileInfo1, mapWithSize
                                            .PutIfAbsent(jobId, fileInfo1));
            // check get()
            NUnit.Framework.Assert.AreEqual("Incorrect get()", fileInfo1, mapWithSize.Get(jobId
                                                                                          ));
            NUnit.Framework.Assert.IsTrue("Incorrect size()", CheckSize(mapWithSize, 1));
            // check navigableKeySet()
            NavigableSet <JobId> set = mapWithSize.NavigableKeySet();

            NUnit.Framework.Assert.AreEqual("Incorrect navigableKeySet()", 1, set.Count);
            NUnit.Framework.Assert.IsTrue("Incorrect navigableKeySet()", set.Contains(jobId));
            // check values()
            ICollection <HistoryFileManager.HistoryFileInfo> values = mapWithSize.Values();

            NUnit.Framework.Assert.AreEqual("Incorrect values()", 1, values.Count);
            NUnit.Framework.Assert.IsTrue("Incorrect values()", values.Contains(fileInfo1));
        }
Beispiel #2
0
        public virtual void TestAddExisting()
        {
            HistoryFileManager.JobListCache cache = new HistoryFileManager.JobListCache(2, 1000
                                                                                        );
            JobId jobId = MRBuilderUtils.NewJobId(1, 1, 1);

            HistoryFileManager.HistoryFileInfo fileInfo = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo
                                                                                    >();
            Org.Mockito.Mockito.When(fileInfo.GetJobId()).ThenReturn(jobId);
            cache.AddIfAbsent(fileInfo);
            cache.AddIfAbsent(fileInfo);
            NUnit.Framework.Assert.AreEqual("Incorrect number of cache entries", 1, cache.Values
                                                ().Count);
        }
Beispiel #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestEviction()
        {
            int maxSize = 2;

            HistoryFileManager.JobListCache cache = new HistoryFileManager.JobListCache(maxSize
                                                                                        , 1000);
            JobId jobId1 = MRBuilderUtils.NewJobId(1, 1, 1);

            HistoryFileManager.HistoryFileInfo fileInfo1 = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo
                                                                                     >();
            Org.Mockito.Mockito.When(fileInfo1.GetJobId()).ThenReturn(jobId1);
            JobId jobId2 = MRBuilderUtils.NewJobId(2, 2, 2);

            HistoryFileManager.HistoryFileInfo fileInfo2 = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo
                                                                                     >();
            Org.Mockito.Mockito.When(fileInfo2.GetJobId()).ThenReturn(jobId2);
            JobId jobId3 = MRBuilderUtils.NewJobId(3, 3, 3);

            HistoryFileManager.HistoryFileInfo fileInfo3 = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo
                                                                                     >();
            Org.Mockito.Mockito.When(fileInfo3.GetJobId()).ThenReturn(jobId3);
            cache.AddIfAbsent(fileInfo1);
            cache.AddIfAbsent(fileInfo2);
            cache.AddIfAbsent(fileInfo3);
            ICollection <HistoryFileManager.HistoryFileInfo> values;

            for (int i = 0; i < 9; i++)
            {
                values = cache.Values();
                if (values.Count > maxSize)
                {
                    Sharpen.Thread.Sleep(100);
                }
                else
                {
                    NUnit.Framework.Assert.IsFalse("fileInfo1 should have been evicted", values.Contains
                                                       (fileInfo1));
                    return;
                }
            }
            NUnit.Framework.Assert.Fail("JobListCache didn't delete the extra entry");
        }
 private Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job LoadJob(HistoryFileManager.HistoryFileInfo
                                                            fileInfo)
 {
     try
     {
         Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = fileInfo.LoadJob();
         if (Log.IsDebugEnabled())
         {
             Log.Debug("Adding " + job.GetID() + " to loaded job cache");
         }
         // We can clobber results here, but that should be OK, because it only
         // means that we may have two identical copies of the same job floating
         // around for a while.
         loadedJobCache[job.GetID()] = job;
         return(job);
     }
     catch (IOException e)
     {
         throw new YarnRuntimeException("Could not find/load job: " + fileInfo.GetJobId(),
                                        e);
     }
 }