forked from python-pinot-dbapi/pinot-dbapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinot_quickstart_timeout.py
49 lines (37 loc) · 1.61 KB
/
pinot_quickstart_timeout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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",
extra_request_headers="Database=default")
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,
extra_request_headers="Database=default")
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,
extra_request_headers="Database=default")
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()