google-gax 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/google/gax/api_callable.rb +26 -3
- data/lib/google/gax/version.rb +1 -1
- data/lib/google/longrunning/operations_client.rb +2 -2
- data/spec/google/gax/api_callable_spec.rb +21 -0
- data/spec/google/gax/bundling_spec.rb +8 -8
- data/spec/google/gax/operation_spec.rb +6 -2
- data/spec/google/gax/settings_spec.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 042b5b8369bf9dd8599b15f142f6608fbd7d2eb2
|
4
|
+
data.tar.gz: 1982637288109d3c84bd27d531f0736a8060ce27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0cd057e35054c328494dab34bad86eeb47b90cbe762489be0e3f37598a52bed9097572d9b77a46ccc587fbdf35148a9e4e66e7a671571754a360063e55c5b6f
|
7
|
+
data.tar.gz: 619f3cea1620d36159a1cc51f15899f4b7c608a6cb4a20044c8472ef9ccb84d0cc4c352d4b6b5e69e187907d9dcdc52720f6c4c8ddd6523b8bd48fc5909456b8
|
data/Rakefile
CHANGED
@@ -33,6 +33,8 @@ require 'google/gax/errors'
|
|
33
33
|
require 'google/gax/bundling'
|
34
34
|
|
35
35
|
module Google
|
36
|
+
# rubocop:disable Metrics/ModuleLength
|
37
|
+
|
36
38
|
module Gax
|
37
39
|
# A class to provide the Enumerable interface for page-streaming method.
|
38
40
|
# PagedEnumerable assumes that the API call returns a message for a page
|
@@ -214,10 +216,12 @@ module Google
|
|
214
216
|
#
|
215
217
|
# @param func [Proc] used to make a bare rpc call
|
216
218
|
# @param settings [CallSettings] provides the settings for this call
|
219
|
+
# @param params_extractor [Proc] extracts routing header params from the
|
220
|
+
# request
|
217
221
|
# @return [Proc] a bound method on a request stub used to make an rpc call
|
218
222
|
# @raise [StandardError] if +settings+ has incompatible values,
|
219
223
|
# e.g, if bundling and page_streaming are both configured
|
220
|
-
def create_api_call(func, settings)
|
224
|
+
def create_api_call(func, settings, params_extractor: nil)
|
221
225
|
api_caller = proc do |api_call, request|
|
222
226
|
api_call.call(request)
|
223
227
|
end
|
@@ -237,6 +241,10 @@ module Google
|
|
237
241
|
|
238
242
|
proc do |request, options = nil|
|
239
243
|
this_settings = settings.merge(options)
|
244
|
+
if params_extractor
|
245
|
+
params = params_extractor.call(request)
|
246
|
+
this_settings = with_routing_header(this_settings, params)
|
247
|
+
end
|
240
248
|
api_call = if settings.retry_codes?
|
241
249
|
retryable(func, this_settings.retry_options,
|
242
250
|
this_settings.kwargs)
|
@@ -298,6 +306,20 @@ module Google
|
|
298
306
|
enumerable.method(:start)
|
299
307
|
end
|
300
308
|
|
309
|
+
# Create a new CallSettings with the routing metadata from the request
|
310
|
+
# header params merged with the given settings.
|
311
|
+
#
|
312
|
+
# @param settings [CallSettings] the settings for an API call.
|
313
|
+
# @param params [Hash] the request header params.
|
314
|
+
# @return [CallSettings] a new merged settings.
|
315
|
+
def with_routing_header(settings, params)
|
316
|
+
routing_header = params.map { |k, v| "#{k}=#{v}" }.join('&')
|
317
|
+
options = CallOptions.new(
|
318
|
+
kwargs: { 'x-goog-request-params' => routing_header }
|
319
|
+
)
|
320
|
+
settings.merge(options)
|
321
|
+
end
|
322
|
+
|
301
323
|
# Creates a proc equivalent to a_func, but that retries on certain
|
302
324
|
# exceptions.
|
303
325
|
#
|
@@ -357,8 +379,9 @@ module Google
|
|
357
379
|
end
|
358
380
|
|
359
381
|
module_function :create_api_call, :bundleable,
|
360
|
-
:page_streamable, :
|
382
|
+
:page_streamable, :with_routing_header, :retryable,
|
383
|
+
:add_timeout_arg
|
361
384
|
private_class_method :bundleable, :page_streamable,
|
362
|
-
:retryable, :add_timeout_arg
|
385
|
+
:with_routing_header, :retryable, :add_timeout_arg
|
363
386
|
end
|
364
387
|
end
|
data/lib/google/gax/version.rb
CHANGED
@@ -108,8 +108,8 @@ module Google
|
|
108
108
|
# @param timeout [Numeric]
|
109
109
|
# The default timeout, in seconds, for calls made through this client.
|
110
110
|
def initialize \
|
111
|
-
service_path: SERVICE_ADDRESS,
|
112
|
-
port: DEFAULT_SERVICE_PORT,
|
111
|
+
service_path: self.class::SERVICE_ADDRESS,
|
112
|
+
port: self.class::DEFAULT_SERVICE_PORT,
|
113
113
|
channel: nil,
|
114
114
|
chan_creds: nil,
|
115
115
|
updater_proc: nil,
|
@@ -199,6 +199,27 @@ describe Google::Gax do
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
+
describe 'with_routing_header' do
|
203
|
+
it 'merges request header params with the existing settings' do
|
204
|
+
settings = CallSettings.new
|
205
|
+
metadata_arg = nil
|
206
|
+
func = proc do |_, metadata: nil, **_deadline|
|
207
|
+
metadata_arg = metadata
|
208
|
+
42
|
209
|
+
end
|
210
|
+
params_extractor = proc do |request|
|
211
|
+
{ 'name' => request[:name], 'book.read' => request[:book][:read] }
|
212
|
+
end
|
213
|
+
my_callable = Google::Gax.create_api_call(
|
214
|
+
func, settings, params_extractor: params_extractor
|
215
|
+
)
|
216
|
+
expect(my_callable.call(name: 'foo', book: { read: true })).to eq(42)
|
217
|
+
expect(metadata_arg).to eq(
|
218
|
+
'x-goog-request-params' => 'name=foo&book.read=true'
|
219
|
+
)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
202
223
|
describe 'retryable' do
|
203
224
|
RetryOptions = Google::Gax::RetryOptions
|
204
225
|
BackoffSettings = Google::Gax::BackoffSettings
|
@@ -77,7 +77,7 @@ describe Google::Gax do
|
|
77
77
|
it 'composite value with nil' do
|
78
78
|
actual =
|
79
79
|
Google::Gax.compute_bundle_id(
|
80
|
-
simple_builder('dummy_value'), %w
|
80
|
+
simple_builder('dummy_value'), %w[field1 field2]
|
81
81
|
)
|
82
82
|
expect(actual).to eq(['dummy_value', ''])
|
83
83
|
end
|
@@ -86,16 +86,16 @@ describe Google::Gax do
|
|
86
86
|
actual =
|
87
87
|
Google::Gax.compute_bundle_id(
|
88
88
|
simple_builder('dummy_value', other_value: 'other_value'),
|
89
|
-
%w
|
89
|
+
%w[field1 field2]
|
90
90
|
)
|
91
|
-
expect(actual).to eq(%w
|
91
|
+
expect(actual).to eq(%w[dummy_value other_value])
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'simple dotted value' do
|
95
95
|
actual =
|
96
96
|
Google::Gax.compute_bundle_id(
|
97
97
|
outer_builder('dummy_value'),
|
98
|
-
%w
|
98
|
+
%w[inner.field1]
|
99
99
|
)
|
100
100
|
expect(actual).to eq(['dummy_value'])
|
101
101
|
end
|
@@ -104,9 +104,9 @@ describe Google::Gax do
|
|
104
104
|
actual =
|
105
105
|
Google::Gax.compute_bundle_id(
|
106
106
|
outer_builder('dummy_value'),
|
107
|
-
%w
|
107
|
+
%w[inner.field1 inner.field2 field1]
|
108
108
|
)
|
109
|
-
expect(actual).to eq(%w
|
109
|
+
expect(actual).to eq(%w[dummy_value dummy_value dummy_value])
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'should return false for a single missing field value' do
|
@@ -122,7 +122,7 @@ describe Google::Gax do
|
|
122
122
|
expect(
|
123
123
|
Google::Gax.compute_bundle_id(
|
124
124
|
simple_builder('dummy_value'),
|
125
|
-
%w
|
125
|
+
%w[field1 field3]
|
126
126
|
)
|
127
127
|
).to eq(['dummy_value', nil])
|
128
128
|
end
|
@@ -287,7 +287,7 @@ describe Google::Gax do
|
|
287
287
|
it 'should group the api_calls by bundle_id' do
|
288
288
|
an_elt = 'dummy_message'
|
289
289
|
api_call = return_request
|
290
|
-
bundle_ids = %w
|
290
|
+
bundle_ids = %w[id1 id2]
|
291
291
|
threshold = 5
|
292
292
|
options =
|
293
293
|
Google::Gax::BundleOptions.new(element_count_threshold: threshold)
|
@@ -307,7 +307,9 @@ describe Google::Gax::Operation do
|
|
307
307
|
op = create_op(GrpcOp.new(done: false), client: mock_client)
|
308
308
|
time_now = Time.now
|
309
309
|
allow(Time).to receive(:now) { time_now }
|
310
|
-
expect(op).to
|
310
|
+
expect(op).to(
|
311
|
+
receive(:sleep).exactly(3).times { |secs| time_now += secs }
|
312
|
+
)
|
311
313
|
op.wait_until_done!
|
312
314
|
expect(to_call).to eq(0)
|
313
315
|
end
|
@@ -324,7 +326,9 @@ describe Google::Gax::Operation do
|
|
324
326
|
|
325
327
|
time_now = Time.now
|
326
328
|
allow(Time).to receive(:now) { time_now }
|
327
|
-
expect(op).to
|
329
|
+
expect(op).to(
|
330
|
+
receive(:sleep).exactly(3).times { |secs| time_now += secs }
|
331
|
+
)
|
328
332
|
|
329
333
|
op.wait_until_done!
|
330
334
|
expect(to_call).to eq(0)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-gax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google API Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: googleauth
|
@@ -140,14 +140,14 @@ dependencies:
|
|
140
140
|
requirements:
|
141
141
|
- - '='
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version: 0.
|
143
|
+
version: 0.49.0
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
146
|
version_requirements: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
148
|
- - '='
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: 0.
|
150
|
+
version: 0.49.0
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: simplecov
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|