about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-12-12 07:48:36 +0000
committerEric Wong <normalperson@yhbt.net>2011-12-12 07:48:36 +0000
commit594295a29cbc33fc04b7c0b87ecf664f036819a9 (patch)
tree8fce2eca22344f22a909ca802df7dbc61a776d14
parent8a54653184536b99bf74bcaedb8cf84ea0f4f693 (diff)
downloadmogilefs-client-594295a29cbc33fc04b7c0b87ecf664f036819a9.tar.gz
This adds an internal :ruby_no_raise flag to the backend
to avoid exceptions.
-rw-r--r--lib/mogilefs/backend.rb6
-rw-r--r--lib/mogilefs/mogilefs.rb7
-rw-r--r--test/test_mogilefs_integration.rb2
3 files changed, 8 insertions, 7 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index d04247b..f33c42d 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -264,11 +264,13 @@ class MogileFS::Backend
 
   # Performs the +cmd+ request with +args+.
   def do_request(cmd, args, idempotent = false)
-    request = make_request cmd, args
+    no_raise = args.delete(:ruby_no_raise)
+    request = make_request(cmd, args)
     @mutex.synchronize do
       begin
         io = dispatch_unlocked(request)
-        line = io.timed_gets(@timeout) and return parse_response(line)
+        line = io.timed_gets(@timeout) and
+          return parse_response(line, no_raise ? request : nil)
 
         idempotent or
           raise EOFError, "end of file reached after: #{request.inspect}"
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index 005bb19..1ec357d 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -117,11 +117,8 @@ class MogileFS::MogileFS < MogileFS::Client
 
   # Returns +true+ if +key+ exists, +false+ if not
   def exist?(key)
-    rv = nil
-    args = { :key => key, :domain => @domain }
-    @backend.pipeline_dispatch(:get_paths, args) { |x| rv = (Hash === x) }
-    @backend.pipeline_wait(1)
-    rv
+    args = { :key => key, :domain => @domain , :ruby_no_raise => true}
+    Hash === @backend.get_paths(args)
   end
 
   # Get the URIs for +key+ (paths) as URI::HTTP objects
diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb
index 2ce8159..ba9ffbb 100644
--- a/test/test_mogilefs_integration.rb
+++ b/test/test_mogilefs_integration.rb
@@ -8,7 +8,9 @@ class TestMogileFSIntegration < TestMogIntegration
   end
 
   def test_CRUD
+    assert ! @client.exist?("CRUD")
     assert_equal 4, @client.store_content("CRUD", "default", "DATA")
+    assert @client.exist?("CRUD")
     assert_equal 4, @client.size("CRUD")
     assert_equal "DATA", @client.get_file_data("CRUD")
     assert_equal "DAT", @client.get_file_data("CRUD", nil, 3)