diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-07 08:44:55 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-07 08:44:55 +0000 |
commit | 4f927415dc2a8e8dcaeda510d351192e3cc88747 (patch) | |
tree | edaed73c7025f26956454aad368b9075ec4d37dc /test/test_fresh.rb | |
parent | 5a4650a07f394268884a8dad58fac42f9a9288c5 (diff) | |
download | mogilefs-client-4f927415dc2a8e8dcaeda510d351192e3cc88747.tar.gz |
We'll need to setup a fresh MogileFS instance for some tests.
Diffstat (limited to 'test/test_fresh.rb')
-rw-r--r-- | test/test_fresh.rb | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/test/test_fresh.rb b/test/test_fresh.rb new file mode 100644 index 0000000..48b3395 --- /dev/null +++ b/test/test_fresh.rb @@ -0,0 +1,105 @@ +# -*- encoding: binary -*- +require "./test/exec" +require "tmpdir" +require "fileutils" + +class TestMogFresh < Test::Unit::TestCase + include TestExec + + def setup + @test_host = "127.0.0.1" + @tracker = TCPServer.new(@test_host, 0) + @tracker_port = @tracker.addr[1] + + @mogstored_mgmt = TCPServer.new(@test_host, 0) + @mogstored_http = TCPServer.new(@test_host, 0) + @mogstored_mgmt_port = @mogstored_mgmt.addr[1] + @mogstored_http_port = @mogstored_http.addr[1] + + @dbname = Tempfile.new(["mogfresh", "sqlite3"]) + @docroot = Dir.mktmpdir(["mogfresh", "docroot"]) + @mogstored_conf = Tempfile.new(["mogstored", "conf"]) + @mogilefsd_conf = Tempfile.new(["mogilefsd", "conf"]) + @mogstored_pid = Tempfile.new(["mogstored", "pid"]) + @mogilefsd_pid = Tempfile.new(["mogilefsd", "pid"]) + + cmd = %w(mogdbsetup --yes --type=SQLite --dbname) << @dbname.path + x!(*cmd) + + @mogilefsd_conf.puts "db_dsn DBI:SQLite:#{@dbname.path}" + @mogilefsd_conf.write <<EOF +conf_port #@tracker_port +listen #@test_host +pidfile #{@mogilefsd_pid.path} +replicate_jobs 1 +fsck_jobs 1 +query_jobs 1 +mogstored_stream_port #{@mogstored_mgmt_port} +node_timeout 10 +EOF + @mogilefsd_conf.flush + + @mogstored_conf.write <<EOF +pidfile = #{@mogstored_pid.path} +maxconns = 1000 +httplisten = #@test_host:#{@mogstored_http_port} +mgmtlisten = #@test_host:#{@mogstored_mgmt_port} +docroot = #@docroot +EOF + @mogstored_conf.flush + + @hosts = [ "#@test_host:#@tracker_port" ] + @mogstored_mgmt.close + @mogstored_http.close + @tracker.close + x!("mogstored", "--daemon", "--config=#{@mogstored_conf.path}") + wait_for_port @mogstored_http_port + wait_for_port @mogstored_mgmt_port + x!("mogilefsd", "--daemon", "--config=#{@mogilefsd_conf.path}") + wait_for_port @tracker_port + @admin = MogileFS::Admin.new(:hosts => @hosts) + 10.times do + break if @mogstored_pid.size > 0 + sleep 0.1 + end + end + + def wait_for_port(port) + tries = 50 + begin + TCPSocket.new(@test_host, port).close + return + rescue + sleep 0.1 + end while (tries -= 1) > 0 + raise "#@test_host:#{port} never became ready" + end + + def test_admin_setup_new_host_and_devices + assert_equal [], @admin.get_hosts + args = { :ip => @test_host, :port => @mogstored_http_port } + x = @admin.create_host("me", args) + yield_for_monitor_update { @admin.get_hosts.empty? or break } + hosts = @admin.get_hosts + assert_equal 1, hosts.size + host = @admin.get_hosts[0] + assert_equal "me", host["hostname"] + assert_equal @mogstored_http_port, host["http_port"].to_i + assert_equal @test_host, host["hostip"] + assert_equal hosts, @admin.get_hosts(host["hostid"]) + + assert_equal [], @admin.get_devices + end + + def teardown + if @mogstored_pid && @mogstored_pid.size > 0 + Process.kill(:TERM, @mogstored_pid.read.to_i) + end + if @mogilefsd_pid + s = TCPSocket.new(@test_host, @tracker_port) + s.write "!shutdown\r\n" + s.close + end + FileUtils.rmtree(@docroot) + end +end |