private void GenerateUnitInfoDataFromQueue(DataAggregatorResult result, SlotRun slotRun, ICollection <Unit> unitCollection, Options options, SlotOptions slotOptions, UnitInfo currentUnitInfo, int slotId) { Debug.Assert(unitCollection != null); Debug.Assert(options != null); Debug.Assert(slotOptions != null); Debug.Assert(currentUnitInfo != null); result.UnitInfos = new Dictionary <int, UnitInfo>(); bool foundCurrentUnitInfo = false; foreach (var unit in unitCollection.Where(x => x.Slot == slotId)) { var projectInfo = unit.ToProjectInfo(); if (projectInfo.EqualsProject(currentUnitInfo) && unit.AssignedDateTime.GetValueOrDefault().Equals(currentUnitInfo.DownloadTime)) { foundCurrentUnitInfo = true; } // Get the Log Lines for this queue position from the reader var unitRun = GetUnitRun(slotRun, unit.Id, projectInfo); if (unitRun == null) { string message = String.Format(CultureInfo.CurrentCulture, "Could not find log section for Slot {0} {1}. Cannot update log data for this unit.", slotId, projectInfo); Logger.WarnFormat(Constants.ClientNameFormat, ClientName, message); } UnitInfo unitInfo = BuildUnitInfo(unit, options, slotOptions, unitRun); if (unitInfo != null) { result.UnitInfos.Add(unit.Id, unitInfo); if (unit.StateEnum == UnitState.Running) { result.CurrentUnitIndex = unit.Id; } } } // if no running WU found if (result.CurrentUnitIndex == -1) { // look for a WU with Ready state var unit = unitCollection.FirstOrDefault(x => x.Slot == slotId && x.StateEnum == UnitState.Ready); if (unit != null) { result.CurrentUnitIndex = unit.Id; } } // if the current unit has already left the UnitCollection then find the log section and update here if (!foundCurrentUnitInfo) { // Get the Log Lines for this queue position from the reader var unitRun = GetUnitRun(slotRun, currentUnitInfo.QueueIndex, currentUnitInfo); if (unitRun != null) { // create a clone of the current UnitInfo object so we're not working with an // instance that is referenced by a SlotModel that is bound to the grid - Issue 277 UnitInfo currentClone = currentUnitInfo.DeepClone(); UpdateUnitInfoFromLogData(currentClone, unitRun); result.UnitInfos.Add(currentClone.QueueIndex, currentClone); } } }
public void FahClient_UpdateBenchmarkData_Test() { // setup var benchmarkCollection = new ProteinBenchmarkService(); var database = MockRepository.GenerateMock <IUnitInfoDatabase>(); var fahClient = new FahClient(MockRepository.GenerateStub <IMessageConnection>()) { BenchmarkService = benchmarkCollection, UnitInfoDatabase = database }; var unitInfo1 = new UnitInfo(); unitInfo1.OwningClientName = "Owner"; unitInfo1.OwningClientPath = "Path"; unitInfo1.OwningSlotId = 0; unitInfo1.ProjectID = 2669; unitInfo1.ProjectRun = 1; unitInfo1.ProjectClone = 2; unitInfo1.ProjectGen = 3; unitInfo1.FinishedTime = new DateTime(2010, 1, 1); unitInfo1.QueueIndex = 0; var currentUnitInfo = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1 }; var unitInfo1Clone = unitInfo1.DeepClone(); unitInfo1Clone.FramesObserved = 4; var frameDataDictionary = new Dictionary <int, WorkUnitFrameData>() .With(new WorkUnitFrameData { Duration = TimeSpan.FromMinutes(0), ID = 0 }, new WorkUnitFrameData { Duration = TimeSpan.FromMinutes(5), ID = 1 }, new WorkUnitFrameData { Duration = TimeSpan.FromMinutes(5), ID = 2 }, new WorkUnitFrameData { Duration = TimeSpan.FromMinutes(5), ID = 3 }); unitInfo1Clone.FrameData = frameDataDictionary; unitInfo1Clone.UnitResult = WorkUnitResult.FinishedUnit; var unitInfoLogic1 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone }; var parsedUnits = new[] { unitInfoLogic1 }; // arrange database.Stub(x => x.Connected).Return(true); database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(1); var benchmarkClient = new ProteinBenchmarkSlotIdentifier("Owner Slot 00", "Path"); // assert before act Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(false, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData)); // act fahClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 0); // assert after act Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(true, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime); database.VerifyAllExpectations(); }
public void UpdateBenchmarkDataTest() { // setup var benchmarkCollection = new ProteinBenchmarkService(); var database = MockRepository.GenerateMock <IUnitInfoDatabase>(); var legacyClient = new LegacyClient { BenchmarkService = benchmarkCollection, UnitInfoDatabase = database }; var unitInfo1 = new UnitInfo(); unitInfo1.OwningClientName = "Owner"; unitInfo1.OwningClientPath = "Path"; unitInfo1.ProjectID = 2669; unitInfo1.ProjectRun = 1; unitInfo1.ProjectClone = 2; unitInfo1.ProjectGen = 3; unitInfo1.FinishedTime = new DateTime(2010, 1, 1); var currentUnitInfo = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1 }; var unitInfo1Clone = unitInfo1.DeepClone(); unitInfo1Clone.FramesObserved = 4; unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3 }); var unitInfoLogic1 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone }; var unitInfo2 = new UnitInfo(); unitInfo2.OwningClientName = "Owner"; unitInfo2.OwningClientPath = "Path"; unitInfo2.ProjectID = 2669; unitInfo2.ProjectRun = 2; unitInfo2.ProjectClone = 3; unitInfo2.ProjectGen = 4; unitInfo2.FinishedTime = new DateTime(2010, 1, 1); var unitInfoLogic2 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo2 }; var unitInfo3 = new UnitInfo(); unitInfo3.OwningClientName = "Owner"; unitInfo3.OwningClientPath = "Path"; unitInfo3.ProjectID = 2669; unitInfo3.ProjectRun = 3; unitInfo3.ProjectClone = 4; unitInfo3.ProjectGen = 5; unitInfo3.FinishedTime = new DateTime(2010, 1, 1); var unitInfoLogic3 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo3 }; var parsedUnits = new[] { unitInfoLogic1, unitInfoLogic2, unitInfoLogic3 }; // arrange database.Stub(x => x.Connected).Return(true); database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(3); var benchmarkClient = new ProteinBenchmarkSlotIdentifier("Owner", "Path"); // assert before act Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(false, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData)); // act legacyClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 2); // assert after act Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(true, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime); database.VerifyAllExpectations(); }