@Test public void testException() throws Exception { MongoDatabase db = mock(MongoDatabase.class); when(db.runCommand(new Document("ping", 1))) .thenThrow(new MongoTimeoutException("Timeout")); MongoHealthCheck check = new MongoHealthCheck(db); HealthCheck.Result result = check.check(); assertFalse(result.isHealthy()); assertEquals("Timeout", result.getMessage()); }
@Override protected Result check() throws Exception { try { Document result = db.runCommand(PING); int ok = 0; if (result.containsKey("ok") && result.get("ok") instanceof Number) { ok = result.get("ok", Number.class).intValue(); } if (ok != 1) { LOGGER.warn("Unexpected ping response: " + result.toString()); return Result.unhealthy("Unexpected ping response: " + result.toString()); } return Result.healthy(); } catch (Exception e) { LOGGER.warn("Failed health check", e); return Result.unhealthy(e.getMessage()); } }
MongoHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { try { Document result = db.runCommand(PING); int ok = 0; if (result.containsKey("ok") && result.get("ok") instanceof Number) { ok = result.get("ok", Number.class).intValue(); } if (ok != 1) { LOGGER.warn("Unexpected ping response: " + result.toString()); return Result.unhealthy("Unexpected ping response: " + result.toString()); } return Result.healthy(); } catch (Exception e) { LOGGER.warn("Failed health check", e); return Result.unhealthy(e.getMessage()); } } }
MongoHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { try { Document result = db.runCommand(PING); int ok = 0; if (result.containsKey("ok") && result.get("ok") instanceof Number) { ok = result.get("ok", Number.class).intValue(); } if (ok != 1) { LOGGER.warn("Unexpected ping response: " + result.toString()); return Result.unhealthy("Unexpected ping response: " + result.toString()); } return Result.healthy(); } catch (Exception e) { LOGGER.warn("Failed health check", e); return Result.unhealthy(e.getMessage()); } } @Inject  MongoHealthCheck(MongoDatabase db); }
MongoHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { try { Document result = db.runCommand(PING); int ok = 0; if (result.containsKey("ok") && result.get("ok") instanceof Number) { ok = result.get("ok", Number.class).intValue(); } if (ok != 1) { LOGGER.warn("Unexpected ping response: " + result.toString()); return Result.unhealthy("Unexpected ping response: " + result.toString()); } return Result.healthy(); } catch (Exception e) { LOGGER.warn("Failed health check", e); return Result.unhealthy(e.getMessage()); } } @Inject  MongoHealthCheck(MongoDatabase db);  }
MongoHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { try { Document result = db.runCommand(PING); int ok = 0; if (result.containsKey("ok") && result.get("ok") instanceof Number) { ok = result.get("ok", Number.class).intValue(); } if (ok != 1) { LOGGER.warn("Unexpected ping response: " + result.toString()); return Result.unhealthy("Unexpected ping response: " + result.toString()); } return Result.healthy(); } catch (Exception e) { LOGGER.warn("Failed health check", e); return Result.unhealthy(e.getMessage()); } } @Inject  MongoHealthCheck(MongoDatabase db);   }