kafka: add good test.

Closes Homebrew/homebrew#49841.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Mike McQuaid 2016-03-07 11:14:00 +00:00 committed by Xu Cheng
parent 1620c58ca4
commit afcc825c49

View file

@ -65,38 +65,37 @@ class Kafka < Formula
plist_options :manual => "zookeeper-server-start #{HOMEBREW_PREFIX}/etc/kafka/zookeeper.properties; kafka-server-start #{HOMEBREW_PREFIX}/etc/kafka/server.properties" plist_options :manual => "zookeeper-server-start #{HOMEBREW_PREFIX}/etc/kafka/zookeeper.properties; kafka-server-start #{HOMEBREW_PREFIX}/etc/kafka/server.properties"
test do test do
# This is far from an ideal test, but this is the best we can do, because for whatever reason ENV["LOG_DIR"] = "#{testpath}/kafkalog"
# the test below will not run in Travis 10.9, however will run successfully on any other 10.9 machine
# Likewise, the software runs just fine on 10.9.
ohai "Ensuring the Kafka 0.9.0.0 JAR exists in the right place"
assert File.exists? libexec/"core/build/libs/kafka_2.10-0.9.0.0.jar"
# ====== leaving this in, in case someone can get it to work on mavericks (testpath/"kafka").mkpath
# cp "#{etc}/kafka/zookeeper.properties", testpath/"kafka"
# A REALLY bad test... however Kafka doesn't say its version anywhere so its the best we can do. cp "#{etc}/kafka/server.properties", testpath/"kafka"
# Furthermore, we can't just start and stop a ZK and Kafka instance, as theyd need to daemonize, and inreplace "#{testpath}/kafka/zookeeper.properties", "#{var}/lib", testpath
# in order to daemonize, they need to write access to a place where they expect to put their PID file inreplace "#{testpath}/kafka/server.properties", "#{var}/lib", testpath
# but that's impossible inside the sandbox.
# begin
# The ZooKeeper client that Kafka uses spits out some key JVM parameters when it is first initialized, fork do
# namely "java.class.path", which gets set by kafka-run-class.sh, which is called by kafka-server-start.sh exec "#{bin}/zookeeper-server-start #{testpath}/kafka/zookeeper.properties >/dev/null"
# Thus, a correct java.class.path implies that the correct version of Kafka has been installed and is running when end
# the command to start are invoked and the fact that it runs to begin with indicates that the
# prerequisites for successful environment to run in are met. sleep 5
#
# We simply check that the classpath has the JAR of the Kafka version we want to use. But first, we need to fork do
# set a few environment variables that kafka-run-class.sh uses for things like figuring out where exec "#{bin}/kafka-server-start #{testpath}/kafka/server.properties >/dev/null"
# to save logs. We need to do this so that Kafka doesnt try to write log files into end
# /usr/local/Cellar/kafka/version/blahblah and instead into the sandbox's temporary directory, because otherwise
# instead of lovely ZooKeeper client debug messages, we just get a bunch of "operation not permitted" IO errors sleep 5
# and Kafka will crash (or worse, livelock) before the ZK client has a chance to start and work its magic.
# @demo_pid = fork do
# ohai "Checking that the correct JAR (kafka_2.10.0-0.9.0.0.jar) is being loaded by kafka-run-class.sh" exec "#{libexec}/examples/bin/java-producer-consumer-demo.sh > #{testpath}/kafka/demo.out 2>/dev/null"
# end
# require 'open3'
# Open3.popen3("LOG_DIR=#{testpath}/kafkalog kafka-server-start.sh #{etc}/kafka/server.properties --override zookeeper.connect=localhost:-1") do |_, stdout, _, _| sleep 5
# assert_match /.*environment:java\.class\.path.*kafka_2\.10-0\.9\.0\.0\.jar.*/, stdout.read ensure
# end quiet_system "pkill", "-9", "-f", "#{testpath}/kafka/"
end
assert_match "Received message: ", IO.read("#{testpath}/kafka/demo.out")
end end
def plist; <<-EOS.undent def plist; <<-EOS.undent