protobuf 3.7.2.pre1 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f4f0794925c7662d3fce4dc28345e914f33115b
4
- data.tar.gz: 626caedcbe40e19f74a4d5a8a2a5f22814e03e9d
3
+ metadata.gz: 79198f130aec8d18aae9ef3a3170e16bd67f4ff3
4
+ data.tar.gz: 3c13e8622eea8728f59a9279b37140438ae65d71
5
5
  SHA512:
6
- metadata.gz: 96f02a0023e1229c1201523c5cc857ca4a4e6ab88008addc5283e633d497009b3c48e1374b868740e89cdc9b6a544e0a6130405704f37a02560463614d5cbd74
7
- data.tar.gz: da8b4e50a0420a0182c5f7ae2f09baebd1c4e800beb69e7b915b06201fd447b7893641c4b0bbdd6e0cdbd751853b79e017a415c5390c81b3d52d89829f7d55c3
6
+ metadata.gz: 7931e2b2a6943bd7f0c1e9f2ad5de360e8f127b37a413074a74ae571e70a0ac0331c6a9292918b6ee5836bee3c686a5cc751813a2c851b2824dc244012577d2f
7
+ data.tar.gz: 23a58d4a0b01ea80ad10c4c6857834606341f0f4d8d6df3b3ca3f34a920ba393fe55b5b33feb1e3d05ac53bfb1ef742d254ee79e00613bbee3df2daab4afe824
data/lib/protobuf.rb CHANGED
@@ -37,13 +37,6 @@ module Protobuf
37
37
  #
38
38
  # The name or address of the host to use during client RPC calls.
39
39
  attr_writer :client_host
40
-
41
- # Server Host
42
- #
43
- # Default: first ipv4 address of the system
44
- #
45
- # The name or address of the host to use during client RPC calls.
46
- attr_writer :server_host
47
40
  end
48
41
 
49
42
  def self.client_host
@@ -88,10 +81,6 @@ module Protobuf
88
81
  def self.ignore_unknown_fields=(value)
89
82
  @ignore_unknown_fields = !!value
90
83
  end
91
-
92
- def self.server_host
93
- @server_host ||= Socket.gethostname
94
- end
95
84
  end
96
85
 
97
86
  unless ENV.key?('PB_NO_NETWORKING')
@@ -104,6 +104,7 @@ module Protobuf
104
104
  # Parse out the raw response
105
105
  @stats.response_size = @response_data.size unless @response_data.nil?
106
106
  response_wrapper = ::Protobuf::Socketrpc::Response.decode(@response_data)
107
+ @stats.server = response_wrapper.server if response_wrapper.field?(:server)
107
108
 
108
109
  # Determine success or failure based on parsed data
109
110
  if response_wrapper.field?(:error_reason)
@@ -45,6 +45,7 @@ module Protobuf
45
45
  :response_type,
46
46
  :rpc_method,
47
47
  :rpc_service,
48
+ :server,
48
49
  :service_name,
49
50
  :worker_id
50
51
 
@@ -18,7 +18,7 @@ module Protobuf
18
18
  end
19
19
 
20
20
  def to_response
21
- ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type, :server => ::Protobuf.server_host)
21
+ ::Protobuf::Socketrpc::Response.new(:error => message, :error_reason => error_type)
22
22
  end
23
23
  end
24
24
  end
@@ -72,9 +72,9 @@ module Protobuf
72
72
  #
73
73
  def wrapped_response
74
74
  if response.is_a?(::Protobuf::Rpc::PbError)
75
- ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => ::Protobuf.server_host)
75
+ ::Protobuf::Socketrpc::Response.new(:error => response.message, :error_reason => response.error_type, :server => env.server)
76
76
  else
77
- ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => ::Protobuf.server_host)
77
+ ::Protobuf::Socketrpc::Response.new(:response_proto => response.encode, :server => env.server)
78
78
  end
79
79
  end
80
80
  end
@@ -20,10 +20,10 @@ module Protobuf
20
20
 
21
21
  # Invoke the service method dictated by the proto wrapper request object
22
22
  #
23
- def handle_request(request_data)
23
+ def handle_request(request_data, env_data = {})
24
24
  # Create an env object that holds different parts of the environment and
25
25
  # is available to all of the middlewares
26
- env = Env.new('encoded_request' => request_data, 'log_signature' => log_signature)
26
+ env = Env.new(env_data.merge('encoded_request' => request_data, 'log_signature' => log_signature))
27
27
 
28
28
  # Invoke the middleware stack, the last of which is the service dispatcher
29
29
  env = Rpc.middleware.call(env)
@@ -6,7 +6,8 @@ module Protobuf
6
6
  module Rpc
7
7
  class Stat
8
8
  attr_accessor :mode, :start_time, :end_time, :request_size, :dispatcher
9
- attr_accessor :response_size, :client, :server, :service, :method_name
9
+ attr_accessor :response_size, :client, :service, :method_name
10
+ attr_reader :server
10
11
 
11
12
  MODES = [:SERVER, :CLIENT].freeze
12
13
 
@@ -32,11 +33,12 @@ module Protobuf
32
33
  end
33
34
 
34
35
  def server=(peer)
