From 5fbf6414a43b3da65d99e5a2cb156d45a68734f2 Mon Sep 17 00:00:00 2001 From: Scott Fauerbach Date: Fri, 19 May 2023 07:45:16 -0400 Subject: [PATCH] Remove schema from Service API (#774) --- src/NATS.Client/Service/Discovery.cs | 18 --- src/NATS.Client/Service/Endpoint.cs | 53 +------- src/NATS.Client/Service/EndpointResponse.cs | 9 +- src/NATS.Client/Service/Schema.cs | 86 ------------ src/NATS.Client/Service/SchemaResponse.cs | 83 ------------ src/NATS.Client/Service/Service.cs | 15 +-- src/NATS.Client/Service/ServiceEndpoint.cs | 10 -- .../Miscellany/ServiceCrossClientValidator.cs | 2 - src/Samples/ServiceExample/ServiceExample.cs | 22 --- .../IntegrationTestsInternal/TestService.cs | 36 ----- src/Tests/UnitTests/TestServiceObjects.cs | 126 +----------------- 11 files changed, 11 insertions(+), 449 deletions(-) delete mode 100644 src/NATS.Client/Service/Schema.cs delete mode 100644 src/NATS.Client/Service/SchemaResponse.cs diff --git a/src/NATS.Client/Service/Discovery.cs b/src/NATS.Client/Service/Discovery.cs index 26fad6151..b16326a65 100644 --- a/src/NATS.Client/Service/Discovery.cs +++ b/src/NATS.Client/Service/Discovery.cs @@ -70,24 +70,6 @@ public InfoResponse InfoForNameAndId(string serviceName, string serviceId) { return json == null ? null : new InfoResponse(json); } - // ---------------------------------------------------------------------------------------------------- - // schema - // ---------------------------------------------------------------------------------------------------- - public IList Schema(string serviceName = null) - { - IList list = new List(); - DiscoverMany(Service.SrvSchema, serviceName, json => { - list.Add(new SchemaResponse(json)); - }); - return list; - } - - public SchemaResponse SchemaForNameAndId(string serviceName, string serviceId) - { - string json = DiscoverOne(Service.SrvSchema, serviceName, serviceId); - return json == null ? null : new SchemaResponse(json); - } - // ---------------------------------------------------------------------------------------------------- // stats // ---------------------------------------------------------------------------------------------------- diff --git a/src/NATS.Client/Service/Endpoint.cs b/src/NATS.Client/Service/Endpoint.cs index 69a2be8e1..529732e02 100644 --- a/src/NATS.Client/Service/Endpoint.cs +++ b/src/NATS.Client/Service/Endpoint.cs @@ -12,20 +12,14 @@ public class Endpoint : JsonSerializable { public string Name { get; } public string Subject { get; } - public Schema Schema { get; } public Dictionary Metadata { get; } - public Endpoint(string name, string subject, Schema schema) : this(name, subject, schema, null, true) {} + public Endpoint(string name) : this(name, null, null, true) {} - public Endpoint(string name) : this(name, null, null, null, true) {} - - public Endpoint(string name, string subject) : this(name, subject, null, null, true) {} - - public Endpoint(string name, string subject, string schemaRequest, string schemaResponse) - : this(name, subject, Schema.OptionalInstance(schemaRequest, schemaResponse), null, true) {} + public Endpoint(string name, string subject) : this(name, subject, null, true) {} // internal use constructors - internal Endpoint(string name, string subject, Schema schema, Dictionary metadata, bool validate) { + internal Endpoint(string name, string subject, Dictionary metadata, bool validate) { if (validate) { Name = Validator.ValidateIsRestrictedTerm(name, "Endpoint Name", true); if (subject == null) { @@ -39,7 +33,6 @@ internal Endpoint(string name, string subject, Schema schema, Dictionary Metadata; public EndpointBuilder WithEndpoint(Endpoint endpoint) { Name = endpoint.Name; Subject = endpoint.Subject; - if (endpoint.Schema == null) { - SchemaRequest = null; - SchemaResponse = null; - } - else { - SchemaRequest = endpoint.Schema.Request; - SchemaResponse = endpoint.Schema.Response; - } return this; } @@ -98,28 +79,6 @@ public EndpointBuilder WithSubject(string subject) { return this; } - public EndpointBuilder WithSchemaRequest(string schemaRequest) { - SchemaRequest = schemaRequest; - return this; - } - - public EndpointBuilder WithSchemaResponse(string schemaResponse) { - SchemaResponse = schemaResponse; - return this; - } - - public EndpointBuilder WithSchema(Schema schema) { - if (schema == null) { - SchemaRequest = null; - SchemaResponse = null; - } - else { - SchemaRequest = schema.Request; - SchemaResponse = schema.Response; - } - return this; - } - public EndpointBuilder WithMetadata(Dictionary metadata) { Metadata = metadata; @@ -138,7 +97,7 @@ public override string ToString() protected bool Equals(Endpoint other) { - return Name == other.Name && Subject == other.Subject && Equals(Schema, other.Schema); + return Name == other.Name && Subject == other.Subject && Validator.DictionariesEqual(Metadata, other.Metadata); } public override bool Equals(object obj) @@ -155,7 +114,7 @@ public override int GetHashCode() { var hashCode = (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Schema != null ? Schema.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (Metadata != null ? Metadata.GetHashCode() : 0); return hashCode; } } diff --git a/src/NATS.Client/Service/EndpointResponse.cs b/src/NATS.Client/Service/EndpointResponse.cs index 4f3526453..818fc7ca8 100644 --- a/src/NATS.Client/Service/EndpointResponse.cs +++ b/src/NATS.Client/Service/EndpointResponse.cs @@ -26,7 +26,6 @@ public class EndpointResponse : JsonSerializable { public string Name { get; } public string Subject { get; } - public Schema Schema { get; } public long NumRequests { get; } public long NumErrors { get; } public long ProcessingTime { get; } @@ -38,7 +37,6 @@ public class EndpointResponse : JsonSerializable internal EndpointResponse(string name, string subject, long numRequests, long numErrors, long processingTime, string lastError, JSONNode data, DateTime started) { Name = name; Subject = subject; - Schema = null; NumRequests = numRequests; NumErrors = numErrors; ProcessingTime = processingTime; @@ -48,10 +46,9 @@ internal EndpointResponse(string name, string subject, long numRequests, long nu Started = started; } - internal EndpointResponse(string name, string subject, Schema schema) { + internal EndpointResponse(string name, string subject) { Name = name; Subject = subject; - Schema = schema; NumRequests = 0; NumErrors = 0; ProcessingTime = 0; @@ -65,7 +62,6 @@ internal EndpointResponse(JSONNode node) { Name = node[ApiConstants.Name]; Subject = node[ApiConstants.Subject]; - Schema = Schema.OptionalInstance(node[ApiConstants.Schema]); NumRequests = JsonUtils.AsLongOrZero(node, ApiConstants.NumRequests); NumErrors = JsonUtils.AsLongOrZero(node, ApiConstants.NumErrors); ProcessingTime = JsonUtils.AsLongOrZero(node, ApiConstants.ProcessingTime); @@ -93,7 +89,6 @@ public override JSONNode ToJsonNode() JSONObject jso = new JSONObject(); JsonUtils.AddField(jso, ApiConstants.Name, Name); JsonUtils.AddField(jso, ApiConstants.Subject, Subject); - JsonUtils.AddField(jso, ApiConstants.Schema, Schema); JsonUtils.AddFieldWhenGtZero(jso, ApiConstants.NumRequests, NumRequests); JsonUtils.AddFieldWhenGtZero(jso, ApiConstants.NumErrors, NumErrors); JsonUtils.AddFieldWhenGtZero(jso, ApiConstants.ProcessingTime, ProcessingTime); @@ -113,7 +108,6 @@ protected bool Equals(EndpointResponse other) { return Name == other.Name && Subject == other.Subject - && Equals(Schema, other.Schema) && NumRequests == other.NumRequests && NumErrors == other.NumErrors && ProcessingTime == other.ProcessingTime @@ -137,7 +131,6 @@ public override int GetHashCode() { var hashCode = (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Schema != null ? Schema.GetHashCode() : 0); hashCode = (hashCode * 397) ^ NumRequests.GetHashCode(); hashCode = (hashCode * 397) ^ NumErrors.GetHashCode(); hashCode = (hashCode * 397) ^ ProcessingTime.GetHashCode(); diff --git a/src/NATS.Client/Service/Schema.cs b/src/NATS.Client/Service/Schema.cs deleted file mode 100644 index 77b73f549..000000000 --- a/src/NATS.Client/Service/Schema.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2023 The NATS Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using NATS.Client.Internals; -using NATS.Client.Internals.SimpleJSON; -using NATS.Client.JetStream; - -namespace NATS.Client.Service -{ - /// - /// SERVICE IS AN EXPERIMENTAL API SUBJECT TO CHANGE - /// - public class Schema : JsonSerializable - { - public string Request { get; } - public string Response { get; } - - internal static Schema OptionalInstance(JSONNode schemaNode) - { - return schemaNode == null ? null : new Schema(schemaNode); - } - - internal static Schema OptionalInstance(string request, string response) { - request = Validator.EmptyAsNull(request); - response = Validator.EmptyAsNull(response); - return request == null && response == null ? null : new Schema(request, response); - } - - public Schema(string request, string response) - { - Request = request; - Response = response; - } - - internal Schema(JSONNode schemaNode) - { - Request = schemaNode[ApiConstants.Request]; - Response = schemaNode[ApiConstants.Response]; - } - - public override JSONNode ToJsonNode() - { - JSONObject jso = new JSONObject(); - JsonUtils.AddField(jso, ApiConstants.Request, Request); - JsonUtils.AddField(jso, ApiConstants.Response, Response); - return jso; - } - - public override string ToString() - { - return JsonUtils.ToKey(GetType()) + ToJsonString(); - } - - protected bool Equals(Schema other) - { - return Request == other.Request && Response == other.Response; - - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((Schema)obj); - } - - public override int GetHashCode() - { - unchecked - { - return ((Request != null ? Request.GetHashCode() : 0) * 397) ^ (Response != null ? Response.GetHashCode() : 0); - } - } - } -} diff --git a/src/NATS.Client/Service/SchemaResponse.cs b/src/NATS.Client/Service/SchemaResponse.cs deleted file mode 100644 index f82707dbd..000000000 --- a/src/NATS.Client/Service/SchemaResponse.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2023 The NATS Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Collections.Generic; -using NATS.Client.Internals; -using NATS.Client.Internals.SimpleJSON; -using NATS.Client.JetStream; - -namespace NATS.Client.Service -{ - /// - /// SERVICE IS AN EXPERIMENTAL API SUBJECT TO CHANGE - /// - public class SchemaResponse : ServiceResponse - { - public const string ResponseType = "io.nats.micro.v1.schema_response"; - - public string ApiUrl { get; } - public IList Endpoints { get; } - - public SchemaResponse(string id, string name, string version, Dictionary metadata, string apiUrl, IList endpoints) - : base(ResponseType, id, name, version, metadata) - { - ApiUrl = apiUrl; - Endpoints = endpoints; - } - - internal SchemaResponse(string json) : this(JSON.Parse(json)) {} - - internal SchemaResponse(JSONNode node) : base(ResponseType, node) - { - ApiUrl = node[ApiConstants.ApiUrl]; - Endpoints = EndpointResponse.ListOf(node[ApiConstants.Endpoints]); - } - - public override JSONNode ToJsonNode() - { - JSONObject jso = BaseJsonObject(); - JsonUtils.AddField(jso, ApiConstants.ApiUrl, ApiUrl); - JSONArray arr = new JSONArray(); - foreach (var endpoint in Endpoints) - { - arr.Add(null, endpoint.ToJsonNode()); - } - jso[ApiConstants.Endpoints] = arr; - return jso; - } - - protected bool Equals(SchemaResponse other) - { - return base.Equals(other) && ApiUrl == other.ApiUrl && Equals(Endpoints, other.Endpoints); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((SchemaResponse)obj); - } - - public override int GetHashCode() - { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (ApiUrl != null ? ApiUrl.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Endpoints != null ? Endpoints.GetHashCode() : 0); - return hashCode; - } - } - } -} diff --git a/src/NATS.Client/Service/Service.cs b/src/NATS.Client/Service/Service.cs index d8bb075d9..2278d5356 100644 --- a/src/NATS.Client/Service/Service.cs +++ b/src/NATS.Client/Service/Service.cs @@ -38,7 +38,6 @@ public class Service public PingResponse PingResponse { get; } public InfoResponse InfoResponse { get; } - public SchemaResponse SchemaResponse { get; } private readonly Object stopLock; private TaskCompletionSource doneTcs; @@ -54,24 +53,20 @@ internal Service(ServiceBuilder b) // set up the service contexts // ! also while we are here, we need to collect the endpoints for the SchemaResponse IList infoSubjects = new List(); - IList schemaEndpoints = new List(); serviceContexts = new Dictionary(); foreach (ServiceEndpoint se in b.ServiceEndpoints.Values) { serviceContexts[se.Name] = new EndpointContext(conn, true, se); infoSubjects.Add(se.Subject); - schemaEndpoints.Add(new EndpointResponse(se.Name, se.Subject, se.Endpoint.Schema)); } // build static responses PingResponse = new PingResponse(id, b.Name, b.Version, b.Metadata); InfoResponse = new InfoResponse(id, b.Name, b.Version, b.Metadata, b.Description, infoSubjects); - SchemaResponse = new SchemaResponse(id, b.Name, b.Version, b.Metadata, b.ApiUrl, schemaEndpoints); discoveryContexts = new List(); AddDiscoveryContexts(SrvPing, PingResponse); AddDiscoveryContexts(SrvInfo, InfoResponse); - AddDiscoveryContexts(SrvSchema, SchemaResponse); AddStatsContexts(); } @@ -103,7 +98,7 @@ private void AddStatsContexts() private Endpoint InternalEndpoint(string discoveryName, string optionalServiceNameSegment, string optionalServiceIdSegment) { string subject = ToDiscoverySubject(discoveryName, optionalServiceNameSegment, optionalServiceIdSegment); - return new Endpoint(subject, subject, null, null, false); + return new Endpoint(subject, subject, null, false); } internal static string ToDiscoverySubject(string discoverySubject, string serviceName, string serviceId) @@ -198,7 +193,6 @@ public void Reset() public string Name => InfoResponse.Name; public string Version => InfoResponse.Version; public string Description => InfoResponse.Description; - public string ApiUrl => SchemaResponse.ApiUrl; public StatsResponse GetStatsResponse() { @@ -227,14 +221,9 @@ public override string ToString() JsonUtils.AddField(o, ApiConstants.Name, InfoResponse.Name); JsonUtils.AddField(o, ApiConstants.Version, InfoResponse.Version); JsonUtils.AddField(o, ApiConstants.Description, InfoResponse.Description); - JsonUtils.AddField(o, ApiConstants.ApiUrl, SchemaResponse.ApiUrl); JSONArray ja = new JSONArray(); - foreach (EndpointResponse e in SchemaResponse.Endpoints) - { - ja.Add(e.ToJsonNode()); - } o[ApiConstants.Endpoints] = ja; - return "\"Service\":" + o.ToString(); + return "\"Service\":" + o.ToString(); // ToString() is needed because of how the JSONObject was written } } } diff --git a/src/NATS.Client/Service/ServiceEndpoint.cs b/src/NATS.Client/Service/ServiceEndpoint.cs index ab09e3a99..ed3dfd18e 100644 --- a/src/NATS.Client/Service/ServiceEndpoint.cs +++ b/src/NATS.Client/Service/ServiceEndpoint.cs @@ -74,16 +74,6 @@ public ServiceEndpointBuilder WithEndpointSubject(String subject) { return this; } - public ServiceEndpointBuilder WithEndpointSchemaRequest(String schemaRequest) { - EndpointBuilder.WithSchemaRequest(schemaRequest); - return this; - } - - public ServiceEndpointBuilder WithEndpointSchemaResponse(String schemaResponse) { - EndpointBuilder.WithSchemaResponse(schemaResponse); - return this; - } - public ServiceEndpointBuilder WithHandler(EventHandler handler) { Handler = handler; return this; diff --git a/src/Samples/Miscellany/ServiceCrossClientValidator.cs b/src/Samples/Miscellany/ServiceCrossClientValidator.cs index 812780249..886f6e908 100644 --- a/src/Samples/Miscellany/ServiceCrossClientValidator.cs +++ b/src/Samples/Miscellany/ServiceCrossClientValidator.cs @@ -61,8 +61,6 @@ public static void CrossClientValidationMain() .WithVersion("0.0.1") .AddServiceEndpoint(ServiceEndpoint.Builder() .WithEndpointName("jccv") - .WithEndpointSchemaRequest("schema request string/url") - .WithEndpointSchemaResponse("schema response string/url") .WithStatsDataSupplier(SupplyData) .WithHandler(handler) .Build()) diff --git a/src/Samples/ServiceExample/ServiceExample.cs b/src/Samples/ServiceExample/ServiceExample.cs index 574bed823..feb7f8430 100644 --- a/src/Samples/ServiceExample/ServiceExample.cs +++ b/src/Samples/ServiceExample/ServiceExample.cs @@ -37,8 +37,6 @@ public static void Main(string[] args) Endpoint epEcho = Endpoint.Builder() .WithName("EchoEndpoint") .WithSubject("echo") - .WithSchemaRequest("echo schema request info") // optional - .WithSchemaResponse("echo schema response info") // optional .Build(); // Sort is going to be grouped. This will affect the actual subject @@ -63,8 +61,6 @@ public static void Main(string[] args) .WithGroup(sortGroup) .WithEndpointName("SortEndpointAscending") .WithEndpointSubject("ascending") - .WithEndpointSchemaRequest("sort ascending schema request info") // optional - .WithEndpointSchemaResponse("sort ascending schema response info") // optional .WithHandler((s, a) => HandleSortAscending(c, a.Message, "S1A")) .Build(); @@ -160,18 +156,6 @@ public static void Main(string[] args) infoResponses = discovery.Info("Service2"); PrintDiscovery("Info", "Service2", infoResponses); - // ---------------------------------------------------------------------------------------------------- - // schema discover variations - // ---------------------------------------------------------------------------------------------------- - IList schemaResponsList = discovery.Schema(); - PrintDiscovery("Schema", "[All]", schemaResponsList); - - schemaResponsList = discovery.Schema("Service1"); - PrintDiscovery("Schema", "Service1", schemaResponsList); - - schemaResponsList = discovery.Schema("Service2"); - PrintDiscovery("Schema", "Service2", schemaResponsList); - // ---------------------------------------------------------------------------------------------------- // stats discover variations // ---------------------------------------------------------------------------------------------------- @@ -264,12 +248,6 @@ private static void PrintDiscovery(string action, string label, IList responses) - { - Console.WriteLine("\n" + action + " " + label); - foreach (SchemaResponse r in responses) { Console.WriteLine(" " + r); } - } - private static void PrintDiscovery(string action, string label, IList responses) { Console.WriteLine("\n" + action + " " + label); diff --git a/src/Tests/IntegrationTestsInternal/TestService.cs b/src/Tests/IntegrationTestsInternal/TestService.cs index 7a12c8ff1..b3cac784f 100644 --- a/src/Tests/IntegrationTestsInternal/TestService.cs +++ b/src/Tests/IntegrationTestsInternal/TestService.cs @@ -54,15 +54,11 @@ public void TestServiceWorkflow() Endpoint endEcho = Endpoint.Builder() .WithName(EchoEndpointName) .WithSubject(EchoEndpointSubject) - .WithSchemaRequest("echo schema request info") // optional - .WithSchemaResponse("echo schema response info") // optional .Build(); Endpoint endSortA = Endpoint.Builder() .WithName(SortEndpointAscendingName) .WithSubject(SortEndpointAscendingSubject) - .WithSchemaRequest("sort ascending schema request info") // optional - .WithSchemaResponse("sort ascending schema response info") // optional .Build(); // constructor coverage @@ -100,8 +96,6 @@ public void TestServiceWorkflow() .WithGroup(sortGroup) .WithEndpointName(endSortA.Name) .WithEndpointSubject(endSortA.Subject) - .WithEndpointSchemaRequest(endSortA.Schema.Request) - .WithEndpointSchemaResponse(endSortA.Schema.Response) .WithHandler((source, args) => { args.Message.Respond(serviceNc2, SortA(args.Message.Data)); }) .Build(); @@ -149,8 +143,6 @@ public void TestServiceWorkflow() PingResponse pingResponse2 = service2.PingResponse; InfoResponse infoResponse1 = service1.InfoResponse; InfoResponse infoResponse2 = service2.InfoResponse; - SchemaResponse schemaResponse1 = service1.SchemaResponse; - SchemaResponse schemaResponse2 = service2.SchemaResponse; StatsResponse statsResponse1 = service1.GetStatsResponse(); StatsResponse statsResponse2 = service2.GetStatsResponse(); EndpointResponse[] endpointResponseArray1 = new EndpointResponse[] @@ -171,8 +163,6 @@ public void TestServiceWorkflow() Assert.Equal(serviceId2, pingResponse2.Id); Assert.Equal(serviceId1, infoResponse1.Id); Assert.Equal(serviceId2, infoResponse2.Id); - Assert.Equal(serviceId1, schemaResponse1.Id); - Assert.Equal(serviceId2, schemaResponse2.Id); Assert.Equal(serviceId1, statsResponse1.Id); Assert.Equal(serviceId2, statsResponse2.Id); @@ -233,30 +223,6 @@ void VerifyInfoDiscoveries(IList responses, params InfoResponse[] VerifyInfoDiscovery(discovery.InfoForNameAndId(ServiceName1, serviceId1), infoResponse1); Assert.Null(discovery.InfoForNameAndId(ServiceName1, "badId")); Assert.Null(discovery.InfoForNameAndId("bad", "badId")); - - // schema discovery - void VerifySchemaDiscovery(SchemaResponse r, SchemaResponse exp) { - VerifyServiceResponseFields(r, exp); - Assert.Equal(exp.ApiUrl, r.ApiUrl); - Assert.Equal(exp.Endpoints, r.Endpoints); - } - void VerifySchemaDiscoveries(IList responses, params SchemaResponse[] expectedResponses) - { - Assert.Equal(expectedResponses.Length, responses.Count); - foreach (SchemaResponse r in responses) - { - // ReSharper disable once CoVariantArrayConversion - SchemaResponse exp = (SchemaResponse)Find(expectedResponses, r); - Assert.NotNull(exp); - VerifySchemaDiscovery(r, exp); - } - } - VerifySchemaDiscoveries(discovery.Schema(), schemaResponse1, schemaResponse2); - VerifySchemaDiscoveries(discovery.Schema(ServiceName1), schemaResponse1); - VerifySchemaDiscoveries(discovery.Schema(ServiceName2), schemaResponse2); - VerifySchemaDiscovery(discovery.SchemaForNameAndId(ServiceName1, serviceId1), schemaResponse1); - Assert.Null(discovery.SchemaForNameAndId(ServiceName1, "badId")); - Assert.Null(discovery.SchemaForNameAndId("bad", "badId")); // stats discovery void VerifyStatsDiscovery(StatsResponse r, StatsResponse exp) { @@ -379,7 +345,6 @@ public void TestServiceBuilderConstruction() Assert.Equal(ServiceBuilder.DefaultDrainTimeoutMillis, service.DrainTimeoutMillis); Assert.Equal("1.0.0", service.Version); Assert.Null(service.Description); - Assert.Null(service.ApiUrl); service = Service.Builder().WithConnection(conn).WithName(NAME).WithVersion("1.0.0").AddServiceEndpoint(se) .WithApiUrl("apiUrl") @@ -387,7 +352,6 @@ public void TestServiceBuilderConstruction() .WithDrainTimeoutMillis(1000) .Build(); Assert.Equal("desc", service.Description); - Assert.Equal("apiUrl", service.ApiUrl); Assert.Equal(1000, service.DrainTimeoutMillis); Assert.Throws(() => Service.Builder().WithName(null)); diff --git a/src/Tests/UnitTests/TestServiceObjects.cs b/src/Tests/UnitTests/TestServiceObjects.cs index 60a9ec5f0..d03e0c47d 100644 --- a/src/Tests/UnitTests/TestServiceObjects.cs +++ b/src/Tests/UnitTests/TestServiceObjects.cs @@ -30,68 +30,26 @@ public void TestEndpointConstruction() Endpoint e = new Endpoint(NAME); Assert.Equal(NAME, e.Name); Assert.Equal(NAME, e.Subject); - Assert.Null(e.Schema); Assert.Equal(e, Endpoint.Builder().WithEndpoint(e).Build()); Assert.Null(e.Metadata); e = new Endpoint(NAME, SUBJECT); Assert.Equal(NAME, e.Name); Assert.Equal(SUBJECT, e.Subject); - Assert.Null(e.Schema); - Assert.Equal(e, Endpoint.Builder().WithEndpoint(e).Build()); - - e = new Endpoint(NAME, SUBJECT, "schema-request", null); - Assert.Equal(NAME, e.Name); - Assert.Equal(SUBJECT, e.Subject); - Assert.Equal("schema-request", e.Schema.Request); - Assert.Null(e.Schema.Response); - Assert.Equal(e, Endpoint.Builder().WithEndpoint(e).Build()); - - e = new Endpoint(NAME, SUBJECT, null, "schema-response"); - Assert.Equal(NAME, e.Name); - Assert.Equal(SUBJECT, e.Subject); - Assert.Null(e.Schema.Request); - Assert.Equal("schema-response", e.Schema.Response); - Assert.Equal(e, Endpoint.Builder().WithEndpoint(e).Build()); - - e = Endpoint.Builder() - .WithName(NAME) - .WithSubject(SUBJECT) - .WithSchemaRequest("schema-request") - .WithSchemaResponse("schema-response") - .Build(); - Assert.Equal(NAME, e.Name); - Assert.Equal(SUBJECT, e.Subject); - Assert.Equal("schema-request", e.Schema.Request); - Assert.Equal("schema-response", e.Schema.Response); Assert.Equal(e, Endpoint.Builder().WithEndpoint(e).Build()); e = Endpoint.Builder() .WithName(NAME).WithSubject(SUBJECT) - .WithSchema(e.Schema) .Build(); Assert.Equal(NAME, e.Name); Assert.Equal(SUBJECT, e.Subject); - Assert.Equal("schema-request", e.Schema.Request); - Assert.Equal("schema-response", e.Schema.Response); String j = e.ToJsonString(); Assert.StartsWith("{", j); Assert.Contains("\"name\":\"name\"", j); Assert.Contains("\"subject\":\"subject\"", j); - Assert.Contains("\"schema\":{", j); - Assert.Contains("\"request\":\"schema-request\"", j); - Assert.Contains("\"response\":\"schema-response\"", j); Assert.Equal(JsonUtils.ToKey(typeof(Endpoint)) +j, e.ToString()); - e = Endpoint.Builder() - .WithName(NAME).WithSubject(SUBJECT) - .WithSchema(null) - .Build(); - Assert.Equal(NAME, e.Name); - Assert.Equal(SUBJECT, e.Subject); - Assert.Null(e.Schema); - Dictionary dictionary = new Dictionary(); e = Endpoint.Builder() .WithName(NAME).WithSubject(SUBJECT) @@ -143,41 +101,6 @@ public void TestEndpointConstruction() Assert.Throws(() => new Endpoint(NAME, "foo.>.bar")); // gt is not last segment } - [Fact] - public void TestSchemaConstruction() - { - Schema s1 = new Schema("request", "response"); - Assert.Equal("request", s1.Request); - Assert.Equal("response", s1.Response); - - Assert.Null(Schema.OptionalInstance(null, "")); - Assert.Null(Schema.OptionalInstance("", null)); - Assert.Null(Schema.OptionalInstance(null)); - - Schema s2 = new Schema("request", null); - Assert.Equal("request", s2.Request); - Assert.Null(s2.Response); - - s2 = new Schema(null, "response"); - Assert.Null(s2.Request); - Assert.Equal("response", s2.Response); - - s2 = new Schema(s1.ToJsonNode()); - Assert.Equal(s1, s2); - - s2 = Schema.OptionalInstance(s1.ToJsonNode()); - Assert.Equal(s1, s2); - - String j = s1.ToJsonString(); - Assert.StartsWith("{", j); - Assert.Contains("\"request\":\"request\"", j); - Assert.Contains("\"response\":\"response\"", j); - String s = s1.ToString(); - Assert.StartsWith(JsonUtils.ToKey(typeof(Schema)), s); - Assert.Contains("\"request\":\"request\"", s); - Assert.Contains("\"response\":\"response\"", s); - } - [Fact] public void TestEndpointResponseConstruction() { @@ -186,7 +109,6 @@ public void TestEndpointResponseConstruction() EndpointResponse es = new EndpointResponse("name", "subject", 0, 0, 0, null, null, dt); Assert.Equal("name", es.Name); Assert.Equal("subject", es.Subject); - Assert.Null(es.Schema); Assert.Null(es.LastError); Assert.Null(es.Data); Assert.Equal(0, es.NumRequests); @@ -198,7 +120,6 @@ public void TestEndpointResponseConstruction() es = new EndpointResponse("name", "subject", 2, 4, 10, "lastError", data, dt); Assert.Equal("name", es.Name); Assert.Equal("subject", es.Subject); - Assert.Null(es.Schema); Assert.Equal("lastError", es.LastError); Assert.Equal("\"data\"", es.Data.ToString()); Assert.Equal(2, es.NumRequests); @@ -219,31 +140,6 @@ public void TestEndpointResponseConstruction() Assert.Contains("\"processing_time\":10", j); Assert.Contains("\"average_processing_time\":5", j); Assert.Equal(JsonUtils.ToKey(typeof(EndpointResponse)) + j, es.ToString()); - - Schema schema = new Schema("req", "res"); - es = new EndpointResponse("name", "subject", schema); - Assert.Equal("name", es.Name); - Assert.Equal("subject", es.Subject); - Assert.Null(es.LastError); - Assert.Null(es.Data); - Assert.Equal(0, es.NumRequests); - Assert.Equal(0, es.NumErrors); - Assert.Equal(0, es.ProcessingTime); - Assert.Equal(0, es.AverageProcessingTime); - Assert.Equal(DateTime.MinValue, es.Started); - - j = es.ToJsonString(); - Assert.StartsWith("{", j); - Assert.Contains("\"name\":\"name\"", j); - Assert.Contains("\"subject\":\"subject\"", j); - Assert.Contains("\"schema\":{\"request\":\"req\",\"response\":\"res\"}", j); - Assert.DoesNotContain("\"last_error\":", j); - Assert.DoesNotContain("\"data\":", j); - Assert.DoesNotContain("\"num_requests\":", j); - Assert.DoesNotContain("\"num_errors\":", j); - Assert.DoesNotContain("\"processing_time\":", j); - Assert.DoesNotContain("\"average_processing_time\":", j); - Assert.Equal(JsonUtils.ToKey(typeof(EndpointResponse)) + j, es.ToString()); } [Fact] @@ -412,12 +308,8 @@ public void TestServiceResponsesConstruction() ValidateApiInOutInfoResponse(ir2); IList endpoints = new List(); - endpoints.Add(new EndpointResponse("endName0", "endSubject0", new Schema("endSchemaRequest0", "endSchemaResponse0"))); - endpoints.Add(new EndpointResponse("endName1", "endSubject1", new Schema("endSchemaRequest1", "endSchemaResponse1"))); - SchemaResponse sch1 = new SchemaResponse("id", "name", "0.0.0", dictionary, "apiUrl", endpoints); - SchemaResponse sch2 = new SchemaResponse(sch1.ToJsonString()); - ValidateApiInOutSchemaResponse(sch1); - ValidateApiInOutSchemaResponse(sch2); + endpoints.Add(new EndpointResponse("endName0", "endSubject0")); + endpoints.Add(new EndpointResponse("endName1", "endSubject1")); DateTime serviceStarted = DateTime.UtcNow; DateTime[] endStarteds = new DateTime[2]; @@ -461,20 +353,6 @@ private static void ValidateApiInOutStatsResponse(StatsResponse stat, DateTime s } } - private static void ValidateApiInOutSchemaResponse(SchemaResponse r) - { - ValidateApiInOutServiceResponse(r, SchemaResponse.ResponseType); - Assert.Equal("apiUrl", r.ApiUrl); - Assert.Equal(2, r.Endpoints.Count); - for (int x = 0; x < 2; x++) { - EndpointResponse e = r.Endpoints[x]; - Assert.Equal("endName" + x, e.Name); - Assert.Equal("endSubject" + x, e.Subject); - Assert.Equal("endSchemaRequest" + x, e.Schema.Request); - Assert.Equal("endSchemaResponse" + x, e.Schema.Response); - } - } - private static void ValidateApiInOutInfoResponse(InfoResponse r) { ValidateApiInOutServiceResponse(r, InfoResponse.ResponseType);