Skip to content

Commit 0d1ccc7

Browse files
committed
Support setting kafka instance port explicitly in fixture
1 parent 251d4a9 commit 0d1ccc7

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

test/fixtures.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,20 @@ def close(self):
151151

152152
class KafkaFixture(Fixture):
153153
@classmethod
154-
def instance(cls, broker_id, zk_host, zk_port, zk_chroot=None, replicas=1, partitions=2):
154+
def instance(cls, broker_id, zk_host, zk_port,
155+
zk_chroot=None, port=None, replicas=1, partitions=2):
155156
if zk_chroot is None:
156157
zk_chroot = "kafka-python_" + str(uuid.uuid4()).replace("-", "_")
157158
if "KAFKA_URI" in os.environ:
158159
parse = urlparse(os.environ["KAFKA_URI"])
159160
(host, port) = (parse.hostname, parse.port)
160161
fixture = ExternalService(host, port)
161162
else:
162-
(host, port) = ("127.0.0.1", get_open_port())
163-
fixture = KafkaFixture(host, port, broker_id, zk_host, zk_port, zk_chroot, replicas, partitions)
163+
if port is None:
164+
port = get_open_port()
165+
host = "127.0.0.1"
166+
fixture = KafkaFixture(host, port, broker_id, zk_host, zk_port, zk_chroot,
167+
replicas=replicas, partitions=partitions)
164168
fixture.open()
165169
return fixture
166170

test/test_consumer_integration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def setUpClass(cls):
2727

2828
cls.zk = ZookeeperFixture.instance()
2929
chroot = random_string(10)
30-
cls.server1 = KafkaFixture.instance(0, cls.zk.host, cls.zk.port, chroot)
31-
cls.server2 = KafkaFixture.instance(1, cls.zk.host, cls.zk.port, chroot)
30+
cls.server1 = KafkaFixture.instance(0, cls.zk.host, cls.zk.port,
31+
zk_chroot=chroot)
32+
cls.server2 = KafkaFixture.instance(1, cls.zk.host, cls.zk.port,
33+
zk_chroot=chroot)
3234

3335
cls.server = cls.server1 # Bootstrapping server
3436

test/test_failover_integration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def setUp(self):
2828

2929
# mini zookeeper, 3 kafka brokers
3030
self.zk = ZookeeperFixture.instance()
31-
kk_args = [self.zk.host, self.zk.port, zk_chroot, replicas, partitions]
32-
self.brokers = [KafkaFixture.instance(i, *kk_args) for i in range(replicas)]
31+
kk_args = [self.zk.host, self.zk.port]
32+
kk_kwargs = {'zk_chroot': zk_chroot, 'replicas': replicas,
33+
'partitions': partitions}
34+
self.brokers = [KafkaFixture.instance(i, *kk_args, **kk_kwargs)
35+
for i in range(replicas)]
3336

3437
hosts = ['%s:%d' % (b.host, b.port) for b in self.brokers]
3538
self.client = SimpleClient(hosts, timeout=2)

0 commit comments

Comments
 (0)