about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-03-22 21:44:17 +0000
committerEric Wong <normalperson@yhbt.net>2012-03-22 21:44:17 +0000
commitd18a8b31a573feaec3da7ce292440eee628f464f (patch)
tree6f27ca0a4b26f04b6433c35df1c41b59b063c2ea
parentd5718e3ebeae61409bd5e260b8355ea68685ae84 (diff)
downloadmogilefs-client-d18a8b31a573feaec3da7ce292440eee628f464f.tar.gz
This changes the class associated with +key+.
This is _not_ the same as the "update_class" admin command
which actually modifies the class itself.
-rw-r--r--lib/mogilefs/backend.rb1
-rw-r--r--lib/mogilefs/mogilefs.rb8
-rw-r--r--test/test_mogilefs_integration.rb21
3 files changed, 30 insertions, 0 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index c60bd2b..a6b5e93 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -118,6 +118,7 @@ class MogileFS::Backend
   add_command :delete_domain
   add_command :create_class
   add_command :update_class
+  add_command :updateclass
   add_command :delete_class
   add_command :create_host
   add_command :update_host
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index 75a3936..9f4f988 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -256,6 +256,14 @@ class MogileFS::MogileFS < MogileFS::Client
     true
   end
 
+  # Updates +key+ to +newclass+
+  def updateclass(key, newclass)
+    raise MogileFS::ReadOnlyError if readonly?
+
+    @backend.updateclass(:domain => @domain, :key => key, :class => newclass)
+    true
+  end
+
   # Sleeps +duration+, only used for testing
   def sleep(duration) # :nodoc:
     @backend.sleep :duration => duration
diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb
index ba9ffbb..4882cce 100644
--- a/test/test_mogilefs_integration.rb
+++ b/test/test_mogilefs_integration.rb
@@ -290,4 +290,25 @@ class TestMogileFSIntegration < TestMogIntegration
 
     assert_equal "HIHI", @client.get_file_data("unlinked")
   end
+
+  def test_updateclass
+    admin = MogileFS::Admin.new(:hosts => @trackers)
+    admin.create_class(@domain, "one", 1)
+    admin.create_class(@domain, "two", 2)
+    4.times { admin.clear_cache }
+
+    assert_equal 4, @client.store_content("uc", "default", "DATA")
+    assert_equal true, @client.updateclass("uc", "one")
+    assert_equal true, @client.updateclass("uc", "two")
+    assert_raises(MogileFS::Backend::ClassNotFoundError) do
+      @client.updateclass("uc", "wtf")
+    end
+    assert_raises(MogileFS::Backend::InvalidKeyError) do
+      @client.updateclass("nonexistent", "one")
+    end
+
+    @client.delete "uc"
+    admin.delete_class @domain, "one"
+    admin.delete_class @domain, "two"
+  end
 end