Use kafka_run_class_env() to set environment vars in test fixtures

This commit is contained in:
Dana Powers
2014-08-12 20:15:46 -07:00
parent cfac060c5c
commit 141e2db112
2 changed files with 17 additions and 17 deletions

View File

@@ -81,16 +81,11 @@ class Fixture(object):
result.extend(args) result.extend(args)
return result return result
# ./kafka-src/bin/kafka-run-class.sh is the authority. @classmethod
result = ["java", "-Xmx512M", "-server"] def kafka_run_class_env(cls):
result.append("-Dlog4j.configuration=file:%s" % cls.test_resource("log4j.properties")) env = os.environ.copy()
result.append("-Dcom.sun.management.jmxremote") env['KAFKA_LOG4J_OPTS'] = "-Dlog4j.configuration=file:%s" % cls.test_resource("log4j.properties")
result.append("-Dcom.sun.management.jmxremote.authenticate=false") return env
result.append("-Dcom.sun.management.jmxremote.ssl=false")
result.append("-cp")
result.append(cls.test_classpath())
result.extend(args)
return result
@classmethod @classmethod
def render_template(cls, source_file, target_file, binding): def render_template(cls, source_file, target_file, binding):
@@ -137,10 +132,11 @@ class ZookeeperFixture(Fixture):
self.render_template(template, properties, vars(self)) self.render_template(template, properties, vars(self))
# Configure Zookeeper child process # 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", "org.apache.zookeeper.server.quorum.QuorumPeerMain",
properties properties),
)) env=self.kafka_run_class_env()
)
# Party! # Party!
self.out("Starting...") self.out("Starting...")
@@ -218,9 +214,10 @@ class KafkaFixture(Fixture):
self.render_template(template, properties, vars(self)) self.render_template(template, properties, vars(self))
# Configure Kafka child process # Configure Kafka child process
self.child = SpawnedService(self.kafka_run_class_args( self.child = SpawnedService(args=self.kafka_run_class_args(
"kafka.Kafka", properties "kafka.Kafka", properties),
)) env=self.kafka_run_class_env()
)
# Party! # Party!
self.out("Creating Zookeeper chroot node...") self.out("Creating Zookeeper chroot node...")
@@ -229,6 +226,7 @@ class KafkaFixture(Fixture):
"-server", "%s:%d" % (self.zk_host, self.zk_port), "-server", "%s:%d" % (self.zk_host, self.zk_port),
"create", "/%s" % self.zk_chroot, "kafka-python" "create", "/%s" % self.zk_chroot, "kafka-python"
), ),
env=self.kafka_run_class_env(),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)

View File

@@ -26,10 +26,11 @@ class ExternalService(object):
class SpawnedService(threading.Thread): class SpawnedService(threading.Thread):
def __init__(self, args=[]): def __init__(self, args=[], env=None):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.args = args self.args = args
self.env = env
self.captured_stdout = [] self.captured_stdout = []
self.captured_stderr = [] self.captured_stderr = []
@@ -41,6 +42,7 @@ class SpawnedService(threading.Thread):
def run_with_handles(self): def run_with_handles(self):
self.child = subprocess.Popen( self.child = subprocess.Popen(
self.args, self.args,
env=self.env,
bufsize=1, bufsize=1,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)