-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for providing a timeout option while setting up a conne…
…ction (#85)
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pinotdb import connect | ||
import time | ||
import pytest | ||
import httpx | ||
|
||
## Start Pinot Quickstart Batch | ||
## docker run --name pinot-quickstart -p 2123:2123 -p 9000:9000 -p 8000:8000 \ | ||
## -d apachepinot/pinot:latest QuickStart -type hybrid | ||
|
||
def run_pinot_quickstart_timeout_example() -> None: | ||
|
||
#Test 1 : Try without timeout. The request should succeed. | ||
|
||
conn = connect(host="localhost", port=8000, path="/query/sql", scheme="http") | ||
curs = conn.cursor() | ||
sql = "SELECT * FROM airlineStats LIMIT 5" | ||
print(f"Sending SQL to Pinot: {sql}") | ||
curs.execute(sql) | ||
conn.close() | ||
|
||
#Test 2 : Try with timeout=None. The request should succeed. | ||
|
||
conn = connect(host="localhost", port=8000, path="/query/sql", scheme="http", timeout=None) | ||
curs = conn.cursor() | ||
sql = "SELECT count(*) FROM airlineStats LIMIT 5" | ||
print(f"Sending SQL to Pinot: {sql}") | ||
curs.execute(sql) | ||
conn.close() | ||
|
||
#Test 3 : Try with a really small timeout. The query should raise an exception. | ||
|
||
conn = connect(host="localhost", port=8000, path="/query/sql", scheme="http", timeout=0.001) | ||
curs = conn.cursor() | ||
sql = "SELECT AirlineID, sum(Cancelled) FROM airlineStats WHERE Year > 2010 GROUP BY AirlineID LIMIT 5" | ||
print(f"Sending SQL to Pinot: {sql}") | ||
with pytest.raises(httpx.ReadTimeout): | ||
curs.execute(sql) | ||
conn.close() | ||
|
||
|
||
def run_main(): | ||
run_pinot_quickstart_timeout_example() | ||
|
||
|
||
if __name__ == '__main__': | ||
run_main() |
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