Example #1
0
        public void Assert_endpoint_appropriately_massages_duplicated_data()
        {
            var endpoint = Substitute.For <SqlEndpointBase>("", "");

            var resultSet1 = new object[]
            {
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("AA11"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("INSERT INTO FOO"),
                    ExecutionCount   = 10,
                    QueryType        = "Writes",
                },
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("AA11"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("INSERT INTO BAR"),
                    ExecutionCount   = 8,
                    QueryType        = "Writes",
                },
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("AA11"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("INSERT INTO BAR"),
                    ExecutionCount   = 8,
                    QueryType        = "Writes",
                },
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("BB12"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("SELECT * FROM FOO"),
                    ExecutionCount   = 500,
                    QueryType        = "Reads",
                },
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("CC12"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("SELECT * FROM FOO"),
                    ExecutionCount   = 600,
                    QueryType        = "Reads",
                },
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("EE12"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("SELECT * FROM BAR"),
                    ExecutionCount   = 100,
                    QueryType        = "Reads",
                },
            };

            IEnumerable <SqlDmlActivity> outputResults1 = endpoint.CalculateSqlDmlActivityIncrease(resultSet1, Substitute.For <ILog>()).Cast <SqlDmlActivity>().ToArray();

            Assert.That(outputResults1, Is.Not.Null);
            Assert.That(outputResults1.Count(), Is.EqualTo(1));

            SqlDmlActivity sqlDmlActivity = outputResults1.First();

            Assert.That(string.Format("Reads:{0} Writes:{1}", sqlDmlActivity.Reads, sqlDmlActivity.Writes), Is.EqualTo("Reads:0 Writes:0"));
        }
Example #2
0
        public void Assert_sql_dml_actvity_data_takes_create_time_ms_into_account()
        {
            var endpoint = Substitute.For <SqlEndpointBase>("", "");
            var d1       = new DateTime(2013, 06, 20, 8, 28, 10, 100);
            var d2       = new DateTime(2013, 06, 20, 8, 28, 10, 200);

            var resultSet1 = new object[]
            {
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("AA11"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("INSERT INTO FOO"),
                    CreationTime     = d1,
                    ExecutionCount   = 10,
                    QueryType        = "Writes",
                },
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("AA11"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("INSERT INTO FOO"),
                    CreationTime     = d2,
                    ExecutionCount   = 12,
                    QueryType        = "Writes",
                },
            };

            IEnumerable <SqlDmlActivity> outputResults1 = endpoint.CalculateSqlDmlActivityIncrease(resultSet1, Substitute.For <ILog>()).Cast <SqlDmlActivity>().ToArray();

            Assert.That(outputResults1, Is.Not.Null);
            Assert.That(outputResults1.Count(), Is.EqualTo(1));

            SqlDmlActivity sqlDmlActivity = outputResults1.First();

            Assert.That(string.Format("Reads:{0} Writes:{1}", sqlDmlActivity.Reads, sqlDmlActivity.Writes), Is.EqualTo("Reads:0 Writes:0"));

            var resultSet2 = new object[]
            {
                new SqlDmlActivity
                {
                    PlanHandle       = Encoding.UTF8.GetBytes("AA11"),
                    SqlStatementHash = Encoding.UTF8.GetBytes("INSERT INTO FOO"),
                    CreationTime     = d2,
                    ExecutionCount   = 15,
                    QueryType        = "Writes",
                },
            };

            SqlDmlActivity[] outputResults2 = endpoint.CalculateSqlDmlActivityIncrease(resultSet2, Substitute.For <ILog>()).Cast <SqlDmlActivity>().ToArray();
            Assert.That(outputResults2, Is.Not.Null);
            Assert.That(outputResults2.Count(), Is.EqualTo(1));

            sqlDmlActivity = outputResults2.First();

            Assert.That(string.Format("Reads:{0} Writes:{1}", sqlDmlActivity.Reads, sqlDmlActivity.Writes), Is.EqualTo("Reads:0 Writes:3"));
        }