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)); }
private static IProteinBenchmarkService CreateBenchmarkServiceWithOneSlotAndProject() { var benchmarkService = new ProteinBenchmarkService(new ProteinBenchmarkDataContainer()); var slotIdentifier = CreateSlotIdentifier("Test", SlotIdentifier.NoSlotID); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(12345); benchmarkService.Update(slotIdentifier, benchmarkIdentifier, Array.Empty <TimeSpan>()); return(benchmarkService); }
public void ReadBinaryTest() { var container = new ProteinBenchmarkService { FileName = Path.Combine("..\\..\\TestFiles", Constants.BenchmarkCacheFileName), }; container.Read(); Assert.AreEqual(1246, container.GetAll().Count); }
public void WriteAndReadBinaryTest() { var collection = new ProteinBenchmarkService { FileName = "TestProteinBenchmark.dat", }; collection.Data = CreateTestList(); collection.Write(); collection.Data = null; collection.Read(); ValidateTestList(collection.Data); }
private static IProteinBenchmarkService CreateBenchmarkServiceWithTwoSlotsAndProjects() { var benchmarkService = new ProteinBenchmarkService(new ProteinBenchmarkDataContainer()); var slotIdentifier = CreateSlotIdentifier("Test", 0); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(12345); benchmarkService.Update(slotIdentifier, benchmarkIdentifier, Array.Empty <TimeSpan>()); slotIdentifier = CreateSlotIdentifier("Test", 1); benchmarkIdentifier = new ProteinBenchmarkIdentifier(23456); benchmarkService.Update(slotIdentifier, benchmarkIdentifier, Array.Empty <TimeSpan>()); benchmarkIdentifier = new ProteinBenchmarkIdentifier(65432); benchmarkService.Update(slotIdentifier, benchmarkIdentifier, Array.Empty <TimeSpan>()); return(benchmarkService); }
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(); }
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); }