use of net.jodah.failsafe.RetryPolicy in project ddf by codice.
the class SolrClientAdaptor method init.
public void init() {
RetryPolicy retryPolicy = new RetryPolicy();
Failsafe.with(retryPolicy).onRetry((exception) -> LOGGER.debug("Failed to get Solr client for SolrCache. Retrying...", exception)).onSuccess((result, context) -> LOGGER.debug("SolrCache successfully initialized after {} retries", context.getExecutions())).run(this::getSolrClient);
}
use of net.jodah.failsafe.RetryPolicy in project ddf by codice.
the class SolrCloudClientFactory method isCollectionReady.
private static boolean isCollectionReady(CloudSolrClient client, String collection) {
RetryPolicy retryPolicy = new RetryPolicy().retryWhen(false).withMaxRetries(30).withDelay(1, TimeUnit.SECONDS);
boolean collectionCreated = Failsafe.with(retryPolicy).onFailure(failure -> LOGGER.debug("All attempts failed to read Zookeeper state for collection existence (" + collection + ")", failure)).get(() -> client.getZkStateReader().getClusterState().hasCollection(collection));
if (!collectionCreated) {
LOGGER.debug("Timeout while waiting for collection to be created: " + collection);
return false;
}
boolean shardsStarted = Failsafe.with(retryPolicy).onFailure(failure -> LOGGER.debug("All attempts failed to read Zookeeper state for collection's shard count (" + collection + ")", failure)).get(() -> client.getZkStateReader().getClusterState().getSlices(collection).size() == SHARD_COUNT);
if (!shardsStarted) {
LOGGER.debug("Timeout while waiting for collection shards to start: " + collection);
}
return shardsStarted;
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method shouldRequireValidDelay.
public void shouldRequireValidDelay() {
shouldFail(() -> new RetryPolicy().withDelay(5, null), NullPointerException.class);
shouldFail(() -> new RetryPolicy().withMaxDuration(1, TimeUnit.MILLISECONDS).withDelay(100, TimeUnit.MILLISECONDS), IllegalStateException.class);
shouldFail(() -> new RetryPolicy().withBackoff(1, 2, TimeUnit.MILLISECONDS).withDelay(100, TimeUnit.MILLISECONDS), IllegalStateException.class);
shouldFail(() -> new RetryPolicy().withDelay(-1, TimeUnit.MILLISECONDS), IllegalArgumentException.class);
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method testCanRetryForFailurePredicate.
public void testCanRetryForFailurePredicate() {
RetryPolicy policy = new RetryPolicy().retryOn(failure -> failure instanceof ConnectException);
assertTrue(policy.canRetryFor(null, new ConnectException()));
assertFalse(policy.canRetryFor(null, new IllegalStateException()));
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method testCanRetryForResultPredicate.
public void testCanRetryForResultPredicate() {
RetryPolicy policy = new RetryPolicy().retryIf((Integer result) -> result > 100);
assertTrue(policy.canRetryFor(110, null));
assertFalse(policy.canRetryFor(50, null));
}
Aggregations