riak-client 0.9.8 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.gitignore +32 -0
  2. data/Gemfile +17 -11
  3. data/Guardfile +14 -0
  4. data/Rakefile +18 -44
  5. data/erl_src/riak_kv_test_backend.beam +0 -0
  6. data/erl_src/riak_kv_test_backend.erl +461 -128
  7. data/erl_src/riak_search_test_backend.beam +0 -0
  8. data/erl_src/riak_search_test_backend.erl +175 -0
  9. data/lib/active_support/cache/riak_store.rb +0 -13
  10. data/lib/riak.rb +11 -16
  11. data/lib/riak/bucket.rb +59 -41
  12. data/lib/riak/cache_store.rb +1 -14
  13. data/lib/riak/client.rb +145 -73
  14. data/lib/riak/client/beefcake/messages.rb +36 -31
  15. data/lib/riak/client/beefcake/object_methods.rb +27 -19
  16. data/lib/riak/client/beefcake_protobuffs_backend.rb +27 -33
  17. data/lib/riak/client/excon_backend.rb +0 -13
  18. data/lib/riak/client/http_backend.rb +95 -60
  19. data/lib/riak/client/http_backend/configuration.rb +144 -19
  20. data/lib/riak/client/http_backend/key_streamer.rb +1 -14
  21. data/lib/riak/client/http_backend/object_methods.rb +16 -16
  22. data/lib/riak/client/http_backend/request_headers.rb +0 -13
  23. data/lib/riak/client/http_backend/transport_methods.rb +26 -56
  24. data/lib/riak/client/net_http_backend.rb +11 -13
  25. data/lib/riak/client/protobuffs_backend.rb +21 -19
  26. data/lib/riak/client/pump.rb +1 -15
  27. data/lib/riak/client/search.rb +85 -0
  28. data/lib/riak/cluster.rb +151 -0
  29. data/lib/riak/core_ext.rb +1 -0
  30. data/lib/riak/core_ext/deep_dup.rb +13 -0
  31. data/lib/riak/core_ext/json.rb +15 -0
  32. data/lib/riak/core_ext/stringify_keys.rb +1 -1
  33. data/lib/riak/core_ext/symbolize_keys.rb +1 -1
  34. data/lib/riak/encoding.rb +6 -0
  35. data/lib/riak/failed_request.rb +2 -15
  36. data/lib/riak/i18n.rb +0 -13
  37. data/lib/riak/json.rb +19 -8
  38. data/lib/riak/link.rb +18 -20
  39. data/lib/riak/locale/en.yml +13 -16
  40. data/lib/riak/map_reduce.rb +40 -20
  41. data/lib/riak/map_reduce/filter_builder.rb +14 -18
  42. data/lib/riak/map_reduce/phase.rb +0 -13
  43. data/lib/riak/map_reduce_error.rb +0 -13
  44. data/lib/riak/node.rb +38 -0
  45. data/lib/riak/node/configuration.rb +286 -0
  46. data/lib/riak/node/console.rb +139 -0
  47. data/lib/riak/node/control.rb +207 -0
  48. data/lib/riak/node/defaults.rb +70 -0
  49. data/lib/riak/node/generation.rb +99 -0
  50. data/lib/riak/node/log.rb +34 -0
  51. data/lib/riak/node/version.rb +37 -0
  52. data/lib/riak/robject.rb +45 -41
  53. data/lib/riak/search.rb +2 -161
  54. data/lib/riak/serializers.rb +74 -0
  55. data/lib/riak/stamp.rb +77 -0
  56. data/lib/riak/test_server.rb +56 -220
  57. data/lib/riak/util/escape.rb +58 -17
  58. data/lib/riak/util/headers.rb +2 -15
  59. data/lib/riak/util/multipart.rb +0 -13
  60. data/lib/riak/util/multipart/stream_parser.rb +0 -13
  61. data/lib/riak/util/tcp_socket_extensions.rb +1 -14
  62. data/lib/riak/util/translation.rb +0 -13
  63. data/lib/riak/version.rb +3 -0
  64. data/lib/riak/walk_spec.rb +0 -13
  65. data/riak-client.gemspec +27 -47
  66. data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -0
  67. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -0
  68. data/spec/integration/riak/cache_store_spec.rb +2 -40
  69. data/spec/integration/riak/cluster_spec.rb +88 -0
  70. data/spec/integration/riak/http_backends_spec.rb +6 -30
  71. data/spec/integration/riak/node_spec.rb +184 -0
  72. data/spec/integration/riak/protobuffs_backends_spec.rb +2 -26
  73. data/spec/integration/riak/test_server_spec.rb +31 -167
  74. data/spec/riak/beefcake_protobuffs_backend_spec.rb +5 -4
  75. data/spec/riak/bucket_spec.rb +26 -36
  76. data/spec/riak/client_spec.rb +44 -38
  77. data/spec/riak/escape_spec.rb +56 -30
  78. data/spec/riak/excon_backend_spec.rb +4 -17
  79. data/spec/riak/headers_spec.rb +1 -14
  80. data/spec/riak/http_backend/configuration_spec.rb +211 -34
  81. data/spec/riak/http_backend/object_methods_spec.rb +52 -18
  82. data/spec/riak/http_backend/transport_methods_spec.rb +5 -38
  83. data/spec/riak/http_backend_spec.rb +84 -78
  84. data/spec/riak/link_spec.rb +19 -18
  85. data/spec/riak/map_reduce/filter_builder_spec.rb +1 -14
  86. data/spec/riak/map_reduce/phase_spec.rb +1 -14
  87. data/spec/riak/map_reduce_spec.rb +141 -43
  88. data/spec/riak/multipart_spec.rb +1 -14
  89. data/spec/riak/net_http_backend_spec.rb +2 -15
  90. data/spec/riak/robject_spec.rb +129 -97
  91. data/spec/riak/search_spec.rb +45 -62
  92. data/spec/riak/serializers_spec.rb +93 -0
  93. data/spec/riak/stamp_spec.rb +54 -0
  94. data/spec/riak/stream_parser_spec.rb +3 -16
  95. data/spec/riak/walk_spec_spec.rb +1 -14
  96. data/spec/spec_helper.rb +22 -27
  97. data/spec/support/http_backend_implementation_examples.rb +49 -79
  98. data/spec/support/integration_setup.rb +10 -0
  99. data/spec/support/mock_server.rb +0 -14
  100. data/spec/support/mocks.rb +0 -13
  101. data/spec/support/test_server.rb +30 -0
  102. data/spec/support/test_server.yml.example +14 -2
  103. data/spec/support/unified_backend_examples.rb +36 -27
  104. metadata +100 -31
  105. data/lib/riak/client/curb_backend.rb +0 -89
  106. data/spec/riak/curb_backend_spec.rb +0 -76
