use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.
the class ExceptionSerializationTests method testSearchPhaseExecutionException.
public void testSearchPhaseExecutionException() throws IOException {
ShardSearchFailure[] empty = new ShardSearchFailure[0];
SearchPhaseExecutionException ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), empty));
assertEquals("boom", ex.getPhaseName());
assertEquals("baam", ex.getMessage());
assertTrue(ex.getCause() instanceof NullPointerException);
assertEquals(empty.length, ex.shardFailures().length);
ShardSearchFailure[] one = new ShardSearchFailure[] { new ShardSearchFailure(new IllegalArgumentException("nono!")) };
ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), one));
assertEquals("boom", ex.getPhaseName());
assertEquals("baam", ex.getMessage());
assertTrue(ex.getCause() instanceof NullPointerException);
assertEquals(one.length, ex.shardFailures().length);
assertTrue(ex.shardFailures()[0].getCause() instanceof IllegalArgumentException);
}
use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.
the class OpenSearchExceptionTests method randomExceptions.
public static Tuple<Throwable, OpenSearchException> randomExceptions() {
Throwable actual;
OpenSearchException expected;
int type = randomIntBetween(0, 5);
switch(type) {
case 0:
actual = new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES));
expected = new OpenSearchException("OpenSearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]");
break;
case // Simple opensearch exception with headers (other metadata of type number are not parsed)
1:
actual = new ParsingException(3, 2, "Unknown identifier", null);
expected = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=Unknown identifier]");
break;
case 2:
actual = new SearchParseException(SHARD_TARGET, "Parse failure", new XContentLocation(12, 98));
expected = new OpenSearchException("OpenSearch exception [type=search_parse_exception, reason=Parse failure]");
break;
case 3:
actual = new IllegalArgumentException("Closed resource", new RuntimeException("Resource"));
expected = new OpenSearchException("OpenSearch exception [type=illegal_argument_exception, reason=Closed resource]", new OpenSearchException("OpenSearch exception [type=runtime_exception, reason=Resource]"));
break;
case 4:
actual = new SearchPhaseExecutionException("search", "all shards failed", new ShardSearchFailure[] { new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new ShardId("foo", "_na_", 1), null, OriginalIndices.NONE)) });
expected = new OpenSearchException("OpenSearch exception [type=search_phase_execution_exception, " + "reason=all shards failed]");
expected.addMetadata("opensearch.phase", "search");
break;
case 5:
actual = new OpenSearchException("Parsing failed", new ParsingException(9, 42, "Wrong state", new NullPointerException("Unexpected null value")));
OpenSearchException expectedCause = new OpenSearchException("OpenSearch exception [type=parsing_exception, " + "reason=Wrong state]", new OpenSearchException("OpenSearch exception [type=null_pointer_exception, " + "reason=Unexpected null value]"));
expected = new OpenSearchException("OpenSearch exception [type=exception, reason=Parsing failed]", expectedCause);
break;
default:
throw new UnsupportedOperationException("No randomized exceptions generated for type [" + type + "]");
}
if (actual instanceof OpenSearchException) {
OpenSearchException actualException = (OpenSearchException) actual;
if (randomBoolean()) {
int nbHeaders = randomIntBetween(1, 5);
Map<String, List<String>> randomHeaders = new HashMap<>(nbHeaders);
for (int i = 0; i < nbHeaders; i++) {
List<String> values = new ArrayList<>();
int nbValues = randomIntBetween(1, 3);
for (int j = 0; j < nbValues; j++) {
values.add(frequently() ? randomAlphaOfLength(5) : "");
}
randomHeaders.put("header_" + i, values);
}
for (Map.Entry<String, List<String>> entry : randomHeaders.entrySet()) {
actualException.addHeader(entry.getKey(), entry.getValue());
expected.addHeader(entry.getKey(), entry.getValue());
}
if (rarely()) {
// Empty or null headers are not printed out by the toXContent method
actualException.addHeader("ignored", randomBoolean() ? emptyList() : null);
}
}
if (randomBoolean()) {
int nbMetadata = randomIntBetween(1, 5);
Map<String, List<String>> randomMetadata = new HashMap<>(nbMetadata);
for (int i = 0; i < nbMetadata; i++) {
List<String> values = new ArrayList<>();
int nbValues = randomIntBetween(1, 3);
for (int j = 0; j < nbValues; j++) {
values.add(frequently() ? randomAlphaOfLength(5) : "");
}
randomMetadata.put("opensearch.metadata_" + i, values);
}
for (Map.Entry<String, List<String>> entry : randomMetadata.entrySet()) {
actualException.addMetadata(entry.getKey(), entry.getValue());
expected.addMetadata(entry.getKey(), entry.getValue());
}
if (rarely()) {
// Empty or null metadata are not printed out by the toXContent method
actualException.addMetadata("opensearch.ignored", randomBoolean() ? emptyList() : null);
}
}
if (randomBoolean()) {
int nbResources = randomIntBetween(1, 5);
for (int i = 0; i < nbResources; i++) {
String resourceType = "type_" + i;
String[] resourceIds = new String[randomIntBetween(1, 3)];
for (int j = 0; j < resourceIds.length; j++) {
resourceIds[j] = frequently() ? randomAlphaOfLength(5) : "";
}
actualException.setResources(resourceType, resourceIds);
expected.setResources(resourceType, resourceIds);
}
}
}
return new Tuple<>(actual, expected);
}
use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.
the class ExceptionsHelperTests method createShardFailureParsingException.
private static ShardSearchFailure createShardFailureParsingException(String error, String nodeId, String index, int shardId, String clusterAlias) {
ParsingException ex = new ParsingException(0, 0, error, new IllegalArgumentException("some bad argument"));
ex.setIndex(index);
return new ShardSearchFailure(ex, createSearchShardTarget(nodeId, shardId, index, clusterAlias));
}
use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.
the class ExceptionsHelperTests method testGroupByNullIndex.
public void testGroupByNullIndex() {
ShardOperationFailedException[] failures = new ShardOperationFailedException[] { new ShardSearchFailure(new IllegalArgumentException("error")), new ShardSearchFailure(new ParsingException(0, 0, "error", null)) };
ShardOperationFailedException[] groupBy = ExceptionsHelper.groupBy(failures);
assertThat(groupBy.length, equalTo(2));
}
use of org.opensearch.action.search.ShardSearchFailure in project OpenSearch by opensearch-project.
the class ExceptionsHelperTests method createShardFailureQueryShardException.
private static ShardSearchFailure createShardFailureQueryShardException(String error, String indexName, String clusterAlias) {
Index index = new Index(RemoteClusterAware.buildRemoteIndexName(clusterAlias, indexName), "uuid");
QueryShardException queryShardException = new QueryShardException(index, error, new IllegalArgumentException("parse error"));
return new ShardSearchFailure(queryShardException, null);
}
Aggregations