Skip to content

Commit

Permalink
Merge pull request #223 from elangoravi/main
Browse files Browse the repository at this point in the history
Fix: serverStatus command to execute in both admin and non-admin db(s)
  • Loading branch information
bwaldvogel committed Mar 19, 2024
2 parents a6c1f22 + 2f421bb commit 11de691
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Expand Up @@ -198,8 +198,6 @@ private Document handleAdminCommand(String command, Document query) {
return handleGetCmdLineOpts();
} else if (command.equalsIgnoreCase("getFreeMonitoringStatus")) {
return handleGetFreeMonitoringStatus();
} else if (command.equalsIgnoreCase("serverStatus")) {
return getServerStatus();
} else if (command.equalsIgnoreCase("endSessions")) {
log.debug("endSessions on admin database");
return successResponse();
Expand Down Expand Up @@ -332,6 +330,8 @@ public Document handleCommand(Channel channel, String databaseName, String comma
return handleKillCursors(query);
} else if (command.equalsIgnoreCase("ping")) {
return successResponse();
} else if (command.equalsIgnoreCase("serverStatus")) {
return getServerStatus();
} else if (databaseName.equals(ADMIN_DB_NAME)) {
return handleAdminCommand(command, query);
}
Expand Down
Expand Up @@ -2468,7 +2468,11 @@ private static String repeat(String str, int num) {

@Test
public void testServerStatus() throws Exception {
Document serverStatus = runCommand("serverStatus");
verifyServerStatus(runCommand("serverStatus"));
verifyServerStatus(getDatabase().runCommand(json("serverStatus:1")));
}

private void verifyServerStatus(Document serverStatus) {
assertThat(serverStatus.getDouble("ok")).isEqualTo(1);
assertThat(serverStatus.get("uptime")).isInstanceOf(Number.class);
assertThat(serverStatus.get("uptimeMillis")).isInstanceOf(Long.class);
Expand Down
Expand Up @@ -115,7 +115,11 @@ public void testQueryWithSubdocumentIndex() throws Exception {
@Test
@Override
public void testServerStatus() throws Exception {
Document serverStatus = runCommand("serverStatus");
verifyServerStatus(runCommand("serverStatus"));
verifyServerStatus(db.runCommand(json("serverStatus:1")));
}

private void verifyServerStatus(Document serverStatus) {
assertThat(serverStatus.getDouble("ok")).isEqualTo(1);
assertThat(serverStatus.get("uptime")).isInstanceOf(Number.class);
assertThat(serverStatus.get("uptimeMillis")).isInstanceOf(Long.class);
Expand Down

0 comments on commit 11de691

Please sign in to comment.