@@ -1,16 +1,3 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
1
 
15
2
  require 'riak/failed_request'
16
3
  require 'riak/client/http_backend'
@@ -21,29 +8,159 @@ module Riak
21
8
  class HTTPBackend
22
9
  # Riak 0.14 provides a root URL that enumerates all of the
23
10
  # HTTP endpoints and their paths. This module adds methods to
24
- # auto-discover those endpoints via the root URL.
11
+ # auto-discover those endpoints via the root URL. It also adds
12
+ # methods for generating URL paths for specific resources.
25
13
  module Configuration
14
+ # @return [URI] a URL path to the "ping" resource
15
+ def ping_path
16
+ path(riak_kv_wm_ping)
17
+ end
18
+
19
+ # @return [URI] a URL path to the "stats" resource
20
+ def stats_path
21
+ path(riak_kv_wm_stats)
22
+ end
23
+
24
+ # @return [URI] a URL path to the "mapred" resource
25
+ # @param options [Hash] query parameters, e.g. chunked=true
26
+ def mapred_path(options={})
27
+ path(riak_kv_wm_mapred, options)
28
+ end
29
+
30
+ # @return [URI] a URL path for the "buckets list" resource
31
+ def bucket_list_path(options={})
32
+ if new_scheme?
33
+ path(riak_kv_wm_buckets, options.merge(:buckets => true))
34
+ else
35
+ path(riak_kv_wm_raw, options.merge(:buckets => true))
36
+ end
37
+ end
38
+
39
+ # @return [URI] a URL path for the "bucket properties"
40
+ # resource
41
+ # @param [String] bucket the bucket name
42
+ def bucket_properties_path(bucket, options={})
43
+ if new_scheme?
44
+ path(riak_kv_wm_buckets, escape(bucket), "props", options)
45
+ else
46
+ path(riak_kv_wm_raw, escape(bucket), options.merge(:props => true, :keys => false))
47
+ end
48
+ end
49
+
50
+ # @return [URI] a URL path for the "list keys" resource
51
+ # @param [String] bucket the bucket whose keys to list
52
+ # @param [Hash] options query parameters, e.g. keys=stream
53
+ def key_list_path(bucket, options={:keys => true})
54
+ if new_scheme?
55
+ path(riak_kv_wm_buckets, escape(bucket), "keys", options)
56
+ else
57
+ path(riak_kv_wm_raw, escape(bucket), options.merge(:props => false))
58
+ end
59
+ end
60
+
61
+ # @return [URI] a URL path for the "object" resource
62
+ # @param [String] bucket the bucket of the object
63
+ # @param [String,nil] key the key of the object, or nil for a
64
+ # server-assigned key when using POST
65
+ def object_path(bucket, key, options={})
66
+ key = escape(key) if key
67
+ if new_scheme?
68
+ path([riak_kv_wm_buckets, escape(bucket), "keys", key, options].compact)
69
+ else
70
+ path([riak_kv_wm_raw, escape(bucket), key, options].compact)
71
+ end
72
+ end
73
+
74
+ # @return [URI] a URL path for the "link-walking" resource
75
+ # @param [String] bucket the bucket of the origin object
76
+ # @param [String] key the key of the origin object
77
+ # @param [Array<WalkSpec>] specs a list of walk specifications
78
+ # to traverse
79
+ def link_walk_path(bucket, key, specs)
80
+ specs = specs.map {|s| s.to_s }
81
+ if new_scheme?
82
+ path(riak_kv_wm_buckets, escape(bucket), "keys", escape(key), *specs)
83
+ else
84
+ path(riak_kv_wm_link_walker, escape(bucket), escape(key), *specs)
85
+ end
86
+ end
87
+
88
+ # @return [URI] a URL path for the "index range query"
89
+ # resource
90
+ # @param [String] bucket the bucket whose index to query
91
+ # @param [String] index the name of the index to query
92
+ # @param [String,Integer] start the start of the range
93
+ # @param [String,Integer] finish the end of the range
94
+ def index_range_path(bucket, index, start, finish, options={})
95
+ raise t('indexes_unsupported') unless new_scheme?
96
+ path(riak_kv_wm_buckets, escape(bucket), "index", escape(index), escape(start.to_s), escape(finish.to_s), options)
97
+ end
98
+
99
+ # @return [URI] a URL path for the "index range query"
100
+ # resource
101
+ # @param [String] bucket the bucket whose index to query
102
+ # @param [String] index the name of the index to query
103
+ # @param [String,Integer] start the start of the range
104
+ # @param [String,Integer] finish the end of the range
105
+ def index_eq_path(bucket, index, value, options={})
106
+ raise t('indexes_unsupported') unless new_scheme?
107
+ path(riak_kv_wm_buckets, escape(bucket), "index", escape(index), escape(value.to_s), options)
108
+ end
109
+
110
+ # @return [URI] a URL path for a Solr query resource
111
+ # @param [String] index the index to query
112
+ # @param [String] query the Lucene-style query string
113
+ # @param [Hash] options additional query options
114
+ def solr_select_path(index, query, options={})
115
+ raise t('search_unsupported') unless riak_solr_searcher_wm
116
+ options = {"q" => query, "wt" => "json"}.merge(options)
117
+ if index
118
+ path(riak_solr_searcher_wm, index, 'select', options)
119
+ else
120
+ path(riak_solr_searcher_wm, 'select', options)
121
+ end
122
+ end
123
+
124
+ # @return [URI] a URL path for a Solr update resource
125
+ # @param [String] index the index to update
126
+ def solr_update_path(index)
127
+ raise t('search_unsupported') unless riak_solr_indexer_wm
128
+ if index
129
+ path(riak_solr_indexer_wm, index, 'update')
130
+ else
131
+ path(riak_solr_indexer_wm, 'update')
132
+ end
133
+ end
134
+
26
135
  private
