load_balanced_tire 0.1 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/rails-application-template.rb +7 -7
- data/examples/tire-dsl.rb +1 -1
- data/lib/tire.rb +1 -1
- data/lib/tire/configuration.rb +1 -1
- data/lib/tire/http/client.rb +12 -12
- data/lib/tire/search.rb +1 -1
- data/test/test_helper.rb +6 -6
- data/test/unit/configuration_test.rb +2 -2
- data/test/unit/http_client_test.rb +16 -16
- data/test/unit/search_test.rb +2 -2
- data/tire.gemspec +2 -3
- metadata +2 -2
@@ -27,17 +27,17 @@
|
|
27
27
|
require 'rubygems'
|
28
28
|
|
29
29
|
begin
|
30
|
-
require '
|
30
|
+
require 'loadbalanceclient'
|
31
31
|
rescue LoadError
|
32
32
|
puts "\n"
|
33
|
-
say_status "ERROR", "Rubygem '
|
33
|
+
say_status "ERROR", "Rubygem 'load_balance_client' not installed\n", :red
|
34
34
|
puts '-'*80
|
35
|
-
say_status "", "gem install
|
35
|
+
say_status "", "gem install load_balance_client"
|
36
36
|
puts "\n"
|
37
37
|
|
38
38
|
if yes?("Should I install it for you?", :bold)
|
39
|
-
say_status "gem", "install
|
40
|
-
system "gem install
|
39
|
+
say_status "gem", "install load_balance_client", :yellow
|
40
|
+
system "gem install load_balance_client"
|
41
41
|
else
|
42
42
|
exit(1)
|
43
43
|
end
|
@@ -69,7 +69,7 @@ git :init
|
|
69
69
|
git :add => '.'
|
70
70
|
git :commit => "-m 'Initial commit: Clean application'"
|
71
71
|
|
72
|
-
unless (
|
72
|
+
unless (LoadBalanceClient.get('http://localhost:9200') rescue false)
|
73
73
|
COMMAND = <<-COMMAND.gsub(/^ /, '')
|
74
74
|
curl -k -L -# -o elasticsearch-0.19.0.tar.gz \
|
75
75
|
"http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.0.tar.gz"
|
@@ -232,7 +232,7 @@ puts '-'*80, ''
|
|
232
232
|
|
233
233
|
run "git log --reverse --pretty=format:'%Cblue%h%Creset | %s'"
|
234
234
|
|
235
|
-
if (begin;
|
235
|
+
if (begin; LoadBalanceClient.get('http://localhost:3000'); rescue Errno::ECONNREFUSED; false; rescue Exception; true; end)
|
236
236
|
puts "\n"
|
237
237
|
say_status "ERROR", "Some other application is running on port 3000!\n", :red
|
238
238
|
puts '-'*80
|
data/examples/tire-dsl.rb
CHANGED
@@ -41,7 +41,7 @@ require 'tire'
|
|
41
41
|
#### Prerequisites
|
42
42
|
|
43
43
|
# We'll need a working and running _ElasticSearch_ server, of course. Thankfully, that's easy.
|
44
|
-
( puts <<-"INSTALL" ; exit(1) ) unless (
|
44
|
+
( puts <<-"INSTALL" ; exit(1) ) unless (LoadBalanceClient.get('http://localhost:9200') rescue false)
|
45
45
|
|
46
46
|
[ERROR] You don’t appear to have ElasticSearch installed. Please install and launch it with the following commands:
|
47
47
|
|
data/lib/tire.rb
CHANGED
data/lib/tire/configuration.rb
CHANGED
data/lib/tire/http/client.rb
CHANGED
@@ -4,46 +4,46 @@ module Tire
|
|
4
4
|
|
5
5
|
module Client
|
6
6
|
|
7
|
-
class
|
8
|
-
ConnectionExceptions = [::
|
7
|
+
class LoadBalanceClient
|
8
|
+
ConnectionExceptions = [::LoadBalanceClient::ServerBrokeConnection, ::LoadBalanceClient::RequestTimeout]
|
9
9
|
|
10
10
|
def self.get(url, data=nil)
|
11
|
-
perform ::
|
11
|
+
perform ::LoadBalanceClient::Request.new(:method => :get, :url => url, :payload => data).execute
|
12
12
|
rescue *ConnectionExceptions
|
13
13
|
raise
|
14
|
-
rescue ::
|
14
|
+
rescue ::LoadBalanceClient::Exception => e
|
15
15
|
Response.new e.http_body, e.http_code
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.post(url, data)
|
19
|
-
perform ::
|
19
|
+
perform ::LoadBalanceClient.post(url, data)
|
20
20
|
rescue *ConnectionExceptions
|
21
21
|
raise
|
22
|
-
rescue ::
|
22
|
+
rescue ::LoadBalanceClient::Exception => e
|
23
23
|
Response.new e.http_body, e.http_code
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.put(url, data)
|
27
|
-
perform ::
|
27
|
+
perform ::LoadBalanceClient.put(url, data)
|
28
28
|
rescue *ConnectionExceptions
|
29
29
|
raise
|
30
|
-
rescue ::
|
30
|
+
rescue ::LoadBalanceClient::Exception => e
|
31
31
|
Response.new e.http_body, e.http_code
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.delete(url)
|
35
|
-
perform ::
|
35
|
+
perform ::LoadBalanceClient.delete(url)
|
36
36
|
rescue *ConnectionExceptions
|
37
37
|
raise
|
38
|
-
rescue ::
|
38
|
+
rescue ::LoadBalanceClient::Exception => e
|
39
39
|
Response.new e.http_body, e.http_code
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.head(url)
|
43
|
-
perform ::
|
43
|
+
perform ::LoadBalanceClient.head(url)
|
44
44
|
rescue *ConnectionExceptions
|
45
45
|
raise
|
46
|
-
rescue ::
|
46
|
+
rescue ::LoadBalanceClient::Exception => e
|
47
47
|
Response.new e.http_body, e.http_code
|
48
48
|
end
|
49
49
|
|
data/lib/tire/search.rb
CHANGED
@@ -168,7 +168,7 @@ module Tire
|
|
168
168
|
code = @response.code rescue nil
|
169
169
|
|
170
170
|
if Configuration.logger.level.to_s == 'debug'
|
171
|
-
# FIXME: Depends on
|
171
|
+
# FIXME: Depends on LoadBalanceClient implementation
|
172
172
|
body = if @json
|
173
173
|
defined?(Yajl) ? Yajl::Encoder.encode(@json, :pretty => true) : MultiJson.encode(@json)
|
174
174
|
else
|
data/test/test_helper.rb
CHANGED
@@ -58,20 +58,20 @@ module Test::Integration
|
|
58
58
|
begin; Object.send(:remove_const, :Rails); rescue; end
|
59
59
|
|
60
60
|
begin
|
61
|
-
::
|
61
|
+
::LoadBalanceClient.get URL
|
62
62
|
rescue Errno::ECONNREFUSED
|
63
63
|
abort "\n\n#{'-'*87}\n[ABORTED] You have to run ElasticSearch on #{URL} for integration tests\n#{'-'*87}\n\n"
|
64
64
|
end
|
65
65
|
|
66
|
-
::
|
67
|
-
::
|
66
|
+
::LoadBalanceClient.delete "#{URL}/articles-test" rescue nil
|
67
|
+
::LoadBalanceClient.post "#{URL}/articles-test", ''
|
68
68
|
fixtures_path.join('articles').entries.each do |f|
|
69
69
|
filename = f.to_s
|
70
70
|
next if filename =~ /^\./
|
71
|
-
::
|
71
|
+
::LoadBalanceClient.put "#{URL}/articles-test/article/#{File.basename(filename, '.*')}",
|
72
72
|
fixtures_path.join('articles').join(f).read
|
73
73
|
end
|
74
|
-
::
|
74
|
+
::LoadBalanceClient.post "#{URL}/articles-test/_refresh", ''
|
75
75
|
|
76
76
|
Dir[File.dirname(__FILE__) + '/models/**/*.rb'].each { |m| load m }
|
77
77
|
end
|
@@ -87,7 +87,7 @@ module Test::Integration
|
|
87
87
|
supermodel_articles
|
88
88
|
dynamic_index
|
89
89
|
model_with_nested_documents ].each do |index|
|
90
|
-
::
|
90
|
+
::LoadBalanceClient.delete "#{URL}/#{index}" rescue nil
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -39,7 +39,7 @@ module Tire
|
|
39
39
|
end
|
40
40
|
|
41
41
|
should "return default client" do
|
42
|
-
assert_equal HTTP::Client::
|
42
|
+
assert_equal HTTP::Client::LoadBalanceClient, Configuration.client
|
43
43
|
end
|
44
44
|
|
45
45
|
should "return nil as logger by default" do
|
@@ -65,7 +65,7 @@ module Tire
|
|
65
65
|
assert_equal 'http://example.com', Configuration.url
|
66
66
|
Configuration.reset
|
67
67
|
assert_equal 'http://localhost:9200', Configuration.url
|
68
|
-
assert_equal HTTP::Client::
|
68
|
+
assert_equal HTTP::Client::LoadBalanceClient, Configuration.client
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -6,41 +6,41 @@ module Tire
|
|
6
6
|
|
7
7
|
class ClientTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
context "
|
9
|
+
context "LoadBalanceClient" do
|
10
10
|
|
11
11
|
should "be default" do
|
12
|
-
assert_equal Client::
|
12
|
+
assert_equal Client::LoadBalanceClient, Configuration.client
|
13
13
|
end
|
14
14
|
|
15
15
|
should "respond to HTTP methods" do
|
16
|
-
assert_respond_to Client::
|
17
|
-
assert_respond_to Client::
|
18
|
-
assert_respond_to Client::
|
19
|
-
assert_respond_to Client::
|
20
|
-
assert_respond_to Client::
|
16
|
+
assert_respond_to Client::LoadBalanceClient, :get
|
17
|
+
assert_respond_to Client::LoadBalanceClient, :post
|
18
|
+
assert_respond_to Client::LoadBalanceClient, :put
|
19
|
+
assert_respond_to Client::LoadBalanceClient, :delete
|
20
|
+
assert_respond_to Client::LoadBalanceClient, :head
|
21
21
|
end
|
22
22
|
|
23
23
|
should "not rescue generic exceptions" do
|
24
|
-
Client::
|
24
|
+
Client::LoadBalanceClient.expects(:get).raises(RuntimeError, "Something bad happened in YOUR code")
|
25
25
|
|
26
26
|
assert_raise(RuntimeError) do
|
27
|
-
Client::
|
27
|
+
Client::LoadBalanceClient.get 'http://example.com'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
should "not rescue ServerBrokeConnection errors" do
|
32
|
-
Client::
|
32
|
+
Client::LoadBalanceClient.expects(:get).raises(LoadBalanceClient::ServerBrokeConnection)
|
33
33
|
|
34
|
-
assert_raise(
|
35
|
-
Client::
|
34
|
+
assert_raise(LoadBalanceClient::ServerBrokeConnection) do
|
35
|
+
Client::LoadBalanceClient.get 'http://example.com'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
should "not rescue RequestTimeout errors" do
|
40
|
-
Client::
|
40
|
+
Client::LoadBalanceClient.expects(:get).raises(LoadBalanceClient::RequestTimeout)
|
41
41
|
|
42
|
-
assert_raise(
|
43
|
-
Client::
|
42
|
+
assert_raise(LoadBalanceClient::RequestTimeout) do
|
43
|
+
Client::LoadBalanceClient.get 'http://example.com'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -52,7 +52,7 @@ module Tire
|
|
52
52
|
end
|
53
53
|
|
54
54
|
teardown do
|
55
|
-
Configuration.client Client::
|
55
|
+
Configuration.client Client::LoadBalanceClient
|
56
56
|
end
|
57
57
|
|
58
58
|
should "use POST method if request body passed" do
|
data/test/unit/search_test.rb
CHANGED
@@ -172,9 +172,9 @@ module Tire
|
|
172
172
|
end
|
173
173
|
|
174
174
|
should "print debugging information on exception and return false" do
|
175
|
-
::
|
175
|
+
::LoadBalanceClient::Request.any_instance.
|
176
176
|
expects(:execute).
|
177
|
-
raises(::
|
177
|
+
raises(::LoadBalanceClient::InternalServerError)
|
178
178
|
STDERR.expects(:puts)
|
179
179
|
|
180
180
|
s = Search::Search.new('index')
|
data/tire.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "tire/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "load_balanced_tire"
|
7
|
-
s.version = 0.
|
7
|
+
s.version = 0.11
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.summary = "Ruby client for ElasticSearch w/ load balancing via load_balance_client"
|
10
10
|
s.homepage = "http://github.com/themattray/tire"
|
@@ -27,7 +27,6 @@ Gem::Specification.new do |s|
|
|
27
27
|
# = Library dependencies
|
28
28
|
#
|
29
29
|
s.add_dependency "rake"
|
30
|
-
#s.add_dependency "rest-client", "~> 1.6"
|
31
30
|
s.add_dependency "load_balance_client"
|
32
31
|
s.add_dependency "multi_json", "~> 1.0"
|
33
32
|
s.add_dependency "activemodel", ">= 3.0"
|
@@ -83,7 +82,7 @@ Gem::Specification.new do |s|
|
|
83
82
|
--------------------------------------------------------------------------------
|
84
83
|
|
85
84
|
#{Tire::CHANGELOG}
|
86
|
-
See the full changelog at <http://github.com/
|
85
|
+
See the full changelog at <http://github.com/themattray/tire/commits/0.1.1>.
|
87
86
|
|
88
87
|
--------------------------------------------------------------------------------
|
89
88
|
CHANGELOG
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: load_balanced_tire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.11'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -449,7 +449,7 @@ post_install_message: ! "=======================================================
|
|
449
449
|
1.8 compatibility\n\n Version 0.4.2\n -------------\n * Fixed incorrect handling
|
450
450
|
of PUT requests in the Curb client\n * Fixed, that blocks passed to `Tire::Index.new`
|
451
451
|
or `Tire.index` losed the scope\n * Added `Tire::Alias`, interface and DSL to manage
|
452
|
-
aliases as resources\n\n See the full changelog at <http://github.com/
|
452
|
+
aliases as resources\n\n See the full changelog at <http://github.com/themattray/tire/commits/0.1.1>.\n\n--------------------------------------------------------------------------------\n"
|
453
453
|
rdoc_options:
|
454
454
|
- --charset=UTF-8
|
455
455
|
require_paths:
|