diff options
author | Dana Powers <dana.powers@rd.io> | 2014-08-12 20:15:46 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@rd.io> | 2014-08-12 20:15:46 -0700 |
commit | 141e2db112fb454f2174b6a5c3b5212a3f1132ab (patch) | |
tree | 88f176c4613b4c4d2cac7f4825ee9b832db6a626 /test | |
parent | cfac060c5c0ef6b64e0582a6c425dc17289d7f36 (diff) | |
download | kafka-python-141e2db112fb454f2174b6a5c3b5212a3f1132ab.tar.gz |
Use kafka_run_class_env() to set environment vars in test fixtures
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures.py | 30 | ||||
-rw-r--r-- | test/service.py | 4 |
2 files changed, 17 insertions, 17 deletions
diff --git a/test/fixtures.py b/test/fixtures.py index e1b5b00..00de82c 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -81,16 +81,11 @@ class Fixture(object): result.extend(args) return result - # ./kafka-src/bin/kafka-run-class.sh is the authority. - result = ["java", "-Xmx512M", "-server"] - result.append("-Dlog4j.configuration=file:%s" % cls.test_resource("log4j.properties")) - result.append("-Dcom.sun.management.jmxremote") - result.append("-Dcom.sun.management.jmxremote.authenticate=false") - result.append("-Dcom.sun.management.jmxremote.ssl=false") - result.append("-cp") - result.append(cls.test_classpath()) - result.extend(args) - return result + @classmethod + def kafka_run_class_env(cls): + env = os.environ.copy() + env['KAFKA_LOG4J_OPTS'] = "-Dlog4j.configuration=file:%s" % cls.test_resource("log4j.properties") + return env @classmethod def render_template(cls, source_file, target_file, binding): @@ -137,10 +132,11 @@ class ZookeeperFixture(Fixture): self.render_template(template, properties, vars(self)) # Configure Zookeeper child process - self.child = SpawnedService(self.kafka_run_class_args( + self.child = SpawnedService(args=self.kafka_run_class_args( "org.apache.zookeeper.server.quorum.QuorumPeerMain", - properties - )) + properties), + env=self.kafka_run_class_env() + ) # Party! self.out("Starting...") @@ -218,9 +214,10 @@ class KafkaFixture(Fixture): self.render_template(template, properties, vars(self)) # Configure Kafka child process - self.child = SpawnedService(self.kafka_run_class_args( - "kafka.Kafka", properties - )) + self.child = SpawnedService(args=self.kafka_run_class_args( + "kafka.Kafka", properties), + env=self.kafka_run_class_env() + ) # Party! self.out("Creating Zookeeper chroot node...") @@ -229,6 +226,7 @@ class KafkaFixture(Fixture): "-server", "%s:%d" % (self.zk_host, self.zk_port), "create", "/%s" % self.zk_chroot, "kafka-python" ), + env=self.kafka_run_class_env(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/test/service.py b/test/service.py index 8872c82..2c667c7 100644 --- a/test/service.py +++ b/test/service.py @@ -26,10 +26,11 @@ class ExternalService(object): class SpawnedService(threading.Thread): - def __init__(self, args=[]): + def __init__(self, args=[], env=None): threading.Thread.__init__(self) self.args = args + self.env = env self.captured_stdout = [] self.captured_stderr = [] @@ -41,6 +42,7 @@ class SpawnedService(threading.Thread): def run_with_handles(self): self.child = subprocess.Popen( self.args, + env=self.env, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |