forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix minor issues with SQL pIT refactor
Signed-off-by: Manasvini B S <[email protected]>
- Loading branch information
1 parent
ce17d0a
commit 90ba952
Showing
3 changed files
with
95 additions
and
6 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
89 changes: 89 additions & 0 deletions
89
...src/test/java/org/opensearch/sql/legacy/executor/format/PrettyFormatRestExecutorTest.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,89 @@ | ||
package org.opensearch.sql.legacy.executor.format; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.opensearch.sql.common.setting.Settings.Key.SQL_PAGINATION_API_SEARCH_AFTER; | ||
|
||
import org.apache.lucene.search.TotalHits; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.search.SearchHit; | ||
import org.opensearch.search.SearchHits; | ||
import org.opensearch.sql.legacy.esdomain.LocalClusterState; | ||
import org.opensearch.sql.legacy.query.DefaultQueryAction; | ||
import org.opensearch.sql.legacy.request.SqlRequest; | ||
import org.opensearch.sql.opensearch.setting.OpenSearchSettings; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class PrettyFormatRestExecutorTest { | ||
|
||
@Mock private SearchResponse searchResponse; | ||
@Mock private SearchHits searchHits; | ||
@Mock private SearchHit searchHit; | ||
@Mock private DefaultQueryAction queryAction; | ||
@Mock private SqlRequest sqlRequest; | ||
private PrettyFormatRestExecutor executor; | ||
|
||
@Before | ||
public void setUp() { | ||
OpenSearchSettings settings = mock(OpenSearchSettings.class); | ||
LocalClusterState.state().setPluginSettings(settings); | ||
when(LocalClusterState.state().getSettingValue(SQL_PAGINATION_API_SEARCH_AFTER)) | ||
.thenReturn(true); | ||
when(queryAction.getSqlRequest()).thenReturn(sqlRequest); | ||
executor = new PrettyFormatRestExecutor("jdbc"); | ||
} | ||
|
||
@Test | ||
public void testIsDefaultCursor_fetchSizeZero() { | ||
when(sqlRequest.fetchSize()).thenReturn(0); | ||
|
||
assertFalse(executor.isDefaultCursor(searchResponse, queryAction)); | ||
} | ||
|
||
@Test | ||
public void testIsDefaultCursor_totalHitsLessThanFetchSize() { | ||
when(sqlRequest.fetchSize()).thenReturn(10); | ||
when(searchResponse.getHits()) | ||
.thenReturn( | ||
new SearchHits( | ||
new SearchHit[] {searchHit}, new TotalHits(5, TotalHits.Relation.EQUAL_TO), 1.0F)); | ||
|
||
assertFalse(executor.isDefaultCursor(searchResponse, queryAction)); | ||
} | ||
|
||
@Test | ||
public void testIsDefaultCursor_totalHitsGreaterThanOrEqualToFetchSize() { | ||
when(sqlRequest.fetchSize()).thenReturn(5); | ||
when(searchResponse.getHits()) | ||
.thenReturn( | ||
new SearchHits( | ||
new SearchHit[] {searchHit}, new TotalHits(5, TotalHits.Relation.EQUAL_TO), 1.0F)); | ||
|
||
assertTrue(executor.isDefaultCursor(searchResponse, queryAction)); | ||
} | ||
|
||
@Test | ||
public void testIsDefaultCursor_PaginationApiDisabled() { | ||
when(LocalClusterState.state().getSettingValue(SQL_PAGINATION_API_SEARCH_AFTER)) | ||
.thenReturn(false); | ||
when(searchResponse.getScrollId()).thenReturn("someScrollId"); | ||
|
||
assertTrue(executor.isDefaultCursor(searchResponse, queryAction)); | ||
} | ||
|
||
@Test | ||
public void testIsDefaultCursor_PaginationApiDisabled_NoScrollId() { | ||
when(LocalClusterState.state().getSettingValue(SQL_PAGINATION_API_SEARCH_AFTER)) | ||
.thenReturn(false); | ||
when(searchResponse.getScrollId()).thenReturn(null); | ||
|
||
assertFalse(executor.isDefaultCursor(searchResponse, queryAction)); | ||
} | ||
} |