35
- @server = { :port => peer[0], :ip => peer[1] }
36
- end
37
-
38
- def server
39
- @server ? "#{@server[:ip]}:#{@server[:port]}" : nil
36
+ case peer
37
+ when Array
38
+ @server = "#{peer[1]}:#{peer[0]}"
39
+ when String
40
+ @server = peer
41
+ end
40
42
  end
41
43
 
42
44
  def service
@@ -1,3 +1,3 @@
1
1
  module Protobuf
2
- VERSION = '3.7.2.pre1' # rubocop:disable Style/MutableConstant
2
+ VERSION = '3.7.2' # rubocop:disable Style/MutableConstant
3
3
  end
@@ -20,6 +20,31 @@ RSpec.describe Protobuf::Rpc::Connectors::Base do
20
20
  specify { expect(subject.respond_to?(:verify_callbacks)).to be true }
21
21
  end
22
22
 
23
+ describe "#parse_response" do
24
+ let(:options) { { :response_type => Test::Resource, :port => 55589, :host => '127.3.4.5' } }
25
+ it "updates stats#server from the response" do
26
+ allow(subject).to receive(:close_connection)
27
+ subject.instance_variable_set(:@response_data, ::Protobuf::Socketrpc::Response.new(:server => "serverless").encode)
28
+ subject.initialize_stats
29
+ subject.parse_response
30
+ expect(subject.stats.server).to eq("serverless")
31
+ end
32
+ it "does not override stats#server when response.server is missing" do
33
+ allow(subject).to receive(:close_connection)
34
+ subject.instance_variable_set(:@response_data, ::Protobuf::Socketrpc::Response.new.encode)
35
+ subject.initialize_stats
36
+ subject.parse_response
37
+ expect(subject.stats.server).to eq("127.3.4.5:55589")
38
+ end
39
+ it "does not override stats#server when response.server is nil" do
40
+ allow(subject).to receive(:close_connection)
41
+ subject.instance_variable_set(:@response_data, ::Protobuf::Socketrpc::Response.new(:server => nil).encode)
42
+ subject.initialize_stats
43
+ subject.parse_response
44
+ expect(subject.stats.server).to eq("127.3.4.5:55589")
45
+ end
46
+ end
47
+
23
48
  describe "#any_callbacks?" do
24
49
  [:@complete_cb, :@success_cb, :@failure_cb].each do |cb|
25
50
  it "returns true if #{cb} is provided" do
@@ -10,13 +10,10 @@ RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do
10
10
  end
11
11
  let(:encoded_response) { response_wrapper.encode }
12
12
  let(:response) { Test::Resource.new(:name => 'required') }
13
- let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => server_host) }
14
- let(:server_host) { 'beepboopbop' }
13
+ let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) }
15
14
 
16
15
  subject { described_class.new(app) }
17
16
 
18
- before { ::Protobuf.server_host = server_host }
19
-
20
17
  describe "#call" do
21
18
  it "encodes the response" do
22
19
  stack_env = subject.call(env)
@@ -74,5 +71,21 @@ RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do
74
71
  expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError)
75
72
  end
76
73
  end
74
+
75
+ context "when server exists in the env" do
76
+ let(:env) do
77
+ Protobuf::Rpc::Env.new(
78
+ 'response_type' => Test::Resource,
79
+ 'log_signature' => 'log_signature',
80
+ 'server' => 'itsaserver',
81
+ )
82
+ end
83
+
84
+ it "adds the servers to the response" do
85
+ expected_response = ::Protobuf::Socketrpc::Response.new(:response_proto => response, :server => 'itsaserver').encode
86
+ subject.call(env)
87
+ expect(env.encoded_response).to eq(expected_response)
88
+ end
89
+ end
77
90
  end
78
91
  end
@@ -8,6 +8,20 @@ RSpec.describe ::Protobuf::Rpc::Stat do
8
8
  BarService = ::Struct.new(:method_name) unless defined?(BarService)
9
9
  end
10
10
 
11
+ describe '#server=' do
12
+ it 'understands Array' do
13
+ stat = ::Protobuf::Rpc::Stat.new
14
+ stat.server = [3333, "127.0.0.1"]
15
+ expect(stat.server).to eq("127.0.0.1:3333")
16
+ end
17
+
18
+ it 'understands String' do
19
+ stat = ::Protobuf::Rpc::Stat.new
20
+ stat.server = "thatserverthough"
21
+ expect(stat.server).to eq("thatserverthough")
22
+ end
23
+ end
24
+
11
25
  describe 'server mode' do
12
26
  it 'describes a server response to a client' do
13
27
  ::Timecop.freeze(10.minutes.ago) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.2.pre1
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Neilsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-05-03 00:00:00.000000000 Z
14
+ date: 2017-05-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -458,12 +458,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
458
458
  version: '0'
459
459
  required_rubygems_version: !ruby/object:Gem::Requirement
460
460
  requirements:
461
- - - ">"
461
+ - - ">="
462
462
  - !ruby/object:Gem::Version
463
- version: 1.3.1
463
+ version: '0'
464
464
  requirements: []
465
465
  rubyforge_project:
466
- rubygems_version: 2.5.2
466
+ rubygems_version: 2.6.11
467
467
  signing_key:
468
468
  specification_version: 4
469
469
  summary: Google Protocol Buffers serialization and RPC implementation for Ruby.