From d18a8b31a573feaec3da7ce292440eee628f464f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 22 Mar 2012 21:44:17 +0000 Subject: client: add support for "updateclass" command This changes the class associated with +key+. This is _not_ the same as the "update_class" admin command which actually modifies the class itself. --- lib/mogilefs/backend.rb | 1 + lib/mogilefs/mogilefs.rb | 8 ++++++++ test/test_mogilefs_integration.rb | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+) 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 -- cgit v1.2.3-24-ge0c7