diff --git a/server/src/main/java/org/opensearch/search/DefaultSearchContext.java b/server/src/main/java/org/opensearch/search/DefaultSearchContext.java index 4d1d774ceb817..4bc40610facf2 100644 --- a/server/src/main/java/org/opensearch/search/DefaultSearchContext.java +++ b/server/src/main/java/org/opensearch/search/DefaultSearchContext.java @@ -49,6 +49,7 @@ import org.opensearch.common.lucene.search.Queries; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.BigArrays; +import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException; import org.opensearch.index.IndexService; import org.opensearch.index.IndexSettings; import org.opensearch.index.cache.bitset.BitsetFilterCache; @@ -309,7 +310,7 @@ public void preProcess(boolean rewrite) { int sliceLimit = indexService.getIndexSettings().getMaxSlicesPerPit(); int numSlices = sliceBuilder.getMax(); if (numSlices > sliceLimit) { - throw new IllegalArgumentException( + throw new OpenSearchRejectedExecutionException( "The number of slices [" + numSlices + "] is too large. It must " diff --git a/server/src/test/java/org/opensearch/search/DefaultSearchContextTests.java b/server/src/test/java/org/opensearch/search/DefaultSearchContextTests.java index 367257aaad5c6..96a4d9ad1d8d9 100644 --- a/server/src/test/java/org/opensearch/search/DefaultSearchContextTests.java +++ b/server/src/test/java/org/opensearch/search/DefaultSearchContextTests.java @@ -52,6 +52,7 @@ import org.opensearch.common.util.BigArrays; import org.opensearch.common.util.MockBigArrays; import org.opensearch.common.util.MockPageCacheRecycler; +import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException; import org.opensearch.index.IndexService; import org.opensearch.index.IndexSettings; import org.opensearch.index.cache.IndexCache; @@ -434,9 +435,12 @@ protected Engine.Searcher acquireSearcherInternal(String source) { when(sliceBuilder.getMax()).thenReturn(numSlicesForPit); context5.sliceBuilder(sliceBuilder); - exception = expectThrows(IllegalArgumentException.class, () -> context5.preProcess(false)); + OpenSearchRejectedExecutionException exception1 = expectThrows( + OpenSearchRejectedExecutionException.class, + () -> context5.preProcess(false) + ); assertThat( - exception.getMessage(), + exception1.getMessage(), equalTo( "The number of slices [" + numSlicesForPit