-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ba-st/service_discovery
Service Discovery Clients
- Loading branch information
Showing
12 changed files
with
568 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
source/Superluminal-RESTfulAPI-Tests/ManifestSuperluminalRESTfulAPITests.class.st
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
.../Superluminal-Service-Discovery-Tests/ConsulAgentHttpAPIBasedDiscoveryClientTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
64 changes: 64 additions & 0 deletions
64
source/Superluminal-Service-Discovery-Tests/FixedServiceDiscoveryClientTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
] |
22 changes: 22 additions & 0 deletions
22
source/Superluminal-Service-Discovery-Tests/NullServiceDiscoveryClientTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
Oops, something went wrong.