diff options
author | Dana Powers <dana.powers@gmail.com> | 2016-02-15 20:20:56 -0800 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2016-02-15 21:56:10 -0800 |
commit | 0d1ccc7485acf09b282d8cc7a06cfd94e690eddb (patch) | |
tree | d39b107f2e0c090cbfb3d48fe89ed592afb42107 /test | |
parent | 251d4a97ced196503cbfbde2769a0394163a4325 (diff) | |
download | kafka-python-0d1ccc7485acf09b282d8cc7a06cfd94e690eddb.tar.gz |
Support setting kafka instance port explicitly in fixture
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures.py | 10 | ||||
-rw-r--r-- | test/test_consumer_integration.py | 6 | ||||
-rw-r--r-- | test/test_failover_integration.py | 7 |
3 files changed, 16 insertions, 7 deletions
diff --git a/test/fixtures.py b/test/fixtures.py index 2613a41..3892416 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -151,7 +151,8 @@ class ZookeeperFixture(Fixture): class KafkaFixture(Fixture): @classmethod - def instance(cls, broker_id, zk_host, zk_port, zk_chroot=None, replicas=1, partitions=2): + def instance(cls, broker_id, zk_host, zk_port, + zk_chroot=None, port=None, replicas=1, partitions=2): if zk_chroot is None: zk_chroot = "kafka-python_" + str(uuid.uuid4()).replace("-", "_") if "KAFKA_URI" in os.environ: @@ -159,8 +160,11 @@ class KafkaFixture(Fixture): (host, port) = (parse.hostname, parse.port) fixture = ExternalService(host, port) else: - (host, port) = ("127.0.0.1", get_open_port()) - fixture = KafkaFixture(host, port, broker_id, zk_host, zk_port, zk_chroot, replicas, partitions) + if port is None: + port = get_open_port() + host = "127.0.0.1" + fixture = KafkaFixture(host, port, broker_id, zk_host, zk_port, zk_chroot, + replicas=replicas, partitions=partitions) fixture.open() return fixture diff --git a/test/test_consumer_integration.py b/test/test_consumer_integration.py index 48e7e0c..1b60c95 100644 --- a/test/test_consumer_integration.py +++ b/test/test_consumer_integration.py @@ -27,8 +27,10 @@ class TestConsumerIntegration(KafkaIntegrationTestCase): cls.zk = ZookeeperFixture.instance() chroot = random_string(10) - cls.server1 = KafkaFixture.instance(0, cls.zk.host, cls.zk.port, chroot) - cls.server2 = KafkaFixture.instance(1, cls.zk.host, cls.zk.port, chroot) + cls.server1 = KafkaFixture.instance(0, cls.zk.host, cls.zk.port, + zk_chroot=chroot) + cls.server2 = KafkaFixture.instance(1, cls.zk.host, cls.zk.port, + zk_chroot=chroot) cls.server = cls.server1 # Bootstrapping server diff --git a/test/test_failover_integration.py b/test/test_failover_integration.py index afa4ebc..9409241 100644 --- a/test/test_failover_integration.py +++ b/test/test_failover_integration.py @@ -28,8 +28,11 @@ class TestFailover(KafkaIntegrationTestCase): # mini zookeeper, 3 kafka brokers self.zk = ZookeeperFixture.instance() - kk_args = [self.zk.host, self.zk.port, zk_chroot, replicas, partitions] - self.brokers = [KafkaFixture.instance(i, *kk_args) for i in range(replicas)] + kk_args = [self.zk.host, self.zk.port] + kk_kwargs = {'zk_chroot': zk_chroot, 'replicas': replicas, + 'partitions': partitions} + self.brokers = [KafkaFixture.instance(i, *kk_args, **kk_kwargs) + for i in range(replicas)] hosts = ['%s:%d' % (b.host, b.port) for b in self.brokers] self.client = SimpleClient(hosts, timeout=2) |