use of org.apache.stanbol.commons.testing.http.RetryLoop in project stanbol by apache.
the class EntityhubTestBase method checkEntityhubReady.
@Before
public void checkEntityhubReady() throws Exception {
// Check only once per test run
if (entityhubReady) {
return;
}
// If we timed out previously, don't waste time checking again
if (timedOut) {
fail("Timeout in previous check of the entityhub, cannot run tests");
}
// We'll retry the check for all engines to be ready
// for up to ENGINES_TIMEOUT_SECONDS
final RetryLoop.Condition c = new RetryLoop.Condition() {
@Override
public boolean isTrue() throws Exception {
/* Check the entityhub and the referenced site dbpedia
*/
executor.execute(builder.buildGetRequest("/entityhub").withHeader("Accept", "text/html")).assertStatus(200).assertContentType("text/html");
/* List of expected referencedSites could also be made
* configurable via system properties, but we don't expect it
* to change often.
*/
RequestExecutor re = executor.execute(builder.buildGetRequest("/entityhub/sites/referenced").withHeader("Accept", "application/json"));
re.assertStatus(200);
re.assertContentType("application/json");
//check if all the required referenced sites are available
for (String referencedSite : referencedSites) {
if (referencedSite != null && !referencedSite.isEmpty()) {
re.assertContentRegexp(String.format("http:\\\\/\\\\/.*\\\\/entityhub\\\\/site\\\\/%s\\\\/", referencedSite));
}
}
//this ensures that JSON and RDF serializer services are up and running
for (String referencedSite : referencedSites) {
re = executor.execute(builder.buildGetRequest("/entityhub/site/" + referencedSite).withHeader("Accept", //check JSON serializer
"application/json"));
re.assertStatus(200);
re.assertContentType("application/json");
re = executor.execute(builder.buildGetRequest("/entityhub/site/" + referencedSite).withHeader("Accept", //check RDF serializer
"application/rdf+xml"));
re.assertStatus(200);
re.assertContentType("application/rdf+xml");
}
log.info("Entityhub services checked, all present");
return true;
}
@Override
public String getDescription() {
return "Checking that teh Entityhub and the dbpedia ReferencedSite are ready";
}
};
new RetryLoop(c, ENTITYHUB_TIMEOUT_SECONDS, WAIT_BETWEEN_TRIES_MSEC) {
@Override
protected void reportException(Throwable t) {
log.info("Exception in RetryLoop, will retry for up to " + getRemainingTimeSeconds() + " seconds: " + t);
}
protected void onTimeout() {
timedOut = true;
}
};
entityhubReady = true;
}
Aggregations