Skip to content

Commit 7a15611

Browse files
committed
Add kafka command to test.brokers; raise FileNotFoundError if version not installed
1 parent a86661f commit 7a15611

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/fixtures.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Fixture(object):
7171

7272
def __init__(self):
7373
self.child = None
74+
if not os.path.isdir(self.kafka_root):
75+
raise FileNotFoundError(self.kafka_root)
7476

7577
@classmethod
7678
def download_official_distribution(cls,
@@ -697,10 +699,7 @@ def get_producers(self, cnt, **params):
697699

698700

699701
def get_api_versions():
700-
import logging
701702
logging.basicConfig(level=logging.ERROR)
702-
703-
from test.fixtures import ZookeeperFixture, KafkaFixture
704703
zk = ZookeeperFixture.instance()
705704
k = KafkaFixture.instance(0, zk)
706705

@@ -717,6 +716,21 @@ def get_api_versions():
717716
zk.close()
718717

719718

719+
def run_brokers():
720+
logging.basicConfig(level=logging.ERROR)
721+
zk = ZookeeperFixture.instance()
722+
k = KafkaFixture.instance(0, zk)
723+
724+
print("Kafka", k.kafka_version, "running on port:", k.port)
725+
try:
726+
while True:
727+
time.sleep(5)
728+
except KeyboardInterrupt:
729+
print("Bye!")
730+
k.close()
731+
zk.close()
732+
733+
720734
if __name__ == '__main__':
721735
import sys
722736
if len(sys.argv) < 2:
@@ -725,6 +739,8 @@ def get_api_versions():
725739
cmd = sys.argv[1]
726740
if cmd == 'get_api_versions':
727741
get_api_versions()
742+
elif cmd == 'kafka':
743+
run_brokers()
728744
else:
729745
print("Unknown cmd: %s", cmd)
730746
exit(1)

0 commit comments

Comments
 (0)