public void ProteinBenchmarkService_GetBenchmark_BenchmarkWithProcessorAndThreadsMatchesBenchmarkIdentifierByProjectIDAndProcessorAndThreads() { const int projectID = 9039; var container = new ProteinBenchmarkDataContainer(); var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, Guid.NewGuid()), 0); container.Data.Add(new ProteinBenchmark { ProjectID = projectID, Processor = Processor, Threads = 12 } .UpdateFromSlotIdentifier(slotIdentifier)); container.Data.Add(new ProteinBenchmark { ProjectID = projectID, Processor = Processor, Threads = Threads } .UpdateFromSlotIdentifier(slotIdentifier)); var benchmarkService = new ProteinBenchmarkService(container); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID, Processor, Threads); // Act var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier); // Assert Assert.IsNotNull(benchmark); Assert.AreSame(container.Data[1], benchmark); Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier); Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier); }
public void ProteinBenchmarkService_Update_CreatesNewBenchmark() { // Arrange using (var artifacts = new ArtifactFolder()) { var container = CreateTestDataContainer(artifacts.GetRandomFilePath()); int containerCount = container.Data.Count; var benchmarkService = new ProteinBenchmarkService(container); var clientGuid = Guid.NewGuid(); var slotIdentifier = new SlotIdentifier(new ClientIdentifier("New Client", "10.9.8.1", ClientSettings.DefaultPort, clientGuid), 0); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(Int32.MaxValue, Processor, Threads); var frameTimes = new[] { TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.2), TimeSpan.FromMinutes(1.1) }; // Act benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes); // Assert Assert.AreEqual(containerCount + 1, container.Data.Count); var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier); Assert.IsNotNull(benchmark); Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier); Assert.AreEqual(clientGuid, benchmark.SlotIdentifier.ClientIdentifier.Guid); Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier); Assert.AreEqual(3, benchmark.FrameTimes.Count); Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmark.FrameTimes[0].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmark.FrameTimes[1].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmark.FrameTimes[2].Duration); } }
public void ProteinBenchmarkService_GetBenchmark_BenchmarkWithGuidMatchesSlotIdentifierByGuid() { var guid = Guid.NewGuid(); const int slotID = 0; const int projectID = 9039; var container = new ProteinBenchmarkDataContainer(); container.Data.Add(new ProteinBenchmark { SourceName = "Foo", SourcePath = "192.168.1.194:36330", SourceGuid = guid, SourceSlotID = slotID, ProjectID = projectID, FrameTimes = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList() }); var benchmarkService = new ProteinBenchmarkService(container); var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Bar", "192.168.1.200", 46330, guid), slotID); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID); // Act var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier); // Assert Assert.IsNotNull(benchmark); Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier); Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier); }
public void ProteinBenchmarkService_GetBenchmark_BenchmarkWithoutGuidMatchesSlotIdentifierByNameAndPath() { var guid = Guid.NewGuid(); const int slotID = 0; const int projectID = 9039; var container = new ProteinBenchmarkDataContainer(); container.Data.Add(new ProteinBenchmark { SourceName = "Foo", SourcePath = "192.168.1.194:36330", SourceGuid = Guid.Empty, SourceSlotID = slotID, ProjectID = projectID, FrameTimes = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList() }); var benchmarkService = new ProteinBenchmarkService(container); var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, guid), slotID); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID); // Act var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier); // Assert Assert.IsNotNull(benchmark); Assert.AreEqual(slotIdentifier.ClientIdentifier.Name, benchmark.SourceName); Assert.AreEqual(slotIdentifier.ClientIdentifier.ToServerPortString(), benchmark.SourcePath); Assert.AreNotEqual(slotIdentifier.ClientIdentifier.Guid, benchmark.SourceGuid); Assert.AreEqual(slotIdentifier.SlotID, benchmark.SourceSlotID); Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier); }
public ProteinBenchmark UpdateFromBenchmarkIdentifier(ProteinBenchmarkIdentifier benchmarkIdentifier) { ProjectID = benchmarkIdentifier.ProjectID; Processor = benchmarkIdentifier.Processor; Threads = benchmarkIdentifier.Threads; return(this); }
public void ProteinBenchmarkService_Update_BenchmarkWithoutProcessorAndThreadsMatchesBenchmarkIdentifierByProjectID() { const int projectID = 9039; var container = new ProteinBenchmarkDataContainer(); var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, Guid.NewGuid()), 0); container.Data.Add(new ProteinBenchmark { ProjectID = projectID } .UpdateFromSlotIdentifier(slotIdentifier)); var benchmarkService = new ProteinBenchmarkService(container); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID, Processor, Threads); var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes); // Act var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes); // Assert Assert.AreEqual(1, container.Data.Count); Assert.IsNotNull(benchmark); Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier); Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier); var benchmarkFrameTimes = benchmark.FrameTimes.Take(3).ToList(); Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmarkFrameTimes[0].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmarkFrameTimes[1].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmarkFrameTimes[2].Duration); }
public void ProteinBenchmarkService_Update_AddsFrameTimes() { var guid = Guid.NewGuid(); const int slotID = 0; const int projectID = 9039; var container = new ProteinBenchmarkDataContainer(); container.Data.Add(new ProteinBenchmark { SourceGuid = guid, SourceSlotID = slotID, ProjectID = projectID }); var benchmarkService = new ProteinBenchmarkService(container); var slotIdentifier = new SlotIdentifier(new ClientIdentifier(null, null, ClientSettings.NoPort, guid), slotID); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID); var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes); // Act var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes); // Assert Assert.AreEqual(1, container.Data.Count); Assert.IsNotNull(benchmark); Assert.AreEqual(3, benchmark.FrameTimes.Count); Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmark.FrameTimes[0].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmark.FrameTimes[1].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmark.FrameTimes[2].Duration); }
public void ProteinBenchmarkIdentifier_AreEqualWhenProjectIDAndProcessorAndThreadsAreEqual() { // Arrange var x = new ProteinBenchmarkIdentifier(1234, "i9", 8); var y = new ProteinBenchmarkIdentifier(1234, "i9", 8); // Act var result = x.Equals(y) & x.GetHashCode() == y.GetHashCode(); // Assert Assert.IsTrue(result); }
public void ProteinBenchmarkIdentifier_AreNotEqualWhenProjectIDAreNotEqual() { // Arrange var x = new ProteinBenchmarkIdentifier(1234, ProteinBenchmarkIdentifier.NoProcessor, ProteinBenchmarkIdentifier.NoThreads); var y = new ProteinBenchmarkIdentifier(5678, ProteinBenchmarkIdentifier.NoProcessor, ProteinBenchmarkIdentifier.NoThreads); // Act var result = x.Equals(y) | x.GetHashCode() == y.GetHashCode(); // Assert Assert.IsFalse(result); }
private static ProteinBenchmark GetBenchmark(List <ProteinBenchmark> benchmarks, ProteinBenchmarkIdentifier benchmarkIdentifier) { // most specific, matches ProjectID, Processor, and Threads var benchmark = benchmarks.Find(b => b.BenchmarkIdentifier.Equals(benchmarkIdentifier)); if (benchmark is null) { // less specific, matches only ProjectID... upgrade any existing benchmark for this slot benchmarkIdentifier = new ProteinBenchmarkIdentifier(benchmarkIdentifier.ProjectID); benchmark = benchmarks.Find(b => b.BenchmarkIdentifier.Equals(benchmarkIdentifier)); } return(benchmark); }
public ProteinBenchmark GetBenchmark(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier) { _cacheLock.EnterReadLock(); try { var benchmarks = DataContainer.Data.FindAll(b => BenchmarkMatchesSlotIdentifier(b, slotIdentifier)); return(GetBenchmark(benchmarks, benchmarkIdentifier)); } finally { _cacheLock.ExitReadLock(); } }
public ProteinBenchmark Update(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier, IEnumerable <TimeSpan> frameTimes) { if (slotIdentifier == SlotIdentifier.AllSlots) { throw new ArgumentException("Cannot update all client slots."); } if (frameTimes == null) { throw new ArgumentNullException(nameof(frameTimes)); } // GetBenchmark() BEFORE entering write lock because it uses a read lock var benchmark = GetBenchmark(slotIdentifier, benchmarkIdentifier); // write lock _cacheLock.EnterWriteLock(); try { if (benchmark is null) { benchmark = new ProteinBenchmark(); DataContainer.Data.Add(benchmark); } benchmark .UpdateFromSlotIdentifier(slotIdentifier) .UpdateFromBenchmarkIdentifier(benchmarkIdentifier); foreach (var f in frameTimes) { benchmark.AddFrameTime(f); } DataContainer.Write(); return(benchmark); } finally { _cacheLock.ExitWriteLock(); } }
public void ProteinBenchmarkService_Update_BenchmarkWithoutGuidMatchesSlotIdentifierByNameAndPath() { var guid = Guid.NewGuid(); const int slotID = 0; const int projectID = 9039; var container = new ProteinBenchmarkDataContainer(); container.Data.Add(new ProteinBenchmark { SourceName = "Foo", SourcePath = "192.168.1.194:36330", SourceGuid = Guid.Empty, SourceSlotID = slotID, ProjectID = projectID, FrameTimes = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList() }); var benchmarkService = new ProteinBenchmarkService(container); var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, guid), slotID); var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID); var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes); // Act var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes); // Assert Assert.AreEqual(1, container.Data.Count); Assert.IsNotNull(benchmark); Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier); Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier); var benchmarkFrameTimes = benchmark.FrameTimes.Take(3).ToList(); Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmarkFrameTimes[0].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmarkFrameTimes[1].Duration); Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmarkFrameTimes[2].Duration); }
public ProteinBenchmark GetBenchmark(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier) { return(null); }
public ProteinBenchmark Update(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier, IEnumerable <TimeSpan> frameTimes) { return(null); }