Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transform] Fix casting in ExceptionRootCauseFinder #66123

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Throwable getRootCauseException(Throwable t) {
Throwable unwrappedThrowable = org.elasticsearch.ExceptionsHelper.unwrapCause(t);

if (unwrappedThrowable instanceof SearchPhaseExecutionException) {
SearchPhaseExecutionException searchPhaseException = (SearchPhaseExecutionException) t;
SearchPhaseExecutionException searchPhaseException = (SearchPhaseExecutionException) unwrappedThrowable;
for (ShardSearchFailure shardFailure : searchPhaseException.shardFailures()) {
Throwable unwrappedShardFailure = org.elasticsearch.ExceptionsHelper.unwrapCause(shardFailure.getCause());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@

package org.elasticsearch.xpack.transform.utils;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.DocWriteRequest.OpType;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.translog.TranslogException;
import org.elasticsearch.indices.IndexCreationException;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESTestCase;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.Matchers.equalTo;

public class ExceptionRootCauseFinderTests extends ESTestCase {

public void testFetFirstIrrecoverableExceptionFromBulkResponses() {
Map<Integer, BulkItemResponse> bulkItemResponses = new HashMap<>();

Expand Down Expand Up @@ -142,10 +149,21 @@ public void testFetFirstIrrecoverableExceptionFromBulkResponses() {
assertNull(ExceptionRootCauseFinder.getFirstIrrecoverableExceptionFromBulkResponses(bulkItemResponses.values()));
}

public void testGetRootCauseException_GivenWrappedSearchPhaseException() {
SearchPhaseExecutionException searchPhaseExecutionException = new SearchPhaseExecutionException("test-phase",
"partial shards failure", new ShardSearchFailure[] { new ShardSearchFailure(new ElasticsearchException("for the cause!")) });

Throwable rootCauseException = ExceptionRootCauseFinder.getRootCauseException(
new IndexCreationException("test-index", searchPhaseExecutionException));

assertThat(rootCauseException.getMessage(), equalTo("for the cause!"));
}

private static void assertFirstException(Collection<BulkItemResponse> bulkItemResponses, Class<?> expectedClass, String message) {
Throwable t = ExceptionRootCauseFinder.getFirstIrrecoverableExceptionFromBulkResponses(bulkItemResponses);
assertNotNull(t);
assertEquals(t.getClass(), expectedClass);
assertEquals(t.getMessage(), message);
}

}