@Test public void checkUnhealthy() { DataBaseConfig dataBaseConfig = mock(DataBaseConfig.class); when(dataBaseConfig.getHost()).thenReturn("localhost"); when(dataBaseConfig.getPort()).thenReturn(8074); DataModelVersionCheck dbCheck = new DataModelVersionCheck(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 DB db = mongo.getDB(config.getDatastore()); if(config.getUser() != null && config.getPwd() != null){ db.authenticate(config.getUser(), config.getPwd()); } final Jongo jongo = new Jongo(db); final DbGrapesInfo info = jongo.getCollection(DbCollections.DB_GRAPES_INFO).findOne().as(DbGrapesInfo.class); if(info == null){ return Result.healthy("not found\n"); } return Result.healthy(info.getDatamodelVersion()+'\n'); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } }
DataModelVersionCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final DB db = mongo.getDB(config.getDatastore()); if(config.getUser() != null && config.getPwd() != null){ db.authenticate(config.getUser(), config.getPwd()); } final Jongo jongo = new Jongo(db); final DbGrapesInfo info = jongo.getCollection(DbCollections.DB_GRAPES_INFO).findOne().as(DbGrapesInfo.class); if(info == null){ return Result.healthy("not found\n"); } return Result.healthy(info.getDatamodelVersion()+'\n'); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } }
DataModelVersionCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final DB db = mongo.getDB(config.getDatastore()); if(config.getUser() != null && config.getPwd() != null){ db.authenticate(config.getUser(), config.getPwd()); } final Jongo jongo = new Jongo(db); final DbGrapesInfo info = jongo.getCollection(DbCollections.DB_GRAPES_INFO).findOne().as(DbGrapesInfo.class); if(info == null){ return Result.healthy("not found\n"); } return Result.healthy(info.getDatamodelVersion()+'\n'); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } DataModelVersionCheck(final DataBaseConfig dataBaseConfig); }
DataModelVersionCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final DB db = mongo.getDB(config.getDatastore()); if(config.getUser() != null && config.getPwd() != null){ db.authenticate(config.getUser(), config.getPwd()); } final Jongo jongo = new Jongo(db); final DbGrapesInfo info = jongo.getCollection(DbCollections.DB_GRAPES_INFO).findOne().as(DbGrapesInfo.class); if(info == null){ return Result.healthy("not found\n"); } return Result.healthy(info.getDatamodelVersion()+'\n'); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } DataModelVersionCheck(final DataBaseConfig dataBaseConfig);  }
DataModelVersionCheck extends HealthCheck { @Override protected Result check() { Mongo mongo = null; try{ final ServerAddress adress = new ServerAddress(config.getHost() , config.getPort()); mongo = new MongoClient(adress); final DB db = mongo.getDB(config.getDatastore()); if(config.getUser() != null && config.getPwd() != null){ db.authenticate(config.getUser(), config.getPwd()); } final Jongo jongo = new Jongo(db); final DbGrapesInfo info = jongo.getCollection(DbCollections.DB_GRAPES_INFO).findOne().as(DbGrapesInfo.class); if(info == null){ return Result.healthy("not found\n"); } return Result.healthy(info.getDatamodelVersion()+'\n'); } catch (Exception e) { return Result.unhealthy(e); } finally{ if(mongo != null){ mongo.close(); } } } DataModelVersionCheck(final DataBaseConfig dataBaseConfig);   }