Skip to content

Commit

Permalink
Merge pull request #13 from ba-st/service_discovery
Browse files Browse the repository at this point in the history
Service Discovery Clients
  • Loading branch information
gcotelli authored Oct 29, 2020
2 parents 8ce6645 + 1675ebc commit ce1f6f2
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 13 deletions.
23 changes: 18 additions & 5 deletions source/BaselineOfSuperluminal/BaselineOfSuperluminal.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,40 @@ BaselineOfSuperluminal >> setUpDependencies: spec [
baseline: 'ObjectPool' with: [ spec repository: 'github://pharo-ide/ObjectPool:v1.0.1' ];
project: 'ObjectPool-Core' copyFrom: 'ObjectPool' with: [ spec loads: 'Core' ].

spec
baseline: 'Teapot' with: [ spec repository: 'github://zeroflag/Teapot:v2.6.0/source' ];
project: 'Teapot-Deployment' copyFrom: 'Teapot' with: [ spec loads: 'Deployment' ].
]

{ #category : #baselines }
BaselineOfSuperluminal >> setUpPackages: spec [

spec
package: 'Superluminal-Model' with: [ spec requires: #('Hyperspace-Deployment' 'NeoJSON-Core') ];
package: 'Superluminal-Model'
with: [ spec requires: #( 'Hyperspace-Deployment' 'NeoJSON-Core' ) ];
group: 'Deployment' with: 'Superluminal-Model'.

spec
package: 'Superluminal-RESTfulAPI'
with: [ spec requires: #('Superluminal-Model' 'ObjectPool-Core') ];
with: [ spec requires: #( 'Superluminal-Model' 'ObjectPool-Core' ) ];
group: 'Deployment' with: 'Superluminal-RESTfulAPI'.

spec
package: 'Superluminal-Service-Discovery';
group: 'Deployment' with: 'Superluminal-Service-Discovery'.

spec
package: 'Superluminal-Model-Tests'
with: [ spec requires: #('Superluminal-Model' 'Hyperspace-SUnit') ];
with: [ spec requires: #( 'Superluminal-Model' 'Hyperspace-SUnit' ) ];
group: 'Tests' with: 'Superluminal-Model-Tests'.

spec
package: 'Superluminal-RESTfulAPI-Tests'
with: [ spec requires: #('Superluminal-RESTfulAPI' 'Hyperspace-SUnit') ];
group: 'Tests' with: 'Superluminal-RESTfulAPI-Tests'
with: [ spec requires: #( 'Superluminal-RESTfulAPI' 'Hyperspace-SUnit' ) ];
group: 'Tests' with: 'Superluminal-RESTfulAPI-Tests'.

spec
package: 'Superluminal-Service-Discovery-Tests'
with: [ spec requires: #( 'Superluminal-Service-Discovery' 'Hyperspace-SUnit' 'Teapot-Deployment') ];
group: 'Tests' with: 'Superluminal-Service-Discovery-Tests'
]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"
A ConsulAgentHttpAPIBasedDiscoveryClientTest is a test class for testing the behavior of ConsulAgentHttpAPIBasedDiscoveryClient
"
Class {
#name : #ConsulAgentHttpAPIBasedDiscoveryClientTest,
#superclass : #TestCase,
#instVars : [
'consulAgent'
],
#category : #'Superluminal-Service-Discovery-Tests'
}

{ #category : #accessing }
ConsulAgentHttpAPIBasedDiscoveryClientTest >> consulAgentLocation [

^ 'http://localhost' asUrl port: self port
]

{ #category : #accessing }
ConsulAgentHttpAPIBasedDiscoveryClientTest >> port [

^ 41663
]

{ #category : #running }
ConsulAgentHttpAPIBasedDiscoveryClientTest >> setUp [

super setUp.
consulAgent := StubbedConsulAgentHealthHttpAPI
configuredBy: {
#port -> self port.
#serverUrl -> self consulAgentLocation.
#debugMode -> true }
on: self.
consulAgent start
]

{ #category : #running }
ConsulAgentHttpAPIBasedDiscoveryClientTest >> tearDown [

consulAgent ifNotNil: #stop.
super tearDown
]

{ #category : #tests }
ConsulAgentHttpAPIBasedDiscoveryClientTest >> testFoundLocation [

| discoveryClient locationWasFound |

discoveryClient := ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn: self consulAgentLocation.

locationWasFound := false.

discoveryClient
withLocationOfService: #mns
do: [ :location |
locationWasFound := true.
self assertUrl: location equals: ( ZnUrl new
host: '01649d6c4b01';
port: 60666 )
]
ifUnable: [ self fail ].

self assert: locationWasFound
]

{ #category : #tests }
ConsulAgentHttpAPIBasedDiscoveryClientTest >> testUnableToFindLocation [

| discoveryClient locationWasFound |

discoveryClient := ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn: self consulAgentLocation.

locationWasFound := true.

discoveryClient withLocationOfService: #'google-finance'
do: [ :location | self fail ]
ifUnable: [ locationWasFound := false ].

self deny: locationWasFound
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"
A FixedServiceDiscoveryClientTest is a test class for testing the behavior of FixedServiceDiscoveryClient
"
Class {
#name : #FixedServiceDiscoveryClientTest,
#superclass : #TestCase,
#category : #'Superluminal-Service-Discovery-Tests'
}

{ #category : #tests }
FixedServiceDiscoveryClientTest >> testClientChaining [

| discoveryClient fallbackClient |

fallbackClient := FixedServiceDiscoveryClient basedOn:
{ #'google-finance' -> 'https://api.finance.google.com/' asUrl }
asDictionary.

discoveryClient := FixedServiceDiscoveryClient basedOn:
{ #reuters -> 'api.reuters.com' asUrl } asDictionary
chainedWith: fallbackClient.

discoveryClient withLocationOfService: #'google-finance'
do: [ :location | self assertUrl: location equals: 'https://api.finance.google.com' ]
ifUnable: [ self fail ].

discoveryClient withLocationOfService: #reuters
do: [ :location | self assertUrl: location equals: 'api.reuters.com' ]
ifUnable: [ self fail ]
]

{ #category : #tests }
FixedServiceDiscoveryClientTest >> testUnableToFindLocation [

| discoveryClient locationWasFound |

discoveryClient := FixedServiceDiscoveryClient basedOn: Dictionary new.

locationWasFound := true.

discoveryClient withLocationOfService: #'google-finance'
do: [ :location | self fail ]
ifUnable: [ locationWasFound := false ].

self deny: locationWasFound
]

{ #category : #tests }
FixedServiceDiscoveryClientTest >> testWithLocationOfDoIfUnable [

| discoveryClient |

discoveryClient := FixedServiceDiscoveryClient basedOn: {
#'google-finance' -> 'https://api.finance.google.com/' asUrl.
#reuters -> 'api.reuters.com' asUrl } asDictionary.

discoveryClient withLocationOfService: #'google-finance'
do: [ :location | self assertUrl: location equals: 'https://api.finance.google.com' ]
ifUnable: [ self fail ].

discoveryClient withLocationOfService: #reuters
do: [ :location | self assertUrl: location equals: 'api.reuters.com' ]
ifUnable: [ self fail ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"
A NullServiceDiscoveryClientTest is a test class for testing the behavior of NullServiceDiscoveryClient
"
Class {
#name : #NullServiceDiscoveryClientTest,
#superclass : #TestCase,
#category : #'Superluminal-Service-Discovery-Tests'
}

{ #category : #test }
NullServiceDiscoveryClientTest >> testWithLocationOfServiceDoIfUnable [

| serviceLookupWasUnsuccesfull |
serviceLookupWasUnsuccesfull := false.

NullServiceDiscoveryClient new
withLocationOfService: #google
do: [ :location | self fail ]
ifUnable: [ serviceLookupWasUnsuccesfull := true ].

self assert: serviceLookupWasUnsuccesfull
]
Loading

0 comments on commit ce1f6f2

Please sign in to comment.