Skip to content
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

Adding feature for - "Test Connection" #532

Merged
merged 3 commits into from
Aug 21, 2019
Merged

Conversation

anu3990
Copy link
Contributor

@anu3990 anu3990 commented Aug 20, 2019

Enhancement feature referring to - #346

@anu3990 anu3990 requested a review from ehennum August 20, 2019 07:10
Copy link
Contributor

@ehennum ehennum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for puzzling out the callbacks.

A few suggestions embedded.

lib/marklogic.js Outdated
* Tests if a connection is successful.
* @method DatabaseClient#testConnection
* @since 2.1
* @returns true if the connection is successful and false otherwise with an error message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more accurate to say that it returns an object with a connected property of true or false and, in the false case, httpStatusCode and httpStatusMessage properties identifying the failure?

lib/marklogic.js Outdated
requestOptions.method = 'HEAD';
requestOptions.path = mlutil.databaseParam(connectionParams, '/v1/ping', '?');
var operation = new Operation(
'test operation', this, requestOptions, 'empty', 'single'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the last parameter be empty? After experimenting with curl, it looks like the HEAD request doesn't return a body in either the success or failure cases.

lib/marklogic.js Outdated
} else {
content = {connected: false,
httpStatusCode: this.responseStatusCode,
httpStatusMessage: operation.responseStatusMessage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the assignment use this.responseStatusMessage instead of operation.responseStatusMessage for consistency and to avoid side effects if the code is refactored to move the addOutputTransform() function out of the the testConnection() function in the future?

The this object refers to the object on which the function is called while operation is a closure on the local variable of testConnection()

lib/marklogic.js Outdated
content = {connected: false,
httpStatusCode: this.responseStatusCode,
httpStatusMessage: operation.responseStatusMessage
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the previous line end with a semicolon to reinforce that it closes the object literal assigment starting on line 399?

lib/marklogic.js Outdated
}
var wrapper = {content: [content]};
}
return wrapper;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've two concerns:

  1. The wrapper variable is assigned only inside the else branch but returned from ddOutputTransform() in the if case as well. Wouldn't the return value be undef in that case?
  2. What is the rationale for wrapping the content value instead of just returning the content value?

.result(function(response) {
flag = true;
}).then(function(){
assert(flag == true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the result() callback doesn't return a promise, I believe the then() callback will never execute.

Same comment on subsequent tests.

var flag = false;
db.testConnection()
.result(function(response) {
flag = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that test connection returns an object in all cases, would a better test assert that response.connected is true?

db1.testConnection()
.result(function(response) {
flag = true;
respContent = response.content[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having to get a content subproperty, would it be better to have the properties directly on the response.

Same comment on the subsequent test.

Copy link
Contributor

@ehennum ehennum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this useful capability.

One last minute thought -- would it convey the intent better to call the method "checkConnection" instead of "testConnection"? I'm wondering if the specific connotations of "test" give people the wrong idea.

Please consider and, after resolving either way, merge the commit.

On to Java -- and then letting the documentation folk know to mention the check in the Node.js and Java guides.

@anu3990
Copy link
Contributor Author

anu3990 commented Aug 21, 2019

Thanks Erik. !
Changed "test connection" to "check connection"

@ehennum ehennum merged commit a0f9e0f into marklogic:develop Aug 21, 2019
@tdiepenbrock
Copy link

The documentation on this still refers to "testConnection".

@jmakeig
Copy link
Contributor

jmakeig commented Apr 23, 2020

Ping @ehennum.

@ehennum
Copy link
Contributor

ehennum commented Apr 23, 2020

Please see Tom's feedback...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants