Created
October 29, 2018 11:01
-
-
Save ebuildy/406312bced8acedd0ca93f0cc57ecfed to your computer and use it in GitHub Desktop.
Python Behave steps to func test Apache Kafka
This file contains hidden or 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
Scenario: send JSON to Kafka with Spark | |
Given kafka topic | |
When I run pipeline "output_kafka_spark.yml" | |
Then I must see 3 messages from kafka |
This file contains hidden or 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
from behave import * | |
from hamcrest import * | |
from kafka import KafkaClient | |
from kafka import SimpleConsumer | |
@given('kafka topic') | |
def step_impl(context): | |
c = context.djobi_config | |
context.kafka_consumer = SimpleConsumer(client=KafkaClient(c["kafka.servers"]), topic=c.get_string("kafka.topic"), group="test") | |
@then('I must see {messages_count:d} messages from kafka') | |
def step_impl(context, messages_count): | |
messages = context.kafka_consumer.get_messages(count=messages_count) | |
assert_that(len(messages), equal_to(messages_count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment