Ruby mogilefs-client dev/users discussion/patches/bugs/help/...
 help / color / Atom feed
* [PATCH] support net-http-persistent 3.x
@ 2017-01-26 22:14 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-01-26 22:14 UTC (permalink / raw)
  To: mogilefs-client-public

The optional net-http-persistent RubyGem we use has a major
incompatible change from the 2.x versions.  Support them both.
---
 examples/stale_fid_checker.rb |  4 +++-
 lib/mogilefs/mogilefs.rb      | 11 +++++++++--
 test/test_nhp_compat.rb       | 25 +++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 test/test_nhp_compat.rb

diff --git a/examples/stale_fid_checker.rb b/examples/stale_fid_checker.rb
index 2dab866..769ffda 100644
--- a/examples/stale_fid_checker.rb
+++ b/examples/stale_fid_checker.rb
@@ -34,7 +34,9 @@
 end
 
 adm = MogileFS::Admin.new(:hosts => trackers)
-NHP = Net::HTTP::Persistent.new(File.basename($0))
+name = File.basename($0)
+Net::HTTP::Persistent::VERSION >= 3.0 and name = { :name => name }
+NHP = Net::HTTP::Persistent.new(name)
 client = MogileFS::MogileFS.new(:hosts => trackers, :domain => "none")
 
 def start_perdev_thread(pfx)
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index d17f0b8..724dfb6 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -73,9 +73,9 @@ def initialize(args = {})
 
     @get_file_data_timeout = args[:get_file_data_timeout] || 5
     @new_file_max_time = args[:new_file_max_time] || 3600.0
-    @nhp_get = MogileFS::NHP.new('get')
+    @nhp_get = nhp_new('get')
     @nhp_get.open_timeout = @nhp_get.read_timeout = @get_file_data_timeout
-    @nhp_put = MogileFS::NHP.new('put')
+    @nhp_put = nhp_new('put')
     @nhp_put.open_timeout = @nhp_put.read_timeout = @new_file_max_time
 
     raise ArgumentError, "you must specify a domain" unless @domain
@@ -548,4 +548,11 @@ def file_debug(args)
       end
     end
   end
+
+  def nhp_new(name) # :nodoc:
+    Net::HTTP::Persistent::VERSION.to_f >= 3.0 and name = { :name => name }
+    MogileFS::NHP.new(name)
+  rescue NameError
+    MogileFS::NHP.new(name)
+  end
 end
diff --git a/test/test_nhp_compat.rb b/test/test_nhp_compat.rb
new file mode 100644
index 0000000..282dcf5
--- /dev/null
+++ b/test/test_nhp_compat.rb
@@ -0,0 +1,25 @@
+require 'test/unit'
+
+class TestNhpCompat < Test::Unit::TestCase
+
+  def test_nhp_compat
+    ver_test_nhp('~> 2.9')
+    ver_test_nhp('~> 3.0')
+  end
+
+  def ver_test_nhp(verspec)
+    pid = fork do
+      begin
+        gem 'net-http-persistent', verspec
+      rescue LoadError => e
+        warn "SKIPPING net-http-persistent #{verspec}\n" \
+             "#{e.message} (#{e.class})\n"
+      end
+      require 'mogilefs'
+      mg = MogileFS::MogileFS.new :hosts => %w(127.0.0.1:7500), :domain => 'x'
+      exit!(Net::HTTP::Persistent === mg.nhp_new('foo'))
+    end
+    _, status = Process.waitpid2(pid)
+    assert status.success?, status.inspect
+  end
+end
-- 
EW


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 22:14 [PATCH] support net-http-persistent 3.x Eric Wong

Ruby mogilefs-client dev/users discussion/patches/bugs/help/...

Archives are clonable:
	git clone --mirror https://yhbt.net/mogilefs-client-public
	git clone --mirror http://ou63pmih66umazou.onion/mogilefs-client-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.file-systems.mogilefs.ruby
	nntp://ou63pmih66umazou.onion/inbox.comp.file-systems.mogilefs.ruby

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git