-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement isMaster with tests for replica and non-replica scenario #60
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
operations | ||
closeIfOpen | ||
self isOpen ifTrue: [ self close ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
operations | ||
isMaster | ||
^ self admin isMaster |
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 |
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/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the other PR we are linking to the most recent docs. It's fine to link to the doc used during impl or latest but we should aim to be consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. What do you think is the best approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link to the document at the time of the implementation. One can go to newer versions (if it exists) then but not the other way around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will take it into account for next time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
instance creation | ||
with: aCollection | ||
^ self basicNew | ||
initializeWith: aCollection; | ||
yourself |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
hasPrimary | ||
^ response includesKey: 'primary' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
initialization | ||
initializeWith: aCollection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a collection or dictionary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More particularly a dictionary, but when somebody presses on "create" in the debugger (in a DNU), the parameter has this name. This was defined in some method of the hierarchy, not sure if it's on purpose or a bug. |
||
self initialize. | ||
|
||
response := aCollection. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
isPrimary | ||
^ (response at: 'ismaster') and: [ self isReplicaSet ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
isReadOnly | ||
^ response at: 'readOnly' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
isReplicaSet | ||
^ response includesKey: 'setName' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
isSecondary | ||
^ response at: 'secondary' ifAbsent: [ false ] |
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' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
primaryUrlString | ||
^ response at: 'primary' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
replicaSetHosts | ||
^ response at: #hosts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
replicaSetName | ||
^ response at: 'setName' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
replica set | ||
replicaSetUrls | ||
^ self replicaSetHosts collect: #asMongoUrl |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
replica set | ||
urlString | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this used? Can you think of a better name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent was to differenciate from the cases when a ZnUrl is useful vs this string version of the url that always comes in the responses. May be |
||
"In a replica set, this is the url of the requested server. Not defined else." | ||
|
||
^ response at: 'me' |
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" | ||
} |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name" : "String" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*Mongo-Core | ||
asMongoUrl | ||
self assert: (self scheme = #mongodb). | ||
^self |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name" : "ZnUrl" | ||
} |
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. |
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'). |
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 ]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to use OrderedIdentityDictionary in many other places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly I don't know, a reason may be to allow repeated String keys but I don't know in which special cases. I think we should unify how the "JSON dictionaries" (Dictionaries that will be converted to json in a mongo call) are created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created issue #61 to maybe discuss more about this.