From: Eric Wong <e@80x24.org>
To: mogilefs-client-public@bogomips.org
Subject: [PATCH] support net-http-persistent 3.x
Date: Thu, 26 Jan 2017 22:14:23 +0000 [thread overview]
Message-ID: <20170126221423.15777-1-e@80x24.org> (raw)
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
reply other threads:[~2017-01-26 22:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/mogilefs-client/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170126221423.15777-1-e@80x24.org \
--to=e@80x24.org \
--cc=mogilefs-client-public@bogomips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/mogilefs-client.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).