Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,38 @@ public String startSut() {
"--app.jwt.secret=abcdef012345678901234567890123456789abcdef012345678901234567890123456789"
});

try {
Thread.sleep(3_000);
} catch (InterruptedException e) {
// do nothing
}

while (!isMongoClientReady()) {
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
// do nothing
}
}

return "http://localhost:" + getSutPort();
}

/**
* Checks if the mongo database is ready to receive commands using a ping command
* @return
*/
private boolean isMongoClientReady() {
try {
MongoDatabase db = mongoClient.getDatabase(MONGODB_DATABASE_NAME);
Document pingResult = db.runCommand(new Document("ping", 1));
return pingResult.getDouble("ok") == 1.0;
} catch (Exception ex) {
// Connection error
return false;
}
}

protected int getSutPort() {
return (Integer) ((Map) ctx.getEnvironment()
.getPropertySources().get("server.ports").getSource())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ public void preStart() {

@Override
public void postStart() {
try {
Thread.sleep(3_000);
} catch (InterruptedException e) {
// do nothing
}

while (!isMongoClientReady()) {
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
// do nothing
}
}
}

/**
* Checks if the mongo database is ready to receive commands using a ping command
* @return
*/
private boolean isMongoClientReady() {
try {
MongoDatabase db = mongoClient.getDatabase(MONGODB_DATABASE_NAME);
Document pingResult = db.runCommand(new Document("ping", 1));
return pingResult.getDouble("ok") == 1.0;
} catch (Exception ex) {
// Connection error
return false;
}
}

@Override
Expand Down Expand Up @@ -270,4 +298,6 @@ public List<DbSpecification> getDbSpecifications() {
public Object getMongoConnection() {
return mongoClient;
}


}