Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
nknize committed May 11, 2023

Verified

This commit was signed with the committer’s verified signature.
nknize Nick Knize
1 parent fbb3330 commit ba35fbd
Showing 7 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ public abstract class BaseOpenSearchException extends RuntimeException {
protected static final String RESOURCE_METADATA_TYPE_KEY = "opensearch.resource.type";
protected static final String RESOURCE_METADATA_ID_KEY = "opensearch.resource.id";
protected static final Version UNKNOWN_VERSION_ADDED = Version.fromId(0);
protected static final String INDEX_METADATA_KEY = "opensearch.index";
private static final boolean REST_EXCEPTION_SKIP_CAUSE_DEFAULT = false;
protected final Map<String, List<String>> metadata = new HashMap<>();
protected final Map<String, List<String>> headers = new HashMap<>();
@@ -524,4 +525,12 @@ public String getResourceType() {
}
return null;
}

public String getIndexName() {
List<String> index = getMetadata(INDEX_METADATA_KEY);
if (index != null && index.isEmpty() == false) {
return index.get(0);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@

package org.opensearch.search.aggregations.bucket;

import org.opensearch.OpenSearchException;
import org.opensearch.BaseOpenSearchException;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchPhaseExecutionException;
import org.opensearch.action.search.SearchResponse;
@@ -650,9 +650,9 @@ public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception {
.get();
fail("Expected an exception");
} catch (SearchPhaseExecutionException e) {
OpenSearchException[] rootCauses = e.guessRootCauses();
BaseOpenSearchException[] rootCauses = e.guessRootCauses();
if (rootCauses.length == 1) {
OpenSearchException rootCause = rootCauses[0];
BaseOpenSearchException rootCause = rootCauses[0];
if (rootCause instanceof AggregationExecutionException) {
AggregationExecutionException aggException = (AggregationExecutionException) rootCause;
assertThat(aggException.getMessage(), Matchers.startsWith("Invalid aggregation order path"));
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
package org.opensearch.search.aggregations.bucket;

import com.carrotsearch.hppc.LongHashSet;
import org.opensearch.OpenSearchException;
import org.opensearch.BaseOpenSearchException;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchPhaseExecutionException;
import org.opensearch.action.search.SearchResponse;
@@ -689,9 +689,9 @@ public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception {
.get();
fail("Expected an exception");
} catch (SearchPhaseExecutionException e) {
OpenSearchException[] rootCauses = e.guessRootCauses();
BaseOpenSearchException[] rootCauses = e.guessRootCauses();
if (rootCauses.length == 1) {
OpenSearchException rootCause = rootCauses[0];
BaseOpenSearchException rootCause = rootCauses[0];
if (rootCause instanceof AggregationExecutionException) {
AggregationExecutionException aggException = (AggregationExecutionException) rootCause;
assertThat(aggException.getMessage(), Matchers.startsWith("Invalid aggregation order path"));
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@

package org.opensearch.search.aggregations.bucket.terms;

import org.opensearch.BaseOpenSearchException;
import org.opensearch.OpenSearchException;
import org.opensearch.action.search.SearchPhaseExecutionException;
import org.opensearch.action.search.SearchResponse;
@@ -420,9 +421,9 @@ public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception {
.get();
fail("Expected an exception");
} catch (SearchPhaseExecutionException e) {
OpenSearchException[] rootCauses = e.guessRootCauses();
BaseOpenSearchException[] rootCauses = e.guessRootCauses();
if (rootCauses.length == 1) {
OpenSearchException rootCause = rootCauses[0];
BaseOpenSearchException rootCause = rootCauses[0];
if (rootCause instanceof AggregationExecutionException) {
AggregationExecutionException aggException = (AggregationExecutionException) rootCause;
assertThat(aggException.getMessage(), startsWith("Invalid aggregation order path"));
Original file line number Diff line number Diff line change
@@ -88,7 +88,6 @@ public class OpenSearchException extends BaseOpenSearchException implements ToXC
*/
private static final int CUSTOM_ELASTICSEARCH_EXCEPTIONS_BASE_ID = 10000;

private static final String INDEX_METADATA_KEY = "opensearch.index";
private static final String INDEX_METADATA_KEY_UUID = "opensearch.index_uuid";
private static final String SHARD_METADATA_KEY = "opensearch.shard";

Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ public Throwable getCause() {
Throwable cause = super.getCause();
if (cause == null) {
// fall back to guessed root cause
for (OpenSearchException rootCause : guessRootCauses()) {
for (BaseOpenSearchException rootCause : guessRootCauses()) {
return rootCause;
}
}
@@ -174,14 +174,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

@Override
public OpenSearchException[] guessRootCauses() {
public BaseOpenSearchException[] guessRootCauses() {
ShardOperationFailedException[] failures = ExceptionsHelper.groupBy(shardFailures);
List<BaseOpenSearchException> rootCauses = new ArrayList<>(failures.length);
for (ShardOperationFailedException failure : failures) {
BaseOpenSearchException[] guessRootCauses = BaseOpenSearchException.guessRootCauses(failure.getCause());
rootCauses.addAll(Arrays.asList(guessRootCauses));
}
return rootCauses.toArray(new OpenSearchException[0]);
return rootCauses.toArray(new BaseOpenSearchException[0]);
}

@Override
Original file line number Diff line number Diff line change
@@ -175,14 +175,14 @@ public void testGuessRootCause() {
"all shards failed",
new ShardSearchFailure[] { failure, failure1, failure2 }
);
final OpenSearchException[] rootCauses = ex.guessRootCauses();
final BaseOpenSearchException[] rootCauses = ex.guessRootCauses();
assertEquals(rootCauses.length, 2);
assertEquals(BaseOpenSearchException.getExceptionName(rootCauses[0]), "parsing_exception");
assertEquals(rootCauses[0].getMessage(), "foobar");
assertEquals(1, ((ParsingException) rootCauses[0]).getLineNumber());
assertEquals(2, ((ParsingException) rootCauses[0]).getColumnNumber());
assertEquals("query_shard_exception", BaseOpenSearchException.getExceptionName(rootCauses[1]));
assertEquals("foo1", rootCauses[1].getIndex().getName());
assertEquals("foo1", rootCauses[1].getIndexName());
assertEquals("foobar", rootCauses[1].getMessage());
}

0 comments on commit ba35fbd

Please sign in to comment.