瀏覽代碼

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
Tal Levy 6 年之前
父節點
當前提交
97efec36e1
共有 1 個文件被更改,包括 9 次插入5 次删除
  1. 9 5
      modules/reindex/src/test/java/org/elasticsearch/index/reindex/RethrottleTests.java

+ 9 - 5
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 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);
             }
         });