public virtual void TestMultiListStartTimeIteratorEmptyAppLists() { IList <IList <FSAppAttempt> > lists = new AList <IList <FSAppAttempt> >(); lists.AddItem(Arrays.AsList(MockAppAttempt(1))); lists.AddItem(Arrays.AsList(MockAppAttempt(2))); IEnumerator <FSAppAttempt> iter = new MaxRunningAppsEnforcer.MultiListStartTimeIterator (lists); NUnit.Framework.Assert.AreEqual(1, iter.Next().GetStartTime()); NUnit.Framework.Assert.AreEqual(2, iter.Next().GetStartTime()); }
/// <summary> /// Checks to see whether applications are runnable now by iterating /// through each one of them and check if the queue and user have slack /// if we know how many apps can be runnable, there is no need to iterate /// through all apps, maxRunnableApps is used to break out of the iteration /// </summary> private void UpdateAppsRunnability(IList <IList <FSAppAttempt> > appsNowMaybeRunnable , int maxRunnableApps) { // Scan through and check whether this means that any apps are now runnable IEnumerator <FSAppAttempt> iter = new MaxRunningAppsEnforcer.MultiListStartTimeIterator (appsNowMaybeRunnable); FSAppAttempt prev = null; IList <FSAppAttempt> noLongerPendingApps = new AList <FSAppAttempt>(); while (iter.HasNext()) { FSAppAttempt next = iter.Next(); if (next == prev) { continue; } if (CanAppBeRunnable(((FSLeafQueue)next.GetQueue()), next.GetUser())) { TrackRunnableApp(next); FSAppAttempt appSched = next; ((FSLeafQueue)next.GetQueue()).AddApp(appSched, true); noLongerPendingApps.AddItem(appSched); if (noLongerPendingApps.Count >= maxRunnableApps) { break; } } prev = next; } // We remove the apps from their pending lists afterwards so that we don't // pull them out from under the iterator. If they are not in these lists // in the first place, there is a bug. foreach (FSAppAttempt appSched_1 in noLongerPendingApps) { if (!((FSLeafQueue)appSched_1.GetQueue()).RemoveNonRunnableApp(appSched_1)) { Log.Error("Can't make app runnable that does not already exist in queue" + " as non-runnable: " + appSched_1 + ". This should never happen."); } if (!usersNonRunnableApps.Remove(appSched_1.GetUser(), appSched_1)) { Log.Error("Waiting app " + appSched_1 + " expected to be in " + "usersNonRunnableApps, but was not. This should never happen." ); } } }