elasticsearch-transport 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,14 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in elasticsearch-transport.gemspec
4
4
  gemspec
5
5
 
6
+ if File.exists? File.expand_path("../../elasticsearch-api/elasticsearch-api.gemspec", __FILE__)
7
+ gem 'elasticsearch-api', :path => File.expand_path("../../elasticsearch-api", __FILE__), :require => false
8
+ end
9
+
6
10
  if File.exists? File.expand_path("../../elasticsearch-extensions", __FILE__)
7
- gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => true
11
+ gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => false
12
+ end
13
+
14
+ if File.exists? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
15
+ gem 'elasticsearch', :path => File.expand_path("../../elasticsearch", __FILE__), :require => false
8
16
  end
@@ -57,6 +57,8 @@ module Elasticsearch
57
57
  #
58
58
  # @option arguments [Boolean] :reload_on_failure Reload connections after failure (false by default)
59
59
  #
60
+ # @option arguments [Hash] :transport_options Options to be passed to the `Faraday::Connection` constructor
61
+ #
60
62
  # @option arguments [Constant] :transport_class A specific transport class to use, will be initialized by
61
63
  # the client and passed hosts and all arguments
62
64
  #
@@ -177,7 +177,13 @@ module Elasticsearch
177
177
  begin
178
178
  tries += 1
179
179
  connection = get_connection or raise Error.new("Cannot get new connection from pool.")
180
+
181
+ if connection.connection.respond_to?(:params) && connection.connection.params.respond_to?(:to_hash)
182
+ params = connection.connection.params.merge(params.to_hash)
183
+ end
184
+
180
185
  url = connection.full_url(path, params)
186
+
181
187
  response = block.call(connection, url)
182
188
 
183
189
  connection.healthy! if connection.failures > 0
@@ -28,7 +28,12 @@ module Elasticsearch
28
28
 
29
29
  connection.connection.http(method.to_sym)
30
30
 
31
- Response.new connection.connection.response_code, connection.connection.body_str
31
+ headers = {}
32
+ headers['content-type'] = 'application/json' if connection.connection.header_str =~ /\/json/
33
+
34
+ Response.new connection.connection.response_code,
35
+ connection.connection.body_str,
36
+ headers
32
37
  end
33
38
  end
34
39
 
@@ -39,7 +39,7 @@ module Elasticsearch
39
39
 
40
40
  Connections::Connection.new \
41
41
  :host => host,
42
- :connection => ::Faraday::Connection.new( :url => url, &@block )
42
+ :connection => ::Faraday::Connection.new(url, options[:transport_options], &@block )
43
43
  },
44
44
  :selector_class => options[:selector_class],
45
45
  :selector => options[:selector]
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Transport
3
- VERSION = "1.0.0.rc1"
3
+ VERSION = "1.0.0.rc2"
4
4
  end
5
5
  end
@@ -32,6 +32,20 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
32
32
  client.perform_request 'GET', ''
33
33
  end
34
34
 
35
+ should "allow to define connection parameters and pass them" do
36
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
37
+ :hosts => [ { :host => 'localhost', :port => @port } ],
38
+ :options => { :transport_options => {
39
+ :params => { :format => 'yaml' }
40
+ }
41
+ }
42
+
43
+ client = Elasticsearch::Transport::Client.new transport: transport
44
+ response = client.perform_request 'GET', ''
45
+
46
+ assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
47
+ end
48
+
35
49
  should "use the Curb client" do
36
50
  require 'curb'
37
51
  require 'elasticsearch/transport/transport/http/curb'
@@ -44,6 +58,23 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
44
58
  client = Elasticsearch::Transport::Client.new transport: transport
45
59
  client.perform_request 'GET', ''
46
60
  end unless JRUBY
61
+
62
+ should "deserialize JSON responses in the Curb client" do
63
+ require 'curb'
64
+ require 'elasticsearch/transport/transport/http/curb'
65
+
66
+ transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
67
+ :hosts => [ { :host => 'localhost', :port => @port } ] do |curl|
68
+ curl.verbose = true
69
+ end
70
+
71
+ client = Elasticsearch::Transport::Client.new transport: transport
72
+ response = client.perform_request 'GET', ''
73
+
74
+ assert_respond_to(response.body, :to_hash)
75
+ assert_equal 200, response.body['status']
76
+ assert_equal 'application/json', response.headers['content-type']
77
+ end unless JRUBY
47
78
  end
48
79
 
49
80
  end
@@ -78,6 +78,16 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
78
78
  end
79
79
 
80
80
  context "with a single-node cluster and the Typhoeus client" do
81
+ # Fix for incompatibility of the Typhoeus adapter
82
+ # Related commit: elasticsearch/elasticsearch-ruby@adc4810227fad03ae5cabfbb2a0905fb75bfb331
83
+ # Related: lostisland/faraday/pull/323, lostisland/faraday/pull/335
84
+ #
85
+ class ::Faraday::Adapter::Typhoeus
86
+ def configure_ssl(req, env)
87
+ # noop
88
+ end
89
+ end
90
+
81
91
  setup do
82
92
  require 'typhoeus'
83
93
  require 'typhoeus/adapters/faraday'
@@ -270,10 +270,14 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
270
270
  context "logging" do
271
271
  setup do
272
272
  @transport = DummyTransportPerformer.new :options => { :logger => Logger.new('/dev/null') }
273
- @transport.stubs(:get_connection).returns stub :full_url => 'localhost:9200/_search?size=1',
274
- :host => 'localhost',
275
- :failures => 0,
276
- :healthy! => true
273
+
274
+ fake_connection = stub :full_url => 'localhost:9200/_search?size=1',
275
+ :host => 'localhost',
276
+ :connection => stub_everything,
277
+ :failures => 0,
278
+ :healthy! => true
279
+
280
+ @transport.stubs(:get_connection).returns(fake_connection)
277
281
  @transport.serializer.stubs(:load).returns 'foo' => 'bar'
278
282
  @transport.serializer.stubs(:dump).returns '{"foo":"bar"}'
279
283
  end
@@ -314,10 +318,14 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
314
318
  context "tracing" do
315
319
  setup do
316
320
  @transport = DummyTransportPerformer.new :options => { :tracer => Logger.new('/dev/null') }
317
- @transport.stubs(:get_connection).returns stub :full_url => 'localhost:9200/_search?size=1',
318
- :host => 'localhost',
319
- :failures => 0,
320
- :healthy! => true
321
+
322
+ fake_connection = stub :full_url => 'localhost:9200/_search?size=1',
323
+ :host => 'localhost',
324
+ :connection => stub_everything,
325
+ :failures => 0,
326
+ :healthy! => true
327
+
328
+ @transport.stubs(:get_connection).returns(fake_connection)
321
329
  @transport.serializer.stubs(:load).returns 'foo' => 'bar'
322
330
  @transport.serializer.stubs(:dump).returns <<-JSON.gsub(/^ /, '')
323
331
  {
@@ -1,10 +1,10 @@
1
+ require 'test_helper'
2
+
1
3
  if JRUBY
2
4
  puts "'#{File.basename(__FILE__)}' not supported on JRuby #{RUBY_VERSION}"
3
5
  exit(0)
4
6
  end
5
7
 
6
-
7
- require 'test_helper'
8
8
  require 'elasticsearch/transport/transport/http/curb'
9
9
  require 'curb'
10
10
 
@@ -53,6 +53,16 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
53
53
  @transport.perform_request 'POST', '/', {}, '{"foo":"bar"}'
54
54
  end
55
55
 
56
+ should "set application/json header" do
57
+ @transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
58
+ @transport.connections.first.connection.expects(:body_str).returns('{"foo":"bar"}')
59
+ @transport.connections.first.connection.expects(:header_str).returns('HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Length: 311\r\n\r\n')
60
+
61
+ response = @transport.perform_request 'GET', '/'
62
+
63
+ assert_equal 'application/json', response.headers['content-type']
64
+ end
65
+
56
66
  should "handle HTTP methods" do
57
67
  @transport.connections.first.connection.expects(:http).with(:HEAD).returns(stub_everything)
58
68
  @transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
@@ -58,15 +58,71 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
58
58
  @transport.connections.selector
59
59
  end
60
60
 
61
- should "allow to set options for Faraday" do
61
+ should "pass a configuration block to the Faraday constructor" do
62
62
  config_block = lambda do |f|
63
63
  f.response :logger
64
+ f.path_prefix = '/moo'
64
65
  end
65
66
 
66
67
  transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ], &config_block
67
68
 
68
- handlers = transport.connections.first.connection.instance_variable_get(:@builder).instance_variable_get(:@handlers)
69
- assert handlers.include?(::Faraday::Response::Logger), "#{handlers.inspect} does not include <::Faraday::Adapter::Typhoeus>"
69
+ handlers = transport.connections.first.connection.builder.handlers
70
+
71
+ assert_equal 1, handlers.size
72
+ assert handlers.include?(::Faraday::Response::Logger), "#{handlers.inspect} does not include <::Faraday::Adapter::Logger>"
73
+
74
+ assert_equal '/moo', transport.connections.first.connection.path_prefix
75
+ assert_equal 'http://foobar:1234/moo', transport.connections.first.connection.url_prefix.to_s
76
+ end
77
+
78
+ should "pass transport_options to the Faraday constructor" do
79
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
80
+ :options => { :transport_options => {
81
+ :request => { :open_timeout => 1 },
82
+ :headers => { :foo_bar => 'bar' },
83
+ :ssl => { :verify => false }
84
+ }
85
+ }
86
+
87
+ assert_equal 1, transport.connections.first.connection.options.open_timeout
88
+ assert_equal 'bar', transport.connections.first.connection.headers['Foo-Bar']
89
+ assert_equal false, transport.connections.first.connection.ssl.verify?
90
+ end
91
+
92
+ should "merge in parameters defined in the Faraday connection parameters" do
93
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
94
+ :options => { :transport_options => {
95
+ :params => { :format => 'yaml' }
96
+ }
97
+ }
98
+ # transport.logger = Logger.new(STDERR)
99
+
100
+ transport.connections.first.connection.expects(:run_request).
101
+ with do |method, url, params, body|
102
+ assert_match /\?format=yaml/, url
103
+ true
104
+ end.
105
+ returns(stub_everything)
106
+
107
+ transport.perform_request 'GET', ''
108
+ end
109
+
110
+ should "not overwrite request parameters with the Faraday connection parameters" do
111
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
112
+ :options => { :transport_options => {
113
+ :params => { :format => 'yaml' }
114
+ }
115
+ }
116
+ # transport.logger = Logger.new(STDERR)
117
+
118
+ transport.connections.first.connection.expects(:run_request).
119
+ with do |method, url, params, body|
120
+ assert_match /\?format=json/, url
121
+ true
122
+ end.
123
+ returns(stub_everything)
124
+
125
+ transport.perform_request 'GET', '', { :format => 'json' }
70
126
  end
71
127
 
72
128
  should "set the credentials if passed" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-09 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json