From 9f27a2540647ef6c8381eaaace3891191ea90c6f Mon Sep 17 00:00:00 2001 From: Philip Lin Date: Tue, 31 Dec 2019 13:28:27 -0800 Subject: [PATCH] Clean up Test Operation Result types and generated codes (#2209) * Clean up TestOperationResult; and AnalyzerClient and TRC Client. * Rename ClientTestResultOperation to TestResultOperationDto * Update descriptions in swagger files. --- Microsoft.Azure.Devices.Edge.sln | 11 ++ .../NetworkStatusReporter.cs | 7 +- test/modules/DirectMethodSender/Program.cs | 13 +- test/modules/ModuleLib/AnalyzerClient.cs | 130 ------------------ test/modules/ModuleLib/ModuleUtil.cs | 4 +- .../TestAnalyzer.swagger.yaml} | 42 +----- .../TestOperationResult.cs | 2 +- ...Client.cs => TestResultReportingClient.cs} | 20 +-- ...=> TestResultReportingClient.swagger.yaml} | 10 +- .../CountingReportGeneratorTest.cs | 1 + .../CountingReportTest.cs | 2 +- .../SimpleTestOperationResultComparerTest.cs | 2 +- .../StoreTestResultCollectionTest.cs | 1 + .../TwinCountingReportGeneratorTest.cs | 3 +- test/modules/Relayer/Program.cs | 7 +- .../TestOperationResultController.cs | 1 + .../TestAnalyzer/TestOperationResult.cs | 29 ---- .../TestOperationResultController.cs | 1 - .../report/CloudTwinTestResultCollection.cs | 10 +- .../report/CountingReportGenerator.cs | 1 - .../SimpleTestOperationResultComparer.cs | 1 + .../report/TestReportGeneratorFactory.cs | 1 + .../report/TwinCountingReportGenerator.cs | 1 - .../service/PartitionReceiverHandler.cs | 1 - .../storage/ITestOperationResultStorage.cs | 1 + .../storage/TestOperationResultStorage.cs | 1 + .../TwinAllOperationsResultHandler.cs | 6 +- .../TwinEdgeOperationsResultHandler.cs | 7 +- test/modules/load-gen/Program.cs | 5 +- 29 files changed, 67 insertions(+), 254 deletions(-) rename test/modules/{TestAnalyzer/swagger.yaml => ModuleLib/TestAnalyzer.swagger.yaml} (68%) rename test/modules/{TestResultCoordinator => ModuleLib}/TestOperationResult.cs (93%) rename test/modules/ModuleLib/{TestResultCoordinatorClient.cs => TestResultReportingClient.cs} (96%) rename test/modules/ModuleLib/{TestResultCoordinatorClient.swagger.yaml => TestResultReportingClient.swagger.yaml} (73%) delete mode 100644 test/modules/TestAnalyzer/TestOperationResult.cs diff --git a/Microsoft.Azure.Devices.Edge.sln b/Microsoft.Azure.Devices.Edge.sln index 57edac917e..f5688d4087 100644 --- a/Microsoft.Azure.Devices.Edge.sln +++ b/Microsoft.Azure.Devices.Edge.sln @@ -209,6 +209,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TemperatureFilter", "test\m EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAnalyzer", "test\modules\TestAnalyzer\TestAnalyzer.csproj", "{6208102C-151C-45CE-B573-B9C15B551B4D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TwinTester", "test\modules\TwinTester\TwinTester.csproj", "{1447EC5D-DD23-4C51-8941-336A495A48EE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CheckInBuild|Any CPU = CheckInBuild|Any CPU @@ -681,6 +683,14 @@ Global {6208102C-151C-45CE-B573-B9C15B551B4D}.Debug|Any CPU.Build.0 = Debug|Any CPU {6208102C-151C-45CE-B573-B9C15B551B4D}.Release|Any CPU.ActiveCfg = Release|Any CPU {6208102C-151C-45CE-B573-B9C15B551B4D}.Release|Any CPU.Build.0 = Release|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.CodeCoverage|Any CPU.ActiveCfg = CheckInBuild|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.CodeCoverage|Any CPU.Build.0 = CheckInBuild|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1447EC5D-DD23-4C51-8941-336A495A48EE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -763,6 +773,7 @@ Global {5918F481-0BE6-4D3F-95EB-34D30C9412DC} = {F921339B-32F9-4BF3-B364-2DB01FA2F1A1} {E6510C48-92B8-4995-A5C5-CBCB98029863} = {F921339B-32F9-4BF3-B364-2DB01FA2F1A1} {6208102C-151C-45CE-B573-B9C15B551B4D} = {F921339B-32F9-4BF3-B364-2DB01FA2F1A1} + {1447EC5D-DD23-4C51-8941-336A495A48EE} = {F921339B-32F9-4BF3-B364-2DB01FA2F1A1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D71830F5-3AF5-46B4-8A9E-1DCE4F2253AC} diff --git a/test/connectivity/modules/NetworkController/NetworkStatusReporter.cs b/test/connectivity/modules/NetworkController/NetworkStatusReporter.cs index acc89e9689..2477abe5c1 100644 --- a/test/connectivity/modules/NetworkController/NetworkStatusReporter.cs +++ b/test/connectivity/modules/NetworkController/NetworkStatusReporter.cs @@ -5,20 +5,19 @@ namespace NetworkController using System.Threading.Tasks; using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.ModuleUtil.NetworkControllerResult; - using Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; class NetworkStatusReporter : INetworkStatusReporter { static readonly ILogger Log = Logger.Factory.CreateLogger(); - readonly TestResultCoordinatorClient trcClient; + readonly TestResultReportingClient testResultReportingClient; readonly string moduleId; readonly string trackingId; public NetworkStatusReporter(Uri testResultCoordinatorEndpoint, string moduleId, string trackingId) { - this.trcClient = new TestResultCoordinatorClient() { BaseUrl = testResultCoordinatorEndpoint.AbsoluteUri }; + this.testResultReportingClient = new TestResultReportingClient() { BaseUrl = testResultCoordinatorEndpoint.AbsoluteUri }; this.moduleId = moduleId; this.trackingId = trackingId; } @@ -26,7 +25,7 @@ namespace NetworkController public Task ReportNetworkStatus(NetworkControllerOperation operation, NetworkControllerStatus networkControllerStatus, NetworkControllerType networkControllerType, bool success = true) { var networkController = new NetworkControllerResult() { Operation = operation.ToString(), OperationStatus = success ? "Success" : "Failed", NetworkControllerType = networkControllerType, NetworkControllerStatus = networkControllerStatus, TrackingId = this.trackingId }; - return ModuleUtil.ReportStatus(this.trcClient, Log, this.moduleId, networkController.ToString(), TestOperationResultType.Network.ToString()); + return ModuleUtil.ReportStatus(this.testResultReportingClient, Log, this.moduleId, networkController.ToString(), TestOperationResultType.Network.ToString()); } } } diff --git a/test/modules/DirectMethodSender/Program.cs b/test/modules/DirectMethodSender/Program.cs index 569e30e2af..d98587a3e6 100644 --- a/test/modules/DirectMethodSender/Program.cs +++ b/test/modules/DirectMethodSender/Program.cs @@ -8,7 +8,6 @@ namespace DirectMethodSender using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; using Microsoft.Azure.Devices.Edge.ModuleUtil; - using Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; using TestOperationResult = Microsoft.Azure.Devices.Edge.ModuleUtil.TestOperationResult; @@ -56,9 +55,9 @@ namespace DirectMethodSender await testReportCoordinatorUrl.ForEachAsync( async (Uri uri) => { - TestResultCoordinatorClient trcClient = new TestResultCoordinatorClient { BaseUrl = uri.AbsoluteUri }; + var testResultReportingClient = new TestResultReportingClient { BaseUrl = uri.AbsoluteUri }; await ModuleUtil.ReportStatus( - trcClient, + testResultReportingClient, Logger, Settings.Current.ModuleId + ".send", ModuleUtil.FormatDirectMethodTestResultValue( @@ -74,8 +73,8 @@ namespace DirectMethodSender await analyzerUrl.ForEachAsync( async (Uri uri) => { - AnalyzerClient analyzerClient = new AnalyzerClient { BaseUrl = uri.AbsoluteUri }; - await ReportStatus(Settings.Current.TargetModuleId, result, analyzerClient); + var testResultReportingClient = new TestResultReportingClient { BaseUrl = uri.AbsoluteUri }; + await ReportStatus(Settings.Current.TargetModuleId, result, testResultReportingClient); }, async () => { @@ -139,11 +138,11 @@ namespace DirectMethodSender return (Settings.Current.TestDuration == TimeSpan.Zero) || (DateTime.UtcNow - testStartAt < Settings.Current.TestDuration); } - static async Task ReportStatus(string moduleId, HttpStatusCode result, AnalyzerClient analyzerClient) + static async Task ReportStatus(string moduleId, HttpStatusCode result, TestResultReportingClient apiClient) { try { - await analyzerClient.ReportResultAsync(new TestOperationResult { Source = moduleId, Result = result.ToString(), CreatedAt = DateTime.UtcNow, Type = Enum.GetName(typeof(TestOperationResultType), TestOperationResultType.LegacyDirectMethod) }); + await apiClient.ReportResultAsync(new TestOperationResultDto { Source = moduleId, Result = result.ToString(), CreatedAt = DateTime.UtcNow, Type = Enum.GetName(typeof(TestOperationResultType), TestOperationResultType.LegacyDirectMethod) }); } catch (Exception e) { diff --git a/test/modules/ModuleLib/AnalyzerClient.cs b/test/modules/ModuleLib/AnalyzerClient.cs index 6708c02021..444b3596f4 100644 --- a/test/modules/ModuleLib/AnalyzerClient.cs +++ b/test/modules/ModuleLib/AnalyzerClient.cs @@ -43,78 +43,6 @@ namespace Microsoft.Azure.Devices.Edge.ModuleUtil partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); - /// Report test operation result - /// Test result details - /// Ok - /// A server side error occurred. - public System.Threading.Tasks.Task ReportResultAsync(TestOperationResult body) - { - return ReportResultAsync(body, System.Threading.CancellationToken.None); - } - - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Report test operation result - /// Test result details - /// Ok - /// A server side error occurred. - public async System.Threading.Tasks.Task ReportResultAsync(TestOperationResult body, System.Threading.CancellationToken cancellationToken) - { - var urlBuilder_ = new System.Text.StringBuilder(); - urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/testoperationresult"); - - var client_ = new System.Net.Http.HttpClient(); - try - { - using (var request_ = new System.Net.Http.HttpRequestMessage()) - { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); - request_.Content = content_; - request_.Method = new System.Net.Http.HttpMethod("POST"); - - PrepareRequest(client_, request_, urlBuilder_); - var url_ = urlBuilder_.ToString(); - request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); - PrepareRequest(client_, request_, url_); - - var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); - try - { - var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); - if (response_.Content != null && response_.Content.Headers != null) - { - foreach (var item_ in response_.Content.Headers) - headers_[item_.Key] = item_.Value; - } - - ProcessResponse(client_, response_); - - var status_ = ((int)response_.StatusCode).ToString(); - if (status_ == "204") - { - return; - } - else - if (status_ != "200" && status_ != "204") - { - var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null); - } - } - finally - { - if (response_ != null) - response_.Dispose(); - } - } - } - finally - { - if (client_ != null) - client_.Dispose(); - } - } - /// Get report /// successful operation /// A server side error occurred. @@ -365,64 +293,6 @@ namespace Microsoft.Azure.Devices.Edge.ModuleUtil } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.0.28.0 (Newtonsoft.Json v11.0.0.0)")] - public partial class TestOperationResult - { - [Newtonsoft.Json.JsonProperty("source", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string Source { get; set; } - - [Newtonsoft.Json.JsonProperty("result", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string Result { get; set; } - - [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string Type { get; set; } - - [Newtonsoft.Json.JsonProperty("createdAt", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public System.DateTimeOffset CreatedAt { get; set; } - - - } - - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.1.6.0 (NJsonSchema v10.0.28.0 (Newtonsoft.Json v11.0.0.0))")] - public partial class ApiException : System.Exception - { - public int StatusCode { get; private set; } - - public string Response { get; private set; } - - public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } - - public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) - : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + response.Substring(0, response.Length >= 512 ? 512 : response.Length), innerException) - { - StatusCode = statusCode; - Response = response; - Headers = headers; - } - - public override string ToString() - { - return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); - } - } - - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.1.6.0 (NJsonSchema v10.0.28.0 (Newtonsoft.Json v11.0.0.0))")] - public partial class ApiException : ApiException - { - public TResult Result { get; private set; } - - public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) - : base(message, statusCode, response, headers, innerException) - { - Result = result; - } - } - } #pragma warning restore 1591 diff --git a/test/modules/ModuleLib/ModuleUtil.cs b/test/modules/ModuleLib/ModuleUtil.cs index ce3c61f36f..c199a622f3 100644 --- a/test/modules/ModuleLib/ModuleUtil.cs +++ b/test/modules/ModuleLib/ModuleUtil.cs @@ -65,11 +65,11 @@ namespace Microsoft.Azure.Devices.Edge.ModuleUtil return $"{trackingId};{batchId};{sequenceNumber};{resultMessage}"; } - public static async Task ReportStatus(TestResultCoordinatorClient.TestResultCoordinatorClient trcClient, ILogger logger, string source, string result, string format) + public static async Task ReportStatus(TestResultReportingClient apiClient, ILogger logger, string source, string result, string format) { try { - await trcClient.ReportResultAsync(new TestResultCoordinatorClient.TestOperationResult { Source = source, Result = result, CreatedAt = DateTime.UtcNow, Type = format }); + await apiClient.ReportResultAsync(new TestOperationResultDto { Source = source, Result = result, CreatedAt = DateTime.UtcNow, Type = format }); } catch (Exception e) { diff --git a/test/modules/TestAnalyzer/swagger.yaml b/test/modules/ModuleLib/TestAnalyzer.swagger.yaml similarity index 68% rename from test/modules/TestAnalyzer/swagger.yaml rename to test/modules/ModuleLib/TestAnalyzer.swagger.yaml index 95f6adfe11..35c313f6a2 100644 --- a/test/modules/TestAnalyzer/swagger.yaml +++ b/test/modules/ModuleLib/TestAnalyzer.swagger.yaml @@ -1,32 +1,11 @@ swagger: "2.0" info: - description: "analyzer API" + description: "Get test result report API implemented by Test Analyzer" version: "1.0.0" - title: "Analyzer API swagger" + title: "Test Analyzer API swagger" schemes: - "https" paths: - /api/testoperationresult: - post: - tags: - - "twinStatus" - summary: "Report test operation result" - description: "" - operationId: "reportResult" - consumes: - - "application/json" - produces: - - "application/json" - parameters: - - in: "body" - name: "body" - description: "Test result details" - required: true - schema: - $ref: "#/definitions/TestOperationResult" - responses: - 204: - description: "Ok" /api/report: get: tags: @@ -106,21 +85,4 @@ definitions: lastReceivedAt: type: "string" format: date-time - TestOperationResult: - type: "object" - required: - - "source" - - "result" - - "type" - - "createdAt" - properties: - source: - type: "string" - result: - type: "string" - type: - type: "string" - createdAt: - type: "string" - format: date-time \ No newline at end of file diff --git a/test/modules/TestResultCoordinator/TestOperationResult.cs b/test/modules/ModuleLib/TestOperationResult.cs similarity index 93% rename from test/modules/TestResultCoordinator/TestOperationResult.cs rename to test/modules/ModuleLib/TestOperationResult.cs index 30ed7e5d73..0699f4e3a6 100644 --- a/test/modules/TestResultCoordinator/TestOperationResult.cs +++ b/test/modules/ModuleLib/TestOperationResult.cs @@ -1,5 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. -namespace TestResultCoordinator +namespace Microsoft.Azure.Devices.Edge.ModuleUtil { using System; using Microsoft.Azure.Devices.Edge.Util; diff --git a/test/modules/ModuleLib/TestResultCoordinatorClient.cs b/test/modules/ModuleLib/TestResultReportingClient.cs similarity index 96% rename from test/modules/ModuleLib/TestResultCoordinatorClient.cs rename to test/modules/ModuleLib/TestResultReportingClient.cs index 6d4af4204d..01e9c37666 100644 --- a/test/modules/ModuleLib/TestResultCoordinatorClient.cs +++ b/test/modules/ModuleLib/TestResultReportingClient.cs @@ -1,4 +1,4 @@ -//---------------------- +//---------------------- // // Generated using the NSwag toolchain v13.1.6.0 (NJsonSchema v10.0.28.0 (Newtonsoft.Json v11.0.0.0)) (http://NSwag.org) // @@ -10,17 +10,17 @@ #pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... #pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." -namespace Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient +namespace Microsoft.Azure.Devices.Edge.ModuleUtil { using System = global::System; [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.1.6.0 (NJsonSchema v10.0.28.0 (Newtonsoft.Json v11.0.0.0))")] - public partial class TestResultCoordinatorClient + public partial class TestResultReportingClient { private string _baseUrl = "https://"; private System.Lazy _settings; - public TestResultCoordinatorClient() + public TestResultReportingClient() { _settings = new System.Lazy(() => { @@ -44,20 +44,20 @@ namespace Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); /// Report test operation result - /// Test result details + /// Test operation result data transfer object (DTO) /// Ok /// A server side error occurred. - public System.Threading.Tasks.Task ReportResultAsync(TestOperationResult body) + public System.Threading.Tasks.Task ReportResultAsync(TestOperationResultDto body) { return ReportResultAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// Report test operation result - /// Test result details + /// Test operation result data transfer object (DTO) /// Ok /// A server side error occurred. - public async System.Threading.Tasks.Task ReportResultAsync(TestOperationResult body, System.Threading.CancellationToken cancellationToken) + public async System.Threading.Tasks.Task ReportResultAsync(TestOperationResultDto body, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/testoperationresult"); @@ -215,7 +215,7 @@ namespace Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.0.28.0 (Newtonsoft.Json v11.0.0.0)")] - public partial class TestOperationResult + public partial class TestOperationResultDto { [Newtonsoft.Json.JsonProperty("source", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] @@ -277,4 +277,4 @@ namespace Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient #pragma warning restore 1573 #pragma warning restore 472 #pragma warning restore 114 -#pragma warning restore 108 \ No newline at end of file +#pragma warning restore 108 diff --git a/test/modules/ModuleLib/TestResultCoordinatorClient.swagger.yaml b/test/modules/ModuleLib/TestResultReportingClient.swagger.yaml similarity index 73% rename from test/modules/ModuleLib/TestResultCoordinatorClient.swagger.yaml rename to test/modules/ModuleLib/TestResultReportingClient.swagger.yaml index cbe3a76c69..c378ab993a 100644 --- a/test/modules/ModuleLib/TestResultCoordinatorClient.swagger.yaml +++ b/test/modules/ModuleLib/TestResultReportingClient.swagger.yaml @@ -1,8 +1,8 @@ swagger: "2.0" info: - description: "analyzer API" + description: "Report test result API implemented by both TestAnalyzer and TestResultCoordinator." version: "1.0.0" - title: "Analyzer API swagger" + title: "Test Result Repoting API swagger" schemes: - "https" paths: @@ -20,17 +20,17 @@ paths: parameters: - in: "body" name: "body" - description: "Test result details" + description: "Test operation result data transfer object (DTO)" required: true schema: - $ref: "#/definitions/TestOperationResult" + $ref: "#/definitions/TestOperationResultDto" responses: 204: description: "Ok" 400: description: "Invalid status value" definitions: - TestOperationResult: + TestOperationResultDto: type: "object" required: - "source" diff --git a/test/modules/Modules.Test/TestResultCoordinator/CountingReportGeneratorTest.cs b/test/modules/Modules.Test/TestResultCoordinator/CountingReportGeneratorTest.cs index be2987ea64..cb0fa9986f 100644 --- a/test/modules/Modules.Test/TestResultCoordinator/CountingReportGeneratorTest.cs +++ b/test/modules/Modules.Test/TestResultCoordinator/CountingReportGeneratorTest.cs @@ -7,6 +7,7 @@ namespace Modules.Test.TestResultCoordinator using System.Threading.Tasks; using global::TestResultCoordinator; using global::TestResultCoordinator.Report; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Storage; using Moq; using Xunit; diff --git a/test/modules/Modules.Test/TestResultCoordinator/CountingReportTest.cs b/test/modules/Modules.Test/TestResultCoordinator/CountingReportTest.cs index ac164174ef..906956d491 100644 --- a/test/modules/Modules.Test/TestResultCoordinator/CountingReportTest.cs +++ b/test/modules/Modules.Test/TestResultCoordinator/CountingReportTest.cs @@ -3,8 +3,8 @@ namespace Modules.Test.TestResultCoordinator { using System; using System.Collections.Generic; - using global::TestResultCoordinator; using global::TestResultCoordinator.Report; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Xunit; public class CountingReportTest diff --git a/test/modules/Modules.Test/TestResultCoordinator/SimpleTestOperationResultComparerTest.cs b/test/modules/Modules.Test/TestResultCoordinator/SimpleTestOperationResultComparerTest.cs index e5c11b2153..9cea18d653 100644 --- a/test/modules/Modules.Test/TestResultCoordinator/SimpleTestOperationResultComparerTest.cs +++ b/test/modules/Modules.Test/TestResultCoordinator/SimpleTestOperationResultComparerTest.cs @@ -3,8 +3,8 @@ namespace Modules.Test.TestResultCoordinator { using System; using System.Collections.Generic; - using global::TestResultCoordinator; using global::TestResultCoordinator.Report; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Xunit; public class SimpleTestOperationResultComparerTest diff --git a/test/modules/Modules.Test/TestResultCoordinator/StoreTestResultCollectionTest.cs b/test/modules/Modules.Test/TestResultCoordinator/StoreTestResultCollectionTest.cs index 81747541c9..cb2d6da871 100644 --- a/test/modules/Modules.Test/TestResultCoordinator/StoreTestResultCollectionTest.cs +++ b/test/modules/Modules.Test/TestResultCoordinator/StoreTestResultCollectionTest.cs @@ -6,6 +6,7 @@ namespace Modules.Test.TestResultCoordinator using System.Linq; using System.Threading.Tasks; using global::TestResultCoordinator; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Storage; using Moq; using Xunit; diff --git a/test/modules/Modules.Test/TestResultCoordinator/TwinCountingReportGeneratorTest.cs b/test/modules/Modules.Test/TestResultCoordinator/TwinCountingReportGeneratorTest.cs index 90aad386bd..742d4e9549 100644 --- a/test/modules/Modules.Test/TestResultCoordinator/TwinCountingReportGeneratorTest.cs +++ b/test/modules/Modules.Test/TestResultCoordinator/TwinCountingReportGeneratorTest.cs @@ -7,6 +7,7 @@ namespace Modules.Test.TestResultCoordinator using System.Threading.Tasks; using global::TestResultCoordinator; using global::TestResultCoordinator.Report; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Storage; using Moq; using Xunit; @@ -269,7 +270,7 @@ namespace Modules.Test.TestResultCoordinator tc[item] = "1"; } - var twinTestResult = new Microsoft.Azure.Devices.Edge.ModuleUtil.TwinTestResult() { Properties = tc }; + var twinTestResult = new TwinTestResult() { Properties = tc }; storeData.Add((count, new TestOperationResult(source, resultType, twinTestResult.ToString(), DateTime.UtcNow))); count++; } diff --git a/test/modules/Relayer/Program.cs b/test/modules/Relayer/Program.cs index 4d4bcdbef5..8bf1b83c48 100644 --- a/test/modules/Relayer/Program.cs +++ b/test/modules/Relayer/Program.cs @@ -7,7 +7,6 @@ namespace Relayer using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; using Microsoft.Azure.Devices.Edge.ModuleUtil; - using Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; @@ -93,9 +92,9 @@ namespace Relayer } // Report receiving message successfully to Test Result Coordinator - TestResultCoordinatorClient trcClient = new TestResultCoordinatorClient { BaseUrl = testResultCoordinatorUrl.AbsoluteUri }; + var testResultReportingClient = new TestResultReportingClient { BaseUrl = testResultCoordinatorUrl.AbsoluteUri }; await ModuleUtil.ReportStatus( - trcClient, + testResultReportingClient, Logger, Settings.Current.ModuleId + ".receive", ModuleUtil.FormatMessagesTestResultValue(trackingId, batchId, sequenceNumber), @@ -109,7 +108,7 @@ namespace Relayer // Report sending message successfully to Test Result Coordinator await ModuleUtil.ReportStatus( - trcClient, + testResultReportingClient, Logger, Settings.Current.ModuleId + ".send", ModuleUtil.FormatMessagesTestResultValue(trackingId, batchId, sequenceNumber), diff --git a/test/modules/TestAnalyzer/Controllers/TestOperationResultController.cs b/test/modules/TestAnalyzer/Controllers/TestOperationResultController.cs index fd5b831981..82577d4145 100644 --- a/test/modules/TestAnalyzer/Controllers/TestOperationResultController.cs +++ b/test/modules/TestAnalyzer/Controllers/TestOperationResultController.cs @@ -4,6 +4,7 @@ namespace TestAnalyzer.Controllers using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; + using Microsoft.Azure.Devices.Edge.ModuleUtil; [Route("api/[controller]")] [ApiController] diff --git a/test/modules/TestAnalyzer/TestOperationResult.cs b/test/modules/TestAnalyzer/TestOperationResult.cs deleted file mode 100644 index b575982ebc..0000000000 --- a/test/modules/TestAnalyzer/TestOperationResult.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -namespace TestAnalyzer -{ - using System; - using Microsoft.Azure.Devices.Edge.Util; - - public class TestOperationResult - { - public TestOperationResult( - string source, - string type, - string result, - DateTime createdAt) - { - this.Source = Preconditions.CheckNonWhiteSpace(source, nameof(source)); - this.Type = Preconditions.CheckNonWhiteSpace(type, nameof(type)); - this.Result = Preconditions.CheckNonWhiteSpace(result, nameof(result)); - this.CreatedAt = createdAt; - } - - public string Source { get; } - - public string Type { get; } - - public string Result { get; } - - public DateTime CreatedAt { get; } - } -} diff --git a/test/modules/TestResultCoordinator/Controllers/TestOperationResultController.cs b/test/modules/TestResultCoordinator/Controllers/TestOperationResultController.cs index 5a66b78f2f..d596acccd1 100644 --- a/test/modules/TestResultCoordinator/Controllers/TestOperationResultController.cs +++ b/test/modules/TestResultCoordinator/Controllers/TestOperationResultController.cs @@ -9,7 +9,6 @@ namespace TestResultCoordinator.Controllers using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; using TestResultCoordinator.Storage; - using TestOperationResult = TestResultCoordinator.TestOperationResult; [Route("api/[controller]")] [ApiController] diff --git a/test/modules/TestResultCoordinator/report/CloudTwinTestResultCollection.cs b/test/modules/TestResultCoordinator/report/CloudTwinTestResultCollection.cs index 137f8a2fe9..2d67e4c4e6 100644 --- a/test/modules/TestResultCoordinator/report/CloudTwinTestResultCollection.cs +++ b/test/modules/TestResultCoordinator/report/CloudTwinTestResultCollection.cs @@ -8,13 +8,13 @@ namespace TestResultCoordinator.Report using Microsoft.Azure.Devices.Shared; using Microsoft.Extensions.Logging; - class CloudTwinTestResultCollection : ITestResultCollection + class CloudTwinTestResultCollection : ITestResultCollection { static readonly ILogger Logger = ModuleUtil.CreateLogger(nameof(CloudTwinTestResultCollection)); readonly RegistryManager registryManager; readonly string moduleId; readonly string trackingId; - TestResultCoordinator.TestOperationResult current; + TestOperationResult current; bool isLoaded; public CloudTwinTestResultCollection(string source, string serviceClientConnectionString, string moduleId, string trackingId) @@ -28,7 +28,7 @@ namespace TestResultCoordinator.Report public string Source { get; } - TestResultCoordinator.TestOperationResult ITestResultCollection.Current => this.current; + TestOperationResult ITestResultCollection.Current => this.current; public void Dispose() { @@ -56,7 +56,7 @@ namespace TestResultCoordinator.Report this.current = null; } - async Task GetTwinAsync() + async Task GetTwinAsync() { try { @@ -68,7 +68,7 @@ namespace TestResultCoordinator.Report } var twinTestResult = new TwinTestResult() { TrackingId = this.trackingId, Properties = twin.Properties.Reported }; - return new TestResultCoordinator.TestOperationResult( + return new TestOperationResult( this.Source, TestOperationResultType.Twin.ToString(), twinTestResult.ToString(), diff --git a/test/modules/TestResultCoordinator/report/CountingReportGenerator.cs b/test/modules/TestResultCoordinator/report/CountingReportGenerator.cs index 555cefba13..88d4e5edb4 100644 --- a/test/modules/TestResultCoordinator/report/CountingReportGenerator.cs +++ b/test/modules/TestResultCoordinator/report/CountingReportGenerator.cs @@ -8,7 +8,6 @@ namespace TestResultCoordinator.Report using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; - using TestOperationResult = TestResultCoordinator.TestOperationResult; /// /// This is used to create counting report based on 2 different sources/stores; it will use given test result comparer to determine whether it matches or not. diff --git a/test/modules/TestResultCoordinator/report/SimpleTestOperationResultComparer.cs b/test/modules/TestResultCoordinator/report/SimpleTestOperationResultComparer.cs index c60a0d8b97..60bbb36296 100644 --- a/test/modules/TestResultCoordinator/report/SimpleTestOperationResultComparer.cs +++ b/test/modules/TestResultCoordinator/report/SimpleTestOperationResultComparer.cs @@ -2,6 +2,7 @@ namespace TestResultCoordinator.Report { using System; + using Microsoft.Azure.Devices.Edge.ModuleUtil; /// /// This test result comparer is used to determine if 2 TestOperationResult instances matches. diff --git a/test/modules/TestResultCoordinator/report/TestReportGeneratorFactory.cs b/test/modules/TestResultCoordinator/report/TestReportGeneratorFactory.cs index 1cda4c88f0..3580e3fa5c 100644 --- a/test/modules/TestResultCoordinator/report/TestReportGeneratorFactory.cs +++ b/test/modules/TestResultCoordinator/report/TestReportGeneratorFactory.cs @@ -2,6 +2,7 @@ namespace TestResultCoordinator.Report { using System; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using TestResultCoordinator.Storage; diff --git a/test/modules/TestResultCoordinator/report/TwinCountingReportGenerator.cs b/test/modules/TestResultCoordinator/report/TwinCountingReportGenerator.cs index 2fc795c82c..89ac519838 100644 --- a/test/modules/TestResultCoordinator/report/TwinCountingReportGenerator.cs +++ b/test/modules/TestResultCoordinator/report/TwinCountingReportGenerator.cs @@ -8,7 +8,6 @@ namespace TestResultCoordinator.Report using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; using Newtonsoft.Json; - using TestOperationResult = TestResultCoordinator.TestOperationResult; class TwinCountingReportGenerator : ITestResultReportGenerator { diff --git a/test/modules/TestResultCoordinator/service/PartitionReceiverHandler.cs b/test/modules/TestResultCoordinator/service/PartitionReceiverHandler.cs index 85f8148fb9..c792ff17df 100644 --- a/test/modules/TestResultCoordinator/service/PartitionReceiverHandler.cs +++ b/test/modules/TestResultCoordinator/service/PartitionReceiverHandler.cs @@ -9,7 +9,6 @@ namespace TestResultCoordinator.Service using Microsoft.Azure.EventHubs; using Microsoft.Extensions.Logging; using TestResultCoordinator.Storage; - using TestOperationResult = TestResultCoordinator.TestOperationResult; class PartitionReceiveHandler : IPartitionReceiveHandler { diff --git a/test/modules/TestResultCoordinator/storage/ITestOperationResultStorage.cs b/test/modules/TestResultCoordinator/storage/ITestOperationResultStorage.cs index 865cff1653..9e170d239e 100644 --- a/test/modules/TestResultCoordinator/storage/ITestOperationResultStorage.cs +++ b/test/modules/TestResultCoordinator/storage/ITestOperationResultStorage.cs @@ -2,6 +2,7 @@ namespace TestResultCoordinator.Storage { using System.Threading.Tasks; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Storage; public interface ITestOperationResultStorage diff --git a/test/modules/TestResultCoordinator/storage/TestOperationResultStorage.cs b/test/modules/TestResultCoordinator/storage/TestOperationResultStorage.cs index 00d937999d..8380b76438 100644 --- a/test/modules/TestResultCoordinator/storage/TestOperationResultStorage.cs +++ b/test/modules/TestResultCoordinator/storage/TestOperationResultStorage.cs @@ -5,6 +5,7 @@ namespace TestResultCoordinator.Storage using System.Collections.Generic; using System.IO; using System.Threading.Tasks; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Storage; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; diff --git a/test/modules/TwinTester/TwinAllOperationsResultHandler.cs b/test/modules/TwinTester/TwinAllOperationsResultHandler.cs index f3ee5e963a..bcb33e7d0a 100644 --- a/test/modules/TwinTester/TwinAllOperationsResultHandler.cs +++ b/test/modules/TwinTester/TwinAllOperationsResultHandler.cs @@ -11,13 +11,13 @@ namespace TwinTester class TwinAllOperationsResultHandler : ITwinTestResultHandler { static readonly ILogger Logger = ModuleUtil.CreateLogger(nameof(TwinAllOperationsResultHandler)); - readonly AnalyzerClient analyzerClient; + readonly TestResultReportingClient testResultReportingClient; readonly string moduleId; readonly TwinEventStorage storage; public TwinAllOperationsResultHandler(Uri analyzerClientUri, TwinEventStorage storage, string moduleId) { - this.analyzerClient = new AnalyzerClient() { BaseUrl = analyzerClientUri.AbsoluteUri }; + this.testResultReportingClient = new TestResultReportingClient { BaseUrl = analyzerClientUri.AbsoluteUri }; this.moduleId = moduleId; this.storage = storage; } @@ -76,7 +76,7 @@ namespace TwinTester { try { - await this.analyzerClient.ReportResultAsync(new TestOperationResult { Source = this.moduleId, Result = failureStatus, CreatedAt = DateTime.UtcNow, Type = "LegacyTwin" }); + await this.testResultReportingClient.ReportResultAsync(new TestOperationResultDto { Source = this.moduleId, Result = failureStatus, CreatedAt = DateTime.UtcNow, Type = "LegacyTwin" }); } catch (Exception e) { diff --git a/test/modules/TwinTester/TwinEdgeOperationsResultHandler.cs b/test/modules/TwinTester/TwinEdgeOperationsResultHandler.cs index 48778f15b6..eaf1e6d1c0 100644 --- a/test/modules/TwinTester/TwinEdgeOperationsResultHandler.cs +++ b/test/modules/TwinTester/TwinEdgeOperationsResultHandler.cs @@ -4,7 +4,6 @@ namespace TwinTester using System; using System.Threading.Tasks; using Microsoft.Azure.Devices.Edge.ModuleUtil; - using Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Shared; using Microsoft.Extensions.Logging; @@ -12,13 +11,13 @@ namespace TwinTester class TwinEdgeOperationsResultHandler : ITwinTestResultHandler { static readonly ILogger Logger = ModuleUtil.CreateLogger(nameof(TwinEdgeOperationsResultHandler)); - readonly TestResultCoordinatorClient trcClient; + readonly TestResultReportingClient testResultReportingClient; readonly string moduleId; readonly string trackingId; public TwinEdgeOperationsResultHandler(Uri reporterUri, string moduleId, Option trackingId) { - this.trcClient = new TestResultCoordinatorClient() { BaseUrl = reporterUri.AbsoluteUri }; + this.testResultReportingClient = new TestResultReportingClient { BaseUrl = reporterUri.AbsoluteUri }; this.moduleId = moduleId; this.trackingId = trackingId.Expect(() => new ArgumentNullException(nameof(trackingId))); } @@ -62,7 +61,7 @@ namespace TwinTester { var result = new TwinTestResult() { Operation = statusCode.ToString(), Properties = details, ErrorMessage = exception, TrackingId = this.trackingId }; Logger.LogDebug($"Sending report {result.ToString()}"); - await ModuleUtil.ReportStatus(this.trcClient, Logger, source, result.ToString(), TestOperationResultType.Twin.ToString()); + await ModuleUtil.ReportStatus(this.testResultReportingClient, Logger, source, result.ToString(), TestOperationResultType.Twin.ToString()); } } } diff --git a/test/modules/load-gen/Program.cs b/test/modules/load-gen/Program.cs index ef242c1f2a..06545b60c4 100644 --- a/test/modules/load-gen/Program.cs +++ b/test/modules/load-gen/Program.cs @@ -7,7 +7,6 @@ namespace LoadGen using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; using Microsoft.Azure.Devices.Edge.ModuleUtil; - using Microsoft.Azure.Devices.Edge.ModuleUtil.TestResultCoordinatorClient; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -54,10 +53,10 @@ namespace LoadGen Uri testResultCoordinatorUrl = new Uri( trcUrl, UriKind.Absolute); - TestResultCoordinatorClient trcClient = new TestResultCoordinatorClient { BaseUrl = testResultCoordinatorUrl.AbsoluteUri }; + var testResultReportingClient = new TestResultReportingClient { BaseUrl = testResultCoordinatorUrl.AbsoluteUri }; await ModuleUtil.ReportStatus( - trcClient, + testResultReportingClient, Logger, Settings.Current.ModuleId + ".send", ModuleUtil.FormatMessagesTestResultValue(