コード例 #1
0
        public override void BindChildren()
        {
            Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
            this.Nodes.Clear();

            BindCollection <Benchmark.QueryVariant>(this, planEquivalenceTest.Variants);
            ChildrenBound = true;
        }
コード例 #2
0
 private void UpdateActivateMenuItem()
 {
     Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
     if (planEquivalenceTest.Active)
     {
         itmActivate.Text = "Deactivate";
     }
     else
     {
         itmActivate.Text = "Activate";
     }
 }
コード例 #3
0
 private void UpdateImageKey()
 {
     Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
     if (planEquivalenceTest.Active)
     {
         this.ImageKey         = "Test";
         this.SelectedImageKey = "Test";
     }
     else
     {
         this.ImageKey         = "TestInactive";
         this.SelectedImageKey = "TestInactive";
     }
 }
コード例 #4
0
 /// <summary>
 /// Test whether the test should be ignored due to some annotation.
 /// </summary>
 /// <param name="planEquivalenceTest"></param>
 /// <returns></returns>
 private bool IgnoreTest(Benchmark.PlanEquivalenceTest planEquivalenceTest)
 {
     foreach (Benchmark.SelectedAnnotation selectedAnnotation in planEquivalenceTest.SelectedAnnotations)
     {
         foreach (Benchmark.SelectedAnnotation ignoreAnnotation in Benchmark.TestRunSettings.IgnoreAnnotations)
         {
             if (selectedAnnotation.AnnotationId == ignoreAnnotation.AnnotationId)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #5
0
        private void AddQueryVariant_Click(object sender, EventArgs e)
        {
            Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
            Benchmark.QueryVariant        queryVariant        = new Benchmark.QueryVariant(planEquivalenceTest);
            queryVariant.Name   = Helpers.GetNewName(planEquivalenceTest.Variants.Select(v => v.Name), "new variant", NumeralStyle.Guess);
            queryVariant.Number = Helpers.GetNewName(planEquivalenceTest.Variants.Select(v => v.Number), null, NumeralStyle.AlphabeticLower);
            planEquivalenceTest.Variants.Add(queryVariant);

            TreeNode newNode = BenchmarkTreeView.GetTreeNode(queryVariant);

            if (newNode != null)
            {
                BenchmarkTreeView.TreeView.SelectedNode = newNode;
                newNode.BeginEdit();
            }
        }
コード例 #6
0
        private void AddTest_Click(object sender, EventArgs e)
        {
            Benchmark.TestGroup           testGroup           = (Benchmark.TestGroup)BenchmarkObject;
            Benchmark.PlanEquivalenceTest planEquivalenceTest =
                new Benchmark.PlanEquivalenceTest(testGroup);
            planEquivalenceTest.Name   = Helpers.GetNewName(testGroup.Tests.Select(t => t.Name), "new test", NumeralStyle.Guess);
            planEquivalenceTest.Number = Helpers.GetNewName(testGroup.Tests.Select(t => t.Number), null, NumeralStyle.Arabic);
            testGroup.Tests.Add(planEquivalenceTest);

            TreeNode newNode = BenchmarkTreeView.GetTreeNode(planEquivalenceTest);

            if (newNode != null)
            {
                BenchmarkTreeView.TreeView.SelectedNode = newNode;
                newNode.BeginEdit();
            }
        }
コード例 #7
0
        public override void BindNode()
        {
            BindNamedObjectText();

            UpdateImageKey();

            Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;

            planEquivalenceTestContextMenu = new ContextMenuStrip();
            planEquivalenceTestContextMenu.Items.Add("Rename", Properties.Resources.Rename_16, Rename_Click);
            planEquivalenceTestContextMenu.Items.Add("Add variant", Properties.Resources.Add_16, AddQueryVariant_Click);
            planEquivalenceTestContextMenu.Items.Add("Remove", Properties.Resources.Remove_16, Remove_Click);
            planEquivalenceTestContextMenu.Items.Add(new ToolStripSeparator());
            itmActivate = planEquivalenceTestContextMenu.Items.Add("Activate", null, Activate_Click);
            UpdateActivateMenuItem();

            this.ContextMenuStrip = planEquivalenceTestContextMenu;

            planEquivalenceTest.PropertyChanged            += PlanEquivalenceTest_PropertyChanged;
            planEquivalenceTest.Variants.CollectionChanged += Variants_CollectionChanged;
        }
コード例 #8
0
 public override bool HasChildren()
 {
     Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
     return(planEquivalenceTest.Variants.Count > 0);
 }
コード例 #9
0
 public PlanEquivalenceTestTreeNode(Benchmark.PlanEquivalenceTest planEquivalenceTest, BenchmarkTreeView benchmarkTreeView)
     : base(planEquivalenceTest, benchmarkTreeView)
 {
 }
コード例 #10
0
 private void Remove_Click(object sender, EventArgs e)
 {
     Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
     planEquivalenceTest.TestGroup.Tests.Remove(planEquivalenceTest);
 }
コード例 #11
0
 private void Activate_Click(object sender, EventArgs e)
 {
     Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)BenchmarkObject;
     planEquivalenceTest.Active = !planEquivalenceTest.Active;
 }
コード例 #12
0
        private void Execute()
        {
            try
            {
                DbProviders.DbProvider db = benchmark.ConnectionSettings.DbProvider;
                db.Connect();

                // Init script.
                if (runInitScript)
                {
                    db.OnBeforeInitScript();

                    Benchmark.StatementList initScriptStatements = benchmark.InitScript.GetStatementList(db.Name);
                    foreach (Benchmark.Statement statement in initScriptStatements.Statements)
                    {
                        if (interruptTesting)
                        {
                            testingThread = null;
                            OnTestingEnded();
                            return;
                        }

                        string commandText = statement.CommandText;
                        try
                        {
                            db.Execute(commandText);

                            ExecutorMessage message = new ExecutorMessage();
                            message.Message     = "Statement completed";
                            message.MessageType = ExecutorMessageType.Info;
                            message.Statement   = commandText;

                            OnMessage(message);
                        }
                        catch (Exception ex)
                        {
                            ExecutorMessage message = new ExecutorMessage();
                            message.Message     = GetAllExceptionMessages(ex);
                            message.MessageType = ExecutorMessageType.Error;
                            message.Statement   = commandText;

                            OnMessage(message);
                            testingThread = null;
                            OnTestingEnded();
                            return;
                        }
                    }

                    db.OnAfterInitScript();
                }

                try
                {
                    foreach (Benchmark.TestGroup testGroup in benchmark.TestGroups)
                    {
                        if (interruptTesting)
                        {
                            testingThread = null;
                            OnTestingEnded();
                            return;
                        }
                        if (stopTesting)
                        {
                            break;
                        }

                        bool activeTests = false;
                        foreach (Benchmark.Test test in testGroup.Tests)
                        {
                            if (test.Active)
                            {
                                activeTests = true;
                                break;
                            }
                        }

                        if (activeTests)
                        {
                            foreach (Benchmark.Configuration configuration in testGroup.Configurations)
                            {
                                if (interruptTesting)
                                {
                                    testingThread = null;
                                    OnTestingEnded();
                                    return;
                                }
                                if (stopTesting)
                                {
                                    break;
                                }

                                Benchmark.ConfigurationResult currentConfigurationResult = null;
                                foreach (Benchmark.ConfigurationResult configurationResult in testRun.ConfigurationResults)
                                {
                                    if (configurationResult.ConfigurationId == configuration.Id)
                                    {
                                        currentConfigurationResult = configurationResult;
                                        break;
                                    }
                                }

                                try
                                {
                                    db.OnBeforeConfigurationInitScript(configuration);

                                    // Init script.
                                    currentConfigurationResult.InitScriptStarted = true;

                                    Benchmark.StatementList configurationInitScriptStatements = configuration.InitScript.GetStatementList(db.Name);
                                    foreach (Benchmark.Statement statement in configurationInitScriptStatements.Statements)
                                    {
                                        if (interruptTesting)
                                        {
                                            testingThread = null;
                                            OnTestingEnded();
                                            return;
                                        }

                                        string commandText = statement.CommandText;
                                        try
                                        {
                                            db.Execute(commandText);

                                            ExecutorMessage message = new ExecutorMessage();
                                            message.Message     = "Statement completed";
                                            message.MessageType = ExecutorMessageType.Info;
                                            message.Statement   = commandText;

                                            OnMessage(message);
                                        }
                                        catch (Exception ex)
                                        {
                                            currentConfigurationResult.InitScriptErrorMessage = GetAllExceptionMessages(ex);

                                            ExecutorMessage message = new ExecutorMessage();
                                            message.Message     = GetAllExceptionMessages(ex);
                                            message.MessageType = ExecutorMessageType.Error;
                                            message.Statement   = commandText;

                                            OnMessage(message);
                                            testingThread = null;
                                            OnTestingEnded();
                                            return;
                                        }
                                    }
                                    currentConfigurationResult.InitScriptCompleted = true;

                                    db.OnAfterConfigurationInitScript(configuration);

                                    foreach (Benchmark.Test test in testGroup.Tests)
                                    {
                                        try
                                        {
                                            if (!test.Active)
                                            {
                                                continue;
                                            }

                                            if (interruptTesting)
                                            {
                                                testingThread = null;
                                                OnTestingEnded();
                                                return;
                                            }
                                            if (stopTesting)
                                            {
                                                break;
                                            }

                                            foreach (Benchmark.TestResult testResult in testRun.TestResults)
                                            {
                                                if (testResult.TestId == test.Id &&
                                                    testResult.ConfigurationId == configuration.Id)
                                                {
                                                    if (testResult is Benchmark.PlanEquivalenceTestResult planEquivalenceTestResult)
                                                    {
                                                        try
                                                        {
                                                            planEquivalenceTestResult.Started = true;
                                                            HashSet <DbProviders.QueryPlan> distinctPlans = new HashSet <DbProviders.QueryPlan>();
                                                            planEquivalenceTestResult.SuccessfullyCompletedVariants = 0;

                                                            Benchmark.PlanEquivalenceTest planEquivalenceTest = (Benchmark.PlanEquivalenceTest)test;

                                                            List <DataTable> results = new List <DataTable>();

                                                            foreach (Benchmark.QueryVariantResult queryVariantResult in planEquivalenceTestResult.QueryVariantResults)
                                                            {
                                                                try
                                                                {
                                                                    if (interruptTesting)
                                                                    {
                                                                        testingThread = null;
                                                                        OnTestingEnded();
                                                                        return;
                                                                    }
                                                                    if (stopTesting)
                                                                    {
                                                                        break;
                                                                    }

                                                                    queryVariantResult.Started = true;

                                                                    List <TimeSpan>             timeSpans = new List <TimeSpan>();
                                                                    DbProviders.QueryStatistics lastStats = null;
                                                                    for (int i = 0; i < queryRuns; i++)
                                                                    {
                                                                        DbProviders.QueryStatistics stats = db.GetQueryStatistics(queryVariantResult.Query, compareResults);

                                                                        if (checkResultSizes && stats.ResultSize != queryVariantResult.ExpectedResultSize)
                                                                        {
                                                                            throw new Exception(string.Format("Unexpected result size ({0} instead of {1}).", stats.ResultSize, planEquivalenceTest.ExpectedResultSize));
                                                                        }

                                                                        timeSpans.Add(stats.QueryProcessingTime);
                                                                        lastStats = stats;
                                                                    }

                                                                    queryVariantResult.QueryProcessingTime = ComputeAvgTimeSpan(timeSpans);
                                                                    queryVariantResult.ResultSize          = lastStats.ResultSize;

                                                                    DbProviders.QueryPlan plan = db.GetQueryPlan(queryVariantResult.Query);
                                                                    queryVariantResult.QueryPlan = plan;

                                                                    if (compareResults)
                                                                    {
                                                                        results.Add(lastStats.Result);
                                                                    }

                                                                    //// TODO - remove.
                                                                    //planEquivalenceTest.ExpectedResultSize = stats.ResultSize;
                                                                    //break;

                                                                    if (!distinctPlans.Contains(plan))
                                                                    {
                                                                        distinctPlans.Add(plan);
                                                                    }

                                                                    ExecutorMessage message = new ExecutorMessage();
                                                                    message.Message     = "Query executed";
                                                                    message.MessageType = ExecutorMessageType.Info;
                                                                    message.Statement   = queryVariantResult.Query;
                                                                    planEquivalenceTestResult.SuccessfullyCompletedVariants++;

                                                                    OnMessage(message);
                                                                }
                                                                catch (Exception ex)
                                                                {
                                                                    queryVariantResult.ErrorMessage = GetAllExceptionMessages(ex);

                                                                    ExecutorMessage message = new ExecutorMessage();
                                                                    message.Message     = GetAllExceptionMessages(ex);
                                                                    message.MessageType = ExecutorMessageType.Error;
                                                                    message.Statement   = queryVariantResult.Query;

                                                                    OnMessage(message);
                                                                }
                                                                queryVariantResult.Completed = true;
                                                            }

                                                            planEquivalenceTestResult.DistinctQueryPlans = distinctPlans.Count;
                                                            planEquivalenceTestResult.Completed          = true;

                                                            if (compareResults)
                                                            {
                                                                if (!CheckResultsEquality(results))
                                                                {
                                                                    throw new Exception(string.Format("The query variants returned different results."));
                                                                }
                                                            }

                                                            ExecutorMessage messageCompleted = new ExecutorMessage();
                                                            messageCompleted.Message     = string.Format("Test {0} completed.", planEquivalenceTestResult.TestName);
                                                            messageCompleted.MessageType = ExecutorMessageType.Info;
                                                            messageCompleted.Statement   = string.Empty;
                                                            OnMessage(messageCompleted);
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            planEquivalenceTestResult.ErrorMessage = GetAllExceptionMessages(ex);

                                                            ExecutorMessage message = new ExecutorMessage();
                                                            message.Message     = GetAllExceptionMessages(ex);
                                                            message.MessageType = ExecutorMessageType.Error;
                                                            message.Statement   = string.Empty;
                                                            OnMessage(message);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            ExecutorMessage message = new ExecutorMessage();
                                            message.Message     = GetAllExceptionMessages(ex);
                                            message.MessageType = ExecutorMessageType.Error;
                                            message.Statement   = string.Empty;
                                            OnMessage(message);
                                        }
                                    }

                                    db.OnBeforeConfigurationCleanUpScript(configuration);

                                    // Clean up script.
                                    currentConfigurationResult.CleanUpScriptStarted = true;

                                    Benchmark.StatementList configurationCleanUpScriptStatements = configuration.CleanUpScript.GetStatementList(db.Name);
                                    foreach (Benchmark.Statement statement in configurationCleanUpScriptStatements.Statements)
                                    {
                                        if (interruptTesting)
                                        {
                                            testingThread = null;
                                            OnTestingEnded();
                                            return;
                                        }

                                        string commandText = statement.CommandText;
                                        try
                                        {
                                            db.Execute(commandText);

                                            ExecutorMessage message = new ExecutorMessage();
                                            message.Message     = "Statement completed";
                                            message.MessageType = ExecutorMessageType.Info;
                                            message.Statement   = commandText;

                                            OnMessage(message);
                                        }
                                        catch (Exception ex)
                                        {
                                            currentConfigurationResult.CleanUpScriptErrorMessage = GetAllExceptionMessages(ex);

                                            ExecutorMessage message = new ExecutorMessage();
                                            message.Message     = GetAllExceptionMessages(ex);
                                            message.MessageType = ExecutorMessageType.Error;
                                            message.Statement   = commandText;

                                            OnMessage(message);
                                            testingThread = null;
                                            OnTestingEnded();
                                            return;
                                        }
                                    }
                                    currentConfigurationResult.CleanUpScriptCompleted = true;

                                    db.OnAfterConfigurationCleanUpScript(configuration);
                                }
                                catch (Exception ex)
                                {
                                    ExecutorMessage message = new ExecutorMessage();
                                    message.Message     = GetAllExceptionMessages(ex);
                                    message.MessageType = ExecutorMessageType.Error;
                                    message.Statement   = string.Empty;
                                    OnMessage(message);
                                }

                                //// TODO - remove.
                                //break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExecutorMessage message = new ExecutorMessage();
                    message.Message     = GetAllExceptionMessages(ex);
                    message.MessageType = ExecutorMessageType.Error;
                    message.Statement   = string.Empty;
                    OnMessage(message);
                }

                // Clean up script.
                if (runCleanUpScript)
                {
                    db.OnBeforeCleanUpScript();

                    Benchmark.StatementList cleanUpScriptStatements = benchmark.CleanUpScript.GetStatementList(db.Name);
                    foreach (Benchmark.Statement statement in cleanUpScriptStatements.Statements)
                    {
                        if (interruptTesting)
                        {
                            testingThread = null;
                            OnTestingEnded();
                            return;
                        }

                        string commandText = statement.CommandText;
                        try
                        {
                            db.Execute(commandText);

                            ExecutorMessage message = new ExecutorMessage();
                            message.Message     = "Statement completed";
                            message.MessageType = ExecutorMessageType.Info;
                            message.Statement   = commandText;

                            OnMessage(message);
                        }
                        catch (Exception ex)
                        {
                            ExecutorMessage message = new ExecutorMessage();
                            message.Message     = GetAllExceptionMessages(ex);
                            message.MessageType = ExecutorMessageType.Error;
                            message.Statement   = commandText;

                            OnMessage(message);
                            testingThread = null;
                            OnTestingEnded();
                            return;
                        }
                    }

                    db.OnAfterCleanUpScript();
                }

                db.Close();
            }
            catch (Exception ex)
            {
                ExecutorMessage message = new ExecutorMessage();
                message.Message     = GetAllExceptionMessages(ex);
                message.MessageType = ExecutorMessageType.Error;
                message.Statement   = string.Empty;
                OnMessage(message);
            }

            testingThread = null;
            OnTestingEnded();

            if (!stopTesting)
            {
                // Zajisteni opakovaneho spusteni testu.
                currentLoop++;
                if (currentLoop < testLoops)
                {
                    OnInvokeStartTesting();
                }
                else
                {
                    if (closeOnComplete)
                    {
                        OnInvokeClose();
                    }
                }
            }
        }
コード例 #13
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);
            }
        }