private static void TestCollectSample(ISupplyCollector supplyCollector, DataContainer dataContainer, TestInfo testInfo) { Console.Write("Testing CollectSample() "); if (testInfo.CollectSampleTestDefinitions.Count == 0) { Console.WriteLine(" - skipped."); Console.WriteLine(); return; } foreach (var definition in testInfo.CollectSampleTestDefinitions) { DataCollection collection = new DataCollection(dataContainer, definition.DataCollectionName); DataEntity entity = new DataEntity(definition.DataEntityName, DataType.String, "string", dataContainer, collection); var samples = supplyCollector.CollectSample(entity, definition.SampleSize); if (samples.Count != definition.SampleSize) { throw new ApplicationException($"The number of samples ({samples.Count}) from DataCollection '{definition.DataCollectionName}' does not match the expected value of {definition.SampleSize}."); } foreach (string sampleValue in definition.SampleValues) { if (!samples.Contains(sampleValue)) { throw new ApplicationException($"The sample value {sampleValue} was not found in the samples"); } } } Console.WriteLine(" - success."); Console.WriteLine(); }
private static (SupplyCollectorDataLoaderBase, ISupplyCollector) LoadSupplyCollector(string supplyCollectorName) { string supplyCollectorPath = Path.Combine(Environment.CurrentDirectory, supplyCollectorName + ".dll"); string supplyCollectorLoaderPath = Path.Combine(Environment.CurrentDirectory, supplyCollectorName + "Loader.dll"); AssemblyLoadContext.Default.Resolving += Assembly_Resolving; if (_debug) { Console.WriteLine($"[DEBUG] Loading supply collector from {supplyCollectorPath}"); } Assembly supplyCollectorAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(supplyCollectorPath); if (_debug) { Console.WriteLine($"[DEBUG] Loading supply collector loader from {supplyCollectorLoaderPath}"); } Assembly supplyCollectorLoaderAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(supplyCollectorLoaderPath); Type supplyCollectorType = supplyCollectorAssembly.GetType(String.Format("{0}.{0}", supplyCollectorName)); Type loaderType = supplyCollectorLoaderAssembly.GetType(String.Format("{0}Loader.{0}Loader", supplyCollectorName)); ISupplyCollector supplyCollector = (ISupplyCollector)Activator.CreateInstance(supplyCollectorType); SupplyCollectorDataLoaderBase loader = (SupplyCollectorDataLoaderBase)Activator.CreateInstance(loaderType); return(loader, supplyCollector); }
private static void TestConnection(ISupplyCollector supplyCollector, DataContainer dataContainer) { bool result = supplyCollector.TestConnection(dataContainer); if (!result) { throw new ApplicationException("Could not connect to data store using " + dataContainer.ConnectionString); } Console.WriteLine("Connection to data store succeeded"); Console.WriteLine(); }
private static void LoadTestEntryPoint(ISupplyCollector supplyCollector, DataContainer dataContainer, TestInfo testInfo, int testIndex) { Console.Write("Load testing... "); var definition = testInfo.LoadTestDefinitions[testIndex]; DataCollection collection = new DataCollection(dataContainer, definition.DataCollectionName); DataEntity entity = new DataEntity(definition.DataEntityName, DataType.String, "string", dataContainer, collection); var samples = supplyCollector.CollectSample(entity, definition.SampleSize); Console.WriteLine($" - success, collected {samples.Count} samples."); Console.WriteLine(); }
private static void TestRandomSampling(ISupplyCollector supplyCollector, DataContainer dataContainer, TestInfo testInfo) { Console.Write("Testing CollectSample() - random sampling method"); if (testInfo.RandomSampleTestDefinitions.Count == 0) { Console.WriteLine(" - skipped."); Console.WriteLine(); return; } foreach (var definition in testInfo.RandomSampleTestDefinitions) { DataCollection collection = new DataCollection(dataContainer, definition.DataCollectionName); DataEntity entity = new DataEntity(definition.DataEntityName, DataType.String, "string", dataContainer, collection); bool equals = true; List <string> prevSamples = null; for (int i = 0; i < 3; i++) { var samples = supplyCollector.CollectSample(entity, definition.SampleSize); if (samples.Count != definition.SampleSize) { throw new ApplicationException( $"The number of samples ({samples.Count}) from DataCollection '{definition.DataCollectionName}' does not match the expected value of {definition.SampleSize}."); } if (prevSamples != null) { equals = !samples.Except(prevSamples).Union(prevSamples.Except(samples)).Any(); if (!equals) { break; } } prevSamples = samples; } if (equals) { throw new ApplicationException($"Samples from DataCollection '{definition.DataCollectionName}' are equal after 3 read attempts."); } } Console.WriteLine(" - success."); Console.WriteLine(); }
private static void TestDataMetrics(ISupplyCollector supplyCollector, DataContainer dataContainer, TestInfo testInfo) { Console.Write("Testing GetDataCollectionMetrics() "); if (testInfo.DataMetricsTestDefinitions.Count == 0) { Console.WriteLine(" - skipped."); Console.WriteLine(); return; } var metrics = supplyCollector.GetDataCollectionMetrics(dataContainer); foreach (var definition in testInfo.DataMetricsTestDefinitions) { var metric = metrics.Find(x => x.Name.Equals(definition.DataCollectionName)); if (metric == null) { throw new ApplicationException($"Metric for DataCollection '{definition.DataCollectionName}' is not found."); } if (metric.RowCount != definition.RowCount) { throw new ApplicationException( $"Row count for DataCollection '{definition.DataCollectionName}' ({metric.RowCount}) does not match expected value {definition.RowCount}."); } var usedSpaceRounded = Math.Round(metric.UsedSpaceKB, definition.UsedSizePrecision); var totalSpaceRounded = Math.Round(metric.TotalSpaceKB, definition.TotalSizePrecision); if (!Decimal.Equals(definition.UsedSize, usedSpaceRounded)) { throw new ApplicationException( $"Used size for DataCollection '{definition.DataCollectionName}' ({usedSpaceRounded}, rounded from {metric.UsedSpaceKB}) does not match expected value {definition.UsedSize}."); } if (!Decimal.Equals(definition.TotalSize, totalSpaceRounded)) { throw new ApplicationException( $"Total size for DataCollection '{definition.DataCollectionName}' ({totalSpaceRounded}, rounded from {metric.TotalSpaceKB}) does not match expected value {definition.TotalSize}."); } } Console.WriteLine(" - success."); Console.WriteLine(); }
private static void TestGetSchema(ISupplyCollector supplyCollector, DataContainer dataContainer, TestInfo testInfo) { Console.Write("Testing GetSchema() "); var(tables, entities) = supplyCollector.GetSchema(dataContainer); if (tables.Count != testInfo.SchemaTableCount) { throw new ApplicationException( $"The table count from GetSchema ({tables.Count}) did not match the expected value of {testInfo.SchemaTableCount}"); } if (entities.Count != testInfo.SchemaEntityCount) { throw new ApplicationException( $"The entity count from GetSchema ({entities.Count}) did not match the expected value of {testInfo.SchemaEntityCount}"); } Console.WriteLine(" - success."); Console.WriteLine(); }
private static void TestDataStoreTypes(ISupplyCollector supplyCollector) { var dataStoreTypes = supplyCollector.DataStoreTypes(); if (dataStoreTypes.Count < 1) { throw new ApplicationException("No data store types found with DataStoreTypes"); } if (dataStoreTypes.Count == 1) { Console.WriteLine("Data store type supported:"); } else { Console.WriteLine("Data store types supported:"); } foreach (string dataStoreType in supplyCollector.DataStoreTypes()) { Console.WriteLine(dataStoreType); } Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("SupplyCollectorTestHarness v." + typeof(Program).Assembly.GetName().Version); string filename = "test_harness.config"; if (args.Length > 0) { filename = args[args.Length - 1]; } Console.WriteLine($" loading {filename}, args len={args.Length}..."); TestInfo testInfo = GetTestInfoFromFile(filename); Console.WriteLine("Testing " + testInfo.SupplyCollectorName); Console.WriteLine(); string supplyCollectorPath = Path.Combine(Environment.CurrentDirectory, testInfo.SupplyCollectorName + ".dll"); AssemblyLoadContext.Default.Resolving += Assembly_Resolving; Assembly supplyCollectorAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(supplyCollectorPath); Type supplyCollectorType = supplyCollectorAssembly.GetType(String.Format("{0}.{0}", testInfo.SupplyCollectorName)); ISupplyCollector supplyCollector = (ISupplyCollector)Activator.CreateInstance(supplyCollectorType); DataContainer dataContainer = new DataContainer() { ConnectionString = testInfo.ConnectionString }; if (args.Length > 0) { if ("-load-test".Equals(args[0], StringComparison.InvariantCultureIgnoreCase)) { int testIndex = Int32.Parse(args[1]); LoadTestEntryPoint(supplyCollector, dataContainer, testInfo, testIndex); return; } for (int i = 0; i < args.Length - 1; i++) { if ("-connect".Equals(args[i], StringComparison.InvariantCultureIgnoreCase)) { testInfo.ConnectionString = args[++i]; } } } try { TestDataStoreTypes(supplyCollector); TestConnection(supplyCollector, dataContainer); TestGetSchema(supplyCollector, dataContainer, testInfo); TestCollectSample(supplyCollector, dataContainer, testInfo); TestRandomSampling(supplyCollector, dataContainer, testInfo); TestDataMetrics(supplyCollector, dataContainer, testInfo); TestMemoryUsageAndProcessingTime(testInfo); Console.WriteLine("All tests passed."); Environment.ExitCode = 0; } catch (Exception ex) { Console.WriteLine($"FAIL! Err: {ex}"); Environment.ExitCode = 1; } }