27
136
  def server_config
28
137
  @server_config ||= {}.tap do |hash|
29
138
  begin
30
- response = get(200, "/", {}, {})
31
- Link.parse(response[:headers]['link'].first).each {|l| hash[l.tag.intern] = l.url }
139
+ response = get(200, path("/"))
140
+ Link.parse(response[:headers]['link'].first).each {|l| hash[l.tag.intern] ||= l.url }
32
141
  rescue Riak::FailedRequest
33
142
  end
34
143
  end
35
144
  end
36
145
 
146
+ def new_scheme?
147
+ !riak_kv_wm_buckets.nil?
148
+ end
149
+
150
+ def riak_kv_wm_buckets
151
+ server_config[:riak_kv_wm_buckets]
152
+ end
153
+
37
154
  def riak_kv_wm_raw
38
- server_config[:riak_kv_wm_raw] || client.prefix
155
+ server_config[:riak_kv_wm_raw] || client.http_paths[:prefix]
39
156
  end
40
157
 
41
158
  def riak_kv_wm_link_walker
42
- server_config[:riak_kv_wm_link_walker] || client.prefix
159
+ server_config[:riak_kv_wm_link_walker] || client.http_paths[:prefix]
43
160
  end
44
161
 
45
162
  def riak_kv_wm_mapred
46
- server_config[:riak_kv_wm_mapred] || client.mapred
163
+ server_config[:riak_kv_wm_mapred] || client.http_paths[:mapred]
47
164
  end
48
165
 
49
166
  def riak_kv_wm_ping
@@ -53,6 +170,14 @@ module Riak
53
170
  def riak_kv_wm_stats
54
171
  server_config[:riak_kv_wm_stats] || "/stats"
55
172
  end
173
+
174
+ def riak_solr_searcher_wm
175
+ server_config[:riak_solr_searcher_wm]
176
+ end
177
+
178
+ def riak_solr_indexer_wm
179
+ server_config[:riak_solr_indexer_wm]
180
+ end
56
181
  end
57
182
  end
58
183
  end
@@ -1,16 +1,3 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License
14
1
  require 'riak/util/escape'
15
2
  require 'riak/json'
16
3
 
@@ -46,7 +33,7 @@ module Riak
46
33
  def stream(str)
47
34
  obj = JSON.parse(str) rescue nil
48
35
  if obj && obj['keys']
49
- @block.call obj['keys'].map(&method(:unescape))
36
+ @block.call obj['keys'].map(&method(:maybe_unescape))
50
37
  end
51
38
  end
52
39
  end
@@ -1,16 +1,3 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
1
  require 'uri'
15
2
  require 'set'
16
3
  require 'time'
@@ -46,13 +33,18 @@ module Riak
46
33
  hash["If-None-Match"] = "*"
47
34
  end
48
35
  unless robject.links.blank?
49
- hash["Link"] = robject.links.reject {|l| l.rel == "up" }.map(&:to_s).join(", ")
36
+ hash["Link"] = robject.links.reject {|l| l.rel == "up" }.map {|l| l.to_s(new_scheme?) }.join(", ")
50
37
  end
51
38
  unless robject.meta.blank?
52
39
  robject.meta.each do |k,v|
53
40
  hash["X-Riak-Meta-#{k}"] = v.to_s
54
41
  end
55
42
  end
43
+ unless robject.indexes.blank?
44
+ robject.indexes.each do |k,v|
45
+ hash["X-Riak-Index-#{k}"] = v.to_a.sort.map {|i| i.to_s }.join(", ")
46
+ end
47
+ end
56
48
  end
57
49
  end
58
50
 
@@ -66,15 +58,23 @@ module Riak
66
58
  extract_header(robject, response, "etag", :etag)
67
59
  extract_header(robject, response, "last-modified", :last_modified) {|v| Time.httpdate(v) }
68
60
  robject.meta = response[:headers].inject({}) do |h,(k,v)|
69
- if k =~ /x-riak-meta-(.*)/
61
+ if k =~ /x-riak-meta-(.*)/i
70
62
  h[$1] = v
71
63
  end
72
64
  h
73
65
  end
66
+ robject.indexes = response[:headers].inject(Hash.new {|h,k| h[k] = Set.new }) do |h,(k,v)|
67
+ if k =~ /x-riak-index-((?:.*)_(?:int|bin))$/i
68
+ key = $1
69
+ h[key].merge Array(v).map {|vals| vals.split(/,\s*/).map {|i| key =~ /int$/ ? i.to_i : i } }.flatten
70
+ end
71
+ h
72
+ end
74
73
  robject.conflict = (response[:code] && response[:code].to_i == 300 && robject.content_type =~ /multipart\/mixed/)
75
74
  robject.siblings = robject.conflict? ? extract_siblings(robject, response[:body]) : nil
76
75
  robject.raw_data = response[:body] if response[:body].present? && !robject.conflict?
77
- robject
76
+
77
+ robject.conflict? ? robject.attempt_conflict_resolution : robject
78
78
  end
79
79
 
80
80
  private
@@ -1,16 +1,3 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
1
 
15
2
  require 'riak/util/headers'
16
3
 
@@ -1,16 +1,3 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
1
 
15
2
  require 'base64'
16
3
  require 'uri'
@@ -33,10 +20,9 @@ module Riak
33
20
  # @param [Hash] headers custom headers to send with the request
34
21
  # @return [Hash] response data, containing only the :headers and :code keys
35
22
  # @raise [FailedRequest] if the response code doesn't match the expected response
36
- def head(expect, *resource)
37
- headers = default_headers.merge(resource.extract_options!)
38
- verify_path!(resource)
39
- perform(:head, path(*resource), headers, expect)
23
+ def head(expect, resource, headers={})
24
+ headers = default_headers.merge(headers)
25
+ perform(:head, resource, headers, expect)
40
26
  end
41
27
 
42
28
  # Performs a GET request to the specified resource on the Riak server.
@@ -53,10 +39,9 @@ module Riak
53
39
  # @return [Hash] response data, containing only the :headers and :code keys
54
40
  # @return [Hash] response data, containing :headers, :body, and :code keys
55
41
  # @raise [FailedRequest] if the response code doesn't match the expected response
56
- def get(expect, *resource, &block)
57
- headers = default_headers.merge(resource.extract_options!)
58
- verify_path!(resource)
59
- perform(:get, path(*resource), headers, expect, &block)
42
+ def get(expect, resource, headers={}, &block)
43
+ headers = default_headers.merge(headers)
44
+ perform(:get, resource, headers, expect, &block)
60
45
  end
61
46
 
62
47
  # Performs a PUT request to the specified resource on the Riak server.
@@ -74,10 +59,10 @@ module Riak
74
59
  # @return [Hash] response data, containing only the :headers and :code keys
75
60
  # @return [Hash] response data, containing :headers, :code, and :body keys
76
61
  # @raise [FailedRequest] if the response code doesn't match the expected response
77
- def put(expect, *resource, &block)
78
- headers = default_headers.merge(resource.extract_options!)
79
- uri, data = verify_path_and_body!(resource)
80
- perform(:put, path(*uri), headers, expect, data, &block)
62
+ def put(expect, resource, body, headers={}, &block)
63
+ headers = default_headers.merge(headers)
64
+ verify_body!(body)
65
+ perform(:put, resource, headers, expect, body, &block)
81
66
  end
82
67
 
83
68
  # Performs a POST request to the specified resource on the Riak server.
@@ -95,10 +80,10 @@ module Riak
95
80
  # @return [Hash] response data, containing only the :headers and :code keys
96
81
  # @return [Hash] response data, containing :headers, :code and :body keys
97
82
  # @raise [FailedRequest] if the response code doesn't match the expected response
98
- def post(expect, *resource, &block)
99
- headers = default_headers.merge(resource.extract_options!)
100
- uri, data = verify_path_and_body!(resource)
101
- perform(:post, path(*uri), headers, expect, data, &block)
83
+ def post(expect, resource, body, headers={}, &block)
84
+ headers = default_headers.merge(headers)
85
+ verify_body!(body)
86
+ perform(:post, resource, headers, expect, body, &block)
102
87
  end
103
88
 
104
89
  # Performs a DELETE request to the specified resource on the Riak server.
@@ -115,10 +100,9 @@ module Riak
115
100
  # @return [Hash] response data, containing only the :headers and :code keys
116
101
  # @return [Hash] response data, containing :headers, :code and :body keys
117
102
  # @raise [FailedRequest] if the response code doesn't match the expected response
118
- def delete(expect, *resource, &block)
119
- headers = default_headers.merge(resource.extract_options!)
120
- verify_path!(resource)
121
- perform(:delete, path(*resource), headers, expect, &block)
103
+ def delete(expect, resource, headers={}, &block)
104
+ headers = default_headers.merge(headers)
105
+ perform(:delete, resource, headers, expect, &block)
122
106
  end
123
107
 
124
108
  # Executes requests according to the underlying HTTP client library semantics.
@@ -169,35 +153,13 @@ module Riak
169
153
  # @param [Array<String,Hash>] segments a relative path or sequence of path segments and optional query params Hash that will be joined to the root URI
170
154
  # @return [URI] an absolute URI for the resource
171
155
  def path(*segments)
156
+ segments = segments.flatten
172
157
  query = segments.extract_options!.to_param
173
158
  root_uri.merge(segments.join("/").gsub(/\/+/, "/").sub(/^\//, '')).tap do |uri|
174
159
  uri.query = query if query.present?
175
160
  end
176
161
  end
177
162
 
178
- # Verifies that both a resource path and body are present in the arguments
179
- # @param [Array] args the arguments to verify
180
- # @raise [ArgumentError] if the body or resource is missing, or if the body is not a String
181
- def verify_path_and_body!(args)
182
- body = args.pop
183
- begin
184
- verify_path!(args)
185
- rescue ArgumentError
186
- raise ArgumentError, t("path_and_body_required")
187
- end
188
-
189
- raise ArgumentError, t("request_body_type") unless String === body || body.respond_to?(:read)
190
- [args, body]
191
- end
192
-
193
- # Verifies that the specified resource is valid
194
- # @param [String, Array] resource the resource specification
195
- # @raise [ArgumentError] if the resource path is too short
196
- def verify_path!(resource)
197
- resource = Array(resource).flatten
198
- raise ArgumentError, t("resource_path_short") unless resource.length > 1 || resource.include?(@client.mapred)
199
- end
200
-
201
163
  # Checks the expected response codes against the actual response code. Use internally when
202
164
  # implementing {#perform}.
203
165
  # @param [String, Fixnum, Array<String,Fixnum>] expected the expected response code(s)
@@ -217,6 +179,14 @@ module Riak
217
179
  method != :head && !valid_response?([204,205,304], code) && !has_block
218
180
  end
219
181
 
182
+ # Checks whether the submitted body is valid. That is, it must
183
+ # be a String or respond to the 'read' method.
184
+ # @param [String, #read] body the body
185
+ # @raise [ArgumentError] if the body is of invalid type
186
+ def verify_body!(body)
187
+ raise ArgumentError, t('request_body_type') unless String === body || body.respond_to?(:read)
188
+ end
189
+
220
190
  private
221
191
  def response_headers
222
192
  Thread.current[:response_headers] ||= Riak::Util::Headers.new
@@ -1,16 +1,3 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
1
 
15
2
  require 'riak/client/http_backend'
16
3
  require 'riak/failed_request'
@@ -30,9 +17,20 @@ module Riak
30
17
  end
31
18
  end
32
19
 
20
+ # Sets the read_timeout applied to Net::HTTP connections
21
+ # Increase this if you have very long request times.
22
+ def self.read_timeout=(timeout)
23
+ @read_timeout = timeout
24
+ end
25
+
26
+ def self.read_timeout
27
+ @read_timeout ||= 4096
28
+ end
29
+
33
30
  private
34
31
  def perform(method, uri, headers, expect, data=nil) #:nodoc:
35
32
  http = Net::HTTP.new(uri.host, uri.port)
33
+ http.read_timeout = self.class.read_timeout
36
34
  configure_ssl(http) if @client.ssl_enabled?
37
35
 
38
36
  request = Net::HTTP.const_get(method.to_s.capitalize).new(uri.request_uri, headers)