public void Assert_that_max_recompile_summary_ignores_other_metrics() { object[] metrics = { new SqlCpuUsage() }; var results = new SqlServerEndpoint(null, null, false).GetMaxRecompileSummaryMetric(metrics); Assert.That(results, Is.Null, "Implementation should have ignored bad data."); }
public void Assert_that_max_recompile_summary_ignores_empty_metric_array() { object[] metrics = {}; var results = new SqlServerEndpoint(null, null, false).GetMaxRecompileSummaryMetric(metrics); Assert.That(results, Is.Null, "Implementation should have ignored empty data."); }
public void Assert_that_max_recompile_summary_is_reported() { object[] metrics = { new RecompileSummary { DatabaseName = "A", SingleUseObjects = 100, SingleUsePercent = 0, MultipleUseObjects = 1, }, new RecompileSummary { DatabaseName = "B", SingleUseObjects = 1, SingleUsePercent = 80, MultipleUseObjects = 1, }, new RecompileSummary { DatabaseName = "C", SingleUseObjects = 1, SingleUsePercent = 0, MultipleUseObjects = 50, }, }; var queryContext = new SqlServerEndpoint(null, null, false).GetMaxRecompileSummaryMetric(metrics); var results = queryContext.Results.ToArray(); Assert.That(queryContext, Is.Not.SameAs(metrics), "Expected a new Array"); var max = results.OfType <RecompileMaximums>().SingleOrDefault(); Assert.That(max, Is.Not.Null, "Expected a new metric in the results"); Assert.That(max.SingleUseObjects, Is.EqualTo(100), "Wrong SingleUseObjects value"); Assert.That(max.SingleUsePercent, Is.EqualTo(80m), "Wrong SingleUsePercent value"); Assert.That(max.MultipleUseObjects, Is.EqualTo(50), "Wrong MultipleUseObjects value"); }
public void Assert_that_duration_is_reported_correctly() { var sqlServerToMonitor = new SqlServerEndpoint("", "", false); Assert.That(sqlServerToMonitor.Duration, Is.EqualTo(0), "Expected 0 second Duration immediately after .ctor called"); Thread.Sleep(1000); Assert.That(sqlServerToMonitor.Duration, Is.EqualTo(1), "Expected 1 second Duration after Thread.Sleep(1000)"); }
public void Assert_include_exclude_lists_built_appropriately() { IEnumerable <Database> includedDbs = new[] { "FooDb", "BarDb" }.Select(x => new Database { Name = x, }); var sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", false, includedDbs, new[] { "Baz" }); Assert.That(sqlServerToMonitor.IncludedDatabaseNames, Is.EquivalentTo(new[] { "FooDb", "BarDb" })); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames, Is.EquivalentTo(Constants.SystemDatabases.Concat(new[] { "Baz" }))); }
public void Assert_include_system_databases_works() { var sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", false); Assert.That(sqlServerToMonitor.IncludedDatabaseNames.Length, Is.EqualTo(0)); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames, Is.EquivalentTo(Constants.SystemDatabases)); sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", true); Assert.That(sqlServerToMonitor.IncludedDatabaseNames.Length, Is.EqualTo(0)); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames.Length, Is.EqualTo(0)); }
public void Should_replace_where_with_included_databases() { var queryType = new SqlServerConnections(); var sqlServer = new SqlServerEndpoint("foo", "foo", false, new[] {new Database {Name = "bar"},}, null); var queryLocator = new QueryLocator(null); IEnumerable<SqlQuery> queries = queryLocator.PrepareQueries(new[] {queryType.GetType()}, false); foreach (SqlQuery query in queries) { string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer); Assert.That(actual, Is.StringContaining("AND (d.Name IN ('bar')")); } }
public void Assert_external_file_can_be_loaded() { // Hate to do this, but the config manager will only load from disk string artifactDir = TestHelper.GetArtifactDir(); string xml = Assembly.GetExecutingAssembly().SearchForStringResource("Configuration.app.config"); string appConfigFile = Path.Combine(artifactDir, "ConfigurationTest.app.config"); File.WriteAllText(appConfigFile, xml); Settings settings = ConfigurationParser.ParseSettings(Substitute.For <ILog>(), appConfigFile); Assert.That(settings, Is.Not.Null, "The settings from the config file should not be null"); Assert.That(settings.LicenseKey, Is.EqualTo("FooGuid"), "LicenseKey not mapped correctly"); Assert.That(settings.PollIntervalSeconds, Is.EqualTo(45), "PollIntervalSeconds not mapped correctly"); Assert.That(settings.ServiceName, Is.EqualTo("NewRelicSqlPlugin"), "ServiceName not mapped correctly"); string[] expectedSqlInstances = new[] { new { Name = "Local", ConnectionString = "Server=.;Database=master;Trusted_Connection=True;", IncludedDatabases = new[] { "Northwind", "tempdb", "master", "model", "msdb" }, ExcludedDatabases = new string[0], }, new { Name = "Important Server", ConnectionString = "Server=192.168.10.123,1234;Database=master;User Id=foo;Password=bar;", IncludedDatabases = new string[0], ExcludedDatabases = new[] { "foo", "bar" }.Concat(Constants.SystemDatabases).ToArray(), }, }.Select(i => SqlServerEndpoint.FormatProperties(i.Name, i.ConnectionString, i.IncludedDatabases, i.ExcludedDatabases)).ToArray(); SqlServerEndpoint[] sqlServers = settings.Endpoints.OfType <SqlServerEndpoint>().ToArray(); string[] actualInstances = sqlServers.Select(s => s.ToString()).ToArray(); Assert.That(actualInstances, Is.EquivalentTo(expectedSqlInstances), "Endpoints Found different from expected"); Database databaseWithDisplayName = sqlServers.Single(e => e.Name == "Local").IncludedDatabases.Single(d => d.Name == "Northwind"); Assert.That(databaseWithDisplayName.DisplayName, Is.EqualTo("Southbreeze"), "Display name cannot be configured"); string[] azureSqlDatabases = settings.Endpoints.OfType <AzureSqlEndpoint>().Select(a => a.ToString()).ToArray(); var expectedAzureDatabases = new[] { "Name: CloudFtw, ConnectionString: Server=zzz,1433;Database=CloudFtw;User ID=NewRelic;Password=aaa;Trusted_Connection=false;Encrypt=true;Connection Timeout=30;" }; Assert.That(azureSqlDatabases, Is.EqualTo(expectedAzureDatabases)); }
public void Should_replace_where_with_excluded_databases() { var queryType = new SqlServerConnections(); var sqlServer = new SqlServerEndpoint("foo", "foo", true, null, new[] { "blah" }); var queryLocator = new QueryLocator(null); IEnumerable <SqlQuery> queries = queryLocator.PrepareQueries(new[] { queryType.GetType() }, false); foreach (SqlQuery query in queries) { string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer); Assert.That(actual, Is.StringContaining("AND (d.Name NOT IN ('blah')")); } }
public void Should_replace_where_with_excluded_databases() { var queryType = new TQuery(); var sqlServer = new SqlServerEndpoint("foo", "foo", true, null, new[] { "exclude" }); var queryLocator = new QueryLocator(null); IEnumerable <SqlQuery> queries = sqlServer.FilterQueries(queryLocator.PrepareQueries(new[] { queryType.GetType() }, false)); foreach (SqlQuery query in queries) { string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer); Assert.That(actual, Is.StringContaining(ExcludedDatabaseExpectedSql)); } }
public void Assert_complex_include_system_databases_works() { var includeDbNames = new[] { "FooDb", "BarDb" }; IEnumerable <Database> includedDbs = includeDbNames.Select(x => new Database { Name = x, }); var sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", true, includedDbs, null); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames.Length, Is.EqualTo(0)); IEnumerable <string> expectedIncludes = Constants.SystemDatabases.ToList().Concat(includeDbNames); Assert.That(sqlServerToMonitor.IncludedDatabaseNames, Is.EquivalentTo(expectedIncludes)); }
public void Should_replace_where_with_included_and_system_databases() { var queryType = new SqlServerConnections(); var sqlServer = new SqlServerEndpoint("foo", "foo", true, new[] { new Database { Name = "bar" }, }, null); var queryLocator = new QueryLocator(null); IEnumerable <SqlQuery> queries = queryLocator.PrepareQueries(new[] { queryType.GetType() }, false); foreach (SqlQuery query in queries) { string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer); Assert.That(actual, Is.StringContaining("AND (d.Name IN ('bar', 'tempdb', 'master', 'model', 'msdb')")); } }
public string[] Assert_that_query_history_updated_appropriately(string[][] queryNames) { var sqlServerToMonitor = new SqlServerEndpoint("Best_DB_Ever", "", false); Assert.That(sqlServerToMonitor.QueryHistory.Count, Is.EqualTo(0), "History Should start off empty"); queryNames.ForEach(queryNamesPass => { IQueryContext[] queryContexts = queryNamesPass.Select(queryName => { var queryContext = Substitute.For <IQueryContext>(); queryContext.QueryName.Returns(queryName); return(queryContext); }).ToArray(); sqlServerToMonitor.UpdateHistory(queryContexts); }); string[] actual = sqlServerToMonitor.QueryHistory.Select(qh => string.Format("{0}:{1}", qh.Key, qh.Value.Count)).ToArray(); return(actual); }
public void Assert_that_max_recompile_summary_is_reported() { object[] metrics = { new RecompileSummary { DatabaseName = "A", SingleUseObjects = 100, SingleUsePercent = 0, MultipleUseObjects = 1, }, new RecompileSummary { DatabaseName = "B", SingleUseObjects = 1, SingleUsePercent = 80, MultipleUseObjects = 1, }, new RecompileSummary { DatabaseName = "C", SingleUseObjects = 1, SingleUsePercent = 0, MultipleUseObjects = 50, }, }; var queryContext = new SqlServerEndpoint(null, null, false).GetMaxRecompileSummaryMetric(metrics); var results = queryContext.Results.ToArray(); Assert.That(queryContext, Is.Not.SameAs(metrics), "Expected a new Array"); var max = results.OfType<RecompileMaximums>().SingleOrDefault(); Assert.That(max, Is.Not.Null, "Expected a new metric in the results"); Assert.That(max.SingleUseObjects, Is.EqualTo(100), "Wrong SingleUseObjects value"); Assert.That(max.SingleUsePercent, Is.EqualTo(80m), "Wrong SingleUsePercent value"); Assert.That(max.MultipleUseObjects, Is.EqualTo(50), "Wrong MultipleUseObjects value"); }
public void Assert_complex_include_system_databases_works() { var includeDbNames = new[] {"FooDb", "BarDb"}; IEnumerable<Database> includedDbs = includeDbNames.Select(x => new Database {Name = x,}); var sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", true, includedDbs, null); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames.Length, Is.EqualTo(0)); IEnumerable<string> expectedIncludes = Constants.SystemDatabases.ToList().Concat(includeDbNames); Assert.That(sqlServerToMonitor.IncludedDatabaseNames, Is.EquivalentTo(expectedIncludes)); }
public void Assert_include_exclude_lists_built_appropriately() { IEnumerable<Database> includedDbs = new[] {"FooDb", "BarDb"}.Select(x => new Database {Name = x,}); var sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", false, includedDbs, new[] {"Baz"}); Assert.That(sqlServerToMonitor.IncludedDatabaseNames, Is.EquivalentTo(new[] {"FooDb", "BarDb"})); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames, Is.EquivalentTo(Constants.SystemDatabases.Concat(new[] {"Baz"}))); }
public void Assert_include_system_databases_works() { var sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", false); Assert.That(sqlServerToMonitor.IncludedDatabaseNames.Length, Is.EqualTo(0)); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames, Is.EquivalentTo(Constants.SystemDatabases)); sqlServerToMonitor = new SqlServerEndpoint("FooServer", ".", true); Assert.That(sqlServerToMonitor.IncludedDatabaseNames.Length, Is.EqualTo(0)); Assert.That(sqlServerToMonitor.ExcludedDatabaseNames.Length, Is.EqualTo(0)); }
public void Assert_that_duration_is_reported_correctly() { var sqlServerToMonitor = new SqlServerEndpoint("", "", false); Assert.That(sqlServerToMonitor.Duration, Is.EqualTo(0), "Expected 0 second Duration immediately after .ctor called"); Thread.Sleep(1000); Assert.That(sqlServerToMonitor.Duration, Is.EqualTo(1), "Expected 1 second Duration after Thread.Sleep(1000)"); }
public void Assert_that_max_recompile_summary_ignores_empty_metric_array() { object[] metrics = {}; var results = new SqlServerEndpoint(null, null, false).GetMaxRecompileSummaryMetric(metrics); Assert.That(results, Is.Null, "Implementation should have ignored empty data."); }
public string[] Assert_that_query_history_updated_appropriately(string[][] queryNames) { var sqlServerToMonitor = new SqlServerEndpoint("Best_DB_Ever", "", false); Assert.That(sqlServerToMonitor.QueryHistory.Count, Is.EqualTo(0), "History Should start off empty"); queryNames.ForEach(queryNamesPass => { IQueryContext[] queryContexts = queryNamesPass.Select(queryName => { var queryContext = Substitute.For<IQueryContext>(); queryContext.QueryName.Returns(queryName); return queryContext; }).ToArray(); sqlServerToMonitor.UpdateHistory(queryContexts); }); string[] actual = sqlServerToMonitor.QueryHistory.Select(qh => string.Format("{0}:{1}", qh.Key, qh.Value.Count)).ToArray(); return actual; }
public void Assert_that_max_recompile_summary_ignores_other_metrics() { object[] metrics = {new SqlCpuUsage()}; var results = new SqlServerEndpoint(null, null, false).GetMaxRecompileSummaryMetric(metrics); Assert.That(results, Is.Null, "Implementation should have ignored bad data."); }