@Override public void check() throws Exception { //throws an exception if unhealthy mongo.getDatabaseNames(); }
private void verifyConnection() { mongo.getDatabaseNames(); } }
@Override public void check() throws Exception { //throws an exception if unhealthy mongo.getDatabaseNames(); }
@Override protected Result check() throws Exception { mongo.getDatabaseNames(); return Result.healthy("MongoDB is running... :)"); }
if (safe) m.setWriteConcern(WriteConcern.SAFE); m.getDatabaseNames();// to test connection db = m.getDB(dbName); if (user.length() > 0) {
databases.add(database); } else { databases = mongo.getDatabaseNames();
@Override public void close() { if (mongoDbName == null) { return; } try { Mongo mongo = new Mongo("127.0.0.1", mongoDbPort); DB db = mongo.getDB(mongoDbName); db.resetError(); db.dropDatabase(); DBObject err = db.getLastError(); if (err != null && err.get("err") != null) { logger.error("Could not drop database {}: {}", mongoDbName, err); } mongo.dropDatabase(mongoDbName); if (mongo.getDatabaseNames().contains(mongoDbName)) { logger.error("Database {} will not go away!", mongoDbName); } } catch (UnknownHostException e) { // weird } catch (MongoException e) { logger.warn("Could not drop database {}: {}", mongoDbName, e.getMessage()); } }
private static boolean testMongoAvailability() { Mongo mongo = null; try { MongoClientURI uri = new MongoClientURI(MONGO_URI + "?connectTimeoutMS=3000"); mongo = new MongoClient(uri); mongo.getDatabaseNames(); return true; } catch (Exception e) { return false; } finally { if (mongo != null) { mongo.close(); } } }
@Test public void dbNameWithSpace() throws Exception { // check initial creation assertThat(mongoClient.getDatabaseNames().contains("foo bar")).isFalse(); assertThat(mongoClient.getDatabaseNames().contains("foo%20bar")).isFalse(); ResourceState config = new DefaultResourceState(); config.putProperty("db", "foo bar"); setUpSystem(config); // check via reading from LiveOak ResourceState result = client.read(new RequestContext.Builder().build(), ADMIN_PATH); assertThat(result.getProperty("db")).isEqualTo("foo bar"); // we need to write something to the database, otherwise its not created in the database server client.create(new RequestContext.Builder().build(), "/testApp/storage/", new DefaultResourceState()); // check via what is in mongo assertThat(mongoClient.getDatabaseNames().contains("foo%20bar")).isTrue(); assertThat(mongoClient.getDatabaseNames().contains("foo bar")).isFalse(); mongoClient.dropDatabase("foo%20bar"); // check on update result.putProperty("db", "hello <world>"); ResourceState updatedResult = client.update(new RequestContext.Builder().build(), ADMIN_PATH, result); assertThat(updatedResult.getProperty("db")).isEqualTo("hello <world>"); // check what is in mongo assertThat(mongoClient.getDatabaseNames().contains("hello%20%3Cworld%3E")).isTrue(); assertThat(mongoClient.getDatabaseNames().contains("foo <world>")).isFalse(); mongoClient.dropDatabase("hello%20%3Cworld%3E"); }