Example #1
0
        public void FahClient_UpdateBenchmarkFrameTimes_DoesNotUpdateBenchmarksWhenNoFramesAreComplete()
        {
            // Arrange
            var benchmarkService = new ProteinBenchmarkService(new ProteinBenchmarkDataContainer());
            var fahClient        = new FahClient(null, new InMemoryPreferencesProvider(), benchmarkService, null, null);

            var workUnit = new WorkUnit();

            workUnit.ProjectID    = 12345;
            workUnit.ProjectRun   = 6;
            workUnit.ProjectClone = 7;
            workUnit.ProjectGen   = 8;
            workUnit.Assigned     = DateTime.UtcNow;
            var settings = new ClientSettings {
                Name = "Foo", Server = "Bar", Port = ClientSettings.DefaultPort
            };
            var workUnitModel = new WorkUnitModel(new SlotModel(new NullClient {
                Settings = settings
            }), workUnit);
            var newWorkUnitModel = new WorkUnitModel(workUnitModel.SlotModel, workUnit.Copy());

            // Act
            fahClient.UpdateBenchmarkFrameTimes(workUnitModel, newWorkUnitModel);

            // Assert
            Assert.IsNull(benchmarkService.GetBenchmark(newWorkUnitModel.SlotModel.SlotIdentifier, newWorkUnitModel.BenchmarkIdentifier));
        }
Example #2
0
        private void BuildWorkUnits(ClientMessageAggregatorResult result,
                                    SlotRun slotRun,
                                    ICollection <Unit> unitCollection,
                                    Options options,
                                    WorkUnit currentWorkUnit,
                                    int slotId)
        {
            Debug.Assert(unitCollection != null);
            Debug.Assert(options != null);
            Debug.Assert(currentWorkUnit != null);

            result.WorkUnits = new Dictionary <int, WorkUnit>();

            bool foundCurrentUnitInfo = false;

            foreach (var unit in unitCollection.Where(x => x.Slot == slotId))
            {
                var projectInfo = unit.ToProjectInfo();
                if (projectInfo.EqualsProject(currentWorkUnit) &&
                    unit.AssignedDateTime.GetValueOrDefault().Equals(currentWorkUnit.Assigned))
                {
                    foundCurrentUnitInfo = true;
                }

                // Get the Log Lines for this queue position from the reader
                var unitRun = GetUnitRun(slotRun, unit.ID.GetValueOrDefault(), projectInfo);
                if (unitRun == null)
                {
                    string message = $"Could not find log section for Slot {slotId} {projectInfo}.";
                    FahClient.Logger.Debug(String.Format(Logger.NameFormat, FahClient.Settings.Name, message));
                }

                WorkUnit workUnit = BuildWorkUnit(unit, options, unitRun);
                if (workUnit != null)
                {
                    result.WorkUnits.Add(unit.ID.GetValueOrDefault(), workUnit);
                    if (unit.State.Equals("RUNNING", StringComparison.OrdinalIgnoreCase))
                    {
                        result.CurrentUnitIndex = unit.ID.GetValueOrDefault();
                    }
                }
            }

            // 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.State.Equals("READY", StringComparison.OrdinalIgnoreCase));
                if (unit != null)
                {
                    result.CurrentUnitIndex = unit.ID.GetValueOrDefault();
                }
            }

            // 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, currentWorkUnit.QueueIndex, currentWorkUnit);
                if (unitRun != null)
                {
                    // create a copy of the current WorkUnit object so we're not working with an
                    // instance that is referenced by a SlotModel that is bound to the grid - Issue 277
                    var workUnitCopy = currentWorkUnit.Copy();

                    PopulateWorkUnitFromLogData(workUnitCopy, unitRun);
                    result.WorkUnits.Add(workUnitCopy.QueueIndex, workUnitCopy);
                }
            }
        }
Example #3
0
        public void FahClient_UpdateWorkUnitBenchmarkAndRepository()
        {
            // Arrange
            var benchmarkService       = new ProteinBenchmarkService(new ProteinBenchmarkDataContainer());
            var mockWorkUnitRepository = new Mock <IWorkUnitRepository>();
            var fahClient = new FahClient(null, new InMemoryPreferencesProvider(), benchmarkService, null, mockWorkUnitRepository.Object);

            var workUnit = new WorkUnit();

            workUnit.ProjectID    = 2669;
            workUnit.ProjectRun   = 1;
            workUnit.ProjectClone = 2;
            workUnit.ProjectGen   = 3;
            workUnit.Finished     = new DateTime(2010, 1, 1);
            workUnit.QueueIndex   = 0;
            var settings = new ClientSettings {
                Name = "Owner", Server = "Path", Port = ClientSettings.NoPort
            };
            var currentWorkUnit = new WorkUnitModel(new SlotModel(new NullClient {
                Settings = settings
            }), workUnit);
            var slotIdentifier = currentWorkUnit.SlotModel.SlotIdentifier;

            var workUnitCopy = workUnit.Copy();

            workUnitCopy.FramesObserved = 4;
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(new LogLineFrameData {
                Duration = TimeSpan.FromMinutes(0), ID = 0
            },
                               new LogLineFrameData {
                Duration = TimeSpan.FromMinutes(5), ID = 1
            },
                               new LogLineFrameData {
                Duration = TimeSpan.FromMinutes(5), ID = 2
            },
                               new LogLineFrameData {
                Duration = TimeSpan.FromMinutes(5), ID = 3
            });

            workUnitCopy.Frames     = frames;
            workUnitCopy.UnitResult = WorkUnitResult.FinishedUnit;

            var parsedUnits = new[] { new WorkUnitModel(new SlotModel(new NullClient {
                    Settings = settings
                }), workUnitCopy) };

            mockWorkUnitRepository.SetupGet(x => x.Connected).Returns(true);

            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(2669);

            // Assert (pre-condition)
            Assert.IsFalse(benchmarkService.DataContainer.Data.Any(x => x.SlotIdentifier.Equals(slotIdentifier)));
            Assert.IsFalse(benchmarkService.GetBenchmarkProjects(slotIdentifier).Contains(2669));
            Assert.IsNull(benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier));

            // Act
            fahClient.UpdateWorkUnitBenchmarkAndRepository(currentWorkUnit, parsedUnits);

            // Assert
            Assert.IsTrue(benchmarkService.DataContainer.Data.Any(x => x.SlotIdentifier.Equals(slotIdentifier)));
            Assert.IsTrue(benchmarkService.GetBenchmarkProjects(slotIdentifier).Contains(2669));
            Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier).AverageFrameTime);

            mockWorkUnitRepository.Verify(x => x.Insert(It.IsAny <WorkUnitModel>()), Times.Once);
        }