MdpRelationalCapacityTests.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Admin.NET.Plugin.AiDOP.DataPlatform.Core.Connectors;
  2. using Xunit;
  3. namespace Admin.NET.Plugin.AiDOP.Tests.DataPlatform;
  4. public sealed class MdpRelationalCapacityTests
  5. {
  6. [Fact]
  7. public void ExtrapolatesObservedBatchRangeAndKeepsRawBytesPerRow()
  8. {
  9. var estimate = RelationalCapacityEstimate.FromSamples(100, [
  10. new(10, 500, 100, 50, 100, 200, 50),
  11. new(20, 1500, 400, 100, 100, 700, 100)
  12. ]);
  13. Assert.Equal(30, estimate.SampleRows);
  14. Assert.Equal(66.67m, estimate.RawBytesPerRow);
  15. Assert.Equal(6667, estimate.FullRawBytes);
  16. Assert.Equal(5m, estimate.FullSecondsLow);
  17. Assert.Equal(7m, estimate.FullSecondsHigh);
  18. }
  19. [Fact]
  20. public void PreservesUnknownScaleAndSingleBatchEvidence()
  21. {
  22. Assert.Null(RelationalCapacityEstimate.FromSamples(100, []).RawBytesPerRow);
  23. var estimate = RelationalCapacityEstimate.FromSamples(null, [new(2, 100, 10, 20, 10, 50, 10)]);
  24. Assert.Equal(1, estimate.SampleBatches);
  25. Assert.Equal(50m, estimate.RawBytesPerRow);
  26. Assert.Null(estimate.FullSecondsLow);
  27. Assert.Null(estimate.FullRawBytes);
  28. }
  29. [Fact]
  30. public void DistinguishesAnEmptySourceFromMissingSourceStatistics()
  31. {
  32. var estimate = RelationalCapacityEstimate.FromSamples(0, []);
  33. Assert.Equal(0, estimate.FullRawBytes);
  34. Assert.Null(estimate.FullSecondsLow);
  35. }
  36. [Fact]
  37. public void ObservedRowsTakePrecedenceWhenCatalogStatisticsLag()
  38. {
  39. RelationalCapacityBatch[] batches = [new(4, 1060, 20, 250, 10, 800, 250)];
  40. var allRows = RelationalCapacityEstimate.FromSamples(3, batches, reachedEnd: true);
  41. Assert.Equal(4, allRows.SourceRows);
  42. Assert.Equal("sample", allRows.SourceRowsBasis);
  43. Assert.Equal(1060, allRows.FullRawBytes);
  44. var incomplete = RelationalCapacityEstimate.FromSamples(3, batches);
  45. Assert.Equal(4, incomplete.SourceRows);
  46. Assert.Equal("sample-floor", incomplete.SourceRowsBasis);
  47. }
  48. }