public void UpdateBenchmarkDataTest() { // setup var benchmarkCollection = new ProteinBenchmarkCollection(); var database = MockRepository.GenerateMock<IUnitInfoDatabase>(); var fahClient = new FahClient(MockRepository.GenerateStub<IMessageConnection>()) { BenchmarkCollection = 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; 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 }); 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 BenchmarkClient("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(); }
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 == FahUnitStatus.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 == FahUnitStatus.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); } } }
private IDictionary<int, UnitInfo> GenerateUnitInfoDataFromQueue(IEnumerable<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); var parsedUnits = new Dictionary<int, UnitInfo>(); _unitLogLines = new Dictionary<int, IList<LogLine>>(); bool foundCurrentUnitInfo = false; foreach (var unit in unitCollection) { if (unit.Slot != slotId) { // does not match requested slot continue; } var projectInfo = new ProjectInfo { ProjectID = unit.Project, ProjectRun = unit.Run, ProjectClone = unit.Clone, ProjectGen = unit.Gen }; if (projectInfo.EqualsProject(currentUnitInfo) && unit.AssignedDateTime.GetValueOrDefault().Equals(currentUnitInfo.DownloadTime)) { foundCurrentUnitInfo = true; } FahLogUnitData fahLogUnitData = null; // Get the Log Lines for this queue position from the reader var logLines = _logInterpreter.GetLogLinesForQueueIndex(unit.Id, projectInfo); if (logLines == null) { string message = String.Format(CultureInfo.CurrentCulture, "Could not find log section for slot {0}. Cannot update frame data for this slot.", slotId); _logger.Warn(Constants.ClientNameFormat, ClientName, message); } else { // Get the FAH Log Data from the Log Lines fahLogUnitData = LogReader.GetFahLogDataFromLogLines(logLines); } UnitInfo unitInfo = BuildUnitInfo(unit, options, slotOptions, fahLogUnitData); if (unitInfo != null) { parsedUnits.Add(unit.Id, unitInfo); if (logLines != null) { _unitLogLines.Add(unit.Id, logLines); } if (unit.StateEnum.Equals(FahUnitStatus.Running)) { _currentUnitIndex = unit.Id; } } } // if no running WU found if (_currentUnitIndex == -1) { // look for a WU with Ready state var unit = unitCollection.FirstOrDefault(x => x.Slot == slotId && x.StateEnum.Equals(FahUnitStatus.Ready)); if (unit != null) { _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 logLines = _logInterpreter.GetLogLinesForQueueIndex(currentUnitInfo.QueueIndex, currentUnitInfo); if (logLines != null) { // Get the FAH Log Data from the Log Lines FahLogUnitData fahLogUnitData = LogReader.GetFahLogDataFromLogLines(logLines); // 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(); UpdateUnitInfo(currentClone, fahLogUnitData); parsedUnits.Add(currentClone.QueueIndex, currentClone); _unitLogLines.Add(currentClone.QueueIndex, logLines); } } return parsedUnits; }