Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created October 29, 2018 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebuildy/406312bced8acedd0ca93f0cc57ecfed to your computer and use it in GitHub Desktop.
Save ebuildy/406312bced8acedd0ca93f0cc57ecfed to your computer and use it in GitHub Desktop.
Python Behave steps to func test Apache Kafka
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
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