about summary refs log tree commit homepage
path: root/test/test_fresh.rb
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 /test/test_fresh.rb
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.
Diffstat (limited to 'test/test_fresh.rb')
-rw-r--r--test/test_fresh.rb71
1 files changed, 71 insertions, 0 deletions
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