-
Notifications
You must be signed in to change notification settings - Fork 13
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 #60 from tinchodias/59-Add-isMaster-command
Implement isMaster with tests for replica and non-replica scenario
- Loading branch information
Showing
25 changed files
with
139 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
operations | ||
closeIfOpen | ||
self isOpen ifTrue: [ self close ] |
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,3 @@ | ||
operations | ||
isMaster | ||
^ self admin isMaster |
7 changes: 7 additions & 0 deletions
7
mc/Mongo-Core.package/MongoDatabase.class/instance/isMaster.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,7 @@ | ||
operations | ||
isMaster | ||
|
||
| reply | | ||
reply := self command: (OrderedDictionary new at: #ismaster put: 1; yourself). | ||
|
||
^ MongoIsMaster with: reply |
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,12 @@ | ||
I represent the response of a "isMaster" command, defined by documentation in the following way: | ||
|
||
isMaster returns a document that describes the role of the mongod instance. If the optional field saslSupportedMechs is specified, the command also returns an array of SASL mechanisms used to create the specified user’s credentials. | ||
|
||
If the instance is a member of a replica set, then isMaster returns a subset of the replica set configuration and status including whether or not the instance is the primary of the replica set. | ||
|
||
When sent to a mongod instance that is not a member of a replica set, isMaster returns a subset of this information. | ||
|
||
MongoDB drivers and clients use isMaster to determine the state of the replica set members and to discover additional members of a replica set. | ||
|
||
|
||
Read more at: https://docs.mongodb.com/v4.0/reference/command/isMaster/ |
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,5 @@ | ||
instance creation | ||
with: aCollection | ||
^ self basicNew | ||
initializeWith: aCollection; | ||
yourself |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/hasPrimary.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,3 @@ | ||
replica set | ||
hasPrimary | ||
^ response includesKey: 'primary' |
5 changes: 5 additions & 0 deletions
5
mc/Mongo-Core.package/MongoIsMaster.class/instance/initializeWith..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,5 @@ | ||
initialization | ||
initializeWith: aCollection | ||
self initialize. | ||
|
||
response := aCollection. |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/isPrimary.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,3 @@ | ||
replica set | ||
isPrimary | ||
^ (response at: 'ismaster') and: [ self isReplicaSet ] |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/isReadOnly.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,3 @@ | ||
accessing | ||
isReadOnly | ||
^ response at: 'readOnly' |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/isReplicaSet.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,3 @@ | ||
replica set | ||
isReplicaSet | ||
^ response includesKey: 'setName' |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/isSecondary.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,3 @@ | ||
replica set | ||
isSecondary | ||
^ response at: 'secondary' ifAbsent: [ false ] |
9 changes: 9 additions & 0 deletions
9
mc/Mongo-Core.package/MongoIsMaster.class/instance/isWrittable.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,9 @@ | ||
accessing | ||
isWrittable | ||
"A boolean value that reports when this node is writable. If true, then this instance is a primary in a replica set, or a mongos instance, or a standalone mongod. | ||
This field will be false if the instance is a secondary member of a replica set or if the member is an arbiter of a replica set. | ||
Source: https://docs.mongodb.com/manual/reference/command/isMaster/#isMaster.ismaster" | ||
|
||
^ response at: 'ismaster' |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/primaryUrlString.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,3 @@ | ||
replica set | ||
primaryUrlString | ||
^ response at: 'primary' |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/replicaSetHosts.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,3 @@ | ||
replica set | ||
replicaSetHosts | ||
^ response at: #hosts |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/replicaSetName.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,3 @@ | ||
replica set | ||
replicaSetName | ||
^ response at: 'setName' |
3 changes: 3 additions & 0 deletions
3
mc/Mongo-Core.package/MongoIsMaster.class/instance/replicaSetUrls.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,3 @@ | ||
replica set | ||
replicaSetUrls | ||
^ self replicaSetHosts collect: #asMongoUrl |
5 changes: 5 additions & 0 deletions
5
mc/Mongo-Core.package/MongoIsMaster.class/instance/urlString.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,5 @@ | ||
replica set | ||
urlString | ||
"In a replica set, this is the url of the requested server. Not defined else." | ||
|
||
^ response at: 'me' |
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,13 @@ | ||
{ | ||
"commentStamp" : "MartinDias 7/24/2019 12:23", | ||
"super" : "Object", | ||
"category" : "Mongo-Core-Responses", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"response" | ||
], | ||
"name" : "MongoIsMaster", | ||
"type" : "normal" | ||
} |
6 changes: 6 additions & 0 deletions
6
mc/Mongo-Core.package/String.extension/instance/asMongoUrl.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,6 @@ | ||
*Mongo-Core | ||
asMongoUrl | ||
| url | | ||
url := ZnUrl fromString: self defaultScheme: #mongodb. | ||
url hasPort ifFalse: [ url port: 27017 ]. | ||
^ url |
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,3 @@ | ||
{ | ||
"name" : "String" | ||
} |
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,4 @@ | ||
*Mongo-Core | ||
asMongoUrl | ||
self assert: (self scheme = #mongodb). | ||
^self |
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,3 @@ | ||
{ | ||
"name" : "ZnUrl" | ||
} |
15 changes: 15 additions & 0 deletions
15
mc/Mongo-Tests-Core.package/MongoNoReplicationTest.class/instance/testIsMaster.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,15 @@ | ||
tests | ||
testIsMaster | ||
|
||
| response | | ||
response := mongo isMaster. | ||
|
||
"Common API is short." | ||
self deny: response isNil. | ||
self deny: response isReadOnly. | ||
self deny: response isReplicaSet. | ||
|
||
"Replica Set API that works, anyway." | ||
self deny: response hasPrimary. | ||
self deny: response isPrimary. | ||
self deny: response isSecondary. |
18 changes: 18 additions & 0 deletions
18
mc/Mongo-Tests-Core.package/MongoReplicationOkTest.class/instance/testIsMaster.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,18 @@ | ||
tests | ||
testIsMaster | ||
|
||
| response | | ||
response := mongo isMaster. | ||
|
||
"Common API is short." | ||
self deny: response isNil. | ||
self deny: response isReadOnly. | ||
self assert: response isReplicaSet. | ||
|
||
"Replica Set specific API." | ||
self assert: response hasPrimary. | ||
self assert: response isPrimary. | ||
self deny: response isSecondary. | ||
self assert: response urlString equals: mongo host, ':', mongo port asString. | ||
self assert: response primaryUrlString equals: response urlString. | ||
self assert: response replicaSetHosts equals: #('localhost:27031' 'localhost:27032'). |
2 changes: 1 addition & 1 deletion
2
mc/Mongo-Tests-Core.package/MongoReplicationTest.class/instance/tearDown.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
running | ||
tearDown | ||
super tearDown. | ||
(mongo isNotNil and: [mongo isOpen]) ifTrue: [mongo close]. | ||
mongo ifNotNil: [ mongo closeIfOpen ]. |