Exemplo n.º 1
0
 private bool IgnoreTemplate(Benchmark.Template template)
 {
     foreach (Benchmark.SelectedAnnotation selectedAnnotation in template.SelectedAnnotations)
     {
         foreach (Benchmark.SelectedAnnotation ignoreAnnotation in Benchmark.TestRunSettings.IgnoreAnnotations)
         {
             if (selectedAnnotation.AnnotationId == ignoreAnnotation.AnnotationId)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private void PreparePlanEquivalenceTest(Benchmark.PlanEquivalenceTest planEquivalenceTest,
                                                Benchmark.Test test, Benchmark.TestGroup testGroup, Benchmark.Configuration configuration, DbProviders.DbProvider db,
                                                Benchmark.Template template = null)
        {
            Benchmark.PlanEquivalenceTestResult planEquivalenceTestResult = new Benchmark.PlanEquivalenceTestResult(testRun);
            planEquivalenceTestResult.TestId          = test.Id;
            planEquivalenceTestResult.TestNumber      = test.Number;
            planEquivalenceTestResult.TestName        = test.Name;
            planEquivalenceTestResult.TestGroupId     = testGroup.Id;
            planEquivalenceTestResult.ConfigurationId = configuration.Id;

            if (template != null)
            {
                planEquivalenceTestResult.TemplateNumber = template.Number;
            }

            foreach (Benchmark.QueryVariant variant in planEquivalenceTest.Variants)
            {
                if (IgnoreVariant(variant))
                {
                    continue;
                }

                Benchmark.QueryVariantResult queryVariantResult = new Benchmark.QueryVariantResult(planEquivalenceTestResult);
                Benchmark.Statement          statement          = variant.GetStatement(db.Name);

                // Skip not supported variants.
                if (statement is Benchmark.SpecificStatement specificStatement)
                {
                    if (specificStatement.NotSupported)
                    {
                        continue;
                    }
                }

                foreach (Benchmark.SelectedAnnotation selectedAnnotation in variant.SelectedAnnotations)
                {
                    Benchmark.SelectedAnnotationResult selectedAnnotationResult = new Benchmark.SelectedAnnotationResult(queryVariantResult);
                    selectedAnnotationResult.AnnotationId = selectedAnnotation.AnnotationId;
                    queryVariantResult.SelectedAnnotationResults.Add(selectedAnnotationResult);
                }

                string commandText = statement.CommandText;
                if (template != null)
                {
                    // Parametrized template substitution.
                    foreach (Benchmark.Parameter parameter in planEquivalenceTest.Parameters)
                    {
                        Benchmark.ParameterValue parameterValue =
                            planEquivalenceTest.ParameterValues.Where(pv => pv.ParameterId == parameter.Id && pv.TemplateId == template.Id).FirstOrDefault();
                        if (parameterValue != null)
                        {
                            string paramStr = Controls.Helpers.GetParamStr(parameter.Name);
                            commandText = commandText.Replace(paramStr, parameterValue.Value);
                        }
                    }
                }

                queryVariantResult.Query              = commandText;
                queryVariantResult.QueryVariantId     = variant.Id;
                queryVariantResult.QueryVariantNumber = variant.Number;
                queryVariantResult.QueryVariantName   = variant.Name;

                if (template != null)
                {
                    queryVariantResult.ExpectedResultSize = template.ExpectedResultSize;
                }
                else
                {
                    queryVariantResult.ExpectedResultSize = planEquivalenceTest.ExpectedResultSize;
                }

                // Token analysis.
                try
                {
                    Classes.SqlScanner scanner = new Classes.SqlScanner(commandText);
                    scanner.Scan();
                    queryVariantResult.TokenCount = scanner.Tokens.Length;
                }
                catch
                {
                    queryVariantResult.TokenCount = -1;
                }

                planEquivalenceTestResult.QueryVariantResults.Add(queryVariantResult);
            }

            foreach (Benchmark.SelectedAnnotation selectedAnnotation in planEquivalenceTest.SelectedAnnotations)
            {
                Benchmark.SelectedAnnotationResult selectedAnnotationResult = new Benchmark.SelectedAnnotationResult(planEquivalenceTestResult);
                selectedAnnotationResult.AnnotationId = selectedAnnotation.AnnotationId;
                planEquivalenceTestResult.SelectedAnnotationResults.Add(selectedAnnotationResult);
            }
            if (template != null)
            {
                foreach (Benchmark.SelectedAnnotation selectedAnnotation in template.SelectedAnnotations)
                {
                    Benchmark.SelectedAnnotationResult selectedAnnotationResult = new Benchmark.SelectedAnnotationResult(planEquivalenceTestResult);
                    selectedAnnotationResult.AnnotationId         = selectedAnnotation.AnnotationId;
                    selectedAnnotationResult.IsTemplateAnnotation = true;
                    planEquivalenceTestResult.SelectedAnnotationResults.Add(selectedAnnotationResult);
                }
            }

            if (planEquivalenceTestResult.QueryVariantResults.Count > 0)
            {
                testRun.TestResults.Add(planEquivalenceTestResult);
            }
        }