-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#138 - kafka.read test finally works
- Loading branch information
wheelly
committed
Feb 8, 2024
1 parent
da42af4
commit 831a7e6
Showing
2 changed files
with
39 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import logging | ||
import os | ||
|
||
from common import kafka_utils | ||
from common.utils import run_job | ||
|
||
logger = logging.getLogger("dy") | ||
message_one = b'{"id":1,"name":"Boris"}' | ||
message_two = b'{"id":2,"name":"Ivan"}' | ||
|
||
def test_kafka_to_stdout(tmpdir): | ||
kafka_container = kafka_utils.get_kafka_container() | ||
with kafka_container as kafka: | ||
bootstrap_servers = kafka.get_bootstrap_server() | ||
logger.info(f"Connecting to Kafka: {bootstrap_servers}") | ||
producer = kafka_utils.get_kafka_producer(bootstrap_servers) | ||
producer.produce("integration-tests", b'{"hello": "Earth"}') | ||
producer.produce("integration-tests", b'{"bye": "Mars"}') | ||
producer.flush() | ||
output_file = tmpdir.join("tests_kafka_to_stdout.txt") | ||
run_job("tests.kafka_to_stdout", None, output_file) | ||
logger.error(output_file.read()) | ||
# result = json.loads(output_file.read()) | ||
# assert result[0]["hello"] == "Earth" | ||
# assert result[1]["bye"] == "Mars" | ||
try: | ||
with kafka_container as kafka: | ||
bootstrap_servers = kafka.get_bootstrap_server() | ||
producer = kafka_utils.get_kafka_producer(bootstrap_servers) | ||
producer.produce("integration-tests", message_one) | ||
producer.produce("integration-tests", message_two) | ||
producer.flush() | ||
output_file = tmpdir.join("tests_kafka_to_stdout.txt") | ||
run_job("tests.kafka_to_stdout", None, output_file) | ||
result = output_file.readlines() | ||
assert result[0].strip().encode() == message_one | ||
assert result[1].strip().encode() == message_two | ||
finally: | ||
os.remove(output_file) | ||
|
||
|
||
|