From 2f421bb53a327756f8a61720d56ba1ad0b20da82 Mon Sep 17 00:00:00 2001 From: Elango Ravikumar Date: Fri, 21 Jul 2023 16:13:03 +0530 Subject: [PATCH] serverStatus command to work in admin and non-admin dbs --- .../de/bwaldvogel/mongo/backend/AbstractMongoBackend.java | 4 ++-- .../de/bwaldvogel/mongo/backend/AbstractBackendTest.java | 6 +++++- .../test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java index 45055bf4..69c65540 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoBackend.java @@ -197,8 +197,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(); @@ -331,6 +329,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); } diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendTest.java index c5e47394..8170355c 100755 --- a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendTest.java @@ -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); diff --git a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java index 2a4de91f..a44d6755 100644 --- a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java +++ b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java @@ -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);