From 4eff14775ad7ad81c91a97a2b65bf6f28f3b88a7 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Tue, 19 Feb 2019 09:37:02 -0800 Subject: [PATCH] fix RethrottleTests retry (#38978) 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 --- .../index/reindex/RethrottleTests.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RethrottleTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RethrottleTests.java index 6572313308b32..58067cd2cdbbf 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RethrottleTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RethrottleTests.java @@ -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 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 @@ private ListTasksResponse rethrottleTask(TaskId taskToRethrottle, float newReque 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); } });