@Test public void checkUnhealthy() { DataBaseConfig dataBaseConfig = mock(DataBaseConfig.class); when(dataBaseConfig.getHost()).thenReturn("localhost"); when(dataBaseConfig.getPort()).thenReturn(8074); DataBaseCheck dbCheck = new DataBaseCheck(dataBaseConfig); Result result = dbCheck.check(); assertNotNull(result); assertFalse(result.isHealthy()); }
@Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final StringBuilder sb = new StringBuilder(); sb.append("MogoDb version " + mongo.getVersion() + '\n'); sb.append(" Available databases: "); for(final String dbName: mongo.getDatabaseNames()){ sb.append(dbName); sb.append(' '); } sb.append('\n'); return Result.healthy(sb.toString()); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } }
DataBaseCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final StringBuilder sb = new StringBuilder(); sb.append("MogoDb version " + mongo.getVersion() + '\n'); sb.append(" Available databases: "); for(final String dbName: mongo.getDatabaseNames()){ sb.append(dbName); sb.append(' '); } sb.append('\n'); return Result.healthy(sb.toString()); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } }
DataBaseCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final StringBuilder sb = new StringBuilder(); sb.append("MogoDb version " + mongo.getVersion() + '\n'); sb.append(" Available databases: "); for(final String dbName: mongo.getDatabaseNames()){ sb.append(dbName); sb.append(' '); } sb.append('\n'); return Result.healthy(sb.toString()); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } DataBaseCheck(final DataBaseConfig dataBaseConfig); }
DataBaseCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final StringBuilder sb = new StringBuilder(); sb.append("MogoDb version " + mongo.getVersion() + '\n'); sb.append(" Available databases: "); for(final String dbName: mongo.getDatabaseNames()){ sb.append(dbName); sb.append(' '); } sb.append('\n'); return Result.healthy(sb.toString()); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } DataBaseCheck(final DataBaseConfig dataBaseConfig);  }
DataBaseCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final StringBuilder sb = new StringBuilder(); sb.append("MogoDb version " + mongo.getVersion() + '\n'); sb.append(" Available databases: "); for(final String dbName: mongo.getDatabaseNames()){ sb.append(dbName); sb.append(' '); } sb.append('\n'); return Result.healthy(sb.toString()); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } DataBaseCheck(final DataBaseConfig dataBaseConfig);   }