From 416ed67d61ebbdc98b30e0f22b70fd1304e9aac8 Mon Sep 17 00:00:00 2001 From: Jon Armen Date: Sat, 16 Apr 2022 12:25:47 -0400 Subject: [PATCH] Add support for net462 --- .github/workflows/ci.yml | 2 +- sdk/Directory.Build.props | 2 +- sdk/src/Core/AWSXRayRecorder.Core.csproj | 14 +-- sdk/src/Core/AWSXRayRecorderImpl.cs | 10 +- sdk/src/Core/AwsXrayRecorderBuilder.cs | 4 +- ...s => CallContextContainer.netframework.cs} | 2 +- .../Internal/Context/DefaultTraceContext.cs | 2 +- ...=> HybridContextContainer.netframework.cs} | 2 +- ...s.net45.cs => AppSettings.netframework.cs} | 0 .../DynamicSegmentNamingStrategy.cs | 4 +- .../Strategies/FixedSegmentNamingStrategy.cs | 4 +- .../Core/Strategies/SegmentNamingStrategy.cs | 4 +- .../AWSXRayRecorder.Handlers.AspNet.csproj | 6 +- .../AWSXRayRecorder.Handlers.AwsSdk.csproj | 4 +- ...ayRecorder.Handlers.EntityFramework.csproj | 8 +- ...net45.cs => EFInterceptor.netframework.cs} | 2 +- sdk/src/Handlers/EntityFramework/EFUtil.cs | 4 +- .../AWSXRayRecorder.Handlers.SqlServer.csproj | 6 +- .../SqlServer/DbCommandInterceptor.cs | 2 +- ...cs => TraceableSqlCommand.netframework.cs} | 2 +- ...AWSXRayRecorder.Handlers.System.Net.csproj | 2 +- .../AWSXRayRecorder.IntegrationTests.csproj | 2 +- sdk/test/IntegrationTests/TestBase.cs | 31 +----- .../IntegrationTests/ValidateSegmentTests.cs | 52 ++++------ .../AWSXRayRecorder.SmokeTests.csproj | 6 +- sdk/test/UnitTests/AWSSDKHandlerTests.cs | 95 +++++++------------ .../AWSXRayRecorder.UnitTests.csproj | 22 +---- .../UnitTests/AWSXRayRecorderBuilderTests.cs | 18 ++-- sdk/test/UnitTests/AWSXRayRecorderTests.cs | 32 ++----- sdk/test/UnitTests/CauseTest.cs | 4 - .../UnitTests/DbCommandInterceptorTests.cs | 20 ++-- .../HttpClientXRayTracingHandlerTests.cs | 12 --- .../HttpWebRequestTracingExtensionTests.cs | 18 +--- .../LocalizedSamplingStrategyTests.cs | 16 ++-- .../UnitTests/SegmentNamingStrategyTests.cs | 6 +- sdk/test/UnitTests/SegmentTests.cs | 2 +- sdk/test/UnitTests/Tools/CustomResponses.cs | 2 +- sdk/test/UnitTests/Tools/MockWebResponse.cs | 2 +- 38 files changed, 143 insertions(+), 283 deletions(-) rename sdk/src/Core/Internal/Context/{CallContextContainer.net45.cs => CallContextContainer.netframework.cs} (97%) rename sdk/src/Core/Internal/Context/{HybridContextContainer.net45.cs => HybridContextContainer.netframework.cs} (98%) rename sdk/src/Core/Internal/Utils/{AppSettings.net45.cs => AppSettings.netframework.cs} (100%) rename sdk/src/Handlers/EntityFramework/{EFInterceptor.net45.cs => EFInterceptor.netframework.cs} (98%) rename sdk/src/Handlers/SqlServer/{TraceableSqlCommand.net45.cs => TraceableSqlCommand.netframework.cs} (99%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88dc0afc..a1b95d3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - version: [net452, netcoreapp2.0, netcoreapp3.1] + version: [net452, net462, netcoreapp2.0, netcoreapp3.1] steps: - name: Checkout repository diff --git a/sdk/Directory.Build.props b/sdk/Directory.Build.props index db7ec858..cdf3ac9f 100644 --- a/sdk/Directory.Build.props +++ b/sdk/Directory.Build.props @@ -4,7 +4,7 @@ - + portable diff --git a/sdk/src/Core/AWSXRayRecorder.Core.csproj b/sdk/src/Core/AWSXRayRecorder.Core.csproj index 9e3d1809..fe7c7805 100644 --- a/sdk/src/Core/AWSXRayRecorder.Core.csproj +++ b/sdk/src/Core/AWSXRayRecorder.Core.csproj @@ -1,7 +1,7 @@  - net45;netstandard2.0;netcoreapp3.1 + net45;net462;netstandard2.0;netcoreapp3.1 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -47,14 +47,14 @@ - - - - + + + + - + @@ -63,7 +63,7 @@ - + diff --git a/sdk/src/Core/AWSXRayRecorderImpl.cs b/sdk/src/Core/AWSXRayRecorderImpl.cs index bb689227..258b3e8f 100644 --- a/sdk/src/Core/AWSXRayRecorderImpl.cs +++ b/sdk/src/Core/AWSXRayRecorderImpl.cs @@ -37,7 +37,7 @@ namespace Amazon.XRay.Recorder.Core public abstract class AWSXRayRecorderImpl : IAWSXRayRecorder { private static readonly Logger _logger = Logger.GetLogger(typeof(AWSXRayRecorderImpl)); -#if NET45 +#if NETFRAMEWORK private static Lazy _lazyDefaultRecorder = new Lazy(() => AWSXRayRecorderBuilder.GetDefaultBuilder().Build()); protected static Lazy LazyDefaultRecorder { @@ -151,7 +151,7 @@ public ContextMissingStrategy ContextMissingStrategy /// The argument has a null value. public void BeginSegment(string name, string traceId = null, string parentId = null, SamplingResponse samplingResponse = null, DateTime? timestamp = null) { -#if !NET45 +#if !NETFRAMEWORK if (AWSXRayRecorder.IsLambda()) { throw new UnsupportedOperationException("Cannot override Facade Segment. New segment not created."); @@ -193,7 +193,7 @@ public void BeginSegment(string name, string traceId = null, string parentId = n /// Entity is not available in trace context. public void EndSegment(DateTime? timestamp = null) { -#if !NET45 +#if !NETFRAMEWORK if (AWSXRayRecorder.IsLambda()) { throw new UnsupportedOperationException("Cannot override Facade Segment. New segment not created."); @@ -728,7 +728,7 @@ protected void PopulateContexts() // Prepare XRay section for runtime context var xrayContext = new ConcurrentDictionary(); -#if NET45 +#if NETFRAMEWORK xrayContext["sdk"] = "X-Ray for .NET"; #else xrayContext["sdk"] = "X-Ray for .NET Core"; @@ -744,7 +744,7 @@ protected void PopulateContexts() } RuntimeContext["xray"] = xrayContext; -#if NET45 +#if NETFRAMEWORK ServiceContext["runtime"] = ".NET Framework"; #else ServiceContext["runtime"] = ".NET Core Framework"; diff --git a/sdk/src/Core/AwsXrayRecorderBuilder.cs b/sdk/src/Core/AwsXrayRecorderBuilder.cs index 8f895900..dfdbd6f5 100644 --- a/sdk/src/Core/AwsXrayRecorderBuilder.cs +++ b/sdk/src/Core/AwsXrayRecorderBuilder.cs @@ -56,7 +56,7 @@ public IReadOnlyList Plugins } } -#if NET45 +#if NETFRAMEWORK /// /// Initializes instance with default settings. /// @@ -67,7 +67,7 @@ public static AWSXRayRecorderBuilder GetDefaultBuilder() } #endif -#if NET45 +#if NETFRAMEWORK /// /// Reads plugin settings from app settings, and adds new instance of each plugin into the builder. /// If the plugin settings doesn't exist or the value of the settings is invalid, nothing will be added. diff --git a/sdk/src/Core/Internal/Context/CallContextContainer.net45.cs b/sdk/src/Core/Internal/Context/CallContextContainer.netframework.cs similarity index 97% rename from sdk/src/Core/Internal/Context/CallContextContainer.net45.cs rename to sdk/src/Core/Internal/Context/CallContextContainer.netframework.cs index d92cc770..3f4151a1 100644 --- a/sdk/src/Core/Internal/Context/CallContextContainer.net45.cs +++ b/sdk/src/Core/Internal/Context/CallContextContainer.netframework.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// +// // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/sdk/src/Core/Internal/Context/DefaultTraceContext.cs b/sdk/src/Core/Internal/Context/DefaultTraceContext.cs index f0dc2fe5..ad4a85d5 100644 --- a/sdk/src/Core/Internal/Context/DefaultTraceContext.cs +++ b/sdk/src/Core/Internal/Context/DefaultTraceContext.cs @@ -25,7 +25,7 @@ public static class DefaultTraceContext /// default instance of public static ITraceContext GetTraceContext() { -#if NET45 +#if NETFRAMEWORK return new CallContextContainer(); #else if (AWSXRayRecorder.IsLambda()) diff --git a/sdk/src/Core/Internal/Context/HybridContextContainer.net45.cs b/sdk/src/Core/Internal/Context/HybridContextContainer.netframework.cs similarity index 98% rename from sdk/src/Core/Internal/Context/HybridContextContainer.net45.cs rename to sdk/src/Core/Internal/Context/HybridContextContainer.netframework.cs index d182c2cb..040b70af 100644 --- a/sdk/src/Core/Internal/Context/HybridContextContainer.net45.cs +++ b/sdk/src/Core/Internal/Context/HybridContextContainer.netframework.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// +// // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/sdk/src/Core/Internal/Utils/AppSettings.net45.cs b/sdk/src/Core/Internal/Utils/AppSettings.netframework.cs similarity index 100% rename from sdk/src/Core/Internal/Utils/AppSettings.net45.cs rename to sdk/src/Core/Internal/Utils/AppSettings.netframework.cs diff --git a/sdk/src/Core/Strategies/DynamicSegmentNamingStrategy.cs b/sdk/src/Core/Strategies/DynamicSegmentNamingStrategy.cs index 770e8c04..ba119c46 100644 --- a/sdk/src/Core/Strategies/DynamicSegmentNamingStrategy.cs +++ b/sdk/src/Core/Strategies/DynamicSegmentNamingStrategy.cs @@ -20,7 +20,7 @@ using System.Text.RegularExpressions; using Amazon.Runtime.Internal.Util; using Amazon.XRay.Recorder.Core.Internal.Utils; -#if NET45 +#if NETFRAMEWORK using System.Net.Http; #else using Microsoft.AspNetCore.Http; @@ -81,7 +81,7 @@ public DynamicSegmentNamingStrategy(string fallbackSegmentName, string hostNameP /// public string FallbackSegmentName { get; set; } -#if NET45 +#if NETFRAMEWORK /// /// Gets the name of the segment. /// diff --git a/sdk/src/Core/Strategies/FixedSegmentNamingStrategy.cs b/sdk/src/Core/Strategies/FixedSegmentNamingStrategy.cs index 90ead918..bd4378b8 100644 --- a/sdk/src/Core/Strategies/FixedSegmentNamingStrategy.cs +++ b/sdk/src/Core/Strategies/FixedSegmentNamingStrategy.cs @@ -18,7 +18,7 @@ using System; using Amazon.Runtime.Internal.Util; -#if NET45 +#if NETFRAMEWORK using System.Net.Http; #else using Microsoft.AspNetCore.Http; @@ -61,7 +61,7 @@ public FixedSegmentNamingStrategy(string fixedName) /// public string FixedName { get; set; } -#if NET45 +#if NETFRAMEWORK /// /// Gets the name of the segment. /// diff --git a/sdk/src/Core/Strategies/SegmentNamingStrategy.cs b/sdk/src/Core/Strategies/SegmentNamingStrategy.cs index 9e288331..57136d17 100644 --- a/sdk/src/Core/Strategies/SegmentNamingStrategy.cs +++ b/sdk/src/Core/Strategies/SegmentNamingStrategy.cs @@ -18,7 +18,7 @@ using System; -#if NET45 +#if NETFRAMEWORK using System.Net.Http; #else using Microsoft.AspNetCore.Http; @@ -46,7 +46,7 @@ public static string GetSegmentNameFromEnvironmentVariable() return Environment.GetEnvironmentVariable(SegmentNamingStrategy.EnvironmentVariableSegmentName); } -#if NET45 +#if NETFRAMEWORK /// /// Gets the name of the segment. /// diff --git a/sdk/src/Handlers/AspNet/AWSXRayRecorder.Handlers.AspNet.csproj b/sdk/src/Handlers/AspNet/AWSXRayRecorder.Handlers.AspNet.csproj index fd0a792c..6614a6fb 100644 --- a/sdk/src/Handlers/AspNet/AWSXRayRecorder.Handlers.AspNet.csproj +++ b/sdk/src/Handlers/AspNet/AWSXRayRecorder.Handlers.AspNet.csproj @@ -1,7 +1,7 @@  - net45 + net45;net462 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -25,10 +25,6 @@ - - - - diff --git a/sdk/src/Handlers/AwsSdk/AWSXRayRecorder.Handlers.AwsSdk.csproj b/sdk/src/Handlers/AwsSdk/AWSXRayRecorder.Handlers.AwsSdk.csproj index 6a606101..bdd82393 100644 --- a/sdk/src/Handlers/AwsSdk/AWSXRayRecorder.Handlers.AwsSdk.csproj +++ b/sdk/src/Handlers/AwsSdk/AWSXRayRecorder.Handlers.AwsSdk.csproj @@ -1,7 +1,7 @@  - net45;netstandard2.0 + net45;net462;netstandard2.0 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -33,7 +33,7 @@ - + diff --git a/sdk/src/Handlers/EntityFramework/AWSXRayRecorder.Handlers.EntityFramework.csproj b/sdk/src/Handlers/EntityFramework/AWSXRayRecorder.Handlers.EntityFramework.csproj index 7bf8a8e6..3abef6dc 100644 --- a/sdk/src/Handlers/EntityFramework/AWSXRayRecorder.Handlers.EntityFramework.csproj +++ b/sdk/src/Handlers/EntityFramework/AWSXRayRecorder.Handlers.EntityFramework.csproj @@ -1,7 +1,7 @@ - + - net45;netstandard2.0 + net45;net462;netstandard2.0 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -25,10 +25,10 @@ - + - + diff --git a/sdk/src/Handlers/EntityFramework/EFInterceptor.net45.cs b/sdk/src/Handlers/EntityFramework/EFInterceptor.netframework.cs similarity index 98% rename from sdk/src/Handlers/EntityFramework/EFInterceptor.net45.cs rename to sdk/src/Handlers/EntityFramework/EFInterceptor.netframework.cs index b7130a2d..996af347 100644 --- a/sdk/src/Handlers/EntityFramework/EFInterceptor.net45.cs +++ b/sdk/src/Handlers/EntityFramework/EFInterceptor.netframework.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// +// // Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/sdk/src/Handlers/EntityFramework/EFUtil.cs b/sdk/src/Handlers/EntityFramework/EFUtil.cs index 74d49182..1aef6705 100644 --- a/sdk/src/Handlers/EntityFramework/EFUtil.cs +++ b/sdk/src/Handlers/EntityFramework/EFUtil.cs @@ -20,7 +20,7 @@ using System.Text.RegularExpressions; using Amazon.Runtime.Internal.Util; using Amazon.XRay.Recorder.Core; -#if NET45 +#if NETFRAMEWORK using Amazon.XRay.Recorder.Core.Internal.Utils; #endif @@ -191,7 +191,7 @@ private static string RemovePortNumberFromDataSource(string dataSource) return _portNumberRegex.Replace(dataSource, string.Empty); } -#if !NET45 +#if !NETFRAMEWORK private static bool ShouldCollectSqlText(bool? collectSqlQueriesOverride) => collectSqlQueriesOverride ?? _recorder.XRayOptions.CollectSqlQueries; #else diff --git a/sdk/src/Handlers/SqlServer/AWSXRayRecorder.Handlers.SqlServer.csproj b/sdk/src/Handlers/SqlServer/AWSXRayRecorder.Handlers.SqlServer.csproj index 217548c0..c8325569 100644 --- a/sdk/src/Handlers/SqlServer/AWSXRayRecorder.Handlers.SqlServer.csproj +++ b/sdk/src/Handlers/SqlServer/AWSXRayRecorder.Handlers.SqlServer.csproj @@ -1,7 +1,7 @@  - net45;netstandard2.0 + net45;net462;netstandard2.0 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -29,8 +29,8 @@ - - + + diff --git a/sdk/src/Handlers/SqlServer/DbCommandInterceptor.cs b/sdk/src/Handlers/SqlServer/DbCommandInterceptor.cs index 311f6729..de437e7e 100644 --- a/sdk/src/Handlers/SqlServer/DbCommandInterceptor.cs +++ b/sdk/src/Handlers/SqlServer/DbCommandInterceptor.cs @@ -150,7 +150,7 @@ protected virtual void CollectSqlInformation(DbCommand command) private static string BuildSubsegmentName(DbCommand command) => command.Connection.Database + "@" + SqlUtil.RemovePortNumberFromDataSource(command.Connection.DataSource); -#if !NET45 +#if !NETFRAMEWORK private bool ShouldCollectSqlText() => _collectSqlQueriesOverride ?? _recorder.XRayOptions.CollectSqlQueries; #else diff --git a/sdk/src/Handlers/SqlServer/TraceableSqlCommand.net45.cs b/sdk/src/Handlers/SqlServer/TraceableSqlCommand.netframework.cs similarity index 99% rename from sdk/src/Handlers/SqlServer/TraceableSqlCommand.net45.cs rename to sdk/src/Handlers/SqlServer/TraceableSqlCommand.netframework.cs index 9b5e0c14..afbd143d 100644 --- a/sdk/src/Handlers/SqlServer/TraceableSqlCommand.net45.cs +++ b/sdk/src/Handlers/SqlServer/TraceableSqlCommand.netframework.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// +// // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/sdk/src/Handlers/System.Net/AWSXRayRecorder.Handlers.System.Net.csproj b/sdk/src/Handlers/System.Net/AWSXRayRecorder.Handlers.System.Net.csproj index 3333ba99..e6d690dc 100644 --- a/sdk/src/Handlers/System.Net/AWSXRayRecorder.Handlers.System.Net.csproj +++ b/sdk/src/Handlers/System.Net/AWSXRayRecorder.Handlers.System.Net.csproj @@ -1,7 +1,7 @@  - net45;netstandard2.0 + net45;net462;netstandard2.0 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/sdk/test/IntegrationTests/AWSXRayRecorder.IntegrationTests.csproj b/sdk/test/IntegrationTests/AWSXRayRecorder.IntegrationTests.csproj index 62e5fdd0..f01e525b 100644 --- a/sdk/test/IntegrationTests/AWSXRayRecorder.IntegrationTests.csproj +++ b/sdk/test/IntegrationTests/AWSXRayRecorder.IntegrationTests.csproj @@ -2,7 +2,7 @@ - net45;netcoreapp2.0;netcoreapp3.1 + net45;net462;netcoreapp2.0;netcoreapp3.1 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/sdk/test/IntegrationTests/TestBase.cs b/sdk/test/IntegrationTests/TestBase.cs index 6f25de65..ac52bb15 100644 --- a/sdk/test/IntegrationTests/TestBase.cs +++ b/sdk/test/IntegrationTests/TestBase.cs @@ -17,6 +17,7 @@ using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Amazon.XRay; using Amazon.XRay.Model; using Amazon.XRay.Recorder.Core; @@ -44,34 +45,7 @@ protected static void ClassCleanup() Recorder.Dispose(); } -#if NET45 - protected static BatchGetTracesResponse BatchGetTraces(string traceId) - { - var request = new BatchGetTracesRequest(); - - request.TraceIds = new List() { traceId }; - - int retries = 0; - BatchGetTracesResponse response = null; - - while (retries < 60) - { - response = XrayClient.BatchGetTraces(request); - if (response.Traces.Count > 0) - { - break; - } - else - { - retries++; - Thread.Sleep(500); - } - } - - return response; - } -#else - protected static async System.Threading.Tasks.Task BatchGetTracesAsync(string traceId) + protected async Task BatchGetTracesAsync(string traceId) { var request = new BatchGetTracesRequest(); request.TraceIds = new List() { traceId }; @@ -96,6 +70,5 @@ protected static async System.Threading.Tasks.Task Batch return response; } -#endif } } diff --git a/sdk/test/IntegrationTests/ValidateSegmentTests.cs b/sdk/test/IntegrationTests/ValidateSegmentTests.cs index c74bf34c..430fb7dc 100644 --- a/sdk/test/IntegrationTests/ValidateSegmentTests.cs +++ b/sdk/test/IntegrationTests/ValidateSegmentTests.cs @@ -17,9 +17,9 @@ using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Amazon.XRay.Recorder.Core; using Amazon.XRay.Recorder.Core.Internal.Entities; -using Amazon.XRay.Recorder.Core.Internal.Utils; using Amazon.XRay.Recorder.Core.Plugins; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -43,18 +43,16 @@ public static void ClassInit(TestContext context) } [TestMethod] - public void TestMinimalSegment() + public async Task TestMinimalSegment() { var traceId = TraceId.NewId(); Recorder.BeginSegment(GetType().Name, traceId); var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); Thread.Sleep(100); Recorder.EndSegment(); -#if NET45 - var response = BatchGetTraces(traceId); -#else - var response = TestBase.BatchGetTracesAsync(traceId).Result; -#endif + + var response = await BatchGetTracesAsync(traceId); + Assert.IsTrue(response.Traces.Count > 0); var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document); @@ -65,7 +63,7 @@ public void TestMinimalSegment() Assert.AreEqual(segment.EndTime.ToString("F5"), ((double)segmentJsonData["end_time"]).ToString("F5")); } [TestMethod] - public void TestMultipleSubsegments() + public async Task TestMultipleSubsegments() { var traceId = TraceId.NewId(); Recorder.BeginSegment(GetType().Name, traceId); @@ -80,11 +78,9 @@ public void TestMultipleSubsegments() AWSXRayRecorder.Instance.TraceContext.GetEntity().Subsegments.ForEach(x => subsegmentNames[x.Id] = x.Name); Recorder.EndSegment(); -#if NET45 - var response = BatchGetTraces(traceId); -#else - var response = TestBase.BatchGetTracesAsync(traceId).Result; -#endif + + var response = await BatchGetTracesAsync(traceId); + Assert.IsTrue(response.Traces.Count > 0); var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document); @@ -102,7 +98,7 @@ public void TestMultipleSubsegments() Assert.AreEqual(0, subsegmentNames.Count); } [TestMethod] - public void TestEC2Plugin() + public async Task TestEC2Plugin() { var mockEC2Plugin = new Mock(); IDictionary fakeEC2Context = new Dictionary(); @@ -120,11 +116,9 @@ public void TestEC2Plugin() Thread.Sleep(100); recorder.EndSegment(); -#if NET45 - var response = BatchGetTraces(traceId); -#else - var response = TestBase.BatchGetTracesAsync(traceId).Result; -#endif + + var response = await BatchGetTracesAsync(traceId); + Assert.IsTrue(response.Traces.Count > 0); var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document); @@ -137,7 +131,7 @@ public void TestEC2Plugin() } [TestMethod] - public void TestECSPlugin() + public async Task TestECSPlugin() { var mockECSPlugin = new Mock(); IDictionary fakeECSContext = new Dictionary(); @@ -151,11 +145,9 @@ public void TestECSPlugin() recorder.BeginSegment(GetType().Name, traceId); Thread.Sleep(100); recorder.EndSegment(); -#if NET45 - var response = BatchGetTraces(traceId); -#else - var response = TestBase.BatchGetTracesAsync(traceId).Result; -#endif + + var response = await BatchGetTracesAsync(traceId); + Assert.IsTrue(response.Traces.Count > 0); var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document); @@ -165,7 +157,7 @@ public void TestECSPlugin() } [TestMethod] - public void TestElasticBeanstalkPlugin() + public async Task TestElasticBeanstalkPlugin() { var mockEBPlugin = new Mock(); IDictionary fakeEBContext = new Dictionary(); @@ -182,11 +174,9 @@ public void TestElasticBeanstalkPlugin() recorder.BeginSegment(GetType().Name, traceId); Thread.Sleep(100); recorder.EndSegment(); -#if NET45 - var response = BatchGetTraces(traceId); -#else - var response = TestBase.BatchGetTracesAsync(traceId).Result; -#endif + + var response = await BatchGetTracesAsync(traceId); + Assert.IsTrue(response.Traces.Count > 0); var segmentJsonData = JsonMapper.ToObject(response.Traces[0].Segments[0].Document); diff --git a/sdk/test/SmokeTests/AWSXRayRecorder.SmokeTests.csproj b/sdk/test/SmokeTests/AWSXRayRecorder.SmokeTests.csproj index 15b0da58..ca3a555d 100644 --- a/sdk/test/SmokeTests/AWSXRayRecorder.SmokeTests.csproj +++ b/sdk/test/SmokeTests/AWSXRayRecorder.SmokeTests.csproj @@ -1,7 +1,7 @@  - net452;netcoreapp2.0;netcoreapp3.1 + net452;net462;netcoreapp2.0;netcoreapp3.1 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -11,10 +11,6 @@ true - - NET45 - - diff --git a/sdk/test/UnitTests/AWSSDKHandlerTests.cs b/sdk/test/UnitTests/AWSSDKHandlerTests.cs index e5a5800b..16809019 100644 --- a/sdk/test/UnitTests/AWSSDKHandlerTests.cs +++ b/sdk/test/UnitTests/AWSSDKHandlerTests.cs @@ -44,7 +44,7 @@ public class AWSSDKHandlerTests : TestBase private AWSXRayRecorder _recorder; private static String _path = $"JSONs{Path.DirectorySeparatorChar}AWSRequestInfo.json"; -#if !NET45 +#if !NETFRAMEWORK private XRayOptions _xRayOptions = new XRayOptions(); #endif @@ -52,18 +52,14 @@ public class AWSSDKHandlerTests : TestBase public void TestInitialize() { _recorder = new AWSXRayRecorder(); -#if NET45 - AWSXRayRecorder.InitializeInstance(recorder:_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif } [TestCleanup] public new void TestCleanup() { base.TestCleanup(); -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = null; AppSettings.Reset(); #else @@ -76,7 +72,7 @@ public void TestInitialize() } [TestMethod] - public void TestContextMissingStrategyForAWSSDKHandler() + public async Task TestContextMissingStrategyForAWSSDKHandler() { AWSXRayRecorder.Instance.ContextMissingStrategy = Core.Strategies.ContextMissingStrategy.LOG_ERROR; AWSSDKHandler.RegisterXRayForAllServices(); @@ -89,27 +85,22 @@ public void TestContextMissingStrategyForAWSSDKHandler() AWSXRayRecorder.Instance.EndSegment(); // The test should not break. No segment is available in the context, however, since the context missing strategy is log error, // no exception should be thrown by below code. -#if NET45 - dynamo.ListTables(); -#else - dynamo.ListTablesAsync().Wait(); -#endif + await dynamo.ListTablesAsync(); + Assert.IsNotNull(segment); } [TestMethod] - public void TestS3SubsegmentNameIsCorrectForAWSSDKHandler() + public async Task TestS3SubsegmentNameIsCorrectForAWSSDKHandler() { AWSSDKHandler.RegisterXRay(); var s3 = new AmazonS3Client(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); CustomResponses.SetResponse(s3, null, "TestAmazonId"); _recorder.BeginSegment("test s3", TraceId); -#if NET45 - s3.GetObject("testBucket", "testKey"); -#else - s3.GetObjectAsync("testBucket", "testKey").Wait(); -#endif + + await s3.GetObjectAsync("testBucket", "testKey"); + var segment = _recorder.TraceContext.GetEntity(); _recorder.EndSegment(); Assert.AreEqual("S3", segment.Subsegments[0].Name); @@ -120,7 +111,7 @@ public void TestS3SubsegmentNameIsCorrectForAWSSDKHandler() } [TestMethod] - public void TestDynamoDbClient() + public async Task TestDynamoDbClient() { AWSSDKHandler.RegisterXRayForAllServices(_path); // IAmazonDynamoDb will be registered. All new instances of AmazonServiceClient will be automatically registered. @@ -131,11 +122,9 @@ public void TestDynamoDbClient() CustomResponses.SetResponse(client, requestId); _recorder.BeginSegment("test", TraceId); -#if NET45 - client.ListTables(); -#else - client.ListTablesAsync().Wait(); -#endif + + await client.ListTablesAsync(); + var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); var subsegment = segment.Subsegments[0]; _recorder.EndSegment(); @@ -182,7 +171,7 @@ public void TestLoadServiceInfoManifestInvalidPathForAWSSDKHandler() } [TestMethod] - public void TestRequestResponseParameterAndDescriptorForAWSSDKHandler() + public async Task TestRequestResponseParameterAndDescriptorForAWSSDKHandler() { using (var client = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1)) { @@ -194,11 +183,8 @@ public void TestRequestResponseParameterAndDescriptorForAWSSDKHandler() var key2 = new Dictionary() { { "id", new AttributeValue("2") } }; var keys = new KeysAndAttributes() { Keys = new List>() { key1, key2 } }; -#if NET45 - client.BatchGetItem(new Dictionary() { { "test", keys } }); -#else - client.BatchGetItemAsync(new Dictionary() { { "test", keys } }).Wait(); -#endif + await client.BatchGetItemAsync(new Dictionary() { { "test", keys } }); + _recorder.EndSegment(); Assert.IsTrue(segment.Subsegments[0].Aws.ContainsKey("request_items")); Assert.IsTrue(segment.Subsegments[0].Aws.ContainsKey("responses")); @@ -254,16 +240,14 @@ await client.GetItemAsync( } [TestMethod] - public void TestDynamoSubsegmentNameIsCorrectForAWSSDKHandler() + public async Task TestDynamoSubsegmentNameIsCorrectForAWSSDKHandler() { var dynamo = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); CustomResponses.SetResponse(dynamo); _recorder.BeginSegment("test dynamo", TraceId); -#if NET45 - dynamo.ListTables(); -#else - dynamo.ListTablesAsync().Wait(); -#endif + + await dynamo.ListTablesAsync(); + var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); _recorder.EndSegment(); @@ -271,46 +255,36 @@ public void TestDynamoSubsegmentNameIsCorrectForAWSSDKHandler() } [TestMethod] - public void TestManifestFileNoLambda() //At this point, current manifest file doen't contain Lambda service. + public async Task TestManifestFileNoLambda() //At this point, current manifest file doen't contain Lambda service. { var lambda = new AmazonLambdaClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); CustomResponses.SetResponse(lambda); _recorder.BeginSegment("lambda", TraceId); -#if NET45 - lambda.Invoke(new InvokeRequest + + await lambda.InvokeAsync(new InvokeRequest { FunctionName = "testFunction" }); -#else - lambda.InvokeAsync(new InvokeRequest - { - FunctionName = "testFunction" - }).Wait(); -#endif + var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); _recorder.EndSegment(); Assert.IsFalse(segment.Subsegments[0].Aws.ContainsKey("function_name")); } [TestMethod] - public void TestLambdaInvokeSubsegmentContainsFunctionNameForAWSSDKHandler() + public async Task TestLambdaInvokeSubsegmentContainsFunctionNameForAWSSDKHandler() { String temp_path = $"JSONs{Path.DirectorySeparatorChar}AWSRequestInfoWithLambda.json"; //registering manifest file with Lambda AWSSDKHandler.RegisterXRayManifest(temp_path); var lambda = new AmazonLambdaClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); CustomResponses.SetResponse(lambda); _recorder.BeginSegment("lambda", TraceId); -#if NET45 - lambda.Invoke(new InvokeRequest + + await lambda.InvokeAsync(new InvokeRequest { FunctionName = "testFunction" }); -#else - lambda.InvokeAsync(new InvokeRequest - { - FunctionName = "testFunction" - }).Wait(); -#endif + var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); _recorder.EndSegment(); @@ -319,7 +293,7 @@ public void TestLambdaInvokeSubsegmentContainsFunctionNameForAWSSDKHandler() } [TestMethod] - public void TestRegisterXRayManifestWithStreamLambdaForAWSSDKHandler() + public async Task TestRegisterXRayManifestWithStreamLambdaForAWSSDKHandler() { String temp_path = $"JSONs{Path.DirectorySeparatorChar}AWSRequestInfoWithLambda.json"; //registering manifest file with Lambda using (Stream stream = new FileStream(temp_path, FileMode.Open, FileAccess.Read)) @@ -329,17 +303,12 @@ public void TestRegisterXRayManifestWithStreamLambdaForAWSSDKHandler() var lambda = new AmazonLambdaClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); CustomResponses.SetResponse(lambda); _recorder.BeginSegment("lambda", TraceId); -#if NET45 - lambda.Invoke(new InvokeRequest + + await lambda.InvokeAsync(new InvokeRequest { FunctionName = "testFunction" }); -#else - lambda.InvokeAsync(new InvokeRequest - { - FunctionName = "testFunction" - }).Wait(); -#endif + var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); _recorder.EndSegment(); diff --git a/sdk/test/UnitTests/AWSXRayRecorder.UnitTests.csproj b/sdk/test/UnitTests/AWSXRayRecorder.UnitTests.csproj index 28af74ef..5699eb9e 100644 --- a/sdk/test/UnitTests/AWSXRayRecorder.UnitTests.csproj +++ b/sdk/test/UnitTests/AWSXRayRecorder.UnitTests.csproj @@ -2,7 +2,7 @@ - net452;netcoreapp2.0;netcoreapp3.1 + net452;net462;netcoreapp2.0;netcoreapp3.1 Amazon.com, Inc Amazon Web Service X-Ray Recorder Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -11,22 +11,6 @@ true ../../../buildtools/local-development.snk - - - TRACE;DEBUG - - - - NET45 - - - - TRACE;DEBUG - - - - TRACE;DEBUG - @@ -67,7 +51,7 @@ - + @@ -75,7 +59,7 @@ - + diff --git a/sdk/test/UnitTests/AWSXRayRecorderBuilderTests.cs b/sdk/test/UnitTests/AWSXRayRecorderBuilderTests.cs index e559a8b3..2ebbdaf8 100644 --- a/sdk/test/UnitTests/AWSXRayRecorderBuilderTests.cs +++ b/sdk/test/UnitTests/AWSXRayRecorderBuilderTests.cs @@ -32,7 +32,7 @@ using Amazon.Runtime; -#if !NET45 +#if !NETFRAMEWORK using Microsoft.Extensions.Configuration; #endif @@ -44,7 +44,7 @@ public class AwsXrayRecorderBuilderTests : TestBase private const string PluginKey = "AWSXRayPlugins"; private const string UseRuntimeErrors = "UseRuntimeErrors"; private AWSXRayRecorder _recorder; -#if !NET45 +#if !NETFRAMEWORK private XRayOptions _xRayOptions = new XRayOptions(); #endif [TestInitialize] @@ -57,7 +57,7 @@ public void Initialize() public new void TestCleanup() { base.TestCleanup(); -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[PluginKey] = null; ConfigurationManager.AppSettings[UseRuntimeErrors] = null; AppSettings.Reset(); @@ -91,7 +91,7 @@ public void TestBuildWithDummyPlugin() public void TestWithDefaultPlugins() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[PluginKey] = "EC2Plugin"; AppSettings.Reset(); AWSXRayRecorderBuilder builder = new AWSXRayRecorderBuilder().WithPluginsFromAppSettings(); @@ -109,7 +109,7 @@ public void TestWithDefaultPlugins() [TestMethod] public void TestPluginSettingMissing() { -#if NET45 +#if NETFRAMEWORK var builder = new AWSXRayRecorderBuilder().WithPluginsFromAppSettings(); #else var builder = new AWSXRayRecorderBuilder().WithPluginsFromConfig(_xRayOptions); @@ -120,7 +120,7 @@ public void TestPluginSettingMissing() [TestMethod] public void TestInvalidPluginSetting() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[PluginKey] = "UnknownPlugin, IPlugin"; AppSettings.Reset(); AWSXRayRecorderBuilder builder = new AWSXRayRecorderBuilder().WithPluginsFromAppSettings(); @@ -162,7 +162,7 @@ public void TestSetContextMissingStrategy() [TestMethod] public void TestSetContextMissingUsingConfiguration1() // Contextmissing startegy set to log error from configuration { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[UseRuntimeErrors] = "false"; AppSettings.Reset(); AWSXRayRecorderBuilder builder = new AWSXRayRecorderBuilder().WithContextMissingStrategyFromAppSettings(); @@ -177,7 +177,7 @@ public void TestSetContextMissingUsingConfiguration1() // Contextmissing starteg [TestMethod] public void TestSetContextMissingUsingConfiguration2() // Contextmissing startegy not set { -#if NET45 +#if NETFRAMEWORK AppSettings.Reset(); AWSXRayRecorderBuilder builder = new AWSXRayRecorderBuilder().WithContextMissingStrategyFromAppSettings(); #else @@ -191,7 +191,7 @@ public void TestSetContextMissingUsingConfiguration2() // Contextmissing starteg public void TestSetContextMissingUsingConfiguration3() // Contextmissing startegy is set through environment and configurations { Environment.SetEnvironmentVariable(AWSXRayRecorder.EnvironmentVariableContextMissingStrategy, "LOG_ERROR"); -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[UseRuntimeErrors] = "true"; AppSettings.Reset(); AWSXRayRecorderBuilder builder = new AWSXRayRecorderBuilder().WithContextMissingStrategyFromAppSettings(); diff --git a/sdk/test/UnitTests/AWSXRayRecorderTests.cs b/sdk/test/UnitTests/AWSXRayRecorderTests.cs index feab6515..fb18a0cf 100644 --- a/sdk/test/UnitTests/AWSXRayRecorderTests.cs +++ b/sdk/test/UnitTests/AWSXRayRecorderTests.cs @@ -43,7 +43,7 @@ public class AwsXrayRecorderTests : TestBase { private const string DisableXRayTracingKey = "DisableXRayTracing"; private AWSXRayRecorder _recorder; -#if !NET45 +#if !NETFRAMEWORK private XRayOptions _xRayOptions = new XRayOptions(); #endif @@ -57,7 +57,7 @@ public void Initialize() public new void TestCleanup() { base.TestCleanup(); -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[DisableXRayTracingKey] = string.Empty; AppSettings.Reset(); @@ -722,7 +722,7 @@ public void TestOverwriteSqlInformationKey() [TestMethod] public void TestDisableXRayTracingAndNoSegmentSent() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[DisableXRayTracingKey] = "true"; AppSettings.Reset(); #else @@ -730,12 +730,12 @@ public void TestDisableXRayTracingAndNoSegmentSent() #endif Mock mockSegmentEmitter = new Mock(); -#if NET45 +#if NETFRAMEWORK AppSettings.Reset(); #endif using (var recorder = AWSXRayRecorderFactory.CreateAWSXRayRecorder(mockSegmentEmitter.Object)) { -#if !NET45 +#if !NETFRAMEWORK recorder.XRayOptions = _xRayOptions; #endif recorder.BeginSegment("test", TraceId); @@ -775,7 +775,7 @@ public void TestXrayContext() .ProductVersion; Assert.AreEqual(versionText, xray["sdk_version"]); -#if NET45 +#if NETFRAMEWORK Assert.AreEqual("X-Ray for .NET", xray["sdk"]); #else Assert.AreEqual("X-Ray for .NET Core", xray["sdk"]); @@ -788,7 +788,7 @@ public void TestServiceContext() _recorder.BeginSegment("test", TraceId); var segment = (Segment)AWSXRayRecorder.Instance.TraceContext.GetEntity(); _recorder.EndSegment(); -#if NET45 +#if NETFRAMEWORK Assert.AreEqual(".NET Framework", segment.Service["runtime"]); #else Assert.AreEqual(".NET Core Framework", segment.Service["runtime"]); @@ -941,7 +941,7 @@ public void TestOverrideContextMissingStrategyToLogError() public void TestDefaultTraceContext() { var recorder = AWSXRayRecorder.Instance; -#if NET45 +#if NETFRAMEWORK Assert.AreEqual(typeof(CallContextContainer).FullName, recorder.TraceContext.GetType().FullName); #else Assert.AreEqual(typeof(AsyncLocalContextContainer).FullName, recorder.TraceContext.GetType().FullName); @@ -952,11 +952,7 @@ public void TestDefaultTraceContext() public void TestInitializeInstanceWithRecorder1() { AWSXRayRecorder recorder = BuildAWSXRayRecorder(new TestSamplingStrategy()); -#if NET45 - AWSXRayRecorder.InitializeInstance(recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: recorder); -#endif Assert.AreEqual(AWSXRayRecorder.Instance.SamplingStrategy, recorder.SamplingStrategy); // Custom recorder set in AWSXRayRecorder.Instance.TraceContext Assert.AreEqual(typeof(TestSamplingStrategy), recorder.SamplingStrategy.GetType()); // custom strategy set Assert.AreEqual(typeof(UdpSegmentEmitter), recorder.Emitter.GetType()); // Default emitter set @@ -970,11 +966,7 @@ public void TestInitializeInstanceWithRecorder2() // setting custom daemon addre IPEndPoint expectedUDPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2001); IPEndPoint expectedTCPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2000); AWSXRayRecorder recorder = BuildAWSXRayRecorder(new TestSamplingStrategy(), daemonAddress: daemonAddress); -#if NET45 - AWSXRayRecorder.InitializeInstance(recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: recorder); -#endif Assert.AreEqual(AWSXRayRecorder.Instance.SamplingStrategy, recorder.SamplingStrategy); Assert.AreEqual(typeof(TestSamplingStrategy), recorder.SamplingStrategy.GetType()); // custom strategy set Assert.AreEqual(typeof(UdpSegmentEmitter), recorder.Emitter.GetType()); // Default emitter set @@ -991,11 +983,7 @@ public void TestInitializeInstanceWithRecorder3() // setting custom daemon addre IPEndPoint expectedUDPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2001); IPEndPoint expectedTCPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2000); AWSXRayRecorder recorder = BuildAWSXRayRecorder(daemonAddress: daemonAddress); -#if NET45 - AWSXRayRecorder.InitializeInstance(recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: recorder); -#endif Assert.AreEqual(AWSXRayRecorder.Instance.SamplingStrategy, recorder.SamplingStrategy); Assert.AreEqual(typeof(DefaultSamplingStrategy), recorder.SamplingStrategy.GetType()); // Default startegy set Assert.AreEqual(typeof(UdpSegmentEmitter), recorder.Emitter.GetType()); // Default emitter set @@ -1014,11 +1002,7 @@ public void TestInitializeInstanceWithRecorder3() // setting custom daemon addre public void TestInitializeInstanceWithRecorde4() // Set custom trace context { AWSXRayRecorder recorder = BuildAWSXRayRecorder(traceContext:new DummyTraceContext()); -#if NET45 - AWSXRayRecorder.InitializeInstance(recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: recorder); -#endif Assert.AreEqual(typeof(DummyTraceContext), AWSXRayRecorder.Instance.TraceContext.GetType()); // Custom trace context recorder.Dispose(); AWSXRayRecorder.Instance.Dispose(); diff --git a/sdk/test/UnitTests/CauseTest.cs b/sdk/test/UnitTests/CauseTest.cs index ec8fe0dc..8816d6b7 100644 --- a/sdk/test/UnitTests/CauseTest.cs +++ b/sdk/test/UnitTests/CauseTest.cs @@ -31,11 +31,7 @@ public class CauseTest : TestBase public void TestInitialize() { _recorder = new AWSXRayRecorder(); -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif } [TestCleanup] diff --git a/sdk/test/UnitTests/DbCommandInterceptorTests.cs b/sdk/test/UnitTests/DbCommandInterceptorTests.cs index c70f3331..10d6949c 100644 --- a/sdk/test/UnitTests/DbCommandInterceptorTests.cs +++ b/sdk/test/UnitTests/DbCommandInterceptorTests.cs @@ -59,7 +59,7 @@ public void TestInitialize() public new void TestCleanup() { base.TestCleanup(); -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[_collectSqlQueriesKey] = string.Empty; AppSettings.Reset(); #endif @@ -70,7 +70,7 @@ public void TestInitialize() public void Intercept_DoesNot_CollectQueries_When_NotEnabled() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions() }; @@ -94,7 +94,7 @@ public void Intercept_DoesNot_CollectQueries_When_NotEnabled() public async Task InterceptAsync_DoesNot_CollectQueries_When_NotEnabled() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions() }; @@ -118,7 +118,7 @@ public async Task InterceptAsync_DoesNot_CollectQueries_When_NotEnabled() public void Intercept_CollectsQueries_When_DisabledGlobally_And_EnabledLocally() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions { CollectSqlQueries = false } }; @@ -142,7 +142,7 @@ public void Intercept_CollectsQueries_When_DisabledGlobally_And_EnabledLocally() public async Task InterceptAsync_CollectsQueries_When_DisabledGlobally_And_EnabledLocally() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions { CollectSqlQueries = false } }; @@ -166,7 +166,7 @@ public async Task InterceptAsync_CollectsQueries_When_DisabledGlobally_And_Enabl public void Intercept_CollectsQueries_When_EnabledGlobally() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions { CollectSqlQueries = true } }; @@ -190,7 +190,7 @@ public void Intercept_CollectsQueries_When_EnabledGlobally() public async Task InterceptAsync_CollectsQueries_When_EnabledGlobally() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions { CollectSqlQueries = true } }; @@ -214,7 +214,7 @@ public async Task InterceptAsync_CollectsQueries_When_EnabledGlobally() public void Intercept_DoesNot_CollectQueries_When_EnabledGlobally_And_DisabledLocally() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions { CollectSqlQueries = true } }; @@ -238,7 +238,7 @@ public void Intercept_DoesNot_CollectQueries_When_EnabledGlobally_And_DisabledLo public async Task InterceptAsync_DoesNot_CollectQueries_When_EnabledGlobally_And_DisabledLocally() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions { CollectSqlQueries = true } }; @@ -262,7 +262,7 @@ public async Task InterceptAsync_DoesNot_CollectQueries_When_EnabledGlobally_And public void TestTrustedConnection_DoesNotCollectUserID() { // arrange -#if !NET45 +#if !NETFRAMEWORK var recorder = new AWSXRayRecorder { XRayOptions = new XRayOptions() }; diff --git a/sdk/test/UnitTests/HttpClientXRayTracingHandlerTests.cs b/sdk/test/UnitTests/HttpClientXRayTracingHandlerTests.cs index 77cc773f..4f8775e4 100644 --- a/sdk/test/UnitTests/HttpClientXRayTracingHandlerTests.cs +++ b/sdk/test/UnitTests/HttpClientXRayTracingHandlerTests.cs @@ -32,11 +32,7 @@ public HttpClientXRayTracingHandlerTests() public void TestInitialize() { _recorder = new AWSXRayRecorder(); -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif } [TestCleanup] @@ -77,11 +73,7 @@ public async Task TestSendAsync() public async Task TestXrayDisabledSendAsync() { _recorder = new MockAWSXRayRecorder() { IsTracingDisabledValue = true }; -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif Assert.IsTrue(AWSXRayRecorder.Instance.IsTracingDisabled()); var request = new HttpRequestMessage(HttpMethod.Get, URL); @@ -117,11 +109,7 @@ public async Task Test404SendAsync() public async Task TestXrayContextMissingStrategySendAsync() // Test that respects ContextMissingStrategy { _recorder = new MockAWSXRayRecorder(); -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif AWSXRayRecorder.Instance.ContextMissingStrategy = Core.Strategies.ContextMissingStrategy.LOG_ERROR; Assert.IsFalse(AWSXRayRecorder.Instance.IsTracingDisabled()); diff --git a/sdk/test/UnitTests/HttpWebRequestTracingExtensionTests.cs b/sdk/test/UnitTests/HttpWebRequestTracingExtensionTests.cs index 76b92a9d..377daaea 100644 --- a/sdk/test/UnitTests/HttpWebRequestTracingExtensionTests.cs +++ b/sdk/test/UnitTests/HttpWebRequestTracingExtensionTests.cs @@ -41,11 +41,7 @@ public class HttpWebRequestTracingExtensionTests : TestBase public void TestInitialize() { _recorder = new AWSXRayRecorder(); -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif } [TestCleanup] @@ -87,11 +83,7 @@ public void TestGetResponseTraced() public void TestXrayDisabledGetResponseTraced() { _recorder = new MockAWSXRayRecorder() { IsTracingDisabledValue = true }; -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif Assert.IsTrue(AWSXRayRecorder.Instance.IsTracingDisabled()); var request = (HttpWebRequest)WebRequest.Create(URL); @@ -134,11 +126,7 @@ public async Task TestGetAsyncResponseTraced() public async Task TestXrayDisabledGetAsyncResponseTraced() { _recorder = new MockAWSXRayRecorder() { IsTracingDisabledValue = true }; -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif Assert.IsTrue(AWSXRayRecorder.Instance.IsTracingDisabled()); var request = (HttpWebRequest)WebRequest.Create(URL); @@ -150,7 +138,7 @@ public async Task TestXrayDisabledGetAsyncResponseTraced() } } -#if !NET45 +#if !NETFRAMEWORK [TestMethod] public void TestExceptionGetResponseTraced() { @@ -222,11 +210,7 @@ public async Task TestExceptionGetAsyncResponseTraced() public async Task TestContextMissingStrategyGetAsyncResponseTraced() { _recorder = new AWSXRayRecorder(); -#if NET45 - AWSXRayRecorder.InitializeInstance(_recorder); -#else AWSXRayRecorder.InitializeInstance(recorder: _recorder); -# endif Assert.IsFalse(AWSXRayRecorder.Instance.IsTracingDisabled()); AWSXRayRecorder.Instance.ContextMissingStrategy = Core.Strategies.ContextMissingStrategy.LOG_ERROR; diff --git a/sdk/test/UnitTests/LocalizedSamplingStrategyTests.cs b/sdk/test/UnitTests/LocalizedSamplingStrategyTests.cs index 85b1ee9f..8e21c714 100644 --- a/sdk/test/UnitTests/LocalizedSamplingStrategyTests.cs +++ b/sdk/test/UnitTests/LocalizedSamplingStrategyTests.cs @@ -34,14 +34,14 @@ namespace Amazon.XRay.Recorder.UnitTests public class LocalizedSamplingStrategyTests { private const string ManifestKey = "SamplingRuleManifest"; -#if !NET45 +#if !NETFRAMEWORK private XRayOptions _xRayOtions = new XRayOptions(); #endif [TestCleanup] public void TestCleanup() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = null; AppSettings.Reset(); #else @@ -59,7 +59,7 @@ public void TestFixedTargetAndRateBehaveCorrectly() // fill the fixed target rate Action action = () => { - var input = new SamplingInput("name", "test", "get","", ""); + var input = new SamplingInput("name", "test", "get", "", ""); if (strategy.ShouldTrace(input).SampleDecision == SampleDecision.Sampled) { Interlocked.Increment(ref count); @@ -115,7 +115,7 @@ public void TestDefaultRuleWithRequest() [TestMethod] public void TestLoadJsonConfiguration() // version 1 { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = @"JSONs\DefaultSamplingRules.json"; AppSettings.Reset(); var strategy = new LocalizedSamplingStrategy(AppSettings.SamplingRuleManifest); @@ -143,7 +143,7 @@ public void TestLoadJsonConfiguration() // version 1 [TestMethod] public void TestLoadJsonConfiguration1() // Version 2 { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = @"JSONs\DefaultSamplingRules1.json"; AppSettings.Reset(); var strategy = new LocalizedSamplingStrategy(AppSettings.SamplingRuleManifest); @@ -173,7 +173,7 @@ public void TestLoadJsonConfiguration1() // Version 2 [ExpectedException(typeof(InvalidSamplingConfigurationException))] public void TestLoadSamplingRulesWithoutDefaultRule() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = @"JSONs\SamplingRulesWithoutDefault.json"; AppSettings.Reset(); var strategy = new LocalizedSamplingStrategy(AppSettings.SamplingRuleManifest); @@ -187,7 +187,7 @@ public void TestLoadSamplingRulesWithoutDefaultRule() [ExpectedException(typeof(InvalidSamplingConfigurationException))] public void TestLoadSamplingRulesWithInvalidVersion1() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = @"JSONs\SamplingRulesInvalidV1.json"; AppSettings.Reset(); var strategy = new LocalizedSamplingStrategy(AppSettings.SamplingRuleManifest); @@ -201,7 +201,7 @@ public void TestLoadSamplingRulesWithInvalidVersion1() [ExpectedException(typeof(InvalidSamplingConfigurationException))] public void TestLoadSamplingRulesWithInvalidVersion2() { -#if NET45 +#if NETFRAMEWORK ConfigurationManager.AppSettings[ManifestKey] = @"JSONs\SamplingRulesInvalidV2.json"; AppSettings.Reset(); var strategy = new LocalizedSamplingStrategy(AppSettings.SamplingRuleManifest); diff --git a/sdk/test/UnitTests/SegmentNamingStrategyTests.cs b/sdk/test/UnitTests/SegmentNamingStrategyTests.cs index 74db2aa2..8da89293 100644 --- a/sdk/test/UnitTests/SegmentNamingStrategyTests.cs +++ b/sdk/test/UnitTests/SegmentNamingStrategyTests.cs @@ -19,7 +19,7 @@ using System.Net.Http; using Amazon.XRay.Recorder.Core.Strategies; using Microsoft.VisualStudio.TestTools.UnitTesting; -#if !NET45 +#if !NETFRAMEWORK using Microsoft.AspNetCore.Http; #endif @@ -28,7 +28,7 @@ namespace Amazon.XRay.Recorder.UnitTests [TestClass] public class SegmentNamingStrategyTests { -#if NET45 +#if NETFRAMEWORK private HttpRequestMessage _request; #else private HttpRequest _request; @@ -36,7 +36,7 @@ public class SegmentNamingStrategyTests [TestInitialize] public void TestInitialize() { -#if NET45 +#if NETFRAMEWORK _request = new HttpRequestMessage(); #else _request = new DefaultHttpContext().Request; diff --git a/sdk/test/UnitTests/SegmentTests.cs b/sdk/test/UnitTests/SegmentTests.cs index 5adb7a7d..207158d2 100644 --- a/sdk/test/UnitTests/SegmentTests.cs +++ b/sdk/test/UnitTests/SegmentTests.cs @@ -311,7 +311,7 @@ public void TestHttpOverwriteValue() } -#if NET45 +#if NETFRAMEWORK [TestMethod] public void TestSegmentIsSerializable() { diff --git a/sdk/test/UnitTests/Tools/CustomResponses.cs b/sdk/test/UnitTests/Tools/CustomResponses.cs index e81f47af..5196305a 100644 --- a/sdk/test/UnitTests/Tools/CustomResponses.cs +++ b/sdk/test/UnitTests/Tools/CustomResponses.cs @@ -29,7 +29,7 @@ namespace Amazon.XRay.Recorder.UnitTests.Tools { public static class CustomResponses { -#if NET45 +#if NETFRAMEWORK public static void SetResponse( AmazonServiceClient client, string requestId = null, string s3ExtendedRequestId = null, string content = null, bool isOK = true) { diff --git a/sdk/test/UnitTests/Tools/MockWebResponse.cs b/sdk/test/UnitTests/Tools/MockWebResponse.cs index c30a193f..2b793585 100644 --- a/sdk/test/UnitTests/Tools/MockWebResponse.cs +++ b/sdk/test/UnitTests/Tools/MockWebResponse.cs @@ -27,7 +27,7 @@ namespace Amazon.XRay.Recorder.UnitTests.Tools { public class MockWebResponse { -#if NET45 +#if NETFRAMEWORK public static HttpWebResponse CreateFromResource(string resourceName) { var rawResponse = Utils.GetResourceText(resourceName);