From 446f2bcce0be0bbfb2485509176cbbbfcaaaec41 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Thu, 14 Jan 2021 12:14:21 -0300 Subject: [PATCH 1/2] Improve portability --- ...nsulServiceDiscoveryPluginAPITest.class.st | 27 ++++++++++++++++--- ...iceDiscoveryPluginInteractionTest.class.st | 18 +++++-------- .../ConsulServiceDefinitionBuilder.class.st | 22 +++++++-------- .../ConsulServiceDiscoveryPlugin.class.st | 2 +- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st b/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st index b03a717..15fb4e0 100644 --- a/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st +++ b/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st @@ -2,15 +2,22 @@ Class { #name : #ConsulServiceDiscoveryPluginAPITest, #superclass : #OperationalPluginAPITest, #instVars : [ - 'consulAgent' + 'consulAgent', + 'consulAgentPort' ], #category : #'Stargate-Consul-Tests' } +{ #category : #logging } +ConsulServiceDiscoveryPluginAPITest class >> isLogging [ + + ^ true +] + { #category : #private } ConsulServiceDiscoveryPluginAPITest >> consulAgentLocation [ - ^ 'http://localhost:9998' asUrl + ^ 'http://localhost' asUrl port: consulAgentPort ] { #category : #private } @@ -32,6 +39,19 @@ ConsulServiceDiscoveryPluginAPITest >> requiredPermissions [ ^ #() ] +{ #category : #private } +ConsulServiceDiscoveryPluginAPITest >> runCase [ + + | logs | + + logs := + String streamContents: [:stream | + CurrentLogger + value: (LeveledLogger outputTo: stream errorsTo: stream) + during: [super runCase]]. + self logFailure: logs +] + { #category : #private } ConsulServiceDiscoveryPluginAPITest >> serviceDefinitions [ @@ -41,9 +61,10 @@ ConsulServiceDiscoveryPluginAPITest >> serviceDefinitions [ { #category : #tests } ConsulServiceDiscoveryPluginAPITest >> setUp [ + consulAgentPort := self freeListeningTCPPort. consulAgent := FakeConsulAgentAPI configuredBy: - {( #port -> 9998 ). + {( #port -> consulAgentPort ). ( #serverUrl -> self consulAgentLocation ). ( #debugMode -> true )} on: self. diff --git a/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginInteractionTest.class.st b/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginInteractionTest.class.st index eda7be1..bd61bf3 100644 --- a/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginInteractionTest.class.st +++ b/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginInteractionTest.class.st @@ -2,7 +2,8 @@ Class { #name : #ConsulServiceDiscoveryPluginInteractionTest, #superclass : #TestCase, #instVars : [ - 'consulAgent' + 'consulAgent', + 'port' ], #category : #'Stargate-Consul-Tests' } @@ -16,24 +17,19 @@ ConsulServiceDiscoveryPluginInteractionTest >> apiServer [ { #category : #accessing } ConsulServiceDiscoveryPluginInteractionTest >> baseUrl [ - ^ 'http://localhost' asUrl port: self port -] - -{ #category : #accessing } -ConsulServiceDiscoveryPluginInteractionTest >> port [ - - ^ 9998 + ^ 'http://localhost' asUrl port: port ] { #category : #running } ConsulServiceDiscoveryPluginInteractionTest >> setUp [ super setUp. + port := self freeListeningTCPPort. consulAgent := FakeConsulAgentAPI configuredBy: - {( #port -> self port ). - ( #serverUrl -> self baseUrl ). - ( #debugMode -> true )} + { #port -> port. + #serverUrl -> self baseUrl. + #debugMode -> true } on: self. consulAgent start ] diff --git a/source/Stargate-Consul/ConsulServiceDefinitionBuilder.class.st b/source/Stargate-Consul/ConsulServiceDefinitionBuilder.class.st index 82a05b9..f34b8dd 100644 --- a/source/Stargate-Consul/ConsulServiceDefinitionBuilder.class.st +++ b/source/Stargate-Consul/ConsulServiceDefinitionBuilder.class.st @@ -45,7 +45,7 @@ ConsulServiceDefinitionBuilder >> addCheck: aConsulAgentCheck [ | checks | - checks := serviceDefinition at: 'Checks' ifAbsentPut: [ OrderedCollection new ]. + checks := serviceDefinition at: #Checks ifAbsentPut: [ OrderedCollection new ]. checks add: aConsulAgentCheck ] @@ -55,14 +55,14 @@ ConsulServiceDefinitionBuilder >> addTag: aString [ | tags | AssertionChecker enforce: [ aString notEmpty ] because: 'A tag cannot be empty'. - tags := serviceDefinition at: 'Tags' ifAbsentPut: [ OrderedCollection new ]. + tags := serviceDefinition at: #Tags ifAbsentPut: [ OrderedCollection new ]. tags add: aString ] { #category : #configuring } -ConsulServiceDefinitionBuilder >> address: aString [ - - serviceDefinition at: 'Address' put: aString +ConsulServiceDefinitionBuilder >> address: aString [ + + serviceDefinition at: #Address put: aString ] { #category : #private } @@ -77,21 +77,21 @@ ConsulServiceDefinitionBuilder >> assertIsValidPort: aPortNumber [ ConsulServiceDefinitionBuilder >> buildNamed: aServiceName [ AssertionChecker enforce: [ aServiceName notEmpty ] because: 'A service name cannot be empty'. - serviceDefinition at: 'Name' put: aServiceName. + serviceDefinition at: #Name put: aServiceName. ^ NeoJSONObject newFrom: serviceDefinition ] { #category : #configuring } ConsulServiceDefinitionBuilder >> enableTagOverride [ - serviceDefinition at: 'EnableTagOverride' put: true + serviceDefinition at: #EnableTagOverride put: true ] { #category : #configuring } ConsulServiceDefinitionBuilder >> identifiedBy: aString [ AssertionChecker enforce: [ aString notEmpty ] because: 'An ID cannot be empty'. - serviceDefinition at: 'ID' put: aString + serviceDefinition at: #ID put: aString ] { #category : #initialization } @@ -104,14 +104,14 @@ ConsulServiceDefinitionBuilder >> initialize [ { #category : #configuring } ConsulServiceDefinitionBuilder >> metadataAt: aKey put: aValue [ - serviceDefinition at: 'Meta' at: aKey put: aValue + serviceDefinition at: #Meta at: aKey put: aValue ] { #category : #configuring } ConsulServiceDefinitionBuilder >> port: anInteger [ self assertIsValidPort: anInteger. - serviceDefinition at: 'Port' put: anInteger + serviceDefinition at: #Port put: anInteger ] { #category : #configuring } @@ -126,7 +126,7 @@ ConsulServiceDefinitionBuilder >> taggedAddressesAt: aTag on: aKey put: aValue [ | taggedAddresses | taggedAddresses := serviceDefinition - at: 'TaggedAddresses' + at: #TaggedAddresses ifAbsentPut: [ serviceDefinition species new ]. taggedAddresses at: aTag at: aKey put: aValue ] diff --git a/source/Stargate-Consul/ConsulServiceDiscoveryPlugin.class.st b/source/Stargate-Consul/ConsulServiceDiscoveryPlugin.class.st index 203aec3..8562702 100644 --- a/source/Stargate-Consul/ConsulServiceDiscoveryPlugin.class.st +++ b/source/Stargate-Consul/ConsulServiceDiscoveryPlugin.class.st @@ -72,7 +72,7 @@ ConsulServiceDiscoveryPlugin >> deregisterFromConsul: serviceDefinition [ deregisterRequest := HttpRequest put: ( self deregistrationUrlFor: serviceDefinition ) - configuredUsing: [ :request | request body json: {} asDictionary ]. + configuredUsing: [ :request | request body json: Dictionary new ]. deregisterRequest applyOn: self newHttpClient ] From 36d9a048a7376f3da7c94bf47d125ab6bb2d94d5 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Thu, 14 Jan 2021 12:21:02 -0300 Subject: [PATCH 2/2] Move isLogging method --- .../ConsulServiceDiscoveryPluginAPITest.class.st | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st b/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st index 15fb4e0..66227c2 100644 --- a/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st +++ b/source/Stargate-Consul-Tests/ConsulServiceDiscoveryPluginAPITest.class.st @@ -8,18 +8,18 @@ Class { #category : #'Stargate-Consul-Tests' } -{ #category : #logging } -ConsulServiceDiscoveryPluginAPITest class >> isLogging [ - - ^ true -] - { #category : #private } ConsulServiceDiscoveryPluginAPITest >> consulAgentLocation [ ^ 'http://localhost' asUrl port: consulAgentPort ] +{ #category : #logging } +ConsulServiceDiscoveryPluginAPITest >> isLogging [ + + ^ true +] + { #category : #private } ConsulServiceDiscoveryPluginAPITest >> operationsConfiguration [