fix RethrottleTests retry (#38978) (#39131)

the RethrottleTests assumed that tasks that were
unprepared to rethrottle would bubble up into the
Rethrottle response as an ElasticsearchException
wrapping an IllegalArgumentException. This seems to
have changed to potentially involve further levels of
wrapping.

This change makes the retry logic more resilient to
arbitrary nesting of the underlying IllegalArgumentException
This commit is contained in:
Tal Levy 2019-02-19 11:10:39 -08:00 committed by GitHub
parent 109b6451fd
commit f30f1fe9b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.reindex;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
@ -37,6 +38,7 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
@ -191,13 +193,15 @@ public class RethrottleTests extends ReindexTestCase {
assertThat(rethrottleResponse.getTasks(), hasSize(1));
response.set(rethrottleResponse);
} catch (ElasticsearchException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// We want to retry in this case so we throw an assertion error
logger.info("caught unprepared task, retrying until prepared");
throw new AssertionError("Rethrottle request for task [" + taskToRethrottle.getId() + "] failed", e);
} else {
Throwable unwrapped = ExceptionsHelper.unwrap(e, IllegalArgumentException.class);
if (unwrapped == null) {
throw e;
}
// We want to retry in this case so we throw an assertion error
assertThat(unwrapped.getMessage(), equalTo("task [" + taskToRethrottle.getId()
+ "] has not yet been initialized to the point where it knows how to rethrottle itself"));
logger.info("caught unprepared task, retrying until prepared");
throw new AssertionError("Rethrottle request for task [" + taskToRethrottle.getId() + "] failed", e);
}
});