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_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 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 ProteinBenchmarkService_GetSlotIdentifiers_ReturnsDistinctValuesWithGuidFromBenchmarksWithAndWithoutSourceGuid() { // Arrange var container = new ProteinBenchmarkDataContainer(); container.Data.Add(new ProteinBenchmark { SourceName = "Foo", SourcePath = "192.168.1.255:36330", SourceGuid = Guid.Empty, SourceSlotID = 0 }); container.Data.Add(new ProteinBenchmark { SourceName = "Foo", SourcePath = "192.168.1.255:36330", SourceGuid = Guid.NewGuid(), SourceSlotID = 0 }); var benchmarkService = new ProteinBenchmarkService(container); // Act var identifiers = benchmarkService.GetSlotIdentifiers(); // Assert Assert.AreEqual(1, identifiers.Count); Assert.IsTrue(identifiers.First().ClientIdentifier.HasGuid); }
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); }
private static ProteinBenchmarkDataContainer CreateTestDataContainer(string path, string fileName = ProteinBenchmarkDataContainer.DefaultFileName) { var source = Path.GetFullPath(Path.Combine("TestFiles", fileName)); File.Copy(source, path, true); var dataContainer = new ProteinBenchmarkDataContainer { FilePath = path }; dataContainer.Read(); #if DEBUG Console.WriteLine($"Loaded {dataContainer.Data.Count} benchmarks"); Console.WriteLine("Group By Slot"); foreach (var g in dataContainer.Data.GroupBy(x => x.SlotIdentifier)) { Console.WriteLine(g.Key); foreach (var b in g) { Console.WriteLine("\t" + b.BenchmarkIdentifier); } } Console.WriteLine("Group By Benchmark"); foreach (var g in dataContainer.Data.GroupBy(x => x.BenchmarkIdentifier)) { Console.WriteLine(g.Key); foreach (var b in g) { Console.WriteLine("\t" + b.SlotIdentifier); } } #endif return(dataContainer); }
public ProteinBenchmarkService(ProteinBenchmarkDataContainer dataContainer) { DataContainer = dataContainer; _cacheLock = new ReaderWriterLockSlim(); }