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.
Integration tests for fetch_size, max_result_window, and query.size_l…
…imit (#248) Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
- Loading branch information
Max Ksyunz
authored
Mar 27, 2023
1 parent
ca20d16
commit a58733e
Showing
3 changed files
with
109 additions
and
4 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
98 changes: 98 additions & 0 deletions
98
integ-test/src/test/java/org/opensearch/sql/sql/PaginationWindowIT.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,98 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.sql; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_PHRASE; | ||
|
||
import java.io.IOException; | ||
import org.json.JSONObject; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.sql.legacy.SQLIntegTestCase; | ||
|
||
public class PaginationWindowIT extends SQLIntegTestCase { | ||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.PHRASE); | ||
} | ||
|
||
@After | ||
void resetParams() throws IOException { | ||
resetMaxResultWindow(TEST_INDEX_PHRASE); | ||
resetQuerySizeLimit(); | ||
} | ||
|
||
@Test | ||
public void testFetchSizeLessThanMaxResultWindow() throws IOException { | ||
setMaxResultWindow(TEST_INDEX_PHRASE, 6); | ||
JSONObject response = executeQueryTemplate("SELECT * FROM %s", TEST_INDEX_PHRASE, 5); | ||
|
||
String cursor = ""; | ||
int numRows = 0; | ||
do { | ||
// Process response | ||
cursor = response.getString("cursor"); | ||
numRows += response.getJSONArray("datarows").length(); | ||
response = executeCursorQuery(cursor); | ||
} while (response.has("cursor")); | ||
|
||
var countRows = executeJdbcRequest("SELECT COUNT(*) FROM " + TEST_INDEX_PHRASE) | ||
.getJSONArray("datarows") | ||
.getJSONArray(0) | ||
.get(0); | ||
assertEquals(countRows, numRows); | ||
} | ||
|
||
@Test | ||
public void testQuerySizeLimitDoesNotEffectTotalRowsReturned() throws IOException { | ||
int querySizeLimit = 4; | ||
setQuerySizeLimit(querySizeLimit); | ||
JSONObject response = executeQueryTemplate("SELECT * FROM %s", TEST_INDEX_PHRASE, 5); | ||
assertTrue(response.getInt("size") > querySizeLimit); | ||
|
||
String cursor = ""; | ||
int numRows = 0; | ||
do { | ||
// Process response | ||
cursor = response.getString("cursor"); | ||
numRows += response.getJSONArray("datarows").length(); | ||
response = executeCursorQuery(cursor); | ||
} while (response.has("cursor")); | ||
|
||
var countRows = executeJdbcRequest("SELECT COUNT(*) FROM " + TEST_INDEX_PHRASE) | ||
.getJSONArray("datarows") | ||
.getJSONArray(0) | ||
.get(0); | ||
assertEquals(countRows, numRows); | ||
assertTrue(numRows > querySizeLimit); | ||
} | ||
|
||
@Test | ||
public void testQuerySizeLimitDoesNotEffectPageSize() throws IOException { | ||
setQuerySizeLimit(3); | ||
setMaxResultWindow(TEST_INDEX_PHRASE, 4); | ||
var response | ||
= executeQueryTemplate("SELECT * FROM %s", TEST_INDEX_PHRASE, 4); | ||
assertEquals(4, response.getInt("size")); | ||
|
||
var response2 | ||
= executeQueryTemplate("SELECT * FROM %s", TEST_INDEX_PHRASE, 2); | ||
assertEquals(2, response2.getInt("size")); | ||
} | ||
|
||
@Test | ||
public void testFetchSizeLargerThanResultWindowFails() throws IOException { | ||
final int window = 2; | ||
setMaxResultWindow(TEST_INDEX_PHRASE, 2); | ||
assertThrows(ResponseException.class, | ||
() -> executeQueryTemplate("SELECT * FROM %s", | ||
TEST_INDEX_PHRASE, window + 1)); | ||
resetMaxResultWindow(TEST_INDEX_PHRASE); | ||
} | ||
|
||
|
||
} |