Skip to content

Commit 97efec3

Browse files
authored
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
1 parent 0409228 commit 97efec3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

modules/reindex/src/test/java/org/elasticsearch/index/reindex/RethrottleTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.index.reindex;
2121

2222
import org.elasticsearch.ElasticsearchException;
23+
import org.elasticsearch.ExceptionsHelper;
2324
import org.elasticsearch.action.ActionFuture;
2425
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
2526
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
@@ -37,6 +38,7 @@
3738
import static org.hamcrest.Matchers.allOf;
3839
import static org.hamcrest.Matchers.both;
3940
import static org.hamcrest.Matchers.empty;
41+
import static org.hamcrest.Matchers.equalTo;
4042
import static org.hamcrest.Matchers.greaterThan;
4143
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4244
import static org.hamcrest.Matchers.hasSize;
@@ -191,13 +193,15 @@ private ListTasksResponse rethrottleTask(TaskId taskToRethrottle, float newReque
191193
assertThat(rethrottleResponse.getTasks(), hasSize(1));
192194
response.set(rethrottleResponse);
193195
} catch (ElasticsearchException e) {
194-
if (e.getCause() instanceof IllegalArgumentException) {
195-
// We want to retry in this case so we throw an assertion error
196-
logger.info("caught unprepared task, retrying until prepared");
197-
throw new AssertionError("Rethrottle request for task [" + taskToRethrottle.getId() + "] failed", e);
198-
} else {
196+
Throwable unwrapped = ExceptionsHelper.unwrap(e, IllegalArgumentException.class);
197+
if (unwrapped == null) {
199198
throw e;
200199
}
200+
// We want to retry in this case so we throw an assertion error
201+
assertThat(unwrapped.getMessage(), equalTo("task [" + taskToRethrottle.getId()
202+
+ "] has not yet been initialized to the point where it knows how to rethrottle itself"));
203+
logger.info("caught unprepared task, retrying until prepared");
204+
throw new AssertionError("Rethrottle request for task [" + taskToRethrottle.getId() + "] failed", e);
201205
}
202206
});
203207

0 commit comments

Comments
 (0)