about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-07 07:37:56 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-07 07:37:56 +0000
commit5a4650a07f394268884a8dad58fac42f9a9288c5 (patch)
tree9308ed34234834d004c203795a9baa1e0ee74662
parentc4e2b81f2493f0a0013ba03c11b74a61f3ca56f6 (diff)
downloadmogilefs-client-5a4650a07f394268884a8dad58fac42f9a9288c5.tar.gz
We'll also be testing some admin commands in there.
-rw-r--r--test/integration.rb21
-rw-r--r--test/test_admin_integration.rb33
-rw-r--r--test/test_mogilefs_integration.rb24
3 files changed, 75 insertions, 3 deletions
diff --git a/test/integration.rb b/test/integration.rb
index 548cb02..cd63c3c 100644
--- a/test/integration.rb
+++ b/test/integration.rb
@@ -4,6 +4,8 @@ require 'test/unit'
 require 'securerandom'
 require 'tempfile'
 require 'digest'
+require 'stringio'
+require 'pp'
 require 'mogilefs'
 
 class TestMogIntegration < Test::Unit::TestCase
@@ -19,11 +21,21 @@ class TestMogIntegration < Test::Unit::TestCase
     @trackers = ENV["MOG_TEST_TRACKERS"].split(/,/)
     now = Time.now
     domain = "rbmogtest#{now.strftime('%Y%m%d%H%M%S')}.#{uuid}"
-    mogadm!("domain", "add", domain)
-    sleep 4 # wait for monitor to refresh caches
+    @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 yield_for_monitor_update # mogilefsd should update every 4 seconds
+    50.times do
+      yield
+      sleep 0.1
+    end
+  end
+
   def mogadm(*args)
     x("mogadm", "--trackers=#{@trackers.join(',')}", *args)
   end
@@ -69,7 +81,10 @@ class TestMogIntegration < Test::Unit::TestCase
         p [ :delete, key ] if $VERBOSE
         client.delete(key)
       }
-      mogadm!("domain", "delete", @domain)
+      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
diff --git a/test/test_admin_integration.rb b/test/test_admin_integration.rb
new file mode 100644
index 0000000..e3de379
--- /dev/null
+++ b/test/test_admin_integration.rb
@@ -0,0 +1,33 @@
+# -*- encoding: binary -*-
+require './test/integration'
+
+class TestAdminIntegration < TestMogIntegration
+
+  def test_create_update_delete_class
+    assert_nothing_raised do
+      @admin.create_class(@domain, "klassy", 1)
+    end
+    assert_raises(MogileFS::Backend::ClassExistsError) do
+      @admin.create_class(@domain, "klassy", 1)
+    end
+
+    assert_nothing_raised do
+      @admin.update_class(@domain, "klassy",
+                          :mindevcount => 1, :replpolicy => "MultipleHosts(1)")
+    end
+
+    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"]
+    assert_nothing_raised { @admin.update_class(@domain, "klassy", 2) }
+    @admin.delete_class(@domain, "klassy") rescue nil
+    rescue => err
+      @admin.delete_class(@domain, "klassy") rescue nil
+      raise
+  end
+end
diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb
new file mode 100644
index 0000000..bb2cf6e
--- /dev/null
+++ b/test/test_mogilefs_integration.rb
@@ -0,0 +1,24 @@
+# -*- encoding: binary -*-
+require './test/integration'
+
+class TestMogileFSIntegration < TestMogIntegration
+  def setup
+    super
+    @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)
+  end
+
+  def test_CRUD
+    assert_equal 4, @client.store_content("CRUD", "default", "DATA")
+    assert_equal "DATA", @client.get_file_data("CRUD")
+    sio = StringIO.new("")
+    rv = @client.get_file_data("CRUD") do |rd|
+      MogileFS::X.copy_stream(rd, sio)
+    end
+    assert_equal 4, rv
+    assert_equal "DATA", sio.string
+    assert_equal 8, @client.store_content("CRUD", "default", "MOARDATA")
+    assert_equal "MOARDATA", @client.get_file_data("CRUD")
+    assert_equal true, @client.delete("CRUD")
+    assert_raises(MogileFS::Backend::UnknownKeyError) { @client.delete("CRUD") }
+  end
+end