about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-01-16 03:09:09 +0000
committerEric Wong <e@80x24.org>2015-01-16 03:10:07 +0000
commit63cc3ee529250a6b09dd7e032dc73ec509000c0f (patch)
tree564f21756c31d3774e6a746661bb2b3699306239
parentb1f366f2b764654d0dd1460369531e420b8b988c (diff)
downloadmogilefs-client-63cc3ee529250a6b09dd7e032dc73ec509000c0f.tar.gz
This should make it easier to fully test on machines without
access to an existing MogileFS instance.  You'll still
need mogilefsd and mogstored available, however, but these
tests are skipped on machines without them.
-rw-r--r--test/fresh.rb71
-rw-r--r--test/integration.rb43
-rw-r--r--test/test_fresh.rb71
-rw-r--r--test/test_mogilefs_integration.rb20
-rw-r--r--test/test_mogilefs_integration_large_pipe.rb8
-rw-r--r--test/test_mogilefs_integration_list_keys.rb10
-rw-r--r--test/test_mogtool_bigfile.rb8
7 files changed, 102 insertions, 129 deletions
diff --git a/test/fresh.rb b/test/fresh.rb
index e614b7d..6afacde 100644
--- a/test/fresh.rb
+++ b/test/fresh.rb
@@ -63,59 +63,6 @@ EOF
     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 }
-    @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"]
-    assert_nil host["http_get_port"]
-    assert_equal @test_host, host["hostip"]
-    assert_kind_of Integer, host["hostid"]
-    assert_equal hosts, @admin.get_hosts(host["hostid"])
-
-    assert_equal [], @admin.get_devices
-  end
-
-  def test_replicate_now
-    assert_equal({"count" => 0}, @admin.replicate_now)
-  end
-
-  def test_clear_cache
-    assert_nil @admin.clear_cache
-  end
-
-  def test_create_update_delete_class
-    domain = "rbmogtest#{Time.now.strftime('%Y%m%d%H%M%S')}.#{uuid}"
-    @admin.create_domain(domain)
-    yield_for_monitor_update { @admin.get_domains.include?(domain) and break }
-
-    @admin.create_class(domain, "klassy", 1)
-
-    assert_raises(MogileFS::Backend::ClassExistsError) do
-      @admin.create_class(domain, "klassy", 1)
-    end
-
-    @admin.update_class(domain, "klassy",
-                        :mindevcount => 1, :replpolicy => "MultipleHosts(1)")
-
-    tmp = nil
-    yield_for_monitor_update do
-      tmp = @admin.get_domains[domain]["klassy"]
-      break if tmp && tmp["replpolicy"] == "MultipleHosts(1)"
-    end
-    assert tmp, "domain did not show up"
-    assert_equal 1, tmp["mindevcount"]
-    assert_equal "MultipleHosts(1)", tmp["replpolicy"]
-    @admin.update_class(domain, "klassy", 2)
-    ensure
-      @admin.delete_class(domain, "klassy") rescue nil
-  end
-
   def add_host_device_domain
     assert_equal [], @admin.get_hosts
     args = { :ip => @test_host, :port => @mogstored_http_port }
@@ -161,24 +108,6 @@ EOF
     @domain = domain
   end
 
-  def test_device_file_add
-    add_host_device_domain
-    client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
-    r, w = IO.pipe
-    thr = Thread.new do
-      (0..9).each do |i|
-        sleep 0.05
-        w.write("#{i}\n")
-      end
-      w.close
-      :ok
-    end
-    assert_equal 20, client.store_file("pipe", nil, r)
-    assert_equal :ok, thr.value
-    r.close
-    assert_equal "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", client.get_file_data("pipe")
-  end
-
   def teardown_mogilefs
     if @mogstored_pid
       pid = File.read(@mogstored_pid.path).to_i
diff --git a/test/integration.rb b/test/integration.rb
deleted file mode 100644
index a0c876b..0000000
--- a/test/integration.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# -*- encoding: binary -*-
-require './test/exec'
-
-class TestMogIntegration < Test::Unit::TestCase
-  include TestExec
-
-  def test_dummy
-    assert true, "Ruby 1.8 Test::Unit is broken"
-  end unless defined?(MiniTest)
-
-  def setup
-    @to_close = []
-    @trackers = ENV["MOG_TEST_TRACKERS"].split(/,/)
-    domain = "rbmogtest#{Time.now.strftime('%Y%m%d%H%M%S')}.#{uuid}"
-    @admin = MogileFS::Admin.new(:hosts => @trackers)
-    @admin.create_domain(domain)
-    yield_for_monitor_update do
-      @admin.get_domains.include?(domain) and break
-    end
-    @domain = domain
-  end
-
-  def teardown
-    if defined?(@domain)
-      client = MogileFS::MogileFS.new :hosts => @trackers, :domain => @domain
-      client.each_key("") { |key|
-        p [ :delete, key ] if $VERBOSE
-        client.delete(key)
-      }
-      assert_equal true, @admin.delete_domain(@domain)
-      assert_raises(MogileFS::Backend::DomainNotFoundError) do
-        @admin.delete_domain(@domain)
-      end
-    end
-    @to_close.each do |io|
-      io.closed? or io.close
-    end
-  end
-end if ENV["MOG_TEST_TRACKERS"]
-
-class TestMogIntegration
-  warn "MOG_TEST_TRACKERS not defined"
-end unless ENV["MOG_TEST_TRACKERS"]
diff --git a/test/test_fresh.rb b/test/test_fresh.rb
index 5f420de..f3d3df1 100644
--- a/test/test_fresh.rb
+++ b/test/test_fresh.rb
@@ -197,4 +197,75 @@ class TestMogFresh < Test::Unit::TestCase
     @mogilefsd_pid = nil
     assert_raises(MogileFS::UnreachableBackendError) { client.list_keys }
   end
+
+  def test_admin_setup_new_host_and_devices
+    assert_equal [], @admin.get_hosts
+    args = { :ip => @test_host, :port => @mogstored_http_port }
+    @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"]
+    assert_nil host["http_get_port"]
+    assert_equal @test_host, host["hostip"]
+    assert_kind_of Integer, host["hostid"]
+    assert_equal hosts, @admin.get_hosts(host["hostid"])
+
+    assert_equal [], @admin.get_devices
+  end
+
+  def test_replicate_now
+    assert_equal({"count" => 0}, @admin.replicate_now)
+  end
+
+  def test_clear_cache
+    assert_nil @admin.clear_cache
+  end
+
+  def test_create_update_delete_class
+    domain = "rbmogtest#{Time.now.strftime('%Y%m%d%H%M%S')}.#{uuid}"
+    @admin.create_domain(domain)
+    yield_for_monitor_update { @admin.get_domains.include?(domain) and break }
+
+    @admin.create_class(domain, "klassy", 1)
+
+    assert_raises(MogileFS::Backend::ClassExistsError) do
+      @admin.create_class(domain, "klassy", 1)
+    end
+
+    @admin.update_class(domain, "klassy",
+                        :mindevcount => 1, :replpolicy => "MultipleHosts(1)")
+
+    tmp = nil
+    yield_for_monitor_update do
+      tmp = @admin.get_domains[domain]["klassy"]
+      break if tmp && tmp["replpolicy"] == "MultipleHosts(1)"
+    end
+    assert tmp, "domain did not show up"
+    assert_equal 1, tmp["mindevcount"]
+    assert_equal "MultipleHosts(1)", tmp["replpolicy"]
+    @admin.update_class(domain, "klassy", 2)
+    ensure
+      @admin.delete_class(domain, "klassy") rescue nil
+  end
+
+  def test_device_file_add
+    add_host_device_domain
+    client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
+    r, w = IO.pipe
+    thr = Thread.new do
+      (0..9).each do |i|
+        sleep 0.05
+        w.write("#{i}\n")
+      end
+      w.close
+      :ok
+    end
+    assert_equal 20, client.store_file("pipe", nil, r)
+    assert_equal :ok, thr.value
+    r.close
+    assert_equal "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", client.get_file_data("pipe")
+  end
 end
diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb
index 3c79308..6d16cd7 100644
--- a/test/test_mogilefs_integration.rb
+++ b/test/test_mogilefs_integration.rb
@@ -1,12 +1,16 @@
 # -*- encoding: binary -*-
-require './test/integration'
+require './test/fresh'
 
-class TestMogileFSIntegration < TestMogIntegration
+class TestMogileFSIntegration < Test::Unit::TestCase
+  include TestFreshSetup
   def setup
-    super
+    setup_mogilefs
+    add_host_device_domain
     @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)
   end
 
+  alias teardown teardown_mogilefs
+
   def test_CRUD
     assert ! @client.exist?("CRUD")
     assert_equal 4, @client.store_content("CRUD", "default", "DATA")
@@ -157,9 +161,14 @@ class TestMogileFSIntegration < TestMogIntegration
     end
   end
 
-  # TODO: move this to a fresh instance
   def test_admin_each_fid
     admin = MogileFS::Admin.new(:hosts => @trackers)
+    input = %w(a b c d e)
+    input.each do |k|
+      rv = @client.new_file(k)
+      rv.write(k)
+      assert_nil rv.close
+    end
     seen = {}
     count = admin.each_fid do |info|
       seen[info["fid"]] = true
@@ -171,7 +180,8 @@ class TestMogileFSIntegration < TestMogIntegration
       assert_kind_of String, info["domain"]
     end
     assert_equal count, seen.size
-  end if ENV["TEST_EXPENSIVE"]
+    assert_equal count, input.size
+  end
 
   def test_new_file_no_block
     rv = @client.new_file("no_block")
diff --git a/test/test_mogilefs_integration_large_pipe.rb b/test/test_mogilefs_integration_large_pipe.rb
index 49b9397..16f6d58 100644
--- a/test/test_mogilefs_integration_large_pipe.rb
+++ b/test/test_mogilefs_integration_large_pipe.rb
@@ -1,10 +1,12 @@
 # -*- encoding: binary -*-
-require './test/integration'
+require './test/fresh'
 require "digest/sha1"
 
-class TestMogileFSLargePipe< TestMogIntegration
+class TestMogileFSLargePipe < Test::Unit::TestCase
+  include TestFreshSetup
   def setup
-    super
+    setup_mogilefs
+    add_host_device_domain
     @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)
   end
 
diff --git a/test/test_mogilefs_integration_list_keys.rb b/test/test_mogilefs_integration_list_keys.rb
index 1de6cda..8492a2a 100644
--- a/test/test_mogilefs_integration_list_keys.rb
+++ b/test/test_mogilefs_integration_list_keys.rb
@@ -1,10 +1,12 @@
-
 # -*- encoding: binary -*-
-require './test/integration'
+require './test/fresh'
+
+class TestMogileFSIntegrationListKeys < Test::Unit::TestCase
+  include TestFreshSetup
 
-class TestMogileFSIntegrationListKeys < TestMogIntegration
   def setup
-    super
+    setup_mogilefs
+    add_host_device_domain
     @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)
   end
 
diff --git a/test/test_mogtool_bigfile.rb b/test/test_mogtool_bigfile.rb
index e424def..01de78e 100644
--- a/test/test_mogtool_bigfile.rb
+++ b/test/test_mogtool_bigfile.rb
@@ -1,5 +1,5 @@
 # -*- encoding: binary -*-
-require "./test/integration"
+require "./test/fresh"
 require "net/http"
 ok = true
 unless File.executable?(`which mogtool 2>/dev/null`.strip)
@@ -7,7 +7,8 @@ unless File.executable?(`which mogtool 2>/dev/null`.strip)
   ok = false
 end
 
-class TestMogtoolBigfile < TestMogIntegration
+class TestMogtoolBigfile < Test::Unit::TestCase
+  include TestFreshSetup
   buf = File.open("/dev/urandom") { |fp| fp.read(1024) }
   buf *= 1024
   RAND = Tempfile.new("rand")
@@ -18,7 +19,8 @@ class TestMogtoolBigfile < TestMogIntegration
   RAND_SHA1 = sha1.hexdigest
 
   def setup
-    super
+    setup_mogilefs
+    add_host_device_domain
     RAND.rewind
     @big_uuid = "big-#{uuid}"
     @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)