This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
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.
- Loading branch information
1 parent
0f13432
commit 8207c60
Showing
12 changed files
with
262 additions
and
136 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
import httpx | ||
from time import sleep | ||
|
||
from pykli.ksqldb import KsqlDBClient | ||
|
||
@pytest.fixture(scope="module") | ||
def ksqldb_url(): | ||
return "http://localhost:28088" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def ksqldb(ksqldb_url): | ||
ksqldb = KsqlDBClient(ksqldb_url) | ||
for i in range(5): | ||
try: | ||
ksqldb.stmt(""" | ||
drop stream if exists pykli_stream_json delete topic; | ||
drop type if exists pykli_type; | ||
drop connector if exists pykli_connector; | ||
""") | ||
return ksqldb | ||
except httpx.HTTPError: | ||
print(f"Waiting for KsqlDB #{i}, {i * 10} sec") | ||
sleep(10) | ||
raise RuntimeError(f"{ksqldb_url} unavailable") | ||
|
||
|
||
def list_type_names(ksqldb) -> list[str]: | ||
json = ksqldb.stmt("show types;")[0] | ||
return json["types"].keys() | ||
|
||
|
||
def list_topic_names(ksqldb) -> list[str]: | ||
json = ksqldb.stmt("show topics;")[0] | ||
return [t["name"] for t in json["topics"]] | ||
|
||
|
||
def list_stream_names(ksqldb) -> list[str]: | ||
json = ksqldb.stmt("show streams;")[0] | ||
return [t["name"] for t in json["streams"]] | ||
|
||
|
||
|
||
def list_table_names(ksqldb) -> list[str]: | ||
json = ksqldb.stmt("show tables;")[0] | ||
return [t["name"] for t in json["tables"]] | ||
|
||
|
||
def list_connector_names(ksqldb) -> list[str]: | ||
json = ksqldb.stmt("show connectors;")[0] | ||
return [t["name"] for t in json["connectors"]] | ||
|
||
|
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,29 @@ | ||
import pytest | ||
import httpx | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_define_stmt(ksqldb): | ||
ksqldb.define("ff", "TO_JSON_STRING") | ||
r = ksqldb.stmt("describe function ${ff};") | ||
assert len(r) == 1 | ||
assert r[0]["@type"] == "describe_function" | ||
|
||
ksqldb.undefine("ff") | ||
with pytest.raises(httpx.HTTPStatusError) as ex: | ||
ksqldb.stmt("describe function ${ff};") | ||
assert ex.value.response.json()["message"] == "Can't find any functions with the name '${ff}'" | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_define_pull_query(ksqldb): | ||
ksqldb.define("ff", "KSQL_PROCESSING_LOG") | ||
r = ksqldb.pull_query("select * from ${ff};") | ||
assert len(r) == 1 | ||
assert "columnNames" in r[0] | ||
|
||
ksqldb.undefine("ff") | ||
with pytest.raises(httpx.HTTPStatusError) as ex: | ||
ksqldb.pull_query("select * from ${ff};") | ||
assert ex.value.response.json()["statementText"] == "${FF}" | ||
|
Oops, something went wrong.