-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
- Loading branch information
1 parent
59046ba
commit b583b61
Showing
4 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...t/java/org/opensearch/wlm/listeners/QueryGroupRequestRejectionOperationListenerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.wlm.listeners; | ||
|
||
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.threadpool.TestThreadPool; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.wlm.QueryGroupService; | ||
import org.opensearch.wlm.QueryGroupTask; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class QueryGroupRequestRejectionOperationListenerTests extends OpenSearchTestCase { | ||
ThreadPool testThreadPool; | ||
QueryGroupService queryGroupService; | ||
QueryGroupRequestRejectionOperationListener sut; | ||
|
||
|
||
public void setUp() throws Exception { | ||
super.setUp(); | ||
testThreadPool = new TestThreadPool("RejectionTestThreadPool"); | ||
} | ||
|
||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
testThreadPool.shutdown(); | ||
} | ||
|
||
public void testRejectionCase() { | ||
queryGroupService = mock(QueryGroupService.class); | ||
sut = new QueryGroupRequestRejectionOperationListener(queryGroupService, testThreadPool); | ||
final String testQueryGroupId = "asdgasgkajgkw3141_3rt4t"; | ||
testThreadPool.getThreadContext().putHeader(QueryGroupTask.QUERY_GROUP_ID_HEADER, testQueryGroupId); | ||
when(queryGroupService.shouldRejectFor(testQueryGroupId)).thenReturn(Optional.of("Test query group is contended")); | ||
|
||
assertThrows(OpenSearchRejectedExecutionException.class, () -> sut.onRequestStart(null)); | ||
} | ||
|
||
public void testNonRejectionCase() { | ||
queryGroupService = mock(QueryGroupService.class); | ||
sut = new QueryGroupRequestRejectionOperationListener(queryGroupService, testThreadPool); | ||
final String testQueryGroupId = "asdgasgkajgkw3141_3rt4t"; | ||
testThreadPool.getThreadContext().putHeader(QueryGroupTask.QUERY_GROUP_ID_HEADER, testQueryGroupId); | ||
when(queryGroupService.shouldRejectFor(testQueryGroupId)).thenReturn(Optional.empty()); | ||
|
||
sut.onRequestStart(null); | ||
} | ||